Binance

Provides an API integration for the Binance Crypto exchange.

Config

class BinanceDataClientConfig ( * , 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) , api_key : Optional [ str ] = None , api_secret : Optional [ str ] = None , account_type : nautilus_trader.adapters.binance.common.enums.BinanceAccountType = BinanceAccountType.SPOT , base_url_http : Optional [ str ] = None , base_url_ws : Optional [ str ] = None , us : bool = False , testnet : bool = False )

Bases: nautilus_trader.config.live.LiveDataClientConfig

Configuration for BinanceDataClient instances.

Parameters
  • api_key ( str , optional ) – The Binance API public key. If None then will source the BINANCE_API_KEY or BINANCE_TESTNET_API_KEY environment variables.

  • api_secret ( str , optional ) – The Binance API public key. If None then will source the BINANCE_API_KEY or BINANCE_TESTNET_API_KEY environment variables.

  • account_type ( BinanceAccountType , default BinanceAccountType.SPOT ) – The account type for the client.

  • base_url_http ( str , optional ) – The HTTP client custom endpoint override.

  • base_url_ws ( str , optional ) – The WebSocket client custom endpoint override.

  • us ( bool , default False ) – If client is connecting to Binance US.

  • testnet ( bool , default False ) – If the client is connecting to a Binance testnet.

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 BinanceExecClientConfig ( * , 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) , api_key : Optional [ str ] = None , api_secret : Optional [ str ] = None , account_type : nautilus_trader.adapters.binance.common.enums.BinanceAccountType = BinanceAccountType.SPOT , base_url_http : Optional [ str ] = None , base_url_ws : Optional [ str ] = None , us : bool = False , testnet : bool = False )

Bases: nautilus_trader.config.live.LiveExecClientConfig

Configuration for BinanceExecutionClient instances.

Parameters
  • api_key ( str , optional ) – The Binance API public key. If None then will source the BINANCE_API_KEY or BINANCE_TESTNET_API_KEY environment variables.

  • api_secret ( str , optional ) – The Binance API public key. If None then will source the BINANCE_API_KEY or BINANCE_TESTNET_API_KEY environment variables.

  • account_type ( BinanceAccountType , default BinanceAccountType.SPOT ) – The account type for the client.

  • base_url_http ( str , optional ) – The HTTP client custom endpoint override.

  • base_ws_http ( str , optional ) – The WebSocket client custom endpoint override.

  • us ( bool , default False ) – If client is connecting to Binance US.

  • testnet ( bool , default False ) – If the client is connecting to a Binance testnet.

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.

Factories

get_cached_binance_http_client ( loop : asyncio.events.AbstractEventLoop , clock : nautilus_trader.common.clock.LiveClock , logger : nautilus_trader.common.logging.Logger , account_type : nautilus_trader.adapters.binance.common.enums.BinanceAccountType , key : Optional [ str ] = None , secret : Optional [ str ] = None , base_url : Optional [ str ] = None , is_testnet : bool = False , is_us : bool = False ) nautilus_trader.adapters.binance.http.client.BinanceHttpClient

Cache and return a Binance HTTP client with the given key and secret.

If a cached client with matching key and secret already exists, then that cached client will be returned.

Parameters
  • loop ( asyncio.AbstractEventLoop ) – The event loop for the client.

  • clock ( LiveClock ) – The clock for the client.

  • logger ( Logger ) – The logger for the client.

  • account_type ( BinanceAccountType ) – The account type for the client.

  • key ( str , optional ) – The API key for the client.

  • secret ( str , optional ) – The API secret for the client.

  • base_url ( str , optional ) – The base URL for the API endpoints.

  • is_testnet ( bool , default False ) – If the client is connecting to the testnet API.

  • is_us ( bool , default False ) – If the client is connecting to Binance US.

Returns

BinanceHttpClient

get_cached_binance_spot_instrument_provider ( client : nautilus_trader.adapters.binance.http.client.BinanceHttpClient , logger : nautilus_trader.common.logging.Logger , account_type : nautilus_trader.adapters.binance.common.enums.BinanceAccountType , config : nautilus_trader.config.common.InstrumentProviderConfig ) nautilus_trader.adapters.binance.spot.providers.BinanceSpotInstrumentProvider

Cache and return an instrument provider for the Binance Spot/Margin exchange.

If a cached provider already exists, then that provider will be returned.

Parameters
  • client ( BinanceHttpClient ) – The client for the instrument provider.

  • logger ( Logger ) – The logger for the instrument provider.

  • account_type ( BinanceAccountType ) – The Binance account type for the instrument provider.

  • config ( InstrumentProviderConfig ) – The configuration for the instrument provider.

Returns

BinanceSpotInstrumentProvider

get_cached_binance_futures_instrument_provider ( client : nautilus_trader.adapters.binance.http.client.BinanceHttpClient , logger : nautilus_trader.common.logging.Logger , account_type : nautilus_trader.adapters.binance.common.enums.BinanceAccountType , config : nautilus_trader.config.common.InstrumentProviderConfig ) nautilus_trader.adapters.binance.futures.providers.BinanceFuturesInstrumentProvider

Cache and return an instrument provider for the Binance Futures exchange.

If a cached provider already exists, then that provider will be returned.

Parameters
  • client ( BinanceHttpClient ) – The client for the instrument provider.

  • logger ( Logger ) – The logger for the instrument provider.

  • account_type ( BinanceAccountType ) – The Binance account type for the instrument provider.

  • config ( InstrumentProviderConfig ) – The configuration for the instrument provider.

Returns

BinanceFuturesInstrumentProvider

class BinanceLiveDataClientFactory

Bases: nautilus_trader.live.factories.LiveDataClientFactory

Provides a Binance live data client factory.

static create ( loop : asyncio.events.AbstractEventLoop , name : str , config : nautilus_trader.adapters.binance.config.BinanceDataClientConfig , msgbus : nautilus_trader.msgbus.bus.MessageBus , cache : nautilus_trader.cache.cache.Cache , clock : nautilus_trader.common.clock.LiveClock , logger : nautilus_trader.common.logging.LiveLogger ) Union [ nautilus_trader.adapters.binance.spot.data.BinanceSpotDataClient , nautilus_trader.adapters.binance.futures.data.BinanceFuturesDataClient ]

Create a new Binance data client.

Parameters
  • loop ( asyncio.AbstractEventLoop ) – The event loop for the client.

  • name ( str ) – The client name.

  • config ( BinanceDataClientConfig ) – The client configuration.

  • msgbus ( MessageBus ) – The message bus for the client.

  • cache ( Cache ) – The cache for the client.

  • clock ( LiveClock ) – The clock for the client.

  • logger ( LiveLogger ) – The logger for the client.

Returns

BinanceSpotDataClient or BinanceFuturesDataClient

Raises

ValueError – If config.account_type is not a valid BinanceAccountType .

class BinanceLiveExecClientFactory

Bases: nautilus_trader.live.factories.LiveExecClientFactory

Provides a Binance live execution client factory.

static create ( loop : asyncio.events.AbstractEventLoop , name : str , config : nautilus_trader.adapters.binance.config.BinanceExecClientConfig , msgbus : nautilus_trader.msgbus.bus.MessageBus , cache : nautilus_trader.cache.cache.Cache , clock : nautilus_trader.common.clock.LiveClock , logger : nautilus_trader.common.logging.LiveLogger ) Union [ nautilus_trader.adapters.binance.spot.execution.BinanceSpotExecutionClient , nautilus_trader.adapters.binance.futures.execution.BinanceFuturesExecutionClient ]

Create a new Binance execution client.

Parameters
  • loop ( asyncio.AbstractEventLoop ) – The event loop for the client.

  • name ( str ) – The client name.

  • config ( BinanceExecClientConfig ) – The configuration for the client.

  • msgbus ( MessageBus ) – The message bus for the client.

  • cache ( Cache ) – The cache for the client.

  • clock ( LiveClock ) – The clock for the client.

  • logger ( LiveLogger ) – The logger for the client.

Returns

BinanceExecutionClient

Raises

ValueError – If config.account_type is not a valid BinanceAccountType .

Enums

class BinanceRateLimitType ( value )

Bases: enum.Enum

Represents a Binance rate limit type.

class BinanceRateLimitInterval ( value )

Bases: enum.Enum

Represents a Binance rate limit interval.

class BinanceExchangeFilterType ( value )

Bases: enum.Enum

Represents a Binance exchange filter type.

