class CollectPriceData(ConfigHandler): def __init__(self): ConfigHandler.__init__(self) self.sub_client = SubscriptionClient() def callback(self, candlestick_event: 'CandlestickEvent'): content = f"{str(candlestick_event.timestamp)},{str(candlestick_event.data.close)}" FileReadAndWrite.write( f"{self.get_config_value('strategy', 'price_file_locate')}{candlestick_event.symbol}.txt", content) def run(self, currency_pairs): self.sub_client.subscribe_candlestick_event(currency_pairs, CandlestickInterval.MIN1, self.callback)
def start_request_mbp(): """ need request_mbp_event request to get bids 150 and asks 150 data information :return: """ if (MbpDataFormat.flag_enter_req == False): MbpDataFormat.flag_enter_req = True def request_callback(mbp_req: 'MbpRequest'): mbp = mbp_req.data print("===== Request seqNum : ", mbp.seqNum, "prevSeqNum", mbp.prevSeqNum) MbpDataFormat.req_mbp_base_obj = mbp_req def request_error(e: 'HuobiApiException'): print(e.error_code + e.error_message) sub_client_local = SubscriptionClient() sub_client_local.request_mbp_event(MbpDataFormat.symbol, MbpDataFormat.level, request_callback, request_error)
class CollectAccountData(LogHandler, ConfigHandler): def __init__(self): LogHandler.__init__(self) ConfigHandler.__init__(self) self.sub_client = SubscriptionClient( api_key=self.get_config_value("huobi", "api_key"), secret_key=self.get_config_value("huobi", "secret_key")) @staticmethod def callback(account_event: 'AccountEvent'): print("---- Account Change: " + account_event.change_type + " ----") for change in account_event.account_change_list: print("Account: " + change.account_type) print("Currency: " + change.currency) print("Balance: " + str(change.balance)) print("Balance type: " + str(change.balance_type)) def run(self): self.sub_client.subscribe_account_event(BalanceMode.TOTAL, self.callback)
import logging from huobi import SubscriptionClient from huobi.model import * from huobi.base.printobject import PrintMix, PrintBasic logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient() def callback(trade_event: 'TradeEvent'): print("---- trade_event: ----") trade_event.print_object() sub_client.subscribe_trade_event("btcusdt,eosusdt", callback)
import logging from huobi import SubscriptionClient from huobi.constant.test import * from huobi.model import * from huobi.base.printobject import PrintMix, PrintBasic logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient(api_key=g_api_key, secret_key=g_secret_key) def callback(account_balance: 'AccountBalanceRequest'): print("---- account_balance: ----") PrintBasic.print_basic(account_balance.timestamp, "Timestamp") PrintBasic.print_basic(account_balance.client_req_id, "Client Req ID") PrintBasic.print_basic(account_balance.topic, "Topic") print("Account List as below : count " + str(len(account_balance.account_list))) if len(account_balance.account_list): for account in account_balance.account_list: PrintBasic.print_basic(account.id, "\tId") PrintBasic.print_basic(account.account_type, "\tAccount Type") PrintBasic.print_basic(account.account_state, "\tAccount State") print("\tAccount ID : " + str(account.id) + " Balance List as below :") if len(account.balances):
def __init__(self): ConfigHandler.__init__(self) self.sub_client = SubscriptionClient()
import logging from huobi import SubscriptionClient from huobi.model import * from huobi.exception.huobiapiexception import HuobiApiException logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient() def callback(candlestick_event: 'CandlestickEvent'): print("Symbol: ", candlestick_event.symbol) print("Subscribe Receive Time: ", candlestick_event.timestamp) print("Interval: ", candlestick_event.interval) candlestick_event.data.print_object() print() def error(e: 'HuobiApiException'): print(e.error_code + e.error_message) sub_client.subscribe_candlestick_event("btcusdt", CandlestickInterval.MIN1, callback, error)
import logging from huobi import SubscriptionClient from huobi.model import * logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient() def callback(trade_statistics_event: 'TradeStatisticsRequest'): trade_statistics_event.print_object() print() sub_client.request_24h_trade_statistics_event("btcusdt", callback, auto_close=True)
import logging from huobi import SubscriptionClient from huobi.model import * from huobi.base.printobject import PrintMix, PrintBasic logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient(api_key="xxxxxx", secret_key="xxxxxx") def callback(upd_event: 'OrderUpdateEvent'): print("---- order update : ") PrintBasic.print_basic(upd_event.symbol, "Symbol") PrintBasic.print_basic(upd_event.timestamp, "Timestamp") PrintMix.print_data(upd_event.data) sub_client.subscribe_order_update_event("eosht", callback)
import logging from huobi import SubscriptionClient from huobi.model import * logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient() def callback(trade_statistics_event: 'TradeStatisticsEvent'): print("Timestamp: " + str(trade_statistics_event.trade_statistics.timestamp)) print("High: " + str(trade_statistics_event.trade_statistics.high)) print("Low: " + str(trade_statistics_event.trade_statistics.low)) print("Open: " + str(trade_statistics_event.trade_statistics.open)) print("Close: " + str(trade_statistics_event.trade_statistics.close)) print("Volume: " + str(trade_statistics_event.trade_statistics.volume)) sub_client.subscribe_24h_trade_statistics_event("btcusdt", callback)
import logging from huobi import SubscriptionClient from huobi.model import * from huobi.base.printobject import PrintMix, PrintBasic logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient() def callback(trade_event: 'TradeRequest'): print("---- trade_event: ----") trade_event.print_object() print() sub_client.request_trade_event("btcusdt,eosusdt", callback, auto_close=True)
import logging from huobi import SubscriptionClient from huobi.model import * from huobi.exception.huobiapiexception import HuobiApiException logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient() def callback(candlestick_event: 'CandlestickRequest'): print("Symbol: " + str(candlestick_event.symbol)) print("Timestamp: " + str(candlestick_event.timestamp)) print("Interval: " + str(candlestick_event.interval)) if len(candlestick_event.data): for candlestick in candlestick_event.data: candlestick.print_object() print() def error(e: 'HuobiApiException'): print(e.error_code + e.error_message)
import logging from huobi import SubscriptionClient from huobi.constant.test import * from huobi.model import * from huobi.base.printobject import PrintMix, PrintBasic logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient(api_key=g_api_key, secret_key=g_secret_key) def callback(upd_event: 'TradeClearingEvent'): print("---- trade clearing : ----") upd_event.print_object() print() sub_client.subscribe_trade_clearing_event("eosusdt,trxusdt,btcusdt", callback)
import logging from huobi import SubscriptionClient from huobi.model import * from huobi.base.printobject import PrintMix, PrintBasic logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient() def callback(trade_event: 'TradeEvent'): print("---- trade_event: ----") trade_event.print_object() sub_client.subscribe_trade_event("BTC_CQ", callback)
import logging from huobi import SubscriptionClient from huobi.model import * logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient() def callback(price_depth_event: 'PriceDepthRequest'): print("Timestamp: " + str(price_depth_event.timestamp)) print("Channel : " + price_depth_event.ch) depth = price_depth_event.data for entry in depth.bids: print("Bids: " + " price: " + str(entry.price) + ", amount: " + str(entry.amount)) for entry in depth.asks: print("Asks: " + " price: " + str(entry.price) + ", amount: " + str(entry.amount)) def error(e: 'HuobiApiException'): print(e.error_code + e.error_message)
import logging from huobi import SubscriptionClient, RequestClient from huobi.constant.test import * from huobi.model import * from huobi.base.printobject import PrintMix, PrintBasic logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) def callback(order_req_obj: 'OrderListRequest'): print("---- order list: ----") order_req_obj.print_object() print() request_client = RequestClient(api_key=g_api_key, secret_key=g_secret_key, url = "https://api.huobi.vn") sub_client = SubscriptionClient(api_key=g_api_key, secret_key=g_secret_key, uri = "https://api.huobi.vn") data = request_client.get_account_balance() if len(data): for account in data: print("============= account info =============") PrintBasic.print_basic(account.id, "Account ID") sub_client.request_order_list_event(symbol="nodeusdt", account_id=account.id, callback=callback, order_states = OrderState.FILLED, client_req_id = None, auto_close = True) break # for frequence limit
from huobi import SubscriptionClient from huobi.model import * from huobi.exception.huobiapiexception import HuobiApiException import time logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) mongoclient = pm.MongoClient("mongodb://localhost:27017/") db = mongoclient["huobi"] sub_client = SubscriptionClient() def callbackMbp(event: 'MbpRequest'): # print("Timestamp: " , event.id) # print("Channel : " , event.rep) mbp = event.data # print("seqNum : ", mbp.seqNum) # print("prevSeqNum : ", mbp.prevSeqNum) col = db["market"] for i in range(6): # print("Bids: " + " price: " + (mbp.bids[i].price) + ", amount: " + (mbp.bids[i].amount)) mydict = dict() mydict = {"Timestamp": (event.id)}
import logging from huobi import SubscriptionClient from huobi.constant.test import * from huobi.model import * from huobi.base.printobject import PrintMix, PrintBasic logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient(api_key=g_api_key, secret_key=g_secret_key) def callback(upd_event: 'OrderUpdateNewEvent'): print("---- order update : ----") upd_event.print_object() sub_client.subscribe_order_update_new_event("eosusdt", callback)
import logging from huobi import SubscriptionClient from huobi.model import * logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient() def callback(mbp_event: 'MbpEvent'): print("Timestamp: " + str(mbp_event.ts)) print("Channel : " + mbp_event.ch) mbp = mbp_event.data print("seqNum : ", mbp.seqNum) print("prevSeqNum : ", mbp.prevSeqNum) for entry in mbp.bids: print("Bids: " + " price: " + str(entry.price) + ", amount: " + str(entry.amount)) for entry in mbp.asks: print("Asks: " + " price: " + str(entry.price) + ", amount: " + str(entry.amount)) print()
import logging from huobi import SubscriptionClient from huobi.model import * from huobi.base.printobject import PrintMix, PrintBasic logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient(api_key="xxxxxx", secret_key="xxxxxx") def callback(trade_event: 'TradeEvent'): print("---- trade_event: ----") PrintBasic.print_basic(trade_event.symbol, "Symbol") PrintBasic.print_basic(trade_event.timestamp, "Timestamp") PrintMix.print_data(trade_event.trade_list) sub_client.subscribe_trade_event("btcusdt,eosusdt", callback)
import logging from huobi import SubscriptionClient from huobi.model import * logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient(api_key="xxxxxx", secret_key="xxxxxx") def callback(account_event: 'AccountEvent'): print("---- Account Change: " + account_event.change_type + " ----") for change in account_event.account_change_list: print("Account: " + change.account_type) print("Currency: " + change.currency) print("Balance: " + str(change.balance)) print("Balance type: " + str(change.balance_type)) sub_client.subscribe_account_event(BalanceMode.TOTAL, callback)
from huobi import SubscriptionClient from huobi.model import * from huobi.exception.huobiapiexception import HuobiApiException import time logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) mongoclient = pm.MongoClient("mongodb://localhost:27017/") db = mongoclient["huobi"] sub_client = SubscriptionClient() def callbackMbp(event: 'MbpRequest'): # print("Timestamp: " , event.id) # print("Channel : " , event.rep) mbp = event.data # print("seqNum : ", mbp.seqNum) # print("prevSeqNum : ", mbp.prevSeqNum) market = [] for i in range(6): # print("Bids: " + " price: " + (mbp.bids[i].price) + ", amount: " + (mbp.bids[i].amount)) market += [mbp.asks[6 - i].price, mbp.asks[6 - i].amount]
import logging from huobi import SubscriptionClient from huobi.constant.test import * from huobi.model import * from huobi.base.printobject import PrintMix, PrintBasic logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient(api_key=g_api_key, secret_key=g_secret_key) def callback(upd_event: 'AccountsUpdateEvent'): print("---- accounts update : ----") upd_event.print_object() print() sub_client.subscribe_accounts_update_event(AccountBalanceMode.TOTAL, callback)
import logging from huobi import SubscriptionClient from huobi.constant.test import * from huobi.impl.accountinfomap import account_info_map from huobi.model import * from huobi.base.printobject import PrintMix, PrintBasic from huobi.model.orderdetailrequest import OrderDetailRequest logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient(api_key=g_api_key, secret_key=g_secret_key) def callback(order_req_obj: 'OrderDetailRequest'): print("---- order_detail: ----") order_req_obj.print_object() print() order_id = 100000000 sub_client.request_order_detail_event(order_id, callback, auto_close=True)
import logging from huobi import SubscriptionClient from huobi.model import * logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient() def callback(price_depth_event: 'PriceDepthEvent'): print("Timestamp: " + str(price_depth_event.timestamp)) depth = price_depth_event.data for entry in depth.bids: print("Bids: " + " price: " + str(entry.price) + ", amount: " + str(entry.amount)) for entry in depth.asks: print("Asks: " + " price: " + str(entry.price) + ", amount: " + str(entry.amount)) def error(e: 'HuobiApiException'): print(e.error_code + e.error_message) sub_client.subscribe_price_depth_event("btcusdt", callback, error)
def __init__(self): LogHandler.__init__(self) ConfigHandler.__init__(self) self.sub_client = SubscriptionClient( api_key=self.get_config_value("huobi", "api_key"), secret_key=self.get_config_value("huobi", "secret_key"))
if mbp_event is None: # need check None return mbp = mbp_event.data print("Subscribe seqNum : ", mbp.seqNum, "prevSeqNum", mbp.prevSeqNum, "bids size", len(mbp.bids), "asks size", len(mbp.asks)) PrintMbp.print_mbp_sub(mbp_event) """ user add process code here! """ return def sub_callback(mbp_event: 'MbpEvent'): formated_mbp_event = MbpDataFormat.format_subscribe(mbp_event) user_def_function(formated_mbp_event) def sub_error(e: 'HuobiApiException'): print(e.error_code + e.error_message) if __name__ == '__main__': symbol = "btcusdt" level = MbpLevel.MBP150 MbpDataFormat.set_request_symbol_level(symbol, level) sub_client = SubscriptionClient() sub_client.subscribe_mbp_event(symbol, level, sub_callback, sub_error)
import logging from huobi import SubscriptionClient from huobi.constant.test import * from huobi.model.ordersupdateevent import OrdersUpdateEvent logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient(api_key=g_api_key, secret_key=g_secret_key) def callback(orders_update_event: 'OrdersUpdateEvent'): print("---- orders update : ----") orders_update_event.print_object() print() def error(e: 'HuobiApiException'): print(e.error_code + e.error_message) sub_client.subscribe_orders_update_event("hthusd", callback, error)