def get_current_price(symbol): market_client = MarketClient() depth_size = 2 depth = market_client.get_pricedepth(symbol, DepthStep.STEP0, depth_size) #LogInfo.output("---- Top {size} bids ----".format(size=len(depth.bids))) i = 0 for entry in depth.bids: i = i + 1 if i == 1: first_price = entry.price #LogInfo.output(str(i) + ": price: " + str(entry.price) + ", amount: " + str(entry.amount)) return first_price
def check_insurance_point(): market_client = MarketClient() depth_size = 20 depth = market_client.get_pricedepth(symbol, DepthStep.STEP1, depth_size) LogInfo.output("---- Top {size} bids ----".format(size=len(depth.bids))) i = 0 for entry in depth.bids: i = i + 1 print(entry.price) #printme(depth) return False, False, 0
def get_current_price(symbol): try: market_client = MarketClient() depth_size = 2 depth = market_client.get_pricedepth(symbol, DepthStep.STEP0, depth_size) #LogInfo.output("---- Top {size} bids ----".format(size=len(depth.bids))) i = 0 if not depth: return 0 for entry in depth.bids: i = i + 1 if i == 1: first_price = entry.price return first_price #LogInfo.output(str(i) + ": price: " + str(entry.price) + ", amount: " + str(entry.amount)) except Exception as e: print("ExecuteError in get_current_price", e) return 0
def get_current_price(symbol): try: market_client = MarketClient() depth_size = 2 depth = market_client.get_pricedepth(symbol, DepthStep.STEP0, depth_size) #LogInfo.output("---- Top {size} bids ----".format(size=len(depth.bids))) i = 0 if not depth: return 0 for entry in depth.bids: i += 1 if i == 1: first_price = entry.price return first_price #LogInfo.output(str(i) + ": price: " + str(entry.price) + ", amount: " + str(entry.amount)) except Exception as e: print("ExecuteError in get_current_price", e) send_email( "HB: " + "get_current_price Exception ", "you can have a check if it is break or not after using pass!") pass return 0
# Futures setup URL = 'https://api.hbdm.com' ACCESS_KEY = '' SECRET_KEY = '' dm = HuobiDM(URL, ACCESS_KEY, SECRET_KEY) # BB setup market_client = MarketClient() while True: for contract in contractlist: # Get BB MarketData bbsymbol = contract.lower() + 'usdt' depth = market_client.get_pricedepth(bbsymbol, DepthStep.STEP0, 20) bb_ask = depth.asks[19].price # Get Future MarketData futsymbol = contract.upper() + '_NQ' delivery_date = dm.get_contract_info( symbol=contract.upper(), contract_type="next_quarter")['data'][0]['delivery_date'] waiteday = (datetime.datetime.strptime(delivery_date, '%Y%m%d') - datetime.datetime.now()).days + 2 fut_depth = dm.get_contract_depth(symbol=futsymbol, type='step6') fut_bid = fut_depth['tick']['bids'][19][0] jc = round((fut_bid - bb_ask) / bb_ask * 100 * 365 / waiteday, 6) if jc > watch_thresh: print(contract + ' NQ: ' + str(jc)) time.sleep(1)
from huobi.client.market import MarketClient from huobi.utils import * market_client = MarketClient() symbol = "btcusdt" depth_size = 6 depth = market_client.get_pricedepth(symbol, DepthStep.STEP0, depth_size) LogInfo.output("---- Top {size} bids ----".format(size=len(depth.bids))) i = 0 for entry in depth.bids: i = i + 1 LogInfo.output( str(i) + ": price: " + str(entry.price) + ", amount: " + str(entry.amount)) LogInfo.output("---- Top {size} asks ----".format(size=len(depth.asks))) i = 0 for entry in depth.asks: i = i + 1 LogInfo.output( str(i) + ": price: " + str(entry.price) + ", amount: " + str(entry.amount))