Skip to content

quantpylib.standards.portfolio

Order

__init__(exc=None, oid=None, cloid=None, ticker=None, amount=None, price=None, price_match=None, tif=None, ord_type=None, reduce_only=None, tp=None, sl=None, ord_status=None, filled_sz=Decimal('0'), last_fill_sz=None, timestamp=_time(units='ms'), **kwargs)

Initialize an Order object.

Parameters:

Name Type Description Default
exc str

Alias for the exchange client.

None
oid str

The order id. Defaults to None.

None
cloid str

The client order id. Defaults to None.

None
ticker str

The ticker symbol. Defaults to None.

None
amount Decimal

The quantity of contracts. Defaults to None.

None
price Decimal

The price of the order. Defaults to None.

None
price_match Decimal

The price of the order that was matched. Defaults to None.

None
tif str

The time in force. Defaults to None.

None
ord_type str

The order type. Defaults to None.

None
reduce_only bool

Whether the order is a reduce-only order. Defaults to None.

None
tp Decimal

The take profit price. Defaults to None.

None
sl Decimal

The stop loss price. Defaults to None.

None
ord_status str

The order status. Defaults to None.

None
filled_sz Decimal

The filled size. Defaults to Decimal('0').

Decimal('0')
last_fill_sz Decimal

The last filled size. Defaults to None.

None
timestamp int

The timestamp of the order. Defaults to _time(units='ms').

_time(units='ms')

as_dict(test=False)

Convert the Order object to a dictionary.

is_alive()

Check if the order is alive.

Orders

__init__(orders=None, delta_handlers=None, default_args=None)

Initialize an Orders object.

Parameters:

Name Type Description Default
orders list

The list of orders. Defaults to None.

None
delta_handlers list

List of coroutine handlers for order updates. Defaults to None.

None
default_args dict

Default arguments for orders. Defaults to None.

None

as_dict()

Convert the Orders object to a dictionary where oid is known.

as_list(test=False)

Convert the Orders object to a list.

get_ask_orders(ticker)

Get the ask orders for a ticker sorted with head of list being closest to top of book

Parameters:

Name Type Description Default
ticker str

The ticker symbol.

required

get_bid_orders(ticker)

Get the bid orders for a ticker sorted with head of list being closest to top of book

Parameters:

Name Type Description Default
ticker str

The ticker symbol.

required

get_orders(ticker=None)

Get the snapshot of alive orders.

pending_asks(ticker)

Get the pending ask orders for a ticker sorted with head of list being closest to top of book

Parameters:

Name Type Description Default
ticker str

The ticker symbol.

required

pending_bids(ticker)

Get the pending bid orders for a ticker sorted with head of list being closest to top of book

Parameters:

Name Type Description Default
ticker str

The ticker symbol.

required

Position

__init__(ticker, amount, entry, **kwargs)

Initialize a Position object.

Parameters:

Name Type Description Default
ticker str

The ticker symbol.

required
amount Decimal

The quantity of contracts.

required
entry Decimal

The entry price.

required

as_dict()

Convert the Position object to a dictionary.

get_amount()

Get the signed size of position held.

get_entry()

Get the entry price.

Positions

__init__(positions=None, delta_handlers=None, default_args=None)

Initialize a Positions object.

Parameters:

Name Type Description Default
positions dict

The dictionary of positions. Defaults to None.

None
delta_handlers list

List of coroutine handlers for position updates. Defaults to None.

None

add_delta_handler(handler)

Add a handler for position updates.

Parameters:

Name Type Description Default
handler coroutine

The handler for position updates.

required

add_positions(pos_dict, reset=True)

Add a dictionary of positions.

Parameters:

Name Type Description Default
pos_dict dict

The dictionary of positions.

required
reset bool

Whether to reset the current positions. Defaults to True.

True

as_dict()

Convert the Positions object to a dictionary.

Returns:

Name Type Description
dict

The dictionary of positions.

as_list()

Convert the Positions object to a list.

Returns:

Name Type Description
list

The list of positions.

get_ticker_amount(ticker)

Get the signed size of a position.

Parameters:

Name Type Description Default
ticker str

The ticker symbol.

required

update_position(ticker, amount=None, fill_amount=None, entry=None, fill_entry=None, **kwargs) async

Update a position and broadcast the change to the delta handlers.

Parameters:

Name Type Description Default
ticker str

The ticker symbol.

required
amount Decimal

The new position size. Defaults to None.

None
fill_amount Decimal

The filled size. Defaults to None.

None
entry Decimal

The new entry price. Defaults to None.

None
fill_entry Decimal

The filled entry price. Defaults to None.

None