Order Management
Fetching Orders
Retrieve a list of orders with optional filters using the get_orders() method:
orders = client.get_orders(
expiration_timestamp=expiration_timestamp,
instrument_id=instrument_id,
instrument_name=instrument_name,
instrument_type=instrument_type,
is_expired=is_expired,
option_type=option_type,
ordering=ordering,
status=status,
strike_price=strike_price,
limit=limit,
offset=offset
)
Parameters:
expiration_timestamp(Optional[Union[str, List[str]]]): Filter by expiration timestamp (default is None)instrument_id(Optional[Union[int, List[int]]]): Filter by instrument ID (default is None)instrument_name(Optional[Union[str, List[str]]]): Filter by instrument name (default is None)instrument_type(Optional[Union[InstrumentType, List[InstrumentType]]]): Filter by instrument type (default is None)is_expired(Optional[bool]): Filter by expired status (default is None)option_type(Optional[Union[OptionType, List[OptionType]]]): Filter by option type (default is None)ordering(Optional[str]): Ordering of the results (default is None)status(Optional[Union[OrderStatus, List[OrderStatus]]]): Filter by order status (default is None)strike_price(Optional[Union[float, List[float]]]): Filter by strike price (default is None)limit(Optional[int]): Limit the number of results (default is None)offset(Optional[int]): Offset the results (default is None)
The returned list contains Order objects with the following attributes:
id: The unique identifier of the order, as an intinstrument: The instrument associated with the order, as aSimpleInstrumentobjectaverage_price_matched: The average price matched in the order, as a floatprice: The price of the order, as a floatquantity: The quantity in the order, as a floatquantity_filled: The quantity filled in the order, as an intside: The side of the order (BUY or SELL), as anOrderSideobjectcreated_at: The timestamp when the order was created, as a stringstatus: The status of the order, as anOrderStatusobjectorder_type: The type of the order, as anOrderTypeobjectis_liquidation: Whether the order is a liquidation or not, as a booluser: The identifier of the user who placed the order, as an int
Placing Orders
Place one or multiple orders on the options exchange using the place_order() method:
orders_to_place = [OrderInput(quantity=2, side=OrderSide.SELL, order_type=OrderType.LIMIT, price=100, instrument_id=1)]
placed_orders = client.place_order(orders_to_place)
Parameters:
orders: A single order (OrderInput) or a list of orders (List[OrderInput]) to be placed
The returned list contains Order objects, each containing information about the placed order(s). These objects' attributes are the same as those listed for the get_orders() method.
Canceling Orders
Cancel a single order by its order_id using the cancel_order() method:
order_id = "1234567890"
response = client.cancel_order(order_id)
Parameters:
order_id: The ID of the order that should be canceled, as a string
The returned dictionary contains a status code and a message confirming the order cancellation.
Canceling All Orders
Cancel all orders that match the given filters using the cancel_all_orders() method:
response = client.cancel_all_orders(
expiration_timestamp=expiration_timestamp,
instrument_id=instrument_id,
instrument_name=instrument_name,
instrument_type=instrument_type,
strike_price=strike_price
)
Parameters:
expiration_timestamp(Optional[Union[str, List[str]]]): The expiration timestamp of the options to be canceled, by default Noneinstrument_id(Optional[Union[int, List[int]]]): The ID of the instrument(s) whose orders should be canceled, by default Noneinstrument_name(Optional[Union[str, List[str]]]): The name of the instrument(s) whose orders should be canceled, by default Noneinstrument_type(Optional[Union[str, List[str]]]): The type of instrument(s) whose orders should be canceled, by default Nonestrike_price(Optional[Union[float, List[float]]]): The strike price(s) of the options to be canceled, by default None
The returned dictionary contains a status code and a message confirming the cancellation of all matching orders.
Reducing Order Quantity
Reduce the quantity of a single order by the given amount using the reduce_order() method:
order_id = 1234567890
quantity_to_reduce = 1
response = client.reduce_order(order_id, quantity_to_reduce)
Parameters:
order_id: The ID of the order that should be reduced, as an intquantity: The amount by which the order quantity should be reduced, as an int
The returned dictionary contains a status code and a message confirming the reduction of the order quantity.
Updated almost 3 years ago
