
Build a python-based dydx pairs trading bot running in the cloud with AWS hosting and Telegram alerts, and apply co-integrated crypto spread and z-score signals.
Plan a three-phase approach to building a dydx pairs trading bot in Python, covering the strategy, co-integration, risk management, Telegram alerts, and cloud deployment.
Access a private crypto wizards discord and explore the course resources. Review the GitHub code for the dydx pairs trading bot built in Python.
Explore manual trading on dydx exchange, using market orders to enter and exit positions on testnet. Learn about layer two, zero knowledge rollup, and risk management while protecting capital.
Read Content Here (free links to help with course content) and Code Resources are attached here too
Explore trading the spread in co-integrated pairs using hedge ratio to form the spread, time trades with the z score, and review backtested vanilla strategies.
Understand the hedge ratio and how to compute the crypto spread by normalizing prices, using Bitcoin and Ethereum as examples, and keep trades USD-based.
Understand how half-life measures a spread's reversion speed and helps identify oscillating, zero-crossing pairs with positive returns for automated statistical arbitrage.
Homework: Please watch video on the "Kelly Criterion Crypto Wizards" via YouTube. This video is not available for uploading to Udemy.
Update the DyDx pairs trading bot with Python for version four, detailing new API key flows, the Nevermind library, and end-to-end cloud deployment.
Clone the GitHub repo, set up a Python virtual environment, install requirements, and configure environment variables to run the DYDX trading bot code.
Connect MetaMask to the Cipolla testnet, fund with faucet testnet ether, and securely export your secret phrase and Ethereum address to configure the dy dx trading library.
Learn to set up and test a dy dx pairs trading bot in python on testnet, using environment variables, indexer data, cointegration, and automated trade management.
Install Metamask on Chrome, enable test networks, switch to Gurley test network, and obtain test ether; export the private key to sign transactions programmatically for cloud bot operation.
Set up an http provider via alchemy to access blockchain data, create testnet and mainnet apps, and manage api keys for secure https connections.
Connect to dydx in python using Colab by installing dydx v3 and web3, importing libraries, and configuring testnet credentials. Validate the connection by querying account id and balance.
Fetch public candlestick data via an http endpoint for a market (BTC USD), using hourly candles and a small limit. Extract close prices for co integration in a pairs trading.
Query the dydx private api to fetch your position id, calculate an expiration from server time plus 70 seconds, and place a testnet market order.
Set up your development environment using VS Code, verify Python 3.x, create and activate a virtual environment, install dependencies from requirements.txt, and confirm Git is installed.
Set up a program folder and main.py, add a .env file and requirements.txt, then initialize a GitHub repository and a .gitignore to exclude sensitive data.
Define environment variables for the dydx pairs trading bot, including the private key, main net and testnet keys, dydx api key, api secret, and passphrase, with a production development switch.
Create a constants.py to centralize dydx bot configuration, pulling values from environment variables with python decouple, including mode, abort positions, co-integrated checks, place trades, thresholds, and mainnet/testnet keys.
Format prices to match the ded rest api, implement a format number helper (part 2), integrate with close all positions logic, and run the bot to close and manage orders.
Stage two pulls market prices, builds a historical candles table, evaluates co integration for pairs, and saves co integrated results to a CSV for reuse.
Define a get ISO times function to generate 100-hour slots, convert timestamps to ISO format, and build a times dict for 400 hours of hourly data from the current time.
Identify co integrated pairs and construct market prices for a Python-based trading bot running in the cloud. Schedule hourly or daily market price updates to avoid unnecessary data fetches.
Construct a market prices function that fetches historical candlesticks for each time frame, builds a timestamped close-price data frame, respects rate limits, and merges data from tradable perpetual markets.
Develop a cointegration function to identify co integrated pairs for pairs trading, calculate the half life and z score, estimate hedge ratios with statsmodels OLS, and save the results.
Store co integrated pairs by looping through prices and save the results as a co integrated pairs csv containing base market, quote market, hedge ratio, and half life.
Stage three builds a bot agent class to open multiple trades using recent candlestick and close price data, evaluate with z-scores, prevent duplicate positions, and save trades.
Initialize a bot agent class to manage opening and monitoring pair trades between two cryptos, including defining a check order status function and storing order details for both markets.
Develop the bot to fetch recent price data, identify trading opportunities, and place and save open trades, as a foundation before exit strategies.
Pass recent price data and z-scores into the bot agent to place trades on the DYDX test net, then track live trades in a json file and manage positions.
Learn to manage exits for open trades in a DYDX pairs trading bot, including loading active positions and implementing manage_trade_exits to close positions on a z-score cross.
Explore implementing and testing exit logic for a pairs trading bot, including z-score based triggers, hedge ratios, and safe close of positions.
connect your Python bot to Telegram and create a Telegram bot to send notifications, then deploy the code to GitHub for cloud hosting.
Set up Telegram messaging for your dydx trading bot by creating a new bot with BotFather, choosing a unique name ending in bot, and saving the access token.
Send a start-up notification and telegram alerts from the bot, using structured messages with error codes, and prepare the project for cloud deployment via git.
Sign up for AWS to host your DYDX bot in the cloud, leveraging the free tier for up to 750 hours and precise run time control with EC2.
Set up an AWS EC2 instance by creating a security group, adding an SSH rule on port 22 for any source IP, and launching the instance.
Learn how to interact with the DYDX Layer 2 Ethereum trading exchange using Python by running a trading bot on AWS Elastic Cloud Compute (EC2). Your bot will be highly advanced in trading in being able to take advantage of statistical arbitrage opportunities in Pairs Trading. This is a great strategy to know given how closely linked many cryptocurrencies are in price behaviour.
Your bot will be able to message you via Telegram so that you can receive live notifications on how well the script is performing (or not performing). It will enable you to:
- Automatically close all existing open positions
- Find cointegrated (linked Crypto pairs) for trading and ascertain whether statistically it makes sense to open a trade
- Manage any open positions and look for exits
- Find and place new trading opportunities
- Alert you if something goes wrong
- Run your bot without your laptop whilst you sleep
Our Python code will interact heavily with the DYDX API and to ensure you understand how to use the API, a cheatsheet has been provided to fast-track you onto being able to use DYDX.
To do this course, you should have used Python in the past, having created and installed packages in a virtual environment and be familiar with basic programming concepts.
That said, you do NOT need to be an advanced Python programmer or advanced trader to do this course. Our strategy uses statistical arbitrage for Pairs Trading, of which you will be walked through the strategy and theory in the beginning in reasonable detail so you understand the nature of what is going on.
See you in Class!
About Your Instructor: Shaun McDonogh has been developing tools for traders for over 5 years at Crypto Wizards and is very close to where the action is in regards to trading Crypto. Shaun's passion is developing applications and teaching others and is delighted to bring this information to the retail market.