class BinanceSymbolFilterType ( value )

Bases: enum.Enum

Represents a Binance symbol filter type.

class BinanceAccountType ( value )

Bases: enum.Enum

Represents a Binance account type.

class BinanceOrderSide ( value )

Bases: enum.Enum

Represents a Binance order side.

class BinanceExecutionType ( value )

Bases: enum.Enum

Represents a Binance execution type.

class BinanceOrderStatus ( value )

Bases: enum.Enum

Represents a Binance order status.

Types

class BinanceBar ( bar_type : nautilus_trader.model.data.bar.BarType , open : nautilus_trader.model.objects.Price , high : nautilus_trader.model.objects.Price , low : nautilus_trader.model.objects.Price , close : nautilus_trader.model.objects.Price , volume : nautilus_trader.model.objects.Quantity , quote_volume : decimal.Decimal , count : int , taker_buy_base_volume : decimal.Decimal , taker_buy_quote_volume : decimal.Decimal , ts_event : int , ts_init : int )

Bases: nautilus_trader.model.data.bar.Bar

Represents an aggregated Binance bar.

This data type includes the raw data provided by Binance .

Parameters
  • bar_type ( BarType ) – The bar type for this bar.

  • open ( Price ) – The bars open price.

  • high ( Price ) – The bars high price.

  • low ( Price ) – The bars low price.

  • close ( Price ) – The bars close price.

  • volume ( Quantity ) – The bars volume.

  • quote_volume ( Decimal ) – The bars quote asset volume.

  • count ( int ) – The number of trades for the bar.

  • taker_buy_base_volume ( Decimal ) – The liquidity taker volume on the buy side for the base asset.

  • taker_buy_quote_volume ( Decimal ) – The liquidity taker volume on the buy side for the quote asset.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the data event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the data object was initialized.

References

https://binance-docs.github.io/apidocs/spot/en/#kline-candlestick-data https://binance-docs.github.io/apidocs/futures/en/#kline-candlestick-data

static from_dict ( values : Dict [ str , Any ] ) nautilus_trader.adapters.binance.common.types.BinanceBar

Return a Binance bar parsed from the given values.

Parameters

values ( dict [ str , Any ] ) – The values for initialization.

Returns

BinanceBar

static to_dict ( obj : nautilus_trader.adapters.binance.common.types.BinanceBar ) Dict [ str , Any ]

Return a dictionary representation of this object.

Returns

dict[str, Any]

bar_type

Return the bar type of bar.

Returns

BarType

close

Return the close price of the bar.

Returns

Price

classmethod fully_qualified_name ( type cls ) str

Return the fully qualified name for the Data class.

Returns

str

References

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

high

Return the high price of the bar.

Returns

Price

is_single_price ( self ) bool

If the OHLC are all equal to a single price.

Returns

bool

low

Return the low price of the bar.

Returns

Price

open

Return the open price of the bar.

Returns

Price

ts_event

The UNIX timestamp (nanoseconds) when the data event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

volume

Return the volume of the bar.

Returns

Quantity

class BinanceTicker ( instrument_id : nautilus_trader.model.identifiers.InstrumentId , price_change : decimal.Decimal , price_change_percent : decimal.Decimal , weighted_avg_price : decimal.Decimal , last_price : decimal.Decimal , last_qty : decimal.Decimal , open_price : decimal.Decimal , high_price : decimal.Decimal , low_price : decimal.Decimal , volume : decimal.Decimal , quote_volume : decimal.Decimal , open_time_ms : int , close_time_ms : int , first_id : int , last_id : int , count : int , ts_event : int , ts_init : int , prev_close_price : Optional [ decimal.Decimal ] = None , bid_price : Optional [ decimal.Decimal ] = None , bid_qty : Optional [ decimal.Decimal ] = None , ask_price : Optional [ decimal.Decimal ] = None , ask_qty : Optional [ decimal.Decimal ] = None )

Bases: nautilus_trader.model.data.ticker.Ticker

Represents a Binance 24hr statistics ticker.

This data type includes the raw data provided by Binance .

Parameters
  • instrument_id ( InstrumentId ) – The instrument ID.

  • price_change ( Decimal ) – The price change.

  • price_change_percent ( Decimal ) – The price change percent.

  • weighted_avg_price ( Decimal ) – The weighted average price.

  • prev_close_price ( Decimal , optional ) – The previous close price.

  • last_price ( Decimal ) – The last price.

  • last_qty ( Decimal ) – The last quantity.

  • bid_price ( Decimal , optional ) – The bid price.

  • bid_qty ( Decimal , optional ) – The bid quantity.

  • ask_price ( Decimal , optional ) – The ask price.

  • ask_qty ( Decimal , optional ) – The ask quantity.

  • open_price ( Decimal ) – The open price.

  • high_price ( Decimal ) – The high price.

  • low_price ( Decimal ) – The low price.

  • volume ( Decimal ) – The volume.

  • quote_volume ( Decimal ) – The quote volume.

  • open_time_ms ( int ) – The UNIX timestamp (milliseconds) when the ticker opened.

  • close_time_ms ( int ) – The UNIX timestamp (milliseconds) when the ticker closed.

  • first_id ( int ) – The first trade match ID (assigned by the venue) for the ticker.

  • last_id ( int ) – The last trade match ID (assigned by the venue) for the ticker.

  • count ( int ) – The count of trades over the tickers time range.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the ticker event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the object was initialized.

References

https://binance-docs.github.io/apidocs/spot/en/#24hr-ticker-price-change-statistics https://binance-docs.github.io/apidocs/futures/en/#24hr-ticker-price-change-statistics

static from_dict ( values : Dict [ str , Any ] ) nautilus_trader.adapters.binance.common.types.BinanceTicker

Return a Binance Spot/Margin ticker parsed from the given values.

Parameters

values ( dict [ str , Any ] ) – The values for initialization.

Returns

BinanceTicker

static to_dict ( obj : nautilus_trader.adapters.binance.common.types.BinanceTicker ) Dict [ str , Any ]

Return a dictionary representation of this object.

Returns

dict[str, Any]

classmethod fully_qualified_name ( type cls ) str

Return the fully qualified name for the Data class.

Returns

str

References

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

instrument_id

The ticker instrument ID.

Returns

InstrumentId

ts_event

The UNIX timestamp (nanoseconds) when the data event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

Futures

Data

class BinanceFuturesDataClient ( loop : asyncio.events.AbstractEventLoop , client : nautilus_trader.adapters.binance.http.client.BinanceHttpClient , msgbus : nautilus_trader.msgbus.bus.MessageBus , cache : nautilus_trader.cache.cache.Cache , clock : nautilus_trader.common.clock.LiveClock , logger : nautilus_trader.common.logging.Logger , instrument_provider : nautilus_trader.common.providers.InstrumentProvider , account_type : nautilus_trader.adapters.binance.common.enums.BinanceAccountType = BinanceAccountType.FUTURES_USDT , base_url_ws : Optional [ str ] = None )

Bases: nautilus_trader.live.data_client.LiveMarketDataClient

Provides a data client for the Binance Futures exchange.

Parameters
  • loop ( asyncio.AbstractEventLoop ) – The event loop for the client.

  • client ( BinanceHttpClient ) – The binance HTTP client.

  • msgbus ( MessageBus ) – The message bus for the client.

  • cache ( Cache ) – The cache for the client.

  • clock ( LiveClock ) – The clock for the client.

  • logger ( Logger ) – The logger for the client.

  • instrument_provider ( InstrumentProvider ) – The instrument provider.

  • account_type ( BinanceAccountType ) – The account type for the client.

  • base_url_ws ( str , optional ) – The base URL for the WebSocket client.

connect ( ) None

Connect the client.

disconnect ( ) None

Disconnect the client.

subscribe ( self , DataType data_type ) void

Subscribe to data for the given data type.

Parameters

data_type ( DataType ) – The data type for the subscription.

subscribe_instruments ( self ) void

Subscribe to all Instrument data.

subscribe_instrument ( self , InstrumentId instrument_id ) void

Subscribe to the Instrument with the given instrument ID.

subscribe_order_book_deltas ( self , InstrumentId instrument_id , BookType book_type , int depth=0 , dict kwargs=None ) void

Subscribe to OrderBookDeltas data for the given instrument ID.

Parameters
  • instrument_id ( InstrumentId ) – The order book instrument to subscribe to.

  • book_type (BookType { L1_TBBO , L2_MBP , L3_MBO }) – The order book type.

  • depth ( int , optional , default None ) – The maximum depth for the subscription.

  • kwargs ( dict , optional ) – The keyword arguments for exchange specific parameters.

