示例#1
0
    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)
    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)
示例#3
0
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)
示例#4
0
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)
示例#5
0
 def __init__(self):
     ConfigHandler.__init__(self)
     self.sub_client = SubscriptionClient()
示例#6
0
 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"))
示例#7
0
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