Skip to main content

Trading

A trading call is accepted by the API if and only if it can be transmitted to the Lime trading platform. If the connection with the Lime trading platform is down or congested, calls are synchronously rejected. Any trading method returns an enumeration of CallStatus: 0=Success, 1=ConnectionBusy, 2=ConnectionError.

Note that initially accepted orders can still be rejected by the Lime trading platform or an exchange during further processing. In such cases, the rejects are submitted via a specified callback, asynchronously, to the client application via the callback thread. If the call returns any value other than Success, an order callback is not generated.

New equity order

def place_order(self,
order_id: int, symbol: str, quantity: int,
price: Decimal, side: Side, route: str,
properties: OrderProperties = None) -> CallStatus:

This method places an equity order to a given route or venue. The primary order characteristics are specified explicitly, more specific details can be set on OrderProperties structure

parameterdescription
int order_idThe order id generated by client, must be unique throughout the day.
string symbolSecurity symbol.
int quantityA non-negative quantity of shares.
Decimal priceThe API assumes a limit order when a positive price value is submitted. If the price is explicitly set to lime_trading_api.MARKET_PRICE, the order is interpreted as a market order.
lime_trading_api.Side sideSide enumeration, which is 0=Buy, 1=Sell, 2=SellShort, 3=SellShortExempt, 4=BuyToCover. In some cases the server may re-mark the value.
string routeThe route or venue to send the order to.
lime_trading_api.OrderProperties propertiesDetails of the order, can be very specific to the desired route or to current account settings.

New option order

def place_options_order(self,
order_id: int, symbol: USOptionSymbol, quantity: int,
price: Decimal, side: Side,
position_effect: PositionEffect, route: str,
properties: USOptionsOrderProperties = None) -> CallStatus:

Places an option order to a given route or venue. The primary order characteristics are specified explicitly, more specific details can be set on USOptionsOrderProperties structure

parameterdescription
int order_idThe order id generated by client, must be unique throughout the day.
lime_trading_api.USOptionSymbol symbolThe option symbol, a more complex structure discussed below.
int quantityA non-negative quantity of contracts. Note that options are usually quoted with multiplier of 100. For example, buying 1 priced at $1.5 will actually spend $150.
Decimal priceThe API assumes a limit order unless the price is set to lime_trading_api.MARKET_PRICE. Note that the value of zero is a valid value for Options.
lime_trading_api.Side sideSide enumeration, which is 0=Buy, 1=Sell. Other values make no sense for Options.
lime_trading_api.PositionEffect position_effectOpening or closing position. The values are 0=Nil, 1=Open, 1=Close.
string routeThe route or venue to send the order to.
lime_trading_api.USOptionsOrderProperties propertiesDetails of the order, can be very specific to the desired route or to current account settings.

A USOptionSymbol structure has three different constructors, no args will initialize everything to nothing and variables must be set afterwards. 1 arg will assume an OSI string as a parameter and parse it and put it into the correct instance variables. Can also be constructed by sending all parameters as separate arguments.

# Example instantiating USOptionSymbol structure using OSI symbol standard
options_symbol = USOptionSymbol("MSFT 120821C00022500")

# results in following:
options_symbol.base_symbol = MSFT
options_symbol.put_or_call = 1
options_symbol.expiration_year = 12 (2012)
options_symbol.expiration_month = 8
options_symbol.expiration_day = 21
options_symbol.strike_price = 22500
fielddescription
string base_symbolUnderlying security symbol
Enum put_or_call0 for Puts, 1 for calls
int expiration_yearExpiration year, 2 digits
int expiration_monthExpiraton month
int expiration_dayExpiration day of month
int strike_priceStrike price scaled by 1000, for example $22.5 is expressed as 22500

Cancelling orders

def cancel_order(self, order_id: int) -> CallStatus:
pass

def cancel_all_open_orders(self) -> CallStatus:
pass

A client can cancel a specific order identified by order_id. The ID for the cancel request itself is generated by the Lime trading platform.If an order has been partially filled, the cancel request will be submitted for the unfilled portion of the order. A client can also cancel all open orders for the account at once. Both methods apply to all supported order types and asset classes.

Another way to cancel all orders is to set cancel_on_disconnect flag when creating the API instance instructing Lime to cancel all active orders when connection goes down. It is usually used as safety feature.