Skip to content

quantpylib.hft.oms

OMS

__init__(gateway, exchanges=None, pending_timeout=5000, refresh_orders_snapshot=60 * 3, referesh_positions_snapshot=60 * 3)

Intialize the Order Management System object.

Parameters:

Name Type Description Default
gateway Gateway

Initialized gateway object.

required
exchanges list

The list of exchanges to subscribe to. If None, use the clients in the gateway.

None

add_clock_callback(callback, name='CLOCK', interval_ms=500) async

Add a callback to the event loop that is triggered every interval_ms. Can be used for clock-based trading agents. Callback is shutdown when OMS is cleaned up.

Parameters:

Name Type Description Default
callback coroutine

The callback to trigger.

required
name str

The name of the callback. Defaults to 'CLOCK'.

'CLOCK'
interval_ms int

The interval in milliseconds. Defaults to 500.

500

cancel_order(exc, ticker=None, oid=None, cloid=None) async

Cancel an order by order id or client order id. If both oid and cloid are None, cancel all open orders for given ticker.

Parameters:

Name Type Description Default
exc str

The exchange.

required
ticker str

The ticker. Defaults to None.

None
oid str

The order id. Defaults to None.

None
cloid str

The client order id. Defaults to None.

None

cleanup() async

Clean up the OMS object.

cloid_query(exc, cloid)

Query order information by client order id.

Parameters:

Name Type Description Default
exc str

The exchange.

required
cloid str

The client order id.

required

common_lot_precision(ex1, ticker1, ex2, ticker2)

Get the lot precision for trading on two different exchanges.

Parameters:

Name Type Description Default
ex1 str

The first exchange.

required
ticker1 str

The first ticker.

required
ex2 str

The second exchange.

required
ticker2 str

The second ticker.

required

common_min_notional(ex1, ticker1, ex2, ticker2)

Get the minimum notional trade on two different exchanges.

Parameters:

Name Type Description Default
ex1 str

The first exchange.

required
ticker1 str

The first ticker.

required
ex2 str

The second exchange.

required
ticker2 str

The second ticker.

required

common_price_precision(ex1, ticker1, ex2, ticker2)

Get the price precision for trading on two different exchanges.

Parameters:

Name Type Description Default
ex1 str

The first exchange.

required
ticker1 str

The first ticker.

required
ex2 str

The second exchange.

required
ticker2 str

The second ticker.

required

contract_specs(exc, ticker)

Get the contract specifications for a given exchange and ticker.

Parameters:

Name Type Description Default
exc str

The exchange.

required
ticker str

The ticker.

required

get_all_balances() async

Get the balances for all exchanges. Uses HTTP request.

get_all_equities() async

Get the equity for all exchanges. Uses HTTP request.

get_balance(exc) async

Get the balance for a given exchange. Uses HTTP request.

get_position(exc, ticker)

Get the position for a given exchange and ticker. Uses socket.

Parameters:

Name Type Description Default
exc str

The exchange.

required
ticker str

The ticker.

required

hedge_order(maker_order, hedge_order, trigger_after_ms=0) async

Place a maker-taker order. The maker order is the order that is being hedged. The taker order is the order that hedges the maker order - taker order has no amount specified, size executed is contingent on the size of maker fills. Each order are dictionaries - and are passed as named arguments (**order) into the gateway as per the quantpylib.gateway.executor.limit_order and quantpylib.gateway.executor.market_order methods respectively.

hedge_portfolio_delta(hedge_on='', default_on='', blacklisted_on=set(), by=markets.MARGIN_TOTAL, ord_type=markets.ORDER_TYPE_MARKET, **kwargs) async

init(include_funding=False) async

Initialize the OMS object with information such as exchange contract trading specifications and metadata. To be called after the OMS has been created.

lagged_price(exc, ticker)

Get the lagged price for a given exchange and ticker.

Parameters:

Name Type Description Default
exc str

The exchange.

required
ticker str

The ticker.

required

limit_order(round_to_specs=False, **kwargs) async

