import ccxt
import time
# List of exchanges to check for arbitrage
exchange_ids = [
'binance', 'okx', 'gateio', 'bitmex', 'bitget', 'bybit', 'kucoin',
'bitmart', 'mexc', 'huobi','exmo', 'coinex', 'bitvavo', 'bit2me'
]
# Initialize exchanges
exchanges = {}
for exchange_id in exchange_ids:
try:
exchange_class = getattr(ccxt, exchange_id)
exchange = exchange_class({
'enableRateLimit': True,
})
exchanges[exchange_id] = exchange
except Exception as e:
print(f"Error loading {exchange_id}: {e}")
# Markets to analyze for arbitrage
symbol = 'BTC/USDT', 'ETH/USDT', 'NEO/USDT', 'EURC/USDT', 'EURC/EUR', 'EURC/USDC',
'EURT/USDT'
def fetch_prices(symbol):
prices = {}
for name, exchange in exchanges.items():
try:
ticker = exchange.fetch_ticker(symbol)
bid = ticker.get('bid')
ask = ticker.get('ask')
if bid and ask:
prices[name] = {'bid': bid, 'ask': ask}
except Exception as e:
print(f"Error fetching ticker from {name}: {e}")
return prices
def find_arbitrage_opportunities(prices):
opportunities = []
for ex1, data1 in prices.items():
for ex2, data2 in prices.items():
if ex1 != ex2:
buy_price = data2['ask']
sell_price = data1['bid']
profit = sell_price - buy_price
if profit > 0:
opportunities.append({
'buy_from': ex2,
'sell_to': ex1,
'buy_price': buy_price,
'sell_price': sell_price,
'profit': profit
})
return sorted(opportunities, key=lambda x: x['profit'], reverse=True)
# Main script
if __name__ == "__main__":
while True:
print("Checking for arbitrage opportunities...")
prices = fetch_prices(symbol)
if prices:
opportunities = find_arbitrage_opportunities(prices)
for opp in opportunities[:5]: # Top 5
print(
f"Buy from {opp['buy_from']} at {opp['buy_price']:.2f}, "
f"Sell to {opp['sell_to']} at {opp['sell_price']:.2f}, "
f"Profit: {opp['profit']:.2f}"
)
else:
print("No price data found.")
time.sleep(30) # Wait before next check