-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
75 lines (57 loc) · 1.9 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Arbitrage Cryptocurrency
# Use of CCXT Library
# Use of N-Hayward Algorithm to visualize arbitrage opportunities in Python/Flask
# Anthony Peters, Franz Nastor, Peter Radev, Jack Hudanick, Tim Abbenhaus, Collin Jones
import ccxt
import numpy as np
import networkx as nx
import logic
from firebase import firebase
import routes
import matplotlib.pyplot as plt
# Loads in our Exchange
# Loads in currency_pairs and adds them to a list with BTC/USD as last item
# Creates Graph
exchange = ccxt.binanceus()
exchange.load_markets()
currency_pairs = exchange.symbols
currency_pairs.sort()
G = nx.DiGraph()
# Loads ask and bid price holder for the exchange and currency pairs
ask = np.zeros(5)
bid = np.zeros(5)
# Replace currency in the list function
substring = 'USDT'
substring2 = 'BUSD'
substring3 = '/BTC'
logic.replace_currency(substring, currency_pairs)
logic.replace_currency(substring2, currency_pairs)
logic.replace_currency(substring3, currency_pairs)
# Creates and appends edges to the graph with a calculated weight
n = 0
j = 0
while n < len(currency_pairs):
book = exchange.fetch_order_book(currency_pairs[n], 5)
ask = book['asks'][0][0]
while j < len(currency_pairs):
book = exchange.fetch_order_book(currency_pairs[j], 5)
bid = book['bids'][0][0]
weight = ask / bid
edge = [currency_pairs[n], currency_pairs[j], weight]
if edge[0] != edge[1] and edge[0][0:3] != edge[1][0:3]:
G.add_edge(edge[0], edge[1], weight=edge[2])
j += 1
n += 1
j = 0
G.add_nodes_from(currency_pairs)
print(G.nodes)
print(G.number_of_nodes())
print(G.edges.data())
print(G.number_of_edges())
#Graph = nx.draw_circular(G)
#plt.show()
firebase = firebase.FirebaseApplication("https://crypto-arbitrage-6575e.firebaseio.com/", "")
firebase.delete('crypto-arbitrage-6575e', "Opportunities")
cycles = logic.cycles_algorithm(G)
logic.n_hayward(G, cycles)
routes.__call__()