We've provided support for 2 environment tools: venv and pyenv-virtualenv.
If you use python alias, run:
source scripts/env.sh venv
If you use python3 alias, run:
source scripts/env.sh venv --python3
If you use python alias, run:
source scripts/env.sh pyenv
If you use python3 alias, run:
source scripts/env.sh pyenv --python3
Run the following commands inside an admin powershell.
If you use python alias, run:
. scripts/env.sh venv
If you use python3 alias, run:
. scripts/env.sh venv --python3
If for whatever reason the script doesn't work, you can manually set up the environment by creating a virtual environment and installing the dependencies inside scripts/requirements.in.
To start the docker container:
docker-compose up --build
Once inside /app in the container:
source scripts/env.sh venv
Note the container mounts your local file system of the repo to /app in the container.
If you need to add dependencies, add them to scripts/requirements.in and run the same commmand you used to setup the environment.
main.py is the entry point for the strategy. It is responsible for:
- Initializing the TradingClient
- Initializing the SharedState and Prioritizer using the exchange client
- Initializing the Strategy
- Passing the Strategy to the TradingClient (will run trigger based strategy)
- Starting the Strategy (subscribe to exchange websocket streams and run strategy)
There are 2 triggers:
- Orderbook Update: This trigger is called when the orderbook is updated. The SharedState will contain all updated info. Call the quoter to place trades.
- Portfolio Update: This trigger is called when a portfolio snapshot (positions, balance, open orders, etc.) is sent. The SharedState will contain all updated info. Call the quoter to place trades.
We have provided a simple quoter that performs client-side rate limiting in Prioritizer. You can modify the place order function to implement prioritization logic and decide whether or not to submit trades.
The orderbook is stored in the SharedState. The orderbook is, by default, filtered to exclude your own orders. You can access both the raw orderbook if needed, though.
To access the depth of a bid for a particular ticker and price level:
depth = shared_state.orderbooks[ticker]["bids"][price_level]
Likewise, to access the depth of an ask:
depth = shared_state.orderbooks[ticker]["asks"][price_level]
The user portfolio is stored in the SharedState. You can access the your positions, balance, open orders, etc. The portfolio is stored as a dictionary.
To access the balance of a particular ticker:
balance = shared_state.portfolio.positions[ticker]
To access the open orders of a particular ticker:
open_orders = shared_state.portfolio.orders[ticker]
To access the balance:
balance = shared_state.portfolio.balance
To access the PnL:
pnl = shared_state.portfolio.pnl