Interactive Brokers

Provides an API integration for Interactive Brokers.

Config

class InteractiveBrokersDataClientConfig ( * , instrument_provider : nautilus_trader.config.common.InstrumentProviderConfig = InstrumentProviderConfig(load_all=False, load_ids=None, filters=None, log_warnings=True) , routing : nautilus_trader.config.live.RoutingConfig = RoutingConfig(default=False, venues=None) , username : Optional [ str ] = None , password : Optional [ str ] = None , trading_mode : Literal [ 'paper' , 'live' ] = 'paper' , account_id : str = '001' , gateway_host : str = '127.0.0.1' , gateway_port : Optional [ int ] = None , client_id : int = 1 , start_gateway : bool = True )

Bases: nautilus_trader.config.live.LiveDataClientConfig

Configuration for InteractiveBrokersDataClient instances.

Parameters
  • username ( str , optional ) – The Interactive Brokers account username. If None then will source the TWS_USERNAME

  • password ( str , optional ) – The Interactive Brokers account password. If None then will source the TWS_PASSWORD

  • trading_mode ( str ) – paper or live

  • account_id ( str , optional ) – The account_id to use for nautilus

  • gateway_host ( str , optional ) – The hostname for the gateway server

  • gateway_port ( int , optional ) – The port for the gateway server

  • client_id ( int , optional ) – The client_id to be passed into connect call

  • start_gateway ( bool , optional ) – Start or not internal tws docker container

classmethod construct ( _fields_set : Optional [ SetStr ] = None , ** values : Any ) Model

Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values

copy ( * , include : Optional [ Union [ AbstractSetIntStr , MappingIntStrAny ] ] = None , exclude : Optional [ Union [ AbstractSetIntStr , MappingIntStrAny ] ] = None , update : Optional [ DictStrAny ] = None , deep : bool = False ) Model

Duplicate a model, optionally choose which fields to include, exclude and change.

Parameters
  • include – fields to include in new model

  • exclude – fields to exclude from new model, as with values this takes precedence over include

  • update – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data

  • deep – set to True to make a deep copy of the model

Returns

new model instance

dict ( * , include : Optional [ Union [ AbstractSetIntStr , MappingIntStrAny ] ] = None , exclude : Optional [ Union [ AbstractSetIntStr , MappingIntStrAny ] ] = None , by_alias : bool = False , skip_defaults : Optional [ bool ] = None , exclude_unset : bool = False , exclude_defaults : bool = False , exclude_none : bool = False ) DictStrAny

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the NautilusConfig class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

json ( * , include : Optional [ Union [ AbstractSetIntStr , MappingIntStrAny ] ] = None , exclude : Optional [ Union [ AbstractSetIntStr , MappingIntStrAny ] ] = None , by_alias : bool = False , skip_defaults : Optional [ bool ] = None , exclude_unset : bool = False , exclude_defaults : bool = False , exclude_none : bool = False , encoder : Optional [ Callable [ [ Any ] , Any ] ] = None , models_as_dict : bool = True , ** dumps_kwargs : Any ) unicode

Generate a JSON representation of the model, include and exclude arguments as per dict() .

encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps() .

classmethod update_forward_refs ( ** localns : Any ) None

Try to update ForwardRefs on fields based on this Model, globalns and localns.

class InteractiveBrokersExecClientConfig ( * , instrument_provider : nautilus_trader.config.common.InstrumentProviderConfig = InstrumentProviderConfig(load_all=False, load_ids=None, filters=None, log_warnings=True) , routing : nautilus_trader.config.live.RoutingConfig = RoutingConfig(default=False, venues=None) , username : Optional [ str ] = None , password : Optional [ str ] = None , trading_mode : Literal [ 'paper' , 'live' ] = 'paper' , account_id : str = '001' , gateway_host : str = '127.0.0.1' , gateway_port : Optional [ int ] = None , client_id : int = 1 , start_gateway : bool = True )

Bases: nautilus_trader.config.live.LiveExecClientConfig

Configuration for InteractiveBrokersExecClient instances.

Parameters
  • username ( str , optional ) – The Interactive Brokers account username. If None then will source the TWS_USERNAME

  • password ( str , optional ) – The Interactive Brokers account password. If None then will source the TWS_PASSWORD

  • trading_mode ( str ) – paper or live

  • account_id ( str , optional ) – The account_id to use for nautilus

  • gateway_host ( str , optional ) – The hostname for the gateway server

  • gateway_port ( int , optional ) –

    The port for the gateway server client_id: int, optional

    The client_id to be passed into connect call

  • start_gateway ( bool , optional ) – Start or not internal tws docker container

classmethod construct ( _fields_set : Optional [ SetStr ] = None , ** values : Any ) Model

Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values

copy ( * , include : Optional [ Union [ AbstractSetIntStr , MappingIntStrAny ] ] = None , exclude : Optional [ Union [ AbstractSetIntStr , MappingIntStrAny ] ] = None , update : Optional [ DictStrAny ] = None , deep : bool = False ) Model

Duplicate a model, optionally choose which fields to include, exclude and change.

Parameters
  • include – fields to include in new model

  • exclude – fields to exclude from new model, as with values this takes precedence over include

  • update – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data

  • deep – set to True to make a deep copy of the model

Returns

new model instance

dict ( * , include : Optional [ Union [ AbstractSetIntStr , MappingIntStrAny ] ] = None , exclude : Optional [ Union [ AbstractSetIntStr , MappingIntStrAny ] ] = None , by_alias : bool = False , skip_defaults : Optional [ bool ] = None , exclude_unset : bool = False , exclude_defaults : bool = False , exclude_none : bool = False ) DictStrAny

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

classmethod fully_qualified_name ( ) str

Return the fully qualified name for the NautilusConfig class.

Returns

str

References

https://www.python.org/dev/peps/pep-3155/

json ( * , include : Optional [ Union [ AbstractSetIntStr , MappingIntStrAny ] ] = None , exclude : Optional [ Union [ AbstractSetIntStr , MappingIntStrAny ] ] = None , by_alias : bool = False , skip_defaults : Optional [ bool ] = None , exclude_unset : bool = False , exclude_defaults : bool = False , exclude_none : bool = False , encoder : Optional [ Callable [ [ Any ] , Any ] ] = None , models_as_dict : bool = True , ** dumps_kwargs : Any ) unicode

Generate a JSON representation of the model, include and exclude arguments as per dict() .

encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps() .

classmethod update_forward_refs ( ** localns : Any ) None

Try to update ForwardRefs on fields based on this Model, globalns and localns.

Data

Execution

Factories

Providers