def insert(self, intervals, newInterval): if len(intervals) == 0: return [newInterval] r = [] overlapWithNewInterval = Interval(newInterval.start, newInterval.end) didAddNewInterval = False for i in intervals: if (i.start < overlapWithNewInterval.start and i.end < overlapWithNewInterval.start): r.append(i) elif (i.start < overlapWithNewInterval.start and i.end >= overlapWithNewInterval.start and i.end <= overlapWithNewInterval.end): overlapWithNewInterval.start = i.start elif (i.start < overlapWithNewInterval.start and i.end > overlapWithNewInterval.end): return intervals elif (i.start >= overlapWithNewInterval.start and i.end <= overlapWithNewInterval.end): pass elif (i.start >= overlapWithNewInterval.start and i.start <= overlapWithNewInterval.end and i.end >= overlapWithNewInterval.end): overlapWithNewInterval.end = i.end else: # hxl: i is after overlapWithNewInterval if didAddNewInterval == False: r.append(overlapWithNewInterval) didAddNewInterval = True r.append(i) # hxl: It's possible that the new interval is not added yet! if didAddNewInterval == False: r.append(overlapWithNewInterval) didAddNewInterval = True return r
def start(self, *args, **kwargs): self.particleEffect.clearToInitial() self.currT = 0 Interval.start(self, *args, **kwargs)
def start(self,*args,**kwargs): self.particleEffect.clearToInitial() self.currT = 0 Interval.start(self,*args,**kwargs)
def index(): def clock(start): """ Prints out the elapsed time when called from start. """ send_order() print("elapsed: {:0.3f} seconds", format(time.time() - start)) # Create an interval. interval = Interval(90, clock, args=[ time.time(), ]) print("Starting Interval, press CTRL+C to stop.") interval.start() exchange_id = 'binance' exchange_class = getattr(ccxt, exchange_id) exchange = exchange_class({ 'apiKey': 'QfjdE0edd0npewwOnbKd3OGGvQbnrVifLHIMDY7B2JiasKP2GkAktukgtM6walTP', 'secret': 'zVmxgLUJn863sZeRfG683Wg6YQld42w6t8gPIadtaX8paMOVqrsO2FgYT1DgmLSc', 'timeout': 30000, 'enableRateLimit': True, 'urls': { 'api': { 'public': 'https://fapi.binance.com/fapi/v1', 'private': 'https://fapi.binance.com/fapi/v1', }, } }) ohlcv = exchange.fetch_ohlcv('BTC/USDT') cnx = mysql.connector.connect(host='localhost', database='binance_profiles', user='******', password='******') cur = cnx.cursor() # Read the orders again and print them stmt_select = "SELECT symbolid, size, price, usdvalue FROM orders WHERE side='sell'" cur.execute(stmt_select) records = cur.fetchall() cur.close() cur = cnx.cursor() stmt_selectst = "SELECT usdvalue FROM orders WHERE side='sell'" cur.execute(stmt_selectst) recordss = cur.fetchall() cur.close() sum = 0.0001 for x in recordss: mystring = str(' '.join(map(str, (x)))) print('Sell USDValue', mystring) sum = sum + float(mystring) sumsell = abs(sum) print('Sum Sell', sumsell) cur = cnx.cursor() stmt_selectb_strategies = "SELECT * FROM main_strategy" cur.execute(stmt_selectb_strategies) r_strategies = cur.fetchall() cur.close() cur = cnx.cursor() stmt_selectb = "SELECT symbolid, size, price, usdvalue FROM orders WHERE side='buy'" cur.execute(stmt_selectb) recordsb = cur.fetchall() cur.close() cur = cnx.cursor() stmt_selectbt = "SELECT usdvalue FROM orders WHERE side='buy'" cur.execute(stmt_selectbt) recordssb = cur.fetchall() cur.close() sums = 0.0001 for x in recordssb: mystringsb = str(' '.join(map(str, (x)))) print('Buy USDValue', mystringsb) sums = sums + float(mystringsb) sumbuy = sums print('Sums Zote Za Kubuy', sums) total = abs(sumsell) + sumbuy print('Sums Zote Za Kubuy na za Kusell', total) #buytotalperc=1 buytotalperc = round((sumbuy / total) * 100, 4) #datasellsperc=1 datasellsperc = (sumsell / total) * 100 print(datasellsperc) print(buytotalperc) data_c = () c_type = 'buy' amount = sumbuy percentage = buytotalperc data_c = (c_type, amount, percentage) print(data_c) stmt_insert = "\ INSERT INTO computations \ (computations_type, \ amount, \ percentage) VALUES (%s, %s, %s) \ ON DUPLICATE KEY UPDATE \ computations_type = VALUES(computations_type), \ amount = VALUES(amount), \ percentage = VALUES(percentage)" #stmt_insert = "INSERT INTO orders (symbol, symbolid, size, side, price, usdvalue) VALUES (%s, %s, %s, %s, %s, %s)" cur = cnx.cursor() cur.execute(stmt_insert, data_c) cnx.commit() cur.close() data_c = () c_type = 'sell' amount = sumsell percentage = datasellsperc data_c = (c_type, amount, percentage) print(data_c) stmt_insert = "\ INSERT INTO computations \ (computations_type, \ amount, \ percentage) VALUES (%s, %s, %s) \ ON DUPLICATE KEY UPDATE \ computations_type = VALUES(computations_type), \ amount = VALUES(amount), \ percentage = VALUES(percentage)" #stmt_insert = "INSERT INTO orders (symbol, symbolid, size, side, price, usdvalue) VALUES (%s, %s, %s, %s, %s, %s)" cur = cnx.cursor() cur.execute(stmt_insert, data_c) cnx.commit() cur.close() cg = CoinGeckoAPI() usd_value_json = cg.get_price(ids='bitcoin', vs_currencies='usd') print('USD Value JSON', usd_value_json) usd_value_coin = usd_value_json['bitcoin'] print('USD Value Coin', usd_value_coin) lastPrice = float(usd_value_coin['usd']) #usd_value = lastPrice*size print('BTC Price Fom CoinGeckoAPI', lastPrice) current_btc_price_value = lastPrice print('current_btc_price_value', current_btc_price_value) select_stmt = "SELECT percentage FROM main_strategy WHERE %(price_last_btc)s BETWEEN low_btc_price AND high_btc_price" cur = cnx.cursor() cur.execute(select_stmt, {'price_last_btc': current_btc_price_value}) strategy_records = cur.fetchall() cnx.commit() cur.close() percentage_from_strategy = 0.0 for x in strategy_records: percentage_from_strategy = str(' '.join(map(str, (x)))) #sums=sums+float(mystringsb) percentage_from_strategys = float(percentage_from_strategy) print('percentage_from_strategys', percentage_from_strategys) buy_difference = '' sell_difference = '' buy_difference_amount = 0 sell_difference_amount = 0 mycursor = cnx.cursor(dictionary=True) mycursor.execute( "SELECT total FROM previous_orders WHERE computations_type='buy'") amount_c = mycursor.fetchone() buyprevioustotal = amount_c['total'] print('Previous Amount Buy', buyprevioustotal) mycursor = cnx.cursor(dictionary=True) mycursor.execute( "SELECT amount FROM computations WHERE computations_type='buy'") amount_ccc = mycursor.fetchone() amount_c_bcc = amount_ccc['amount'] print('Current Amount Buy', amount_c_bcc) mycursor = cnx.cursor(dictionary=True) mycursor.execute( "SELECT percentage FROM computations WHERE computations_type='buy'") amount_p = mycursor.fetchone() buypreviousperc = amount_p['percentage'] print('amount_p', buypreviousperc) mycursor = cnx.cursor(dictionary=True) mycursor.execute( "SELECT total FROM previous_orders WHERE computations_type='sell'") amount_c_s_s = mycursor.fetchone() amount_c_s = round(amount_c_s_s['total'], 4) print('Previous Amount Sell', amount_c_s) mycursor = cnx.cursor(dictionary=True) mycursor.execute( "SELECT amount FROM computations WHERE computations_type='sell'") amount_cccbb = mycursor.fetchone() sellscurrenttotal = amount_cccbb['amount'] print('Current Amount Sell', sellscurrenttotal) mycursor = cnx.cursor(dictionary=True) mycursor.execute( "SELECT percentage FROM computations WHERE computations_type='sell'") amount_p_s_s = mycursor.fetchone() sellscurrentperc = round(abs(amount_p_s_s['percentage']), 4) print('amount_p_s', sellscurrentperc) total_database = amount_c_s + buyprevioustotal print('Total From Previous Assets Amount', total_database) total_database2 = amount_c_bcc + abs(sellscurrenttotal) print('Total in the Current Assets Amount', total_database2) amount_p_b = round((amount_c_bcc / total_database) * 100, 4) print('Adjusted Buy Percentage', amount_p_b) sellscurrentperc = round((abs(sellscurrenttotal) / total_database2) * 100, 4) print('Adjusted Sell Percentage', sellscurrentperc) print( '----------------------------------------------------------------------------------------' ) print('Buy Previous % that I want to use', buypreviousperc) use = 100 - amount_p_b print('Buy Previous % that I want to use', use) print( '----------------------------------------------------------------------------------------' ) adjustedbuytotalperc = round((amount_c_bcc / total_database2) * 100, 4) buypreviousperc = round((buyprevioustotal / total_database) * 100, 4) #p = (60-40)/5 #for i in numpy.arange(40, 60, p): #print(i, end=', ') print('Y Value Buys %', y) print('USD Value', usd_value) print('SUMBUY After Fixing Strategy', sumbuy) print('SUMSELL Current', sumsell) print('TOTAL Current', total) datasellsperc = round((sumsell / total) * 100, 4) if percentage_from_strategys > 50: buy_percentage = percentage_from_strategys buy_difference = round((buy_percentage - buytotalperc), 4) # % in the strategy table buy_difference_amount = round((total_database * buy_difference) / 100, 4) else: sell_percentage = percentage_from_strategys sell_difference = round((abs(sellscurrentperc) - sell_percentage), 4) # % in the strategy table sell_difference_amount = round( (total_database * sell_difference) / 100, 4) return render_template("home.html", adjustedbuytotalperc=adjustedbuytotalperc, sellscurrentperc=sellscurrentperc, sellscurrenttotal=sellscurrenttotal, buypreviousperc=buypreviousperc, buyprevioustotal=buyprevioustotal, sell_difference_amount=sell_difference_amount, data=records, bdata_strategies=r_strategies, bdata=recordsb, datasells=amount_c_s, buytotal=amount_c_bcc, datasellsperc=datasellsperc, buytotalperc=amount_p_b, buy_difference=buy_difference, sell_difference=sell_difference, percentage_from_strategys=percentage_from_strategys, buy_difference_amount=usd_value, current_btc_price_value=current_btc_price_value, ohlcv_on_np=ohlcv)