
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.
Build a cloud-running Python bot for statistical arbitrage in crypto using a pairs trading strategy. Set realistic expectations and learn the principles of decentralized trading with divide, avoiding get-rich-quick promises.
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
Learn how to implement a crypto pairs trading strategy using statistical arbitrage and cointegration, trading the spread between co-integrated assets with Python and statsmodels.
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.
Apply disciplined position sizing using the Kelly criterion concepts to protect capital, minimize trading costs, and pursue a statistical arbitrage edge for the dydx pairs trading bot.
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.
Access DYDX automated trading by connecting metamask on the Gurley test network, then extract and safeguard API keys, private keys, and secrets from local storage for later use.
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.
Explore the public and private DYDX API endpoints for markets, order books, and candles. Learn to fetch data with parameters and place market orders using the Python client.
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.
Plan the bot's core steps: connect to the client, implement market orders with abort capability, build a price table for co-integrated crypto pairs, and set a 24/7 trading loop.
Create a modular dydx trading bot in python by wiring a connections module, importing config and client libraries, and validating the cloud deployment connection.
Builds an abort all positions function in a Python dydx trading bot, canceling open orders, fetching markets and open positions, and placing market orders to close positions.
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.
the BotAgent class completion implements check order status by ID, opens two market orders (base and quote), and guards against canceled or failed trades with robust error handling.
Develop the bot to fetch recent price data, identify trading opportunities, and place and save open trades, as a foundation before exit strategies.
Build and test a DYDX pairs trading bot in Python that uses z-score triggers, hedge ratios, half-life, and recent price data to open or exit trades in the cloud.
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.
Run a continuous test of the DYDX pairs trading bot by looping trades, managing exits, opening and closing positions, and validating co-integrated pairs on a testnet.
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.
Learn to send your first Telegram bot message via a url using bot token and chat id, test in a browser, and automate with Python requests.
Learn to send telegram bot messages from python by building a send_message function that uses requests.get with a url, token and chat_id from env vars, and test via main.py.
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.
Deploy your bot to aws ec2 using the default vpc in North Virginia, then fetch code from GitHub, set env vars, install requirements, and configure cron for 5 minutes.
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.
Launch an EC2 instance for the trading bot, choose Ubuntu or Amazon Linux on x86, select a t2 micro free-tier eligible instance, and proceed without a key pair.
Connect to your EC2 instance, manage its state by stopping or rebooting, and install Python 3.10 on Ubuntu with sudo apt-get update and sudo apt-get install.
Update requirements.txt, install python and pip, clone the repo to a cloud instance, install dependencies, configure a .env, and run the bot to verify a live trade.
Make code updates to keep the bot and its json file in sync after aborting all positions, test locally, and push changes to AWS and EC2 for automatic execution.
Set up cron on an ec2 instance to run a Python script at scheduled times, with logging and automatic daily restarts for a reliable cloud trading bot.
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.