subscribe_order_book_snapshots ( self , InstrumentId instrument_id , BookType book_type , int depth=0 , dict kwargs=None ) void

Subscribe to OrderBookSnapshot data for the given instrument ID.

Parameters
  • instrument_id ( InstrumentId ) – The order book instrument to subscribe to.

  • book_type (BookType { L1_TBBO , L2_MBP , L3_MBO }) – The order book level.

  • depth ( int , optional ) – The maximum depth for the order book. A depth of 0 is maximum depth.

  • kwargs ( dict , optional ) – The keyword arguments for exchange specific parameters.

subscribe_ticker ( self , InstrumentId instrument_id ) void

Subscribe to Ticker data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The ticker instrument to subscribe to.

subscribe_quote_ticks ( self , InstrumentId instrument_id ) void

Subscribe to QuoteTick data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The tick instrument to subscribe to.

subscribe_trade_ticks ( self , InstrumentId instrument_id ) void

Subscribe to TradeTick data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The tick instrument to subscribe to.

subscribe_bars ( self , BarType bar_type ) void

Subscribe to Bar data for the given bar type.

Parameters

bar_type ( BarType ) – The bar type to subscribe to.

unsubscribe ( self , DataType data_type ) void

Unsubscribe from data for the given data type.

Parameters

data_type ( DataType ) – The data type for the subscription.

unsubscribe_instruments ( self ) void

Unsubscribe from all Instrument data.

unsubscribe_instrument ( self , InstrumentId instrument_id ) void

Unsubscribe from Instrument data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The instrument to unsubscribe from.

unsubscribe_order_book_deltas ( self , InstrumentId instrument_id ) void

Unsubscribe from OrderBookDeltas data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The order book instrument to unsubscribe from.

unsubscribe_order_book_snapshots ( self , InstrumentId instrument_id ) void

Unsubscribe from OrderBookSnapshot data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The order book instrument to unsubscribe from.

unsubscribe_ticker ( self , InstrumentId instrument_id ) void

Unsubscribe from Ticker data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The ticker instrument to unsubscribe from.

unsubscribe_quote_ticks ( self , InstrumentId instrument_id ) void

Unsubscribe from QuoteTick data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The tick instrument to unsubscribe from.

unsubscribe_trade_ticks ( self , InstrumentId instrument_id ) void

Unsubscribe from TradeTick data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The tick instrument to unsubscribe from.

unsubscribe_bars ( self , BarType bar_type ) void

Unsubscribe from Bar data for the given bar type.

Parameters

bar_type ( BarType ) – The bar type to unsubscribe from.

unsubscribe_instrument_status_updates ( self , InstrumentId instrument_id ) void

Unsubscribe from InstrumentStatusUpdates data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The tick instrument to unsubscribe from.

unsubscribe_instrument_close_prices ( self , InstrumentId instrument_id ) void

Unsubscribe from InstrumentClosePrice data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The tick instrument to unsubscribe from.

request_instrument ( self , InstrumentId instrument_id , UUID4 correlation_id ) void

Request Instrument data for the given instrument ID.

Parameters
  • instrument_id ( InstrumentId ) – The instrument ID for the request.

  • correlation_id ( UUID4 ) – The correlation ID for the request.

request_quote_ticks ( self , InstrumentId instrument_id , int limit , UUID4 correlation_id , datetime from_datetime=None , datetime to_datetime=None ) void

Request historical QuoteTick data.

Parameters
  • instrument_id ( InstrumentId ) – The tick instrument ID for the request.

  • limit ( int ) – The limit for the number of returned ticks.

  • correlation_id ( UUID4 ) – The correlation ID for the request.

  • from_datetime ( datetime , optional ) – The specified from datetime for the data.

  • to_datetime ( datetime , optional ) – The specified to datetime for the data. If None then will default to the current datetime.

request_trade_ticks ( self , InstrumentId instrument_id , int limit , UUID4 correlation_id , datetime from_datetime=None , datetime to_datetime=None ) void

Request historical TradeTick data.

Parameters
  • instrument_id ( InstrumentId ) – The tick instrument ID for the request.

  • limit ( int ) – The limit for the number of returned ticks.

  • correlation_id ( UUID4 ) – The correlation ID for the request.

  • from_datetime ( datetime , optional ) – The specified from datetime for the data.

  • to_datetime ( datetime , optional ) – The specified to datetime for the data. If None then will default to the current datetime.

request_bars ( self , BarType bar_type , int limit , UUID4 correlation_id , datetime from_datetime=None , datetime to_datetime=None ) void

Request historical Bar data.

Parameters
  • bar_type ( BarType ) – The bar type for the request.

  • limit ( int ) – The limit for the number of returned bars.

  • correlation_id ( UUID4 ) – The correlation ID for the request.

  • from_datetime ( datetime , optional ) – The specified from datetime for the data.

  • to_datetime ( datetime , optional ) – The specified to datetime for the data. If None then will default to the current datetime.

degrade ( self ) void

Degrade the component.

While executing on_degrade() , any exception will be logged and reraised. The component will remain in a DEGRADING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

dispose ( self ) void

Dispose of the component.

While executing on_dispose() , any exception will be logged and reraised. The component will remain in a DISPOSING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

fault ( self ) void

Fault the component.

This method is idempotent and irreversible. No other methods should be called after faulting.

While executing on_fault() , any exception will be logged and reraised. The component will remain in a FAULTING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

classmethod fully_qualified_name ( type cls ) str

Return the fully qualified name for the components class.

Returns

str

References

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

id

The components ID.

Returns

ComponentId

is_connected

If the client is connected.

Returns

bool

is_degraded

Return whether the current component state is DEGRADED .

Returns

bool

is_disposed

Return whether the current component state is DISPOSED .

Returns

bool

is_faulted

Return whether the current component state is FAULTED .

Returns

bool

is_initialized

Return whether the component has been initialized (component.state >= INITIALIZED ).

Returns

bool

is_running

Return whether the current component state is RUNNING .

Returns

bool

is_stopped

Return whether the current component state is STOPPED .

Returns

bool

request ( self , DataType data_type , UUID4 correlation_id ) void

Request data for the given data type.

Parameters
  • data_type ( DataType ) – The data type for the subscription.

  • correlation_id ( UUID4 ) – The correlation ID for the response.

reset ( self ) void

Reset the component.

All stateful fields are reset to their initial value.

While executing on_reset() , any exception will be logged and reraised. The component will remain in a RESETTING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

resume ( self ) void

Resume the component.

While executing on_resume() , any exception will be logged and reraised. The component will remain in a RESUMING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

start ( self ) void

Start the component.

While executing on_start() , any exception will be logged and reraised. The component will remain in a STARTING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

state

Return the components current state.

Returns

ComponentState

stop ( self ) void

Stop the component.

While executing on_stop() , any exception will be logged and reraised. The component will remain in a STOPPING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

subscribe_instrument_close_prices ( self , InstrumentId instrument_id ) void

Subscribe to InstrumentClosePrice data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The tick instrument to subscribe to.

subscribe_instrument_status_updates ( self , InstrumentId instrument_id ) void

Subscribe to InstrumentStatusUpdates data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The tick instrument to subscribe to.

subscribed_bars ( self ) list

Return the bar types subscribed to.

Returns

list[BarType]

subscribed_generic_data ( self ) list

Return the generic data types subscribed to.

Returns

list[DataType]

subscribed_instrument_close_prices ( self ) list

Return the close price instruments subscribed to.

Returns

list[InstrumentId]

subscribed_instrument_status_updates ( self ) list

Return the status update instruments subscribed to.

Returns

list[InstrumentId]

subscribed_instruments ( self ) list

Return the instruments subscribed to.

Returns

list[InstrumentId]

subscribed_order_book_deltas ( self ) list

Return the order book delta instruments subscribed to.

Returns

list[InstrumentId]

subscribed_order_book_snapshots ( self ) list

Return the order book snapshot instruments subscribed to.

Returns

list[InstrumentId]

subscribed_quote_ticks ( self ) list

Return the quote tick instruments subscribed to.

Returns

list[InstrumentId]

subscribed_tickers ( self ) list

Return the ticker instruments subscribed to.

Returns

list[InstrumentId]

subscribed_trade_ticks ( self ) list

Return the trade tick instruments subscribed to.

