def sell(self, cur_market_name, price, amount): # print("sell", cur_market_name, price, amount) if self.market_name == "huobi": base_cur, quote_cur = cur_market_name.split("_") if quote_cur == "cny": if base_cur == "eth": return bitexService.BitexServiceAPIKey( key_index="CNY_1").order("ethcny", price, amount, 'sell-limit') elif base_cur == "etc": return bitexService.BitexServiceAPIKey( key_index="CNY_1").order("etccny", price, amount, 'sell-limit') elif base_cur == "btc": return huobiService.sell(1, price, amount, None, None, "cny", "sell") elif base_cur == "ltc": return huobiService.sell(2, price, amount, None, None, "cny", "sell") elif quote_cur == "btc": if base_cur == "ltc": return proService.ProServiceAPIKey(key_index="CNY_1") \ .order("ltcbtc", price, amount, 'sell-limit') elif base_cur == "eth": return proService.ProServiceAPIKey(key_index="CNY_1") \ .order("ethbtc", price, amount, 'sell-limit') elif base_cur == "etc": return proService.ProServiceAPIKey(key_index="CNY_1") \ .order("etcbtc", price, amount, 'sell-limit') else: return None
def get_order_status(self, order_result, cur_market_name): # print("get_order_status:", order_result, cur_market_name) if self.market_name == "huobi": base_cur, quote_cur = cur_market_name.split("_") if quote_cur == "cny": if base_cur == "eth": result = bitexService.BitexServiceAPIKey( key_index="CNY_1").get_order_info( order_result.get("data")) return result.get("data").get("state") elif base_cur == "etc": result = bitexService.BitexServiceAPIKey( key_index="CNY_1").get_order_info( order_result.get("data")) return result.get("data").get("state") elif base_cur == "btc": result = huobiService.getOrderInfo(1, order_result.get("id"), "cny", "order_info") return result.get("status") elif base_cur == "ltc": result = huobiService.getOrderInfo(2, order_result.get("id"), "cny", "order_info") return result.get("status") elif quote_cur == "btc": if base_cur == "ltc" or base_cur == "eth" or base_cur == "etc": result = proService.ProServiceAPIKey(key_index="CNY_1")\ .get_order_info(order_result.get("data")) return result.get("data").get("state") else: return None else: return None
def account_available(self, cur_name, cur_market_name): """ 获取某个currency的可用量 :param cur_name: :param cur_market_name: :return: """ if self.market_name == "huobi": base_cur, quote_cur = cur_market_name.split("_") if quote_cur == "cny": if base_cur == "eth" or base_cur == "etc": bitex_acc = bitexService.BitexServiceAPIKey( key_index="CNY_1").get_spot_acct_info() if cur_name == "eth": return float( bitex_acc.get("data").get("list")[2].get( "balance")) elif cur_name == "etc": return float( bitex_acc.get("data").get("list")[2].get( "balance")) elif cur_name == "cny": return float( bitex_acc.get("data").get("list")[0].get( "balance")) elif base_cur == "btc" or base_cur == "ltc": account_info = huobiService.getAccountInfo( "cny", "get_account_info") return float( account_info.get( "available_{0}_display".format(cur_name))) else: return None elif quote_cur == "btc": # 内测 pro_acc = proService.ProServiceAPIKey( key_index="CNY_1").get_spot_acct_info() if cur_name == "btc": return float( pro_acc.get("data").get("list")[0].get("balance")) elif cur_name == "eth": return float( pro_acc.get("data").get("list")[2].get("balance")) elif cur_name == "etc": return float( pro_acc.get("data").get("list")[2].get("balance")) elif cur_name == "ltc": return float( pro_acc.get("data").get("list")[4].get("balance")) else: return None else: return None
def sell_market(self, cur_market_name, amount): """ 市价卖 :param cur_market_name: 货币对的名称 :param amount: 卖的数量 :return: """ # print("sell_market:", cur_market_name, amount) if self.market_name == "huobi": base_cur, quote_cur = cur_market_name.split("_") if quote_cur == "cny": if base_cur == "eth": return bitexService.BitexServiceAPIKey( key_index="CNY_1").order("ethcny", 0.0, amount, 'sell-market') elif base_cur == "etc": return bitexService.BitexServiceAPIKey( key_index="CNY_1").order("etccny", 0.0, amount, 'sell-market') elif base_cur == "btc": return huobiService.buyMarket(1, amount, None, None, "cny", "sell_market") elif base_cur == "ltc": return huobiService.buy(2, amount, None, None, "cny", "sell_market") elif quote_cur == "btc": if base_cur == "ltc": return proService.ProServiceAPIKey(key_index="CNY_1") \ .order("ltcbtc", 0.0, amount, 'sell-market') elif base_cur == "eth": return proService.ProServiceAPIKey(key_index="CNY_1") \ .order("ethbtc", 0.0, amount, 'sell-market') elif base_cur == "etc": return proService.ProServiceAPIKey(key_index="CNY_1") \ .order("etcbtc", 0.0, amount, 'sell-market') else: return None
def cancel_order(self, order_result, cur_market_name): if self.market_name == "huobi": base_cur, quote_cur = cur_market_name.split("_") if quote_cur == "cny": if base_cur == "eth": return bitexService.BitexServiceAPIKey(key_index="CNY_1")\ .cancel_order(str(order_result.get("data"))) # {'status': 'ok', 'data': '2705970'} elif base_cur == "etc": return bitexService.BitexServiceAPIKey(key_index="CNY_1")\ .cancel_order(str(order_result.get("data"))) # {'status': 'ok', 'data': '2705970'} elif base_cur == "btc": return huobiService.cancelOrder(1, order_result.get("id"), "cny", "cancel_order") elif base_cur == "ltc": return huobiService.cancelOrder(2, order_result.get("id"), "cny", "cancel_order") elif quote_cur == "btc": if base_cur == "ltc" or base_cur == "eth" or base_cur == "etc": return proService.ProServiceAPIKey( key_index="CNY_1").cancel_order( order_result.get("data")) else: return None
def market_detail(self, base_cur, quote_cur): """ 获取市场盘口信息 :param base_cur: :param quote_cur: :return: """ if self.market_name == "huobi": # if quote_cur == "usdt": # if base_cur == "eth": # return bitexService.BitexServiceAPIKey().get_depth("ethusdt","step0").get("tick") # elif base_cur == "etc": # return bitexService.BitexServiceAPIKey().get_depth("etcusdt", "step0").get("tick") # elif base_cur == "btc": # return proService.ProServiceAPIKey().get_depth("btcusdt").get("tick") # # return huobiService.getDepth(uh.HUOBI_COIN_TYPE_BTC, quote_cur) # elif base_cur == "ltc": # return proService.ProServiceAPIKey().get_depth("ltcusdt").get("tick") # # return huobiService.getDepth(uh.HUOBI_COIN_TYPE_LTC, quote_cur) # else: # return None # elif quote_cur == "btc": # if base_cur == "eth": # return proService.ProServiceAPIKey().get_depth("ethbtc").get("tick") # elif base_cur == "etc": # return proService.ProServiceAPIKey().get_depth("etcbtc").get("tick") # elif base_cur == "ltc": # return proService.ProServiceAPIKey().get_depth("ltcbtc").get("tick") # elif base_cur == "cny": # return huobiService.getDepth(uh.HUOBI_COIN_TYPE_BTC, "cny") # else: # return None return proService.ProServiceAPIKey().get_depth( base_cur + quote_cur).get("tick") else: return None