-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
105 lines (74 loc) · 2.59 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from flask import Flask, render_template, request, flash, redirect, jsonify
import config, csv
from binance.client import Client
from binance.enums import *
from flask_cors import CORS
import helperFunctions
app = Flask(__name__)
CORS(app)
# A secret key is required to avoid cross scripting
app.secret_key = config.SECRET_KEY
client = Client(config.API_KEY, config.API_SECRET)
# Using Flask and Jinja for stuff. Jinja is basically html with extra programming stuff like looping
@app.route('/home')
def home():
return "<b> Home Sweet Test </b>"
@app.route('/')
def index():
title = 'CoinSentient'
account = client.get_account()
balances = account['balances']
exchange_info = client.get_exchange_info()
orders = client.futures_get_all_orders()
#trades = client.get_recent_trades(symbol='BTCUSDT',limit=50)
# print (orders)
# print(exchange_info)
symbols = exchange_info['symbols']
return render_template('index.html', title=title, my_balances = balances, symbols = symbols, orders = orders)
@app.route('/buy', methods=['POST'])
def buy():
print(request.form)
try:
order = client.create_order(symbol=request.form['symbol'],
side=SIDE_BUY,
type = ORDER_TYPE_MARKET,
quantity = request.form['quantity'])
except Exception as e:
flash(e.message, "error")
return redirect('/')
@app.route('/sell')
def sell():
return 'sell'
@app.route('/strategy')
def strategy():
print(request.form)
try:
order = client.create_order(symbol=request.form['symbol'],
side=SIDE_BUY,
type = ORDER_TYPE_MARKET,
quantity = request.form['quantity'])
except Exception as e:
flash(e.message, "error")
return redirect('/')
@app.route('/settings')
def settings():
return 'settings'
@app.route('/aggr')
def route():
return render_template("aggr/dist/index.html", title = 'Projects')
@app.route('/history')
def history():
candlesticks = client.get_historical_klines("BTCUSDT", Client.KLINE_INTERVAL_15MINUTE, "1 Aug, 2021", helperFunctions.returnTime())
processed_candlesticks = []
for data in candlesticks:
# creating a dictionary to parse the data from binance in a format that lightweight charts want
candlestick = {
"time": data[0] / 1000,
"open": data[1],
"high": data[2],
"low": data[3],
"close": data[4]
}
processed_candlesticks.append(candlestick)
processed_candlesticks = jsonify(processed_candlesticks)
return processed_candlesticks