Building a crypto pairs trading strategy in Python. Part 2

Mean-reverting strategies for crypto

Fadai Mammadov
5 min readApr 29, 2024

Introduction

This is the second and the last article of the series on crypto pairs trading. The first article can be found at the following link: https://medium.com/coinmonks/building-a-crypto-pairs-trading-strategy-in-python-6b1572d77344

This is the code we have written so far:

import requests
import json
import pandas as pd
import datetime as dt
import numpy as np
# list of about 100 tokens traded on Binance
lst = ["BTC", "ETH", "CAKE", "DOT", "MANA", "SAND", "AVAX", "ALGO", "ATOM", "MATIC", "BNB",
"SNX", "THETA", "GRT", "LINK", "SHIB", "DOGE", "VET", "AXS", "SOL", "FIL", "TRX",
"FTM", "FARM", "LTC", "ETC", "NEAR", "ALICE", "ICP", "EGLD", "UNI", "ADA", "XRP",
"ZEC", "QUICK", "BAT", "ENJ", "GALA", "1INCH", "SLP", "COMP", "ROSE", "ONT", "AAVE",
"ANKR", "NEO", "XTZ", "WTC", "OCEAN", "IOTA", "IOTX", "COTI", "XLM", "QTUM", "AR",
"LINA", "BETA", "CELO", "ZIL", "HBAR", "OGN", "ILV", "ALPHA", "RVN", "KAVA","YGG",
"AUDIO", "STORJ", "ATA", "DODO", "POND", "CHZ", "YFI", "SUPER", "NKN", "INJ", "EOS",
"LRC", "ARPA", "LPT", "XVS", "KLAY", "CRV", "LTO", "MKR", "ONE", "RNDR",
"FOR", "BICO","SYS", "CELR", "ALPACA", "BLZ", "DUSK", "KNC", "PAXG", "DOCK",
"MBOX", "BADGER", "ZRX", "IDEX", "FIDA"]
commissions = 0.01
slippage = 0.001
bid_ask_spread = 0.05
def create_df():
pair = "USDT"
root_url = 'https://api.binance.com/api/v3/klines'
interval = '1d'
close_prices = pd.DataFrame()…

--

--