def check_useridfrozen():#检查Match_Details中计算的费率及计价币种是否正确 config_ex=data_conn.config_init_("ex") conn = data_conn.pymysql.connect(**config_ex) cur = conn.cursor() sql=data_sql_str.sum_frozenamount_calculate() try: frozenset=dict() cur = conn.cursor() cur.execute(sql) row = cur.fetchone() while row is not None: a=[] if row['userId'] is not None: userid=row['userId'] currency=row['currency'] id=repr(userid)+currency #print(id) a.append(row['userId']) a.append(row['currency']) a.append(row['amount']) frozenset[id]=a #frozenset[id]=[row['userId'],row['currency'],row['amount']] #frozenset[id]=({"userid":row['userId'],"currency":row['currency'],"frozeen_amount":float(row['frozeen_amount'])}) #feerate[orderid]=(str(row['makerFeeRate_calculate']),row['makerFeeRate'],float(row['takerFeeRate_calculate']),float(row['takerFeeRate'])) row = cur.fetchone() except Exception as e: #cur.rollback() #cur.close() print('Error') raise e finally: cur.close() conn.close() return frozenset
def get_trades_line(): #获取交易数据 config_ex = data_conn.config_init_("ex") conn = data_conn.pymysql.connect(**config_ex) #cur = conn.cursor() sql = get_database.get_orders_trades() trade_data = dict() try: frozenset = dict() cur = conn.cursor() cur.execute(sql) row = cur.fetchone() message = dict() while row is not None: a = [] mm = 1 if row['orderid'] is not None: message = json.loads(row['message']) #print(message.get('orderId')) #print(message.get('symbol')) #print(message.get('createdAt')) if message.get('matchedRecords') is not None: #print(len( message.get('matchedRecords'))) trade = [] trade = message.get('matchedRecords') for mm in trade: #while mm<= len( message.get('matchedRecords')): #trade=message.get('matchedRecords')[mm-1:mm] #print(mm.get('matchPrice')) #print(mm.get('matchAmount')) cur1 = conn.cursor() str_sql = get_database.K_line(mm.get('matchAmount'), mm.get('matchPrice'), message.get('createdAt'), message.get('symbol'), message.get('orderId')) cur1.execute(str_sql) print(str_sql) row = cur.fetchone() except Exception as e: #cur.rollback() #cur.close() print('Error') raise e finally: cur.close() conn.commit() conn.close()
def check_frozen_compare(): sql="select a.userId,a.balance,a.currency from spot_accounts a where a.type='SPOT_FROZEN'" config_ex=data_conn.config_init_("ex") conn = data_conn.pymysql.connect(**config_ex) cur = conn.cursor() user_frozen=dict() user_frozen=check_useridfrozen() try: frozenset_sys=dict() cur = conn.cursor() cur.execute(sql) row = cur.fetchone() while row is not None: if row['userId'] is not None: userid=row['userId'] currency=row['currency'] id=repr(userid)+currency #print(id) #frozenset[id]=(row['userId'],row['currency'],row['balance']) #print (row['userId'],row['currency'],row['balance']) key=str(row['userId'])+row['currency'] list_frozen=[] list_frozen=user_frozen.get(key) #print(list_frozen) if list_frozen!=None: amount=repr(list_frozen[2:3])[10:len(repr(list_frozen[2:3]))-3] #print(amount, row['balance']) if float(row['balance'])==float(amount) : print('SUCCESS用户'+str(row['userId'])+",币种"+row['currency']+'冻结金额比对一致!'+str(float(row['balance']))+","+str(float(amount))) str1="SUCCESS:冻结金额比对- - 用户"+str(row['userId'])+",币种"+row['currency']+'冻结金额比对一致!' else: print('ERROR用户'+str(row['userId'])+",币种"+row['currency']+'冻结比对不一致,请检查!'+str(float(row['balance']))+","+str(float(amount))) str1=' ERROR:冻结金额比对- - 用户'+str(row['userId'])+",币种"+row['currency']+'冻结金额比对不一致,请检查!'+str(float(row['balance']))+","+str(float(amount)) file_read_write.create_file(str1) #frozenset[id]=({"userid":row['userId'],"currency":row['currency'],"frozeen_amount":float(row['frozeen_amount'])}) #feerate[orderid]=(str(row['makerFeeRate_calculate']),row['makerFeeRate'],float(row['takerFeeRate_calculate']),float(row['takerFeeRate'])) row = cur.fetchone() except Exception as e: #cur.rollback() #cur.close() print('Error') raise e finally: cur.close() conn.close() return frozenset
def get_name(userid): sql=get_database.get_username(userid) config_ex=data_conn.config_init_("ui") conn = data_conn.pymysql.connect(**config_ex) try: cur = conn.cursor() cur.execute(sql) row = cur.fetchone() if row['userId'] is not None: email=row['email'] except Exception as e: print('Error') raise e finally: cur.close() conn.close() return email
def place_inorder(): config_ex = data_conn.config_init_("ex") #print(config_ex) conn = data_conn.pymysql.connect(**config_ex) #print(config_ex) cur = conn.cursor() #price=299.6000 for i in range(0, 20000): print(i) #cur = conn.cursor() #userid= random.randint(99000, 99999) userid = 100023 amount = round(random.uniform(0.01, 0.02), 8) #amount=0.1 #price=price-0.00001 #amount=30 #symbol=random.choice(['BTC_USDT','BCH_USDT','LTC_USDT','ETH_USDT','ETC_USDT','BCH_BTC','ETH_BTC','ETC_BTC','LTC_BTC','BTC_ETH','BCH_ETH','LTC_ETH','ETC_BCH']) #symbol=random.choice(['BCH_BTC','ETH_BTC','ETC_BTC','LTC_BTC','CTC_BTC']) symbol = random.choice(['BTC_USDT']) price = 10564.54 #price= round(random.uniform(1,2),8) #price=5300 type = random.choice( ['BUY_LIMIT', 'SELL_LIMIT', 'BUY_MARKET', 'SELL_MARKET']) #type=random.choice(['BUY_LIMIT']) #type=random.choice(['BUY_LIMIT']) #print(type) #if type=='BUY_LIMIT': #price1=price+10 #type1='SELL_LIMIT' #else: #price1=price-10 #type1='BUY_LIMIT' #print(price1) sql = get_database.get_userid_keySecret(userid) print(sql) try: #custom_sum = dict()g cur = conn.cursor() cur.execute(sql) row = cur.fetchone() while row is not None: if row['userId'] is not None: #apikey=row['apiKey'] #apiSecret=row['apiSecret'] pram = { "withdrawAddressId": 24, "amount": 0.1112, "currency": "ETC" } data = {} #print(apikey,apiSecret,symbol) DATA = "withdrawAddressId=86¤cy=ETC&amount=0.1" apikey = "AAAADBVXv0iwdBujTFS4XFFP" apiSecret = "lE0uLi4Yin1Qr3Ms" client = test.ApiClient(apikey, apiSecret, "", True, 10, False) print( client.post( "/v1/trade/orders", data, { "type": type, "symbol": symbol, "price": price, "amount": amount, "fillOrKill": False, "immediateOrCancel": False, "hidden": False, "postOnly": False })) #报单 #print(client.post("/v1/user/withdraw/submit",pram,{})); row = cur.fetchone() except Exception as e: #cur.rollback() #cur.close() print('Error') raise e finally: #cur.close() print("这是一个测试") cur.close() conn.close()