Trading

The Trading API is used to provide users with access to the trading capabilities of the BidFX platform. Although the API can be used independently of pricing, it is recommended that trading be accessed via the top-level Session class of the BidFX API.

TradingAPI

class bidfx.TradingAPI(config_parser: configparser.ConfigParser)

This class is the top-level API interface for accessing the trading services of BidFX.

Parameters

config_parser (configparser.ConfigParser) – The API configuration settings.

property rest

Gets the REST trading interface.

Returns

the RestTradingAPI

property ws

Gets the WebSocket trading interface.

Returns

the WebSocketTradingAPI

property username

Get the configured username used for sending trades.

Returns

The username.

Return type

str

RESTTradeClient

class bidfx.trading.client.RESTTradeClient(host, port, username, password)
property running
Returns

True if session is running

start()

Start the REST session.

stop()

Stops the REST session.

add_response_listener(listener)

Add listener which is called after getting a response

Parameters

listener (def func(orders: List[FxOrder])) – A listener function

add_error_listener(listener)

Add listener which is called after getting an error

Parameters

listener – Function with signature: def func(error: TradeError)

WSTradeClient

class bidfx.trading.client.WSTradeClient(base_url, username, password)

Websocket client for subscribing to trading information.

Parameters
  • base_url – The URL for the web socket.

  • username – The client username.

  • password – The client password.

start(message=None)

Starts the web socket session.

Parameters

message – The message to send.

static do_open(ws)

Function which is called at opening websocket.

Parameters

ws – WebSocketApp object

static do_message(ws: bidfx.trading.client.WSTradeClient, message)

Function which is called when received data.

Parameters
  • ws – WebSocketApp object

  • message – utf-8 string which we get from the server.

static do_error(ws, error)

Function which is called when we get error.

Parameters
  • ws – WebSocketApp object

  • error – exception object.

static do_close(ws)

Function which is called when closed the connection.

Parameters

ws – WebSocketApp object

ExecutionsSubscription

class bidfx.trading.client.ExecutionsSubscription(base_url, username, password)

Websocket client for subscribing to the executions stream

Parameters
  • base_url – The URL for the web socket.

  • username – The client username.

  • password – The client password.

OrderSubscription

class bidfx.trading.client.OrderSubscription(base_url, username, password)

Websocket client for subscribing to the orders stream

Parameters
  • base_url – The URL for the web socket.

  • username – The client username.

  • password – The client password.