btgsolutions_otcmarkets.websocket package
Submodules
btgsolutions_otcmarkets.websocket.market_data module
- class btgsolutions_otcmarkets.websocket.market_data.MarketDataStream(api_key: str, ssl: bool | None = True, **kwargs)[source]
Bases:
objectThis class connects with OTC Markets Market Data WebSocket, providing an easy way to access our real time market data feed.
Main use case:
>>> from btgsolutions_otcmarkets import MarketDataStream >>> ws = MarketDataStream( >>> api_key='YOUR_API_KEY', >>> )
>>> ws.run()
>>> ws.subscribe(['ZTEST01','ZTEST02'])
>>> ws.unsubscribe(['ZTEST01'])
>>> ws.close()
- Parameters:
api_key (str) – User identification key. Field is required.
ssl (bool) – Enable or disable ssl configuration. Field is not required. Default: True (enable).
- run(on_tob_update=None, on_market_status=None, on_open=None, on_error=None, on_close=None, reconnect=True)[source]
Initializes a connection to websocket and starts to receive high frequency news.
- Parameters:
on_tob_update (function) –
Called every time it receives a top of book update message.
- Arguments:
Top Of Book update message.
Field is not required.
Default: print message.
on_market_status (function) –
Called every time it receives a market status message.
- Arguments:
Market status message.
Field is not required.
Default: print message.
on_open (function) –
Called at opening connection to websocket.
Field is not required.
Default: prints ‘open connection’, in case of success.
on_error (function) –
Called when a error occurs.
- Arguments:
Exception object.
Field is not required.
Default: prints error.
on_close (function) –
Called when connection is closed.
- Arguments:
close_status_code.
close_msg.
Field is not required.
Default: prints ‘closed connection’.
reconnect (bool) – Try reconnect if connection is closed. Field is not required. Default: True.
btgsolutions_otcmarkets.websocket.order_entry module
- class btgsolutions_otcmarkets.websocket.order_entry.OrderEntry(api_key: str, investor_id: str, ssl: bool | None = True, **kwargs)[source]
Bases:
objectThis class connects with OTC Markets Order Entry WebSocket, providing an easy way to send orders.
Main use case:
>>> from btgsolutions_otcmarkets import OrderEntry >>> order_entry = OrderEntry( >>> api_key='YOUR_API_KEY', >>> investor_id='YOUR_INVESTOR_ID', >>> )
>>> order_entry.run()
>>> order_entry.create_new_order( order_temp_id='123', ticker='ZTEST01', rate=10.6, qty=11000, side='sell', req_id='1', )
>>> order_entry.replace_order( external_id='9ef1d212-5daf-439b-b51e-9801d8e492be', rate=6.72, qty=100, req_id='12', )
>>> order_entry.cancel_order( external_id='9ef1d212-5daf-439b-b51e-9801d8e492be', req_id='123', )
>>> order_entry.close()
- Parameters:
api_key (str) – User identification key. Field is required.
investor_id (str) –
Investor ID.
Field is required.
ssl (bool) – Enable or disable ssl configuration. Field is not required. Default: True (enable).
- cancel_order(external_id: str, req_id: str = '1')[source]
Cancel a DMA order.
- Parameters:
external_id (str) –
Order External ID, that remains throughout the order lifecycle.
Field is required.
req_id (str) –
Message request ID.
Field is not required.
Default value: ‘1’
- create_new_order(order_temp_id: str, ticker: str, rate: float, qty: int, side: str, req_id: str = '1')[source]
Create a new DMA order.
- Parameters:
order_temp_id (str) –
Temporary order ID. The temporary order ID will be used to identify the order requested by the client untill the same receives an Execution Report message informing the permanent order ID ‘external_id’.
Field is required.
ticker (str) –
Asset ticker symbol.
Field is required.
rate (float) –
Order rate.
Field is required.
qty (int) –
Order quantity.
Field is required.
side (str) –
Order side.
Field is required.
Available values: ‘buy’, ‘sell’.
req_id (str) –
Message request ID.
Field is not required.
Default value: ‘1’
- replace_order(external_id: str, rate: float, qty: int, req_id: str = '1')[source]
Replace a DMA order.
- Parameters:
external_id (str) –
Order External ID, that remains throughout the order lifecycle.
Field is required.
rate (float) –
Order rate.
Field is not required.
qty (int) –
Order quantity.
Field is not required.
req_id (str) –
Message request ID.
Field is not required.
Default value: ‘1’
- run(on_exec_report=None, on_acknowledgement=None, on_open=None, on_error=None, on_close=None, reconnect=True)[source]
Initializes a connection to websocket and starts to receive high frequency news.
- Parameters:
on_exec_report (function) –
Called every time it receives an order execution report message.
- Arguments:
Execution report message.
Field is not required.
Default: print message.
on_acknowledgement (function) –
Called every time it receives an acknowledgement message. An acknowledgement message is a feedback message sent from server, whenever a client sends a message to it.
- Arguments:
Acknowledgement message.
Field is not required.
Default: print message.
on_open (function) –
Called at opening connection to websocket.
Field is not required.
Default: prints ‘open connection’, in case of success.
on_error (function) –
Called when a error occurs.
- Arguments:
Exception object.
Field is not required.
Default: prints error.
on_close (function) –
Called when connection is closed.
- Arguments:
close_status_code.
close_msg.
Field is not required.
Default: prints ‘closed connection’.
reconnect (bool) – Try reconnect if connection is closed. Field is not required. Default: True.