Exemple #1
0
    def test_generic(self):
        generic_client = GenericClient(api_key=g_api_key,
                                       secret_key=g_secret_key,
                                       performance_test=True)
        # case get_exchange_symbol_list
        tc = TimeCost(
            function_name=generic_client.get_exchange_timestamp.__name__)
        result, tc.server_req_cost, tc.server_api_cost = generic_client.get_exchange_timestamp(
        )
        tc.run_status = RunStatus.SUCCESS if result and result > 0 else RunStatus.FAILED
        tc.add_record()

        # case get_exchange_currencies
        tc = TimeCost(
            function_name=generic_client.get_exchange_currencies.__name__)
        result, tc.server_req_cost, tc.server_api_cost = generic_client.get_exchange_currencies(
        )
        tc.run_status = RunStatus.SUCCESS if result and len(
            result) else RunStatus.FAILED
        tc.add_record()

        # case get_exchange_symbols
        tc = TimeCost(
            function_name=generic_client.get_exchange_symbols.__name__)
        result, tc.server_req_cost, tc.server_api_cost = generic_client.get_exchange_symbols(
        )
        tc.run_status = RunStatus.SUCCESS if result and len(
            result) else RunStatus.FAILED
        tc.add_record()

        # case get_reference_currencies
        tc = TimeCost(
            function_name=generic_client.get_reference_currencies.__name__)
        result, tc.server_req_cost, tc.server_api_cost = generic_client.get_reference_currencies(
        )
        tc.run_status = RunStatus.SUCCESS if result and len(
            result) else RunStatus.FAILED
        tc.add_record()

        # case get_system_status
        tc = TimeCost(function_name=generic_client.get_system_status.__name__)
        result, tc.server_req_cost, tc.server_api_cost = generic_client.get_system_status(
        )
        tc.run_status = RunStatus.SUCCESS if result and result.get(
            "page") and result.get("components") else RunStatus.FAILED
        tc.add_record()
Exemple #2
0
from huobi.client.market import LogInfo, MarketClient
from huobi.client.trade import TradeClient

generic_client = GenericClient()
list_symbol = generic_client.get_exchange_symbols()
list_currency = generic_client.get_reference_currencies()
print(list_symbol[0])
print(list_currency[0].print_object())

a = c
access_key = " "
secret_key = " "

# Create generic client instance and get the timestamp
generic_client = GenericClient()
timestamp = generic_client.get_exchange_timestamp()
print(timestamp)

# Create the market client instance and get the latest btcusdt‘s candlestick
market_client = MarketClient()
list_obj = market_client.get_candlestick("btcusdt", CandlestickInterval.MIN5,
                                         10)
LogInfo.output_list(list_obj)

# // Create an AccountClient instance with APIKey
account_client = AccountClient(api_key=access_key, secret_key=secret_key)

# // Create a TradeClient instance with API Key and customized host
trade_client = TradeClient(api_key=access_key,
                           secret_key=secret_key,
                           url="https://api-aws.huobi.pro")
def print_exchange_time():
    generic_client = GenericClient()
    ts = generic_client.get_exchange_timestamp()
    return datetime.datetime.fromtimestamp(
        ts / 1000).strftime('%Y-%m-%d %H:%M:%S.%f')
Exemple #4
0
    def __init__(self,
                 market_config=MARKET_CONFIG,
                 huobi_config=HUOBI_CONFIG,
                 watchdog_threshold=10,
                 db_api=None):
        path_fixer(market_config)
        path_fixer(huobi_config)

        with open(market_config) as conf:
            config = json.load(conf)
        try:
            self.monitoring = config["monitoring_markets"]
        except Exception as err:
            raise KeyError("failed to load market config, {}".format(err))

        with open(huobi_config) as conf:
            config = json.load(conf)
        try:
            self.timeout = config["timeout"]
            self.url = config["api"]["url"]
            self.fallback_url = config["fallback_api"]["url"]
            if config["api"]["proxies"]["http"] == "" and config["api"][
                    "proxies"]["https"] == "":
                self.proxies = None
            else:
                if config["api"]["proxies"]["http"] == "":
                    config["api"]["proxies"]["http"] = config["api"][
                        "proxies"]["https"]
                if config["api"]["proxies"]["https"] == "":
                    config["api"]["proxies"]["https"] = config["api"][
                        "proxies"]["http"]
                self.proxies = config["api"]["proxies"]
            if config["fallback_api"]["proxies"]["http"] == "" and config[
                    "fallback_api"]["proxies"]["https"] == "":
                self.fallback_proxies = None
            else:
                if config["fallback_api"]["proxies"]["http"] == "":
                    config["fallback_api"]["proxies"]["http"] = config[
                        "fallback_api"]["proxies"]["https"]
                if config["fallback_api"]["proxies"]["https"] == "":
                    config["fallback_api"]["proxies"]["https"] = config[
                        "fallback_api"]["proxies"]["http"]
                self.fallback_proxies = config["fallback_api"]["proxies"]
        except Exception as err:
            raise KeyError("failed to load huobi api config, {}".format(err))

        self.live = False
        self.food = {}
        self.watchdog_threshold = watchdog_threshold
        self.watchdog_int_flag = {}
        self.db_api = db_api
        self.statics = {}
        self.timestamp_offset = 0

        try:
            if self.proxies is None:
                gen_clt = GenericClient(url=self.url, timeout=self.timeout)
            else:
                gen_clt = GenericClient(url=self.url,
                                        timeout=self.timeout,
                                        proxies=self.proxies)
            for i in range(20):
                cloud_ts = gen_clt.get_exchange_timestamp()
                self.timestamp_offset -= (self.get_timestamp() - cloud_ts) * (
                    (20 - i) / 20)
        except:
            if self.fallback_proxies is None:
                gen_clt = GenericClient(url=self.fallback_url,
                                        timeout=self.timeout)
            else:
                gen_clt = GenericClient(url=self.fallback_url,
                                        timeout=self.timeout,
                                        proxies=self.fallback_proxies)
                for i in range(20):
                    cloud_ts = gen_clt.get_exchange_timestamp()
                    self.timestamp_offset -= (self.get_timestamp() -
                                              cloud_ts) * ((20 - i) / 20)
        ECHO.print("[updater] [init] info: timestamp offset fixing: {}".format(
            self.timestamp_offset))
        cloud_ts = gen_clt.get_exchange_timestamp()
        fixed_ts = self.get_timestamp()
        ECHO.print(
            "[updater] [init] debug: huobi cloud timestamp: {}, fixed timestamp: {}"
            .format(cloud_ts, self.get_timestamp()))

        for ele in self.monitoring:
            self.statics.update(
                {ele.upper(): {
                     "price": -1,
                     "avg_cost_1min": 0.0,
                     "ping": 0
                 }})

        self.fallbacked = False