Returns

list[InstrumentId]

trader_id

The trader ID associated with the component.

Returns

TraderId

type

The components type.

Returns

type

venue

The clients venue ID (if not a routing client).

Returns

Venue or None

Enums

class BinanceFuturesContractType ( value )

Bases: enum.Enum

Represents a Binance Futures derivatives contract type.

class BinanceFuturesContractStatus ( value )

Bases: enum.Enum

Represents a Binance Futures contract status.

class BinanceFuturesOrderType ( value )

Bases: enum.Enum

Represents a Binance Futures price type.

class BinanceFuturesPositionSide ( value )

Bases: enum.Enum

Represents a Binance Futures position side.

class BinanceFuturesTimeInForce ( value )

Bases: enum.Enum

Represents a Binance Futures order time in force.

class BinanceFuturesWorkingType ( value )

Bases: enum.Enum

Represents a Binance Futures working type.

class BinanceFuturesMarginType ( value )

Bases: enum.Enum

Represents a Binance Futures margin type.

class BinanceFuturesPositionUpdateReason ( value )

Bases: enum.Enum

Represents a Binance Futures position and balance update reason.

class BinanceFuturesEventType ( value )

Bases: enum.Enum

Represents a Binance Futures event type.

Execution

class BinanceFuturesExecutionClient ( loop : asyncio.events.AbstractEventLoop , client : nautilus_trader.adapters.binance.http.client.BinanceHttpClient , msgbus : nautilus_trader.msgbus.bus.MessageBus , cache : nautilus_trader.cache.cache.Cache , clock : nautilus_trader.common.clock.LiveClock , logger : nautilus_trader.common.logging.Logger , instrument_provider : nautilus_trader.adapters.binance.futures.providers.BinanceFuturesInstrumentProvider , account_type : nautilus_trader.adapters.binance.common.enums.BinanceAccountType = BinanceAccountType.FUTURES_USDT , base_url_ws : Optional [ str ] = None )

Bases: nautilus_trader.live.execution_client.LiveExecutionClient

Provides an execution client for the Binance Futures exchange.

Parameters
  • loop ( asyncio.AbstractEventLoop ) – The event loop for the client.

  • client ( BinanceHttpClient ) – The binance HTTP client.

  • msgbus ( MessageBus ) – The message bus for the client.

  • cache ( Cache ) – The cache for the client.

  • clock ( LiveClock ) – The clock for the client.

  • logger ( Logger ) – The logger for the client.

  • instrument_provider ( BinanceFuturesInstrumentProvider ) – The instrument provider.

  • account_type ( BinanceAccountType ) – The account type for the client.

  • base_url_ws ( str , optional ) – The base URL for the WebSocket client.

connect ( ) None

Abstract method (implement in subclass).

disconnect ( ) None

Abstract method (implement in subclass).

async generate_order_status_report ( instrument_id : nautilus_trader.model.identifiers.InstrumentId , client_order_id : Optional [ nautilus_trader.model.identifiers.ClientOrderId ] = None , venue_order_id : Optional [ nautilus_trader.model.identifiers.VenueOrderId ] = None ) Optional [ nautilus_trader.execution.reports.OrderStatusReport ]

Generate an order status report for the given order identifier parameter(s).

If the order is not found, or an error occurs, then logs and returns None .

Parameters
  • instrument_id ( InstrumentId ) – The instrument ID for the report.

  • client_order_id ( ClientOrderId , optional ) – The client order ID for the report.

  • venue_order_id ( VenueOrderId , optional ) – The venue order ID for the report.

Returns

OrderStatusReport or None

Raises

ValueError – If both the client_order_id and venue_order_id are None .

async generate_order_status_reports ( instrument_id : Optional [ nautilus_trader.model.identifiers.InstrumentId ] = None , start : Optional [ datetime.datetime ] = None , end : Optional [ datetime.datetime ] = None , open_only : bool = False ) List [ nautilus_trader.execution.reports.OrderStatusReport ]

Generate a list of order status reports with optional query filters.

The returned list may be empty if no orders match the given parameters.

Parameters
  • instrument_id ( InstrumentId , optional ) – The instrument ID query filter.

  • start ( pd.Timestamp , optional ) – The start datetime query filter.

  • end ( pd.Timestamp , optional ) – The end datetime query filter.

  • open_only ( bool , default False ) – If the query is for open orders only.

Returns

list[OrderStatusReport]

async generate_trade_reports ( instrument_id : Optional [ nautilus_trader.model.identifiers.InstrumentId ] = None , venue_order_id : Optional [ nautilus_trader.model.identifiers.VenueOrderId ] = None , start : Optional [ datetime.datetime ] = None , end : Optional [ datetime.datetime ] = None ) List [ nautilus_trader.execution.reports.TradeReport ]

Generate a list of trade reports with optional query filters.

The returned list may be empty if no trades match the given parameters.

Parameters
  • instrument_id ( InstrumentId , optional ) – The instrument ID query filter.

  • venue_order_id ( VenueOrderId , optional ) – The venue order ID (assigned by the venue) query filter.

  • start ( pd.Timestamp , optional ) – The start datetime query filter.

  • end ( pd.Timestamp , optional ) – The end datetime query filter.

Returns

list[TradeReport]

async generate_position_status_reports ( instrument_id : Optional [ nautilus_trader.model.identifiers.InstrumentId ] = None , start : Optional [ datetime.datetime ] = None , end : Optional [ datetime.datetime ] = None ) List [ nautilus_trader.execution.reports.PositionStatusReport ]

Generate a list of position status reports with optional query filters.

The returned list may be empty if no positions match the given parameters.

Parameters
  • instrument_id ( InstrumentId , optional ) – The instrument ID query filter.

  • start ( pd.Timestamp , optional ) – The start datetime query filter.

  • end ( pd.Timestamp , optional ) – The end datetime query filter.

Returns

list[PositionStatusReport]

submit_order ( self , SubmitOrder command ) void

Submit the order contained in the given command for execution.

Parameters

command ( SubmitOrder ) – The command to execute.

submit_order_list ( self , SubmitOrderList command ) void

Submit the order list contained in the given command for execution.

Parameters

command ( SubmitOrderList ) – The command to execute.

modify_order ( self , ModifyOrder command ) void

Modify the order with parameters contained in the command.

Parameters

command ( ModifyOrder ) – The command to execute.

cancel_order ( self , CancelOrder command ) void

Cancel the order with the client order ID contained in the given command.

Parameters

command ( CancelOrder ) – The command to execute.

cancel_all_orders ( self , CancelAllOrders command ) void

Cancel all orders for the instrument ID contained in the given command.

Parameters

command ( CancelAllOrders ) – The command to execute.

account_id

The clients account ID.

Returns

AccountId or None

account_type

The clients account type.

Returns

AccountType

base_currency

The clients account base currency (None for multi-currency accounts).

Returns

Currency or None

degrade ( self ) void

Degrade the component.

While executing on_degrade() , any exception will be logged and reraised. The component will remain in a DEGRADING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

dispose ( self ) void

Dispose of the component.

While executing on_dispose() , any exception will be logged and reraised. The component will remain in a DISPOSING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

fault ( self ) void

Fault the component.

This method is idempotent and irreversible. No other methods should be called after faulting.

While executing on_fault() , any exception will be logged and reraised. The component will remain in a FAULTING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

classmethod fully_qualified_name ( type cls ) str

Return the fully qualified name for the components class.

Returns

str

References

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

generate_account_state ( self , list balances , list margins , bool reported , uint64_t ts_event , dict info=None ) void

Generate an AccountState event and publish on the message bus.

Parameters
  • balances ( list [ AccountBalance ] ) – The account balances.

  • margins ( list [ MarginBalance ] ) – The margin balances.

  • reported ( bool ) – If the balances are reported directly from the exchange.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the account state event occurred.

  • info ( dict [ str , object ] ) – The additional implementation specific account information.

async generate_mass_status ( lookback_mins : Optional [ int ] = None )

Generate an execution mass status report.

Parameters

lookback_mins ( int , optional ) – The maximum lookback for querying closed orders, trades and positions.

Returns

ExecutionMassStatus

generate_order_accepted ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , uint64_t ts_event ) void

Generate an OrderAccepted event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order accepted event occurred.

generate_order_cancel_rejected ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , unicode reason , uint64_t ts_event ) void

Generate an OrderCancelRejected event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • reason ( str ) – The order cancel rejected reason.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order cancel rejected event occurred.