Place a limit order. If round_to_specs is True, round the order amount to the lot precision. Updates the orders page maintained by the OMS with a PENDING status.

Parameters:

Name Type Description Default
round_to_specs bool

Round the order amount to the lot precision. Defaults to False.

False
**kwargs

The order parameters. Parameter usage is same as the quantpylib.gateway.executor.limit_order method.

{}

lot_precision(exc, ticker)

Get the lot precision for a given exchange and ticker.

Parameters:

Name Type Description Default
exc str

The exchange.

required
ticker str

The ticker.

required

market_order(round_to_specs=False, **kwargs) async

Place a market order. If round_to_specs is True, round the order amount to the lot precision. Updates the orders page maintained by the OMS with a PENDING status.

Parameters:

Name Type Description Default
round_to_specs bool

Round the order amount to the lot precision. Defaults to False.

False
**kwargs

The order parameters. Parameter usage is same as the quantpylib.gateway.executor.market_order method.

{}

min_notional(exc, ticker)

Get the minimum notional required to trade for a given exchange and ticker.

Parameters:

Name Type Description Default
exc str

The exchange.

required
ticker str

The ticker.

required

oid_query(exc, oid)

Query order information by order id.

Parameters:

Name Type Description Default
exc str

The exchange.

required
oid str

The order id.

required

order_delta_hedge()

Hedge order logic. Fill sizes on maker exchange that are not compatible with trading rules on taker exchange are hedged as much as possible, and size differences are submitted to a hedge balance that waits for future arriving fills to be hedged.

orders_get(exc, **kwargs) async

Get the orders for a given exchange. Uses HTTP request.

Parameters:

Name Type Description Default
exc str

The exchange.

required

orders_get_all() async

Get the orders for all exchanges.Uses HTTP request.

orders_mirror(exc, on_update=None, on_delta=None) async

Mirror the orders for a given exchange. Uses socket.

Parameters:

Name Type Description Default
exc str

The exchange.

required
on_update coroutine

The update handler receives order page snapshots. Defaults to None.

None
on_delta coroutine

The delta handler receives order page changes. Defaults to None.

None

orders_peek(exc)

Return the quantpylib.standards.portfolio.Orders object maintained for a given exchange.

positions_get(exc, **kwargs) async

Get the positions for a given exchange. Uses HTTP request.

Parameters:

Name Type Description Default
exc str

The exchange.

required

positions_get_all() async

Get the positions for all exchanges. Uses HTTP request.

Returns:

Name Type Description
dict

Dictionary of positions for all exchanges.

positions_get_by_base()

Gets mapping from base asset to exchange positions for all exchanges using the mirrored positions.

positions_get_net_base()

Gets the net positions for each base asset across all exchanges using the mirrored positions.

positions_mirror(exc, on_update=None, on_delta=None) async

Mirror the positions for a given exchange. Uses socket.

Parameters:

Name Type Description Default
exc str

The exchange.

required
on_update coroutine

The update handler. Defaults to None.

None
on_delta coroutine

The delta handler. Defaults to None.

None

positions_peek(exc)

Return the quantpylib.standards.portfolio.Positions object maintained for a given exchange.

price_precision(exc, ticker)

Get the price precision for a given exchange and ticker.

Parameters:

Name Type Description Default
exc str

The exchange.

required
ticker str

The ticker.

required

rand_cloid(exc, **kwargs)

Generate a client order id.

Parameters:

Name Type Description Default
exc str

The exchange.

required
**kwargs

Exchange wrapper specific keyword arguments.

{}

rounded_lots(exc, ticker, amount, **kwargs)

Round an amount to the lot precision for a given exchange and ticker.

Parameters:

Name Type Description Default
exc str

The exchange.

required
ticker str

The ticker.

required
amount Decimal

The amount to round.

required

rounded_price(exc, ticker, price, **kwargs)

Round a price to the price precision for a given exchange and ticker.

Parameters:

Name Type Description Default
exc str

The exchange.

required
ticker str

The ticker.

required
price Decimal

The price to round.

required