def get_msg(cls, exchange, base_coin, quote_coin, size=5): # 组合symbol值 symbol = ut.get_symbol(exchange, base_coin, quote_coin) msg = '' if ut.okex_exchange.lower() == exchange.lower(): i = 1 while True: try: msg = okexcoinSpot.depth(str.lower(symbol), size) keys = list(msg.keys()) if cls.get_bids_field_name() in keys and \ cls.get_asks_field_name() in keys: return msg else: i = i + 1 time.sleep(1) except Exception as e: Logger.error(cls.__class__.__name__, "Error in get_msg: %s" % e) i = i + 1 time.sleep(1) if i > ut.RE_TRY_TIMES: return None else: Logger.error(cls.__class__.__name__, 'no support exchange') return msg
def get_tiker_value(self, exchange, base_coin, quote_coin, contractType='this_week'): ticker = Ticker() ex_qt = QuoteTickerFuture() msg = ex_qt.get_msg(exchange, base_coin, quote_coin, contractType) # Date time timestamp = float(msg["date"]) if ut.okex_exchange.lower() == exchange.lower(): ticker.Time = datetime.fromtimestamp(timestamp).strftime( "%Y%m%d %H:%M:%S") elif ut.zb_exchange.lower() == exchange.lower(): ticker.Time = datetime.fromtimestamp( timestamp / 1000).strftime("%Y%m%d %H:%M:%S") msg = msg["ticker"] ticker.Buy = float(msg['buy']) ticker.High = float(msg['high']) ticker.Last = float(msg['last']) ticker.Low = float(msg['low']) ticker.Sell = float(msg['sell']) ticker.Volume = float(msg['vol']) ''' "contract_id":20140926012, "unit_amount":100.0 ''' ticker.Symbol = ut.get_symbol(exchange, base_coin, quote_coin) ticker.Volume_to_value = ticker.Volume * ticker.Last return ticker
def get_kline_value(self, exchange, base_coin, quote_coin, type='5min', size='1000'): qt = q_ticker.QuoteTicker() quote_coin_usdt_price = qt.get_usdt_value_by_coin(exchange, quote_coin) kline = Kline() ex_kl = QuoteKlineZb() msg = ex_kl.get_msg(exchange, base_coin, quote_coin, type, size) # Date time for k in msg: kline.Exchange.append(ut.okex_exchange) kline.Symbol.append(ut.get_symbol(exchange, base_coin, quote_coin)) #timestamp = float(k[0]/1000) kline.Time.append( float(k[0]) ) #datetime.fromtimestamp(timestamp).strftime("%Y%m%d %H:%M:%S")) kline.Open.append(float(k[1])) kline.High.append(float(k[2])) kline.Low.append(float(k[3])) kline.Close.append(float(k[4])) kline.Volume.append(float(k[5])) kline.Volume_to_value.append( float(k[5]) * float(k[4]) * quote_coin_usdt_price) return kline
def post_trade(cls, exchange, base_coin, quote_coin, tradeType, price='', amount=''): # 组合symbol值 symbol = ut.get_symbol(exchange, base_coin, quote_coin) msg = '' # def trade(self, symbol, tradeType, price='', amount=''): if ut.okex_exchange.lower() == exchange.lower(): s_t_rule = spot_trade_rule.SpotTradeRule() #判断价格是否正确 if s_t_rule.if_right_price(exchange, base_coin, quote_coin, tradeType, price): msg = okexcoinSpot.trade(symbol, tradeType, price, amount) print(msg) else: msg = 'not right price' # {"result":true,"order_id":123456} else: print('no support exchange') return msg
def get_tiker_value(self, exchange, base_coin, quote_coin): ticker = Ticker() ex_qt = QuoteTicker() msg = ex_qt.get_msg(exchange, base_coin, quote_coin) # Date time timestamp = float(msg["date"]) if ut.okex_exchange.lower() == exchange.lower(): ticker.Time = datetime.fromtimestamp(timestamp).strftime( "%Y%m%d %H:%M:%S") elif ut.zb_exchange.lower() == exchange.lower(): ticker.Time = datetime.fromtimestamp( timestamp / 1000).strftime("%Y%m%d %H:%M:%S") msg = msg["ticker"] ticker.Buy = float(msg['buy']) ticker.High = float(msg['high']) ticker.Last = float(msg['last']) ticker.Low = float(msg['low']) ticker.Sell = float(msg['sell']) ticker.Volume = float(msg['vol']) ticker.Symbol = ut.get_symbol(exchange, base_coin, quote_coin) ticker.Volume_to_value = ticker.Volume * ticker.Last * ex_qt.get_usdt_value_by_coin( exchange, quote_coin) return ticker
def get_msg(cls, exchange, base_coin, quote_coin, order_id): # 组合symbol值 symbol = ut.get_symbol(exchange, base_coin, quote_coin) msg = '' if ut.okex_exchange.lower() == exchange.lower(): #{'result': True, 'orders': [{'amount': 1, 'avg_price': 0, 'create_date': 1530020990000, 'deal_amount': 0, 'order_id': 480894458, 'orders_id': 480894458, 'price': 108, 'status': 0, 'symbol': 'EOS_USDT', 'type': 'sell'}]} i = 1 while True: try: msg = okexcoinSpot.orderInfo(symbol, order_id) #print(msg) if msg['result'] is True: return msg except Exception as e: #Logger.error(cls.__class__.__name__, "Error in get_msg: %s" % e) i = i + 1 print("error:" + symbol) time.sleep(1) if i > ut.RE_TRY_TIMES: return None else: print('no support exchange') return msg
def get_msg(cls, exchange, base_coin, quote_coin, type='5min', size='1000'): # 组合symbol值 symbol = ut.get_symbol(exchange, base_coin, quote_coin) msg = '' if ut.okex_exchange.lower() == exchange.lower(): msg = okexcoinSpot.kline(symbol, type, size) #print(msg) #[[1532986200000,"0.01010073","0.01010073","0.01010073","0.01010073","12.7557"],[1532986260000,"0.01010381","0.01010381","0.01009715","0.01009715","24.53925"], else: print('no support exchange') return msg
def main(): #===============输入 参数============================= base_coin = 'eos' quote_coin = 'usdt' order_id = '637839142' #===================================================== ex_qt = spot_trad_cancel_api.SpotTradeCancel() exchange_name = 'okex' symbol = ut.get_symbol(exchange_name, base_coin, quote_coin) tk = ex_qt.get_spot_trade_cancel_result(exchange_name, symbol, order_id) print('result:%s' % tk.Result + 'trade_id:%s' % tk.Trade_id)
def post_trade(cls, exchange, base_coin, quote_coin, tradeType, orders_data): # 组合symbol值 symbol = ut.get_symbol(exchange, base_coin, quote_coin) msg = '' # def batchTrade(self, symbol, tradeType, orders_data): if ut.okex_exchange.lower() == exchange.lower(): msg = okexcoinSpot.batchTrade(symbol, tradeType, orders_data) print(msg) # {'result': True, 'order_info': [{'order_id': 624996965}, {'order_id': 624996968}, {'order_id': 624996970}, {'order_id': 624996972}, {'order_id': 624996975}]} else: print('no support exchange') return msg
def get_msg(cls, exchange, base_coin, quote_coin): # 组合symbol值 symbol = ut.get_symbol(exchange, base_coin, quote_coin) msg = '' if ut.okex_exchange.lower() == exchange.lower(): msg = okexcoinSpot.ticker(symbol) #print(msg) #{'date': '1529836574', 'ticker': {'high': '6256.6379', 'vol': '28947.4171', 'last': '5861.3241', 'low': '5782.2121', 'buy': '5861.6735', 'sell': '5864.9063'}} elif ut.zb_exchange.lower() == exchange.lower(): msg = zb_data.zb_api_data(symbol).ticker() else: print('no support exchange') return msg
def get_msg(cls, exchange, base_coin, quote_coin, type='5min', size='1000'): # 组合symbol值 symbol = ut.get_symbol(exchange, base_coin, quote_coin) msg = '' if ut.zb_exchange.lower() == exchange.lower(): msg = zb_data.zb_api_data(symbol).kline(type, size) msg = msg['data'] #print(msg) #[[1532986200000,"0.01010073","0.01010073","0.01010073","0.01010073","12.7557"],[1532986260000,"0.01010381","0.01010381","0.01009715","0.01009715","24.53925"], else: print('no support exchange') return msg
def get_msg(cls, exchange, base_coin, quote_coin, contractType='this_week'): # symbol值: btc_usd ltc_usd eth_usd etc_usd bch_usd #contractType 合约类型: this_week:当周 next_week:下周 quarter:季度 symbol = ut.get_symbol(exchange, base_coin, quote_coin) msg = '' if ut.okex_exchange.lower() == exchange.lower(): msg = okexcoinFuture.future_ticker(symbol, contractType) #print(msg) elif ut.zb_exchange.lower() == exchange.lower(): msg = zb_data.zb_api_data(symbol).ticker() else: print('no support exchange') return msg
def print_direecton(self, i, direct=ut.RIGHT_DIRECT): q_ticker = quote_ticker.QuoteTicker() format_value = "%-5d%-10s%20s" \ "%15s%15s%15s" \ "%15.4f%15.4f%15.4f" \ "%15.4f%15.4f" this_MC_USDT_price = q_ticker.get_usdt_value_by_coin( self.exchange, self.middle_coin) this_QC_USDT_price = q_ticker.get_usdt_value_by_coin( self.exchange, self.quote_coin) if str.lower(direct) == ut.RIGHT_DIRECT.lower(): print(format_value % (i, self.exchange, self.time, ut.get_symbol(ut.okex_exchange, self.base_coin, self.middle_coin), ut.get_symbol(ut.okex_exchange, self.base_coin, self.quote_coin), ut.get_symbol(ut.okex_exchange, self.quote_coin, self.middle_coin), this_MC_USDT_price * self.BC_MC_buy_1_price * self.BC_MC_buy_1_volume, this_QC_USDT_price * self.BC_QC_sell_1_price * self.BC_QC_sell_1_volume, this_MC_USDT_price * self.QC_MC_sell_1_price * self.QC_MC_sell_1_volume, self.right_direction, self.left_direction)) else: print(format_value % (i, self.exchange, self.time, ut.get_symbol(ut.okex_exchange, self.base_coin, self.middle_coin), ut.get_symbol(ut.okex_exchange, self.base_coin, self.quote_coin), ut.get_symbol(ut.okex_exchange, self.quote_coin, self.middle_coin), this_MC_USDT_price * self.BC_MC_sell_1_price * self.BC_MC_sell_1_volume, this_QC_USDT_price * self.BC_QC_buy_1_price * self.BC_QC_buy_1_volume, this_MC_USDT_price * self.QC_MC_buy_1_price * self.QC_MC_buy_1_volume, self.right_direction, self.left_direction))
def get_BC_QC(self): self.symbol = ut.get_symbol(self.exchange, self.base_coin, self.quote_coin) return self.symbol
def get_QC_MC(self): self.symbol = ut.get_symbol(self.exchange, self.quote_coin, self.middle_coin) return self.symbol
def get_BC_MC(self): self.symbol = ut.get_symbol(self.exchange, self.base_coin, self.middle_coin) return self.symbol