generate_order_canceled ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , uint64_t ts_event ) void

Generate an OrderCanceled event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when order canceled event occurred.

generate_order_expired ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , uint64_t ts_event ) void

Generate an OrderExpired event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order expired event occurred.

generate_order_filled ( self, StrategyId strategy_id, InstrumentId instrument_id, ClientOrderId client_order_id, VenueOrderId venue_order_id, PositionId venue_position_id: Optional[PositionId], TradeId trade_id, OrderSide order_side, OrderType order_type, Quantity last_qty, Price last_px, Currency quote_currency, Money commission, LiquiditySide liquidity_side, uint64_t ts_event ) void

Generate an OrderFilled event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • trade_id ( TradeId ) – The trade ID.

  • venue_position_id (PositionId, optional with no default so None must be passed explicitly) – The venue position ID associated with the order. If the trading venue has assigned a position ID / ticket then pass that here, otherwise pass None and the execution engine OMS will handle position ID resolution.

  • order_side (OrderSide { BUY , SELL }) – The execution order side.

  • order_type ( OrderType ) – The execution order type.

  • last_qty ( Quantity ) – The fill quantity for this execution.

  • last_px ( Price ) – The fill price for this execution (not average price).

  • quote_currency ( Currency ) – The currency of the price.

  • commission ( Money ) – The fill commission.

  • liquidity_side (LiquiditySide { NONE , MAKER , TAKER }) – The execution liquidity side.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order filled event occurred.

generate_order_modify_rejected ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , unicode reason , uint64_t ts_event ) void

Generate an OrderModifyRejected event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • reason ( str ) – The order update rejected reason.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order update rejection event occurred.

generate_order_pending_cancel ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , uint64_t ts_event ) void

Generate an OrderPendingCancel event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order pending cancel event occurred.

generate_order_pending_update ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , uint64_t ts_event ) void

Generate an OrderPendingUpdate event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order pending update event occurred.

generate_order_rejected ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , unicode reason , uint64_t ts_event ) void

Generate an OrderRejected event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • reason ( datetime ) – The order rejected reason.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order rejected event occurred.

generate_order_submitted ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , uint64_t ts_event ) void

Generate an OrderSubmitted event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order submitted event occurred.

generate_order_triggered ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , uint64_t ts_event ) void

Generate an OrderTriggered event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order triggered event occurred.

generate_order_updated ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , Quantity quantity , Price price , Price trigger_price , uint64_t ts_event , bool venue_order_id_modified=False ) void

Generate an OrderUpdated event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • quantity ( Quantity ) – The orders current quantity.

  • price ( Price ) – The orders current price.

  • trigger_price (Price, optional with no default so None must be passed explicitly) – The orders current trigger price.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order update event occurred.

  • venue_order_id_modified ( bool ) – If the ID was modified for this event.

get_account ( self ) Account

Return the account for the client (if registered).

Returns

Account or None

id

The components ID.

Returns

ComponentId

is_connected

If the client is connected.

Returns

bool

is_degraded

Return whether the current component state is DEGRADED .

Returns

bool

is_disposed

Return whether the current component state is DISPOSED .

Returns

bool

is_faulted

Return whether the current component state is FAULTED .

Returns

bool

is_initialized

Return whether the component has been initialized (component.state >= INITIALIZED ).

Returns

bool

is_running

Return whether the current component state is RUNNING .

Returns

bool

is_stopped

Return whether the current component state is STOPPED .

Returns

bool

oms_type

The venues order management system type.

Returns

OMSType

reset ( self ) void

Reset the component.

All stateful fields are reset to their initial value.

While executing on_reset() , any exception will be logged and reraised. The component will remain in a RESETTING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

resume ( self ) void

Resume the component.

While executing on_resume() , any exception will be logged and reraised. The component will remain in a RESUMING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

start ( self ) void

Start the component.

While executing on_start() , any exception will be logged and reraised. The component will remain in a STARTING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

state

Return the components current state.

Returns

ComponentState

stop ( self ) void

Stop the component.

While executing on_stop() , any exception will be logged and reraised. The component will remain in a STOPPING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

sync_order_status ( self , QueryOrder command ) void

Request a reconciliation for the queried order which will generate an OrderStatusReport

trader_id

The trader ID associated with the component.

Returns

TraderId

type

The components type.

Returns

type

venue

The clients venue ID (if not a routing client).

Returns

Venue or None

Providers

class BinanceFuturesInstrumentProvider ( client : nautilus_trader.adapters.binance.http.client.BinanceHttpClient , logger : nautilus_trader.common.logging.Logger , account_type : nautilus_trader.adapters.binance.common.enums.BinanceAccountType = BinanceAccountType.FUTURES_USDT , config : Optional [ nautilus_trader.config.common.InstrumentProviderConfig ] = None )

Bases: nautilus_trader.common.providers.InstrumentProvider

Provides a means of loading instruments from the Binance Futures exchange.

Parameters
  • client ( APIClient ) – The client for the provider.

  • logger ( Logger ) – The logger for the provider.

  • config ( InstrumentProviderConfig , optional ) – The configuration for the provider.

async load_all_async ( filters : Optional [ Dict ] = None ) None

Load the latest instruments into the provider asynchronously, optionally applying the given filters.

async load_ids_async ( instrument_ids : List [ nautilus_trader.model.identifiers.InstrumentId ] , filters : Optional [ Dict ] = None ) None

Load the instruments for the given IDs into the provider, optionally applying the given filters.

Parameters
  • instrument_ids ( List [ InstrumentId ] ) – The instrument IDs to load.

  • filters ( Dict , optional ) – The venue specific instrument loading filters to apply.

Raises

ValueError – If any instrument_id.venue is not equal to self.venue .

async load_async ( instrument_id : nautilus_trader.model.identifiers.InstrumentId , filters : Optional [ Dict ] = None ) None

Load the instrument for the given ID into the provider asynchronously, optionally applying the given filters.

Parameters
  • instrument_id ( InstrumentId ) – The instrument ID to load.

  • filters ( Dict , optional ) – The venue specific instrument loading filters to apply.

Raises

ValueError – If instrument_id.venue is not equal to self.venue .

add ( instrument : nautilus_trader.model.instruments.base.Instrument ) None

Add the given instrument to the provider.

Parameters

instrument ( Instrument ) – The instrument to add.

add_bulk ( instruments : List [ nautilus_trader.model.instruments.base.Instrument ] ) None

Add the given instruments bulk to the provider.

Parameters

instruments ( list [ Instrument ] ) – The instruments to add.

add_currency ( currency : nautilus_trader.model.currency.Currency ) None

Add the given currency to the provider.

Parameters

currency ( Currency ) – The currency to add.

property count : int

Return the count of instruments held by the provider.

Returns

int

currencies ( ) Dict [ str , nautilus_trader.model.currency.Currency ]

Return all currencies held by the instrument provider.

Returns

dict[str, Currency]

currency ( code : str ) Optional [ nautilus_trader.model.currency.Currency ]

Return the currency with the given code (if found).

Parameters

code ( str ) – The currency code.

Returns

Currency or None

Raises

ValueError – If code is not a valid string.

find ( instrument_id : nautilus_trader.model.identifiers.InstrumentId ) Optional [ nautilus_trader.model.instruments.base.Instrument ]

Return the instrument for the given instrument ID (if found).

Parameters

instrument_id ( InstrumentId ) – The ID for the instrument

Returns

Instrument or None

get_all ( ) Dict [ nautilus_trader.model.identifiers.InstrumentId , nautilus_trader.model.instruments.base.Instrument ]

Return all loaded instruments as a map keyed by instrument ID.

If no instruments loaded, will return an empty dict.

Returns

dict[InstrumentId, Instrument]

async initialize ( ) None

Initialize the instrument provider.

If initialize() then will immediately return.

list_all ( ) List [ nautilus_trader.model.instruments.base.Instrument ]

Return all loaded instruments.

Returns

list[Instrument]

load ( instrument_id : nautilus_trader.model.identifiers.InstrumentId , filters : Optional [ Dict ] = None )

Load the instrument for the given ID into the provider, optionally applying the given filters.

Parameters
  • instrument_id ( InstrumentId ) – The instrument ID to load.

  • filters ( Dict , optional ) – The venue specific instrument loading filters to apply.

load_all ( filters : Optional [ Dict ] = None ) None

Load the latest instruments into the provider, optionally applying the given filters.

Parameters

