Ledger instances allow the ML team to forward-test their algorithms. An API and database are hosted on the PC that allows members to create instances of Ledgers and tie specific algorithms to trade on them.
-
create_ledgerTo create a ledger.Expected arguments:
name: unique name of algorithmtickerstotrack: two tickers (e.g. (AAPL, GOOG))algo_path: path to algorithm from theprojectsdirectory (ex. algo_path=harv-extension)updatetime: time interval for updates (minutes)end: lifespan of instance (days)
Example command:
https://watstreet/create_ledger?name=krishalgo&tickerstotrack=AAPL,GOOG&algo_path=https://github.com/Wat-Street/money-making/tree/main/projects/ledger_test_model&updatetime=1&end=100 -
view_ledgerTo retrieve details of a specific ledger.Expected arguments:
name: name of ledger.
Example command:
https://watstreet/view_ledger?name=krishalgo -
delete_ledgerTo delete a ledger.Expected arguments:
name: name of ledger.
Example command:
https://watstreet/delete_ledger?name=krishalgo -
update_ledger(Protected Endpoint) To update a ledger's trades and holdings. Requires API key in X-API-Key header.Expected arguments (JSON body):
name: name of ledgertrades: list of new tradesholding: updated holdings dictionary
Example command:
curl -X PATCH https://watstreet/update_ledger \ -H "Content-Type: application/json" \ -H "X-API-Key: your-api-key" \ -d '{ "name": "krishalgo", "trades": [{"type": "buy", "ticker": "AAPL", "price": 176, "quantity": 8}], "holding": {"AAPL": 8, "GOOG": 0} }' -
start_ledger(Protected Endpoint) To start a ledger instance. Requires API key in X-API-Key header.Expected arguments:
name: name of ledger to start
Example command:
curl -X GET https://watstreet/start_ledger?name=krishalgo \ -H "X-API-Key: your-api-key"
The two standard commands are:
trade(): runs the algorithm and, based on current ownership of stocks and balance, will return a tradeupdate_book_status(book_status): gives the trading algorithm the info it needs to make trades (portfolio and balance)
Thus, models' interfaces should look like so:
class Model:
def update_book_status(self, book_status):
"""Gives the trading algorithm the info it needs to make trades (portfolio and balance, retrieved from the view_book endpoint)"""
pass
def trade(self):
"""Runs the algorithm and, based on current ownership of stocks and balance, will return a trade. The result of this trade is updated into the Ledger."""
pass
Some considerations:
- It is the responsibility of the algorithm to not violate the ledger (ie. sell more than you own or buy more than the money you have)
- In case the algorithm violates the ledger, return an exception. The algorithm must be able to deal with these standard exceptions.
KEEP THIS UPDATED AT ALL TIMES.
{
"trades": [
{"type": "buy", "ticker": "AAPL", "price": 176, "quantity": 8},
{"type": "sell", "ticker": "AAPL", "price": 157, "quantity": 7},
{"type": "buy", "ticker": "GOOG", "price": 112, "quantity": 9}
],
}
{
"trades": [
{"type": "buy", "ticker": "AAPL", "price": 176, "quantity": 8},
{"type": "sell", "ticker": "AAPL", "price": 157, "quantity": 7},
{"type": "buy", "ticker": "GOOG", "price": 112, "quantity": 9}
],
"holding": {
"GOOG": 9,
"AAPL": 1,
},
"value": [
"1999-01-08 04:05:06": 100000,
"1999-01-08 04:10:06": 100800,
"1999-01-08 04:15:06": 109000,
],
"balance": 96,485
}
- API Backend (Flask)
- Database (PostgreSQL, in Rebbi's local env)
Database name:
postgresfor now Tables: (wip)
order_books_v2trades
- Scheduler (Celery?) (wip)

