-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
67 lines (48 loc) · 1.66 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
from flask import Flask, render_template, request, flash, redirect, jsonify
from flask_cors import CORS
import config, csv, datetime
from binance.client import Client
from binance.enums import *
app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "*"}})
app.secret_key = b''
client = Client(config.API_KEY, config.API_SECRET, tld="us")
@app.route('/')
def index():
title = 'Coinview'
account = client.get_account()
balances = account['balances']
exchange_info = client.get_exchange_info()
symbols = exchange_info['symbols']
return render_template('index.html', title=title, my_balances=balances, symbols=symbols)
@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('/settings')
def settings():
return 'settings'
@app.route('/history')
def history():
candlesticks = client.get_historical_klines("BTCUSDT", Client.KLINE_INTERVAL_15MINUTE, "1 Mar, 2021", "24 May, 2021")
processed_candlesticks = []
for data in candlesticks:
candlestick = {
"time": data[0] / 1000,
"open": data[1],
"high": data[2],
"low": data[3],
"close": data[4]
}
processed_candlesticks.append(candlestick)
return jsonify(processed_candlesticks)