filters ( Dict , optional ) – The venue specific instrument loading filters to apply.

load_ids ( instrument_ids : List [ nautilus_trader.model.identifiers.InstrumentId ] , filters : Optional [ Dict ] = None )

Load the instruments for the given IDs into the provider, optionally applying the given filters.

Parameters
  • instrument_ids ( List [ InstrumentId ] ) – The instrument IDs to load.

  • filters ( Dict , optional ) – The venue specific instrument loading filters to apply.

property venue : nautilus_trader.model.identifiers.Venue

Return the providers venue.

Returns

Venue

Types

class BinanceFuturesMarkPriceUpdate ( instrument_id : nautilus_trader.model.identifiers.InstrumentId , mark : nautilus_trader.model.objects.Price , index : nautilus_trader.model.objects.Price , estimated_settle : nautilus_trader.model.objects.Price , funding_rate : decimal.Decimal , ts_next_funding : int , ts_event : int , ts_init : int )

Bases: nautilus_trader.core.data.Data

Represents a Binance Futures mark price and funding rate update.

Parameters
  • instrument_id ( InstrumentId ) – The instrument ID for the update.

  • mark ( Price ) – The mark price for the instrument.

  • index ( Price ) – The index price for the instrument.

  • estimated_settle ( Price ) – The estimated settle price for the instrument (only useful in the last hour before the settlement starts).

  • funding_rate ( Decimal ) – The current funding rate for the instrument.

  • ts_next_funding ( uint64_t ) – The UNIX timestamp (nanoseconds) when next funding will occur.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the data event occurred.

  • ts_init ( uint64_t ) – The UNIX timestamp (nanoseconds) when the data object was initialized.

References

https://binance-docs.github.io/apidocs/futures/en/#mark-price-stream

static from_dict ( values : Dict [ str , Any ] ) nautilus_trader.adapters.binance.futures.types.BinanceFuturesMarkPriceUpdate

Return a Binance Futures mark price update parsed from the given values.

Parameters

values ( dict [ str , Any ] ) – The values for initialization.

Returns

BinanceFuturesMarkPriceUpdate

static to_dict ( obj : nautilus_trader.adapters.binance.futures.types.BinanceFuturesMarkPriceUpdate ) Dict [ str , Any ]

Return a dictionary representation of this object.

Returns

dict[str, Any]

classmethod fully_qualified_name ( type cls ) str

Return the fully qualified name for the Data class.

Returns

str

References

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

ts_event

The UNIX timestamp (nanoseconds) when the data event occurred.

Returns

uint64_t

ts_init

The UNIX timestamp (nanoseconds) when the object was initialized.

Returns

uint64_t

Spot

Data

class BinanceSpotDataClient ( loop : asyncio.events.AbstractEventLoop , client : nautilus_trader.adapters.binance.http.client.BinanceHttpClient , msgbus : nautilus_trader.msgbus.bus.MessageBus , cache : nautilus_trader.cache.cache.Cache , clock : nautilus_trader.common.clock.LiveClock , logger : nautilus_trader.common.logging.Logger , instrument_provider : nautilus_trader.common.providers.InstrumentProvider , account_type : nautilus_trader.adapters.binance.common.enums.BinanceAccountType = BinanceAccountType.SPOT , base_url_ws : Optional [ str ] = None )

Bases: nautilus_trader.live.data_client.LiveMarketDataClient

Provides a data client for the Binance Spot/Margin exchange.

Parameters
  • loop ( asyncio.AbstractEventLoop ) – The event loop for the client.

  • client ( BinanceHttpClient ) – The binance HTTP client.

  • msgbus ( MessageBus ) – The message bus for the client.

  • cache ( Cache ) – The cache for the client.

  • clock ( LiveClock ) – The clock for the client.

  • logger ( Logger ) – The logger for the client.

  • instrument_provider ( InstrumentProvider ) – The instrument provider.

  • account_type ( BinanceAccountType ) – The account type for the client.

  • base_url_ws ( str , optional ) – The base URL for the WebSocket client.

connect ( ) None

Connect the client.

disconnect ( ) None

Disconnect the client.

subscribe ( self , DataType data_type ) void

Subscribe to data for the given data type.

Parameters

data_type ( DataType ) – The data type for the subscription.

subscribe_instruments ( self ) void

Subscribe to all Instrument data.

subscribe_instrument ( self , InstrumentId instrument_id ) void

Subscribe to the Instrument with the given instrument ID.

subscribe_order_book_deltas ( self , InstrumentId instrument_id , BookType book_type , int depth=0 , dict kwargs=None ) void

Subscribe to OrderBookDeltas data for the given instrument ID.

Parameters
  • instrument_id ( InstrumentId ) – The order book instrument to subscribe to.

  • book_type (BookType { L1_TBBO , L2_MBP , L3_MBO }) – The order book type.

  • depth ( int , optional , default None ) – The maximum depth for the subscription.

  • kwargs ( dict , optional ) – The keyword arguments for exchange specific parameters.

subscribe_order_book_snapshots ( self , InstrumentId instrument_id , BookType book_type , int depth=0 , dict kwargs=None ) void

Subscribe to OrderBookSnapshot data for the given instrument ID.

Parameters
  • instrument_id ( InstrumentId ) – The order book instrument to subscribe to.

  • book_type (BookType { L1_TBBO , L2_MBP , L3_MBO }) – The order book level.

  • depth ( int , optional ) – The maximum depth for the order book. A depth of 0 is maximum depth.

  • kwargs ( dict , optional ) – The keyword arguments for exchange specific parameters.

subscribe_ticker ( self , InstrumentId instrument_id ) void

Subscribe to Ticker data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The ticker instrument to subscribe to.

subscribe_quote_ticks ( self , InstrumentId instrument_id ) void

Subscribe to QuoteTick data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The tick instrument to subscribe to.

subscribe_trade_ticks ( self , InstrumentId instrument_id ) void

Subscribe to TradeTick data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The tick instrument to subscribe to.

subscribe_bars ( self , BarType bar_type ) void

Subscribe to Bar data for the given bar type.

Parameters

bar_type ( BarType ) – The bar type to subscribe to.

unsubscribe_instruments ( self ) void

Unsubscribe from all Instrument data.

unsubscribe_instrument ( self , InstrumentId instrument_id ) void

Unsubscribe from Instrument data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The instrument to unsubscribe from.

unsubscribe_order_book_deltas ( self , InstrumentId instrument_id ) void

Unsubscribe from OrderBookDeltas data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The order book instrument to unsubscribe from.

unsubscribe_order_book_snapshots ( self , InstrumentId instrument_id ) void

Unsubscribe from OrderBookSnapshot data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The order book instrument to unsubscribe from.

unsubscribe_ticker ( self , InstrumentId instrument_id ) void

Unsubscribe from Ticker data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The ticker instrument to unsubscribe from.

unsubscribe_quote_ticks ( self , InstrumentId instrument_id ) void

Unsubscribe from QuoteTick data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The tick instrument to unsubscribe from.

unsubscribe_trade_ticks ( self , InstrumentId instrument_id ) void

Unsubscribe from TradeTick data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The tick instrument to unsubscribe from.

unsubscribe_bars ( self , BarType bar_type ) void

Unsubscribe from Bar data for the given bar type.

Parameters

bar_type ( BarType ) – The bar type to unsubscribe from.

unsubscribe_instrument_status_updates ( self , InstrumentId instrument_id ) void

Unsubscribe from InstrumentStatusUpdates data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The tick instrument to unsubscribe from.

unsubscribe_instrument_close_prices ( self , InstrumentId instrument_id ) void

Unsubscribe from InstrumentClosePrice data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The tick instrument to unsubscribe from.

request_instrument ( self , InstrumentId instrument_id , UUID4 correlation_id ) void

Request Instrument data for the given instrument ID.

Parameters
  • instrument_id ( InstrumentId ) – The instrument ID for the request.

  • correlation_id ( UUID4 ) – The correlation ID for the request.

request_quote_ticks ( self , InstrumentId instrument_id , int limit , UUID4 correlation_id , datetime from_datetime=None , datetime to_datetime=None ) void

Request historical QuoteTick data.

Parameters
  • instrument_id ( InstrumentId ) – The tick instrument ID for the request.

  • limit ( int ) – The limit for the number of returned ticks.

  • correlation_id ( UUID4 ) – The correlation ID for the request.

  • from_datetime ( datetime , optional ) – The specified from datetime for the data.

  • to_datetime ( datetime , optional ) – The specified to datetime for the data. If None then will default to the current datetime.

