-
Notifications
You must be signed in to change notification settings - Fork 10
/
Arbitrage_Bot.py
49 lines (35 loc) · 1.68 KB
/
Arbitrage_Bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from api_bot import *
import copy
def compare(first_exchange,second_exchange):
#set the min arbitrage percentage we will consider
arbi_list = {}
threshold = 2
upper = 30
for first in first_exchange:
for second in second_exchange:
if first['symbol'] == second['symbol']:
bid_on_first = float(first['bid'])
ask_on_first = float(first['ask'])
bid_on_second = float(second['bid'])
ask_on_second = float(second['ask'])
bid_ask_on_first = (bid_on_first/ask_on_second - 1)*100 #If we sell on first and buy on second
bid_ask_on_second = (bid_on_second/ask_on_first - 1)*100 #If we buy on first and sell on second
if (bid_ask_on_first) > threshold and bid_ask_on_first < upper:
arbi_list[(first['symbol'],"Buy " + second['exchange'] + " Sell " + first['exchange'])] = str(round(bid_ask_on_first,2)) + '%'
elif (bid_ask_on_second) > threshold and (bid_ask_on_second) < upper:
arbi_list[(first['symbol'],"Buy " + first['exchange'] + " Sell " + second['exchange'])] = str(round(bid_ask_on_second,2)) + '%'
return arbi_list
list = [binance(),huobi(),ftx(),okex(),bitfinex(),kucoin()]
def execution(list):
arbitrage_list = []
deepcopy_list = copy.deepcopy(list)
ii = 0
for i in list:
list = list[1:]
for k in list:
if k != i:
ii += len(compare(i,k))
if len(compare(i,k)) != 0:
arbitrage_list.append(compare(i,k))
return arbitrage_list
(execution(list))