def genKlineDay(coin, datee): select_openP = 'select openingPrice from xy_dayk_info where date>=' "'" + str( datee) + "'" 'and code=' "'" + str( coin) + "'" ' order by timestamp asc limit 1;' select_closeP = 'select closingPrice from xy_dayk_info where date>=' "'" + str( datee) + "'" 'and code=' "'" + str( coin) + "'" ' order by timestamp desc limit 1;' select_highP = 'select max(highestPrice) from xy_dayk_info where date>=' "'" + str( datee) + "'" 'and code=' "'" + str(coin) + "';" select_lowP = 'select min(lowestPrice) from xy_dayk_info where date>=' "'" + str( datee) + "'" 'and code=' "'" + str(coin) + "';" volumeCount = 'select sum(volume) from xy_dayk_info where date>=' "'" + str( datee) + "'" 'and code=' "'" + str(coin) + "';" # datetime = 'select date from xy_30min_info where date='"'"+str(datee)+"'"'and code='"'"+str(coin)+"'"' order by timestamp asc limit 1;' cursor.execute(select_openP) openPrice = float(cursor.fetchone()[0]) cursor.execute(select_closeP) closePrice = float(cursor.fetchone()[0]) cursor.execute(select_highP) highPrice = float(cursor.fetchone()[0]) cursor.execute(select_lowP) lowPrice = float(cursor.fetchone()[0]) cursor.execute(volumeCount) volume = int((cursor.fetchone()[0])) name = coin.upper() pid = coinPid.get(name) timeArray = time.strptime(datee, "%Y-%m-%d") time_stamp = int(time.mktime(timeArray)) ttime = time.strftime("%H:%M:00", time.localtime(time_stamp)) datetime = time.strftime("%Y-%m-%d 00:00:00", time.localtime(time_stamp)) # print(openPrice, closePrice, highPrice, lowPrice, volume, datee, datee, datee) #print(datee, time_stamp) dataArr = { 'type': 'month', 'code': coin, 'datetime': str(datee), 'timestamp': time_stamp, 'open': openPrice, 'close': closePrice, 'high': highPrice, 'low': lowPrice, 'volume': volume, } # print(dataArr) # redisConnect.publish('vb:klinemon:chan:test', json.dumps(dataArr)) redisConnect.set('vb:newklinemon:' + str(coin), json.dumps(dataArr)) if name in coinPid.keys(): write_db((pid, coin, name, float(openPrice), float(highPrice), float(closePrice), float(lowPrice), int(volume), datee, ttime, datetime, time_stamp))
if coinMap.get(code)['old_time_index'] is None: coinMap.get(code)['openprice'] = item['close'] coinMap.get(code)['closePrice'] = item['close'] coinMap.get(code)['highprice'] = item['close'] coinMap.get(code)['lowprice'] = item['close'] coinMap.get(code)['volume'] = item['volume'] else: if coinMap.get(code)['old_time_index'] != new_time_index: volumes = int(item['volume'] - coinMap.get(code)['volume']) if volumes < 0: #volumes = int(item['volume']) volumes = abs(int(coinMap.get(code)['volume']/48)) timestamp = timestamp - 1800 datetime = time.strftime("%Y-%m-%d %H:%M:00", time.localtime(timestamp)) #name = code.upper() pid = coinPid.get(name) date = time.strftime("%Y-%m-%d", time.localtime(timestamp)) ttime = time.strftime("%H:%M:00", time.localtime(timestamp)) # write in SQL if name in coinPid.keys(): write_db( (pid, code, name, coinMap.get(code)['openprice'], coinMap.get(code)['highprice'], coinMap.get(code)['closePrice'], coinMap.get(code)['lowprice'], volumes, date, ttime, datetime, timestamp )) # print("1: ", dataArr)