request_trade_ticks ( self , InstrumentId instrument_id , int limit , UUID4 correlation_id , datetime from_datetime=None , datetime to_datetime=None ) void

Request historical TradeTick data.

Parameters
  • instrument_id ( InstrumentId ) – The tick instrument ID for the request.

  • limit ( int ) – The limit for the number of returned ticks.

  • correlation_id ( UUID4 ) – The correlation ID for the request.

  • from_datetime ( datetime , optional ) – The specified from datetime for the data.

  • to_datetime ( datetime , optional ) – The specified to datetime for the data. If None then will default to the current datetime.

request_bars ( self , BarType bar_type , int limit , UUID4 correlation_id , datetime from_datetime=None , datetime to_datetime=None ) void

Request historical Bar data.

Parameters
  • bar_type ( BarType ) – The bar type for the request.

  • limit ( int ) – The limit for the number of returned bars.

  • correlation_id ( UUID4 ) – The correlation ID for the request.

  • from_datetime ( datetime , optional ) – The specified from datetime for the data.

  • to_datetime ( datetime , optional ) – The specified to datetime for the data. If None then will default to the current datetime.

degrade ( self ) void

Degrade the component.

While executing on_degrade() , any exception will be logged and reraised. The component will remain in a DEGRADING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

dispose ( self ) void

Dispose of the component.

While executing on_dispose() , any exception will be logged and reraised. The component will remain in a DISPOSING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

fault ( self ) void

Fault the component.

This method is idempotent and irreversible. No other methods should be called after faulting.

While executing on_fault() , any exception will be logged and reraised. The component will remain in a FAULTING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

classmethod fully_qualified_name ( type cls ) str

Return the fully qualified name for the components class.

Returns

str

References

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

id

The components ID.

Returns

ComponentId

is_connected

If the client is connected.

Returns

bool

is_degraded

Return whether the current component state is DEGRADED .

Returns

bool

is_disposed

Return whether the current component state is DISPOSED .

Returns

bool

is_faulted

Return whether the current component state is FAULTED .

Returns

bool

is_initialized

Return whether the component has been initialized (component.state >= INITIALIZED ).

Returns

bool

is_running

Return whether the current component state is RUNNING .

Returns

bool

is_stopped

Return whether the current component state is STOPPED .

Returns

bool

request ( self , DataType data_type , UUID4 correlation_id ) void

Request data for the given data type.

Parameters
  • data_type ( DataType ) – The data type for the subscription.

  • correlation_id ( UUID4 ) – The correlation ID for the response.

reset ( self ) void

Reset the component.

All stateful fields are reset to their initial value.

While executing on_reset() , any exception will be logged and reraised. The component will remain in a RESETTING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

resume ( self ) void

Resume the component.

While executing on_resume() , any exception will be logged and reraised. The component will remain in a RESUMING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

start ( self ) void

Start the component.

While executing on_start() , any exception will be logged and reraised. The component will remain in a STARTING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

state

Return the components current state.

Returns

ComponentState

stop ( self ) void

Stop the component.

While executing on_stop() , any exception will be logged and reraised. The component will remain in a STOPPING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

subscribe_instrument_close_prices ( self , InstrumentId instrument_id ) void

Subscribe to InstrumentClosePrice data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The tick instrument to subscribe to.

subscribe_instrument_status_updates ( self , InstrumentId instrument_id ) void

Subscribe to InstrumentStatusUpdates data for the given instrument ID.

Parameters

instrument_id ( InstrumentId ) – The tick instrument to subscribe to.

subscribed_bars ( self ) list

Return the bar types subscribed to.

Returns

list[BarType]

subscribed_generic_data ( self ) list

Return the generic data types subscribed to.

Returns

list[DataType]

subscribed_instrument_close_prices ( self ) list

Return the close price instruments subscribed to.

Returns

list[InstrumentId]

subscribed_instrument_status_updates ( self ) list

Return the status update instruments subscribed to.

Returns

list[InstrumentId]

subscribed_instruments ( self ) list

Return the instruments subscribed to.

Returns

list[InstrumentId]

subscribed_order_book_deltas ( self ) list

Return the order book delta instruments subscribed to.

Returns

list[InstrumentId]

subscribed_order_book_snapshots ( self ) list

Return the order book snapshot instruments subscribed to.

Returns

list[InstrumentId]

subscribed_quote_ticks ( self ) list

Return the quote tick instruments subscribed to.

Returns

list[InstrumentId]

subscribed_tickers ( self ) list

Return the ticker instruments subscribed to.

Returns

list[InstrumentId]

subscribed_trade_ticks ( self ) list

Return the trade tick instruments subscribed to.

Returns

list[InstrumentId]

trader_id

The trader ID associated with the component.

Returns

TraderId

type

The components type.

Returns

type

unsubscribe ( self , DataType data_type ) void

Unsubscribe from data for the given data type.

Parameters

data_type ( DataType ) – The data type for the subscription.

venue

The clients venue ID (if not a routing client).

Returns

Venue or None

Enums

class BinanceSpotPermissions ( value )

Bases: enum.Enum

Represents Binance Spot/Margin trading permissions.

class BinanceSpotSymbolStatus ( value )

Bases: enum.Enum

Represents a Binance Spot/Margin symbol status.

class BinanceSpotTimeInForce ( value )

Bases: enum.Enum

Represents a Binance Spot/Margin order time in force.

class BinanceSpotEventType ( value )

Bases: enum.Enum

Represents a Binance Spot/Margin event type.

class BinanceSpotOrderType ( value )

Bases: enum.Enum

Represents a Binance Spot/Margin order type.

class BinanceSpotOrderStatus ( value )

Bases: enum.Enum

Represents a Binance order status.

Execution

class BinanceSpotExecutionClient ( loop : asyncio.events.AbstractEventLoop , client : nautilus_trader.adapters.binance.http.client.BinanceHttpClient , msgbus : nautilus_trader.msgbus.bus.MessageBus , cache : nautilus_trader.cache.cache.Cache , clock : nautilus_trader.common.clock.LiveClock , logger : nautilus_trader.common.logging.Logger , instrument_provider : nautilus_trader.adapters.binance.spot.providers.BinanceSpotInstrumentProvider , account_type : nautilus_trader.adapters.binance.common.enums.BinanceAccountType = BinanceAccountType.SPOT , base_url_ws : Optional [ str ] = None )

Bases: nautilus_trader.live.execution_client.LiveExecutionClient

Provides an execution client for the Binance Spot/Margin exchange.

Parameters
  • loop ( asyncio.AbstractEventLoop ) – The event loop for the client.

  • client ( BinanceHttpClient ) – The binance HTTP client.

  • msgbus ( MessageBus ) – The message bus for the client.

  • cache ( Cache ) – The cache for the client.

  • clock ( LiveClock ) – The clock for the client.

  • logger ( Logger ) – The logger for the client.

  • instrument_provider ( BinanceInstrumentProvider ) – The instrument provider.

  • account_type ( BinanceAccountType ) – The account type for the client.

  • base_url_ws ( str , optional ) – The base URL for the WebSocket client.

connect ( ) None

Abstract method (implement in subclass).

disconnect ( ) None

Abstract method (implement in subclass).

async generate_order_status_report ( instrument_id : nautilus_trader.model.identifiers.InstrumentId , client_order_id : Optional [ nautilus_trader.model.identifiers.ClientOrderId ] = None , venue_order_id : Optional [ nautilus_trader.model.identifiers.VenueOrderId ] = None ) Optional [ nautilus_trader.execution.reports.OrderStatusReport ]

Generate an order status report for the given order identifier parameter(s).

If the order is not found, or an error occurs, then logs and returns None .

Parameters
  • instrument_id ( InstrumentId ) – The instrument ID for the report.

  • client_order_id ( ClientOrderId , optional ) – The client order ID for the report.

  • venue_order_id ( VenueOrderId , optional ) – The venue order ID for the report.

Returns

OrderStatusReport or None

Raises

ValueError – If both the client_order_id and venue_order_id are None .

async generate_order_status_reports ( instrument_id : Optional [ nautilus_trader.model.identifiers.InstrumentId ] = None , start : Optional [ datetime.datetime ] = None , end : Optional [ datetime.datetime ] = None , open_only : bool = False ) List [ nautilus_trader.execution.reports.OrderStatusReport ]

Generate a list of order status reports with optional query filters.

