def get_data(): database = sqliteDb() currency = request.args.get('currency') timeframe = request.args.get('timeframe') indicator_name = request.args.get('indicator_name') indicator_period = request.args.get('indicator_period') candle = request.args.get('candle') response = database.getData(currency, timeframe) database.close() df = pd.DataFrame.from_records( response, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume']) if indicator_name == 'EMA': indicator = ta.ema(df['close'], length=int(indicator_period)) elif indicator_name == 'RSI': indicator = ta.rsi(df['close'], length=int(indicator_period)) indicator = indicator.fillna('undefined') dict = indicator.to_dict() result = { 'open value': response[99 - int(candle)][1], 'high value': response[99 - int(candle)][2], 'low value': response[99 - int(candle)][3], 'close value': response[99 - int(candle)][4], 'timestamp': response[99 - int(candle)][0], indicator_name: dict[99 - int(candle)] } return json.dumps(result)
def get_moment_last_spray(): spray_moments = list(sqliteDb().get_spray_moments()) # we assume the last record in the database is the latest moment_last_spray = spray_moments[len(spray_moments) - 1] format = '%Y-%m-%d %H:%M:%S' return (datetime.strptime(moment_last_spray, format))
def predictions(): accept_header = request.headers.get('Accept') predictions = sqliteDb().get_predictions() if 'application/json' in accept_header: return jsonify(predictions) elif 'text/html' in accept_header: columns = list(predictions[0].keys()) rows = [] for prediction in predictions: rows.append([*prediction.values()]) return render_template('predictions.html', predictions=predictions, columns=columns, rows=rows) else: return ( "I'm sorry but support for that content type has not been implemented yet." )
def get_last_prediction(): predictions = sqliteDb().get_predictions() last_prediction = predictions[len(predictions) - 1] return last_prediction
from binance_api import Binance import datetime import json from db import sqliteDb api = Binance( 'AMWNxQ9DJ7t7ZKEAR8qT5boPYrdUIQHXUXBb7BgGb4fgKP53yK0YXaG9XPPkrJXU', 'tSr4OaBiH0IXqXUNvVzsSRXyYpG314a03Yhltx9NQa9ok6M9h96YJwnu5BDMYGoa') pattern = [["ETHUSDT", "LTCUSDT", "XLMUSDT", "XMRUSDT", "XEMUSDT"], ['1h', '1d']] db = sqliteDb() print('recording to db... ' + datetime.datetime.now().strftime("%m/%d/%Y, %H:%M:%S")) for currency in pattern[0]: for interval in pattern[1]: responses = api.call_api( **{ 'command': 'klines', 'symbol': currency, 'interval': interval, 'limit': 100 }) db.addToDb(currency, interval, json.dumps(responses)) db.close() print('finished ' + datetime.datetime.now().strftime("%m/%d/%Y, %H:%M:%S"))