Trading¶
Place an order¶
The order is accepted immediately, the method returns assigned id. The order is still validated with exactly same logic as in validate method and is sent to market on successful validation pass. Otherwise, the order will reject asynchronously and you can query its status by calling the order details method.
1 from _decimal import Decimal
2 from pprint import pprint
3
4 from lime_trader import LimeClient
5 from lime_trader.models.trading import Order, TimeInForce, OrderType, OrderSide
6
7 client = LimeClient.from_file(file_path="credentials.json")
8
9 accounts = client.account.get_balances() # need to get account numbers first
10
11 account_number = accounts[0].account_number # get account number of first account in a list
12
13 order = Order(account_number=account_number,
14 symbol="AAPL",
15 quantity=Decimal(1),
16 price=Decimal("140.0"),
17 stop_price=Decimal("159.00"),
18 time_in_force=TimeInForce.DAY,
19 order_type=OrderType.LIMIT,
20 side=OrderSide.BUY,
21 exchange="auto",
22 client_order_id="01HWYX297HG2J9V607VSY4GQ3S",
23 tag="order #12"
24 )
25 placed_order_response = client.trading.place_order(order=order)
26 pprint(placed_order_response)
Validate order¶
The method verifies an order and responds with the validation message if the order can not be placed at the moment. The order is not sent to market.
1 from _decimal import Decimal
2 from pprint import pprint
3
4 from lime_trader import LimeClient
5 from lime_trader.models.trading import Order, TimeInForce, OrderType, OrderSide
6
7 client = LimeClient.from_file(file_path="credentials.json")
8
9 accounts = client.account.get_balances() # need to get account numbers first
10
11 account_number = accounts[0].account_number # get account number of first account in a list
12
13 order = Order(account_number=account_number,
14 symbol="AAPL",
15 quantity=Decimal(1),
16 price=Decimal("140.0"),
17 stop_price=Decimal("159.00"),
18 time_in_force=TimeInForce.DAY,
19 order_type=OrderType.LIMIT,
20 side=OrderSide.BUY,
21 exchange="auto",
22 client_order_id="01HWYX297HG2J9V607VSY4GQ3S",
23 tag="order #12"
24 )
25 validation_response = client.trading.validate_order(order=order)
26 pprint(validation_response)
Get Order Details¶
Get the order details by the specified order id:
1 from pprint import pprint
2
3 from lime_trader import LimeClient
4
5 client = LimeClient.from_file(file_path="credentials.json")
6 details = client.trading.get_order_details(order_id="123456789")
7 pprint(details)
Get Active Orders¶
Get list of active orders for the account
1 from pprint import pprint
2
3 from lime_trader import LimeClient
4
5 client = LimeClient.from_file(file_path="credentials.json")
6
7 accounts = client.account.get_balances() # need to get account numbers first
8
9 account_number = accounts[0].account_number # get account number of first account in a list
10
11 validation_response = client.trading.get_active_orders(account_number=account_number)
12 pprint(validation_response)
Cancel an order¶
Cancels order by id, providing optional cancel reason:
1 from pprint import pprint
2
3 from lime_trader import LimeClient
4
5 client = LimeClient.from_file(file_path="credentials.json")
6
7 accounts = client.account.get_balances() # need to get account numbers first
8
9 account_number = accounts[0].account_number # get account number of first account in a list
10
11 cancel_response = client.trading.cancel_order(order_id="123456789", message="Optional cancel reason")
12 pprint(cancel_response)
Estimate fee charges¶
The method returns estimated fees for specified order parameters, breaking down all charges by type:
1 from _decimal import Decimal
2 from pprint import pprint
3
4 from lime_trader import LimeClient
5 from lime_trader.models.accounts import TradeSide
6
7 client = LimeClient.from_file(file_path="credentials.json")
8
9 accounts = client.account.get_balances() # need to get account numbers first
10
11 account_number = accounts[0].account_number # get account number of first account in a list
12
13 fees = client.trading.estimate_fee_charges(account_number=account_number, symbol="AAPL",
14 quantity=Decimal("150"),
15 side=TradeSide.SELL, price=Decimal("100.50"))
16 pprint(fees)