The returned list may be empty if no orders match the given parameters.

Parameters
  • instrument_id ( InstrumentId , optional ) – The instrument ID query filter.

  • start ( pd.Timestamp , optional ) – The start datetime query filter.

  • end ( pd.Timestamp , optional ) – The end datetime query filter.

  • open_only ( bool , default False ) – If the query is for open orders only.

Returns

list[OrderStatusReport]

async generate_trade_reports ( instrument_id : Optional [ nautilus_trader.model.identifiers.InstrumentId ] = None , venue_order_id : Optional [ nautilus_trader.model.identifiers.VenueOrderId ] = None , start : Optional [ datetime.datetime ] = None , end : Optional [ datetime.datetime ] = None ) List [ nautilus_trader.execution.reports.TradeReport ]

Generate a list of trade reports with optional query filters.

The returned list may be empty if no trades match the given parameters.

Parameters
  • instrument_id ( InstrumentId , optional ) – The instrument ID query filter.

  • venue_order_id ( VenueOrderId , optional ) – The venue order ID (assigned by the venue) query filter.

  • start ( pd.Timestamp , optional ) – The start datetime query filter.

  • end ( pd.Timestamp , optional ) – The end datetime query filter.

Returns

list[TradeReport]

async generate_position_status_reports ( instrument_id : Optional [ nautilus_trader.model.identifiers.InstrumentId ] = None , start : Optional [ datetime.datetime ] = None , end : Optional [ datetime.datetime ] = None ) List [ nautilus_trader.execution.reports.PositionStatusReport ]

Generate a list of position status reports with optional query filters.

The returned list may be empty if no positions match the given parameters.

Parameters
  • instrument_id ( InstrumentId , optional ) – The instrument ID query filter.

  • start ( pd.Timestamp , optional ) – The start datetime query filter.

  • end ( pd.Timestamp , optional ) – The end datetime query filter.

Returns

list[PositionStatusReport]

submit_order ( self , SubmitOrder command ) void

Submit the order contained in the given command for execution.

Parameters

command ( SubmitOrder ) – The command to execute.

submit_order_list ( self , SubmitOrderList command ) void

Submit the order list contained in the given command for execution.

Parameters

command ( SubmitOrderList ) – The command to execute.

modify_order ( self , ModifyOrder command ) void

Modify the order with parameters contained in the command.

Parameters

command ( ModifyOrder ) – The command to execute.

sync_order_status ( self , QueryOrder command ) void

Request a reconciliation for the queried order which will generate an OrderStatusReport

cancel_order ( self , CancelOrder command ) void

Cancel the order with the client order ID contained in the given command.

Parameters

command ( CancelOrder ) – The command to execute.

cancel_all_orders ( self , CancelAllOrders command ) void

Cancel all orders for the instrument ID contained in the given command.

Parameters

command ( CancelAllOrders ) – The command to execute.

account_id

The clients account ID.

Returns

AccountId or None

account_type

The clients account type.

Returns

AccountType

base_currency

The clients account base currency (None for multi-currency accounts).

Returns

Currency or None

degrade ( self ) void

Degrade the component.

While executing on_degrade() , any exception will be logged and reraised. The component will remain in a DEGRADING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

dispose ( self ) void

Dispose of the component.

While executing on_dispose() , any exception will be logged and reraised. The component will remain in a DISPOSING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

fault ( self ) void

Fault the component.

This method is idempotent and irreversible. No other methods should be called after faulting.

While executing on_fault() , any exception will be logged and reraised. The component will remain in a FAULTING state.

Warning

Do not override.

If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.

classmethod fully_qualified_name ( type cls ) str

Return the fully qualified name for the components class.

Returns

str

References

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

generate_account_state ( self , list balances , list margins , bool reported , uint64_t ts_event , dict info=None ) void

Generate an AccountState event and publish on the message bus.

Parameters
  • balances ( list [ AccountBalance ] ) – The account balances.

  • margins ( list [ MarginBalance ] ) – The margin balances.

  • reported ( bool ) – If the balances are reported directly from the exchange.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the account state event occurred.

  • info ( dict [ str , object ] ) – The additional implementation specific account information.

async generate_mass_status ( lookback_mins : Optional [ int ] = None )

Generate an execution mass status report.

Parameters

lookback_mins ( int , optional ) – The maximum lookback for querying closed orders, trades and positions.

Returns

ExecutionMassStatus

generate_order_accepted ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , uint64_t ts_event ) void

Generate an OrderAccepted event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order accepted event occurred.

generate_order_cancel_rejected ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , unicode reason , uint64_t ts_event ) void

Generate an OrderCancelRejected event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • reason ( str ) – The order cancel rejected reason.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order cancel rejected event occurred.

generate_order_canceled ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , uint64_t ts_event ) void

Generate an OrderCanceled event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when order canceled event occurred.

generate_order_expired ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , uint64_t ts_event ) void

Generate an OrderExpired event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order expired event occurred.

generate_order_filled ( self, StrategyId strategy_id, InstrumentId instrument_id, ClientOrderId client_order_id, VenueOrderId venue_order_id, PositionId venue_position_id: Optional[PositionId], TradeId trade_id, OrderSide order_side, OrderType order_type, Quantity last_qty, Price last_px, Currency quote_currency, Money commission, LiquiditySide liquidity_side, uint64_t ts_event ) void

Generate an OrderFilled event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • trade_id ( TradeId ) – The trade ID.

  • venue_position_id (PositionId, optional with no default so None must be passed explicitly) – The venue position ID associated with the order. If the trading venue has assigned a position ID / ticket then pass that here, otherwise pass None and the execution engine OMS will handle position ID resolution.

  • order_side (OrderSide { BUY , SELL }) – The execution order side.

  • order_type ( OrderType ) – The execution order type.

  • last_qty ( Quantity ) – The fill quantity for this execution.

  • last_px ( Price ) – The fill price for this execution (not average price).

  • quote_currency ( Currency ) – The currency of the price.

  • commission ( Money ) – The fill commission.

  • liquidity_side (LiquiditySide { NONE , MAKER , TAKER }) – The execution liquidity side.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order filled event occurred.

generate_order_modify_rejected ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , unicode reason , uint64_t ts_event ) void

Generate an OrderModifyRejected event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • reason ( str ) – The order update rejected reason.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order update rejection event occurred.

generate_order_pending_cancel ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , uint64_t ts_event ) void

Generate an OrderPendingCancel event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order pending cancel event occurred.

generate_order_pending_update ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , uint64_t ts_event ) void

Generate an OrderPendingUpdate event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order pending update event occurred.

generate_order_rejected ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , unicode reason , uint64_t ts_event ) void

Generate an OrderRejected event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • reason ( datetime ) – The order rejected reason.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order rejected event occurred.

generate_order_submitted ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , uint64_t ts_event ) void

Generate an OrderSubmitted event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order submitted event occurred.

generate_order_triggered ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , uint64_t ts_event ) void

Generate an OrderTriggered event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order triggered event occurred.

generate_order_updated ( self , StrategyId strategy_id , InstrumentId instrument_id , ClientOrderId client_order_id , VenueOrderId venue_order_id , Quantity quantity , Price price , Price trigger_price , uint64_t ts_event , bool venue_order_id_modified=False ) void

Generate an OrderUpdated event and send it to the ExecutionEngine .

Parameters
  • strategy_id ( StrategyId ) – The strategy ID associated with the event.

  • instrument_id ( InstrumentId ) – The instrument ID.

  • client_order_id ( ClientOrderId ) – The client order ID.

  • venue_order_id ( VenueOrderId ) – The venue order ID (assigned by the venue).

  • quantity ( Quantity ) – The orders current quantity.

  • price ( Price ) – The orders current price.

  • trigger_price (Price, optional with no default so None must be passed explicitly) – The orders current trigger price.

  • ts_event ( uint64_t ) – The UNIX timestamp (nanoseconds) when the order update event occurred.

  • venue_order_id_modified ( bool ) – If the ID was modified for this event.

get_account ( self ) Account

Return the account for the client (if registered).

Returns

Account or None

id

The components ID.

Returns

ComponentId

is_connected

If the client is connected.

Returns

bool

is_degraded

Return whether the current component state is DEGRADED .

Returns

bool

is_disposed

Return whether the current component state is DISPOSED .

Returns

bool

is_faulted

Return whether the current component state is FAULTED .

Returns

bool

is_initialized

Return whether the component has been initialized (component.state >= INITIALIZED