Account

Get Account Balances

Get balance information for all user accounts as a list and print it to console:

1 import pprint
2
3 from lime_trader import LimeClient
4
5 client = LimeClient.from_file(file_path="credentials.json")
6 balances = client.account.get_balances()
7 pprint.pprint(balances)

Get Account Positions

Get list of all account positions:

 1 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 positions = client.account.get_positions(account_number=account_number)
12 pprint.pprint(positions)

Get Page Of Account Trades

Get first page of 20 trades of account trades history on current day, ordered by descending timestamp:

 1 import datetime
 2 import pprint
 3
 4 from lime_trader.models.page import PageRequest
 5 from lime_trader import LimeClient
 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 trades = client.account.get_trades(account_number=account_number, date=datetime.date.today(),
14                                    page=PageRequest(page=1, size=20))
15 pprint.pprint(trades)

Iterate Through Pages Of Account Trades

Iterate all pages, starting from page 2 and size of 3, of account trades history on current day, ordered by descending timestamp:

 1 import datetime
 2 import pprint
 3
 4 from lime_trader.models.page import PageRequest
 5 from lime_trader import LimeClient
 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 for trades_page in client.account.iterate_trades(account_number=account_number, date=datetime.date.today(),
14                                                  start_page=PageRequest(page=2, size=3)):
15     pprint.pprint(trades)

Get Routes

Get list of all routes available for specified account:

 1 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 routes = client.account.get_routes(account_number=account_number)
12 pprint.pprint(routes)

Get Page Of Transactions Journal

Get first page of 20 items in transaction journal for last 7 days:

 1 import datetime
 2 import pprint
 3
 4 from lime_trader.models.page import PageRequest
 5 from lime_trader import LimeClient
 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 journal = client.account.get_transactions_journal(account_number=account_number,
14                                              start_date=datetime.date.today() - datetime.timedelta(days=7),
15                                              end_date=datetime.date.today(),
16                                              page=PageRequest(page=1, size=20))
17 pprint.pprint(journal)

Iterate Through Pages Of Transactions Journal

Iterate all pages, starting from page 2 and size of 10, of transaction journal for previous 7 days:

 1 import datetime
 2 import pprint
 3
 4 from lime_trader.models.page import PageRequest
 5 from lime_trader import LimeClient
 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 for journal_page in client.account.iterate_transactions_journal(
14         account_number=account_number,
15         start_date=datetime.date.today() - datetime.timedelta(days=7),
16         end_date=datetime.date.today(),
17         start_page=PageRequest(page=2, size=10)):
18     pprint.pprint(journal_page)

Stream account feed

Stream Account feed data

 1 from typing import Any
 2
 3 from lime_trader import LimeClient
 4 from lime_trader.handlers.account_feed_handler import AccountFeedHandler
 5 from lime_trader.models.accounts import AccountFeedError, AccountTrade, AccountPositions, AccountDetails
 6 from lime_trader.models.trading import OrderDetails
 7
 8
 9 class MyHandler(AccountFeedHandler):
10
11     def on_account_balance(self, account: AccountDetails):
12         print(account)
13
14     def on_account_position(self, position: AccountPositions):
15         print(position)
16
17     def on_account_order_status_change(self, order: OrderDetails):
18         print(order)
19
20     def on_account_trade_execution(self, trade: AccountTrade):
21         print(trade)
22
23     def on_stream_error(self, error: AccountFeedError):
24         print(f"Stream error: {error}")
25
26     def on_client_error(self, error: Any):
27         print(f"Client error: {error}")
28
29
30 client = LimeClient.from_file(file_path="credentials.json")
31 accounts = client.account.get_balances()  # need to get account numbers first
32
33 account_number = accounts[0].account_number  # get account number of first account in a list
34
35 stream = client.account.stream_account_feed(callback_client=MyHandler())
36
37 # subscribe to changes
38 stream.subscribe_orders(account_number=account_number)
39 stream.subscribe_positions(account_number=account_number)
40 stream.subscribe_balance(account_number=account_number)
41 stream.subscribe_trades(account_number=account_number)
42
43 # subscribe to non-existing account
44 # we expect stream error
45 stream.subscribe_balance(account_number="NON_EXISTING_ACCOUNT")