A collection of scripts for trading stocks and crypto on Alpaca Markets and Binance.
This neural network trading bot trades stocks (long/short) and crypto (long-only) daily at market open/close. It successfully grew my portfolio from $38k to $66k over several months in favorable conditions at the end of 2024.
The bot uses the Amazon Chronos model for time series forecasting.
Breakdown of how it works
https://www.youtube.com/watch?v=56c3OhqJDJk&list=PLVovYLPm_feCybDdwSeXUCCTHZaLPoXZJ&index=9
npm install -g selenium-side-runner
npm install -g chromedriver
sudo apt-get install libsqlite3-dev -y
sudo apt-get update
sudo apt-get install libxml2-dev
sudo apt-get install libxslt1-dev
Clear out positions at bid/ask (much more cost-effective than market orders):
PYTHONPATH=$(pwd) python ./scripts/alpaca_cli.py close_all_positions
Cancel an order with a linear ramp:
PYTHONPATH=$(pwd) python scripts/alpaca_cli.py backout_near_market BTCUSD
Ramp into a position:
PYTHONPATH=$(pwd) python scripts/alpaca_cli.py ramp_into_position ETHUSD
Using the Linux at
command:
echo "PYTHONPATH=$(pwd) python ./scripts/alpaca_cli.py ramp_into_position TSLA" | at 3:30
Show/cancel jobs with atq
:
atq
atrm 1
atq
Cancel any duplicate orders/(need to run this incase of bugs):
PYTHONPATH=$(pwd) python ./scripts/cancel_multi_orders.py
- Proper datastores refreshed data
- Dynamic config
Neural networks:
- Select set of trades to make
- Margin
- Take profit
- Roughly at EOD only to close stock positions violently
Check if numbers are flipped and if so, do something?
Crypto can only be traded non-margin for some time, cant be shorted in alpaca, so this server should be used that loops/does market orders in Binance instead which is also better low fee:
./.env/bin/gunicorn -k uvicorn.workers.UvicornWorker -b :5050 src.crypto_loop.crypto_order_loop_server:app --timeout 1800 --workers 1
uv pip install requirements.txt
python trade_stock_e2e.py
pytest .
PYTHONPATH=$(pwd) python backtest_test3_inline.py
better forecasting transformers better trading alg as on avg its good and accurate but following the sign is loosing some of the power of the model - need a better fuzzy strategy that better exploits the fact that the model is correct on average
You can support us by purchasing Netwrck an AI agent maker and art generator.
- Art Generator/photo editor: AIArt-Generator.art
- Helix.app.nz a dashboard builder
- Text-Generator.io an API server for vision language and speech models