-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
56 lines (46 loc) · 1.95 KB
/
app.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
import os
import secrets
from flask import Flask, render_template, request, flash
import main
from binance_api import fetch_available_pairs
import asyncio
from threading import Thread
app = Flask(__name__)
app.secret_key = secrets.token_hex(16) # Generates a random 32-character-long hexadecimal string
@app.route('/', methods=['GET', 'POST'])
def index():
results = None
currency_pairs = []
if request.method == 'POST':
currency_pairs = [
request.form['currency_pair_1'],
request.form['currency_pair_2'],
request.form['currency_pair_3'],
request.form['currency_pair_4'],
request.form['currency_pair_5'],
request.form['currency_pair_6']
]
if validate_currency_pairs(currency_pairs):
results = asyncio.run(main.run_analysis(currency_pairs))
no_arbitrage_bounds = results['no_arbitrage_bounds']
# Start real-time analysis in a separate thread
analysis_thread = Thread(target=main.start_real_time_analysis, args=(currency_pairs, no_arbitrage_bounds))
analysis_thread.start()
return render_template('index.html', results=results, currency_pairs=currency_pairs)
def validate_currency_pairs(currency_pairs):
available_pairs = fetch_available_pairs()
fiat_currencies = set()
btc_pairs = set()
for pair in currency_pairs:
if pair not in available_pairs:
flash(f"Invalid currency pair: {pair}. Please provide pairs available in the Binance API.", "danger")
return False
if 'BTC' in pair:
btc_pairs.add(pair)
fiat_currencies.add(pair.replace('BTC', ''))
if len(fiat_currencies) != 3 or len(btc_pairs) != 3:
flash("Please provide pairs that can form two different triangular arbitrages with two different FIAT currencies and BTC.", "danger")
return False
return True
if __name__ == '__main__':
app.run(debug=True)