Exemplo n.º 1
0
def get_usdt_symbols():
    usdt_symbols = []
    generic_client = GenericClient()
    list_obj = generic_client.get_exchange_symbols()
    if len(list_obj):
        for symb in list_obj:
            if symb.quote_currency == 'usdt':
                usdt_symbols.append(symb.symbol)
    return usdt_symbols
Exemplo n.º 2
0
Arquivo: app.py Projeto: ljmljz/trader
def get_all_symbols():
    try:
        generic_client = GenericClient(url=settings.config['COMMON']['host'])
        symbols = generic_client.get_exchange_symbols()
        ret_val = {}

        for sym in symbols:
            ret_val[sym.symbol] = sym

        return ret_val
    except Exception as e:
        print(e)
        return None
Exemplo n.º 3
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()
Exemplo n.º 4
0
def get_symbol_info(symbol):
    generic_client = GenericClient()
    while (1):
        try:
            list_obj = generic_client.get_exchange_symbols()
            break
        except requests.exceptions.ProxyError as e:
            print(e)
            continue
        except requests.exceptions.ConnectionError as e:
            print(e)
            continue
        except requests.exceptions.ReadTimeout as e:
            print(e)
            continue

    if len(list_obj):
        for symbol_info_obj in list_obj:
            if symbol_info_obj.symbol == symbol:
                return symbol_info_obj
Exemplo n.º 5
0
from huobi.client.account import AccountClient
from huobi.client.generic import CandlestickInterval, GenericClient
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,
Exemplo n.º 6
0
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')
Exemplo n.º 7
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
Exemplo n.º 8
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     self.generic_client = GenericClient()
     self.symbols_info: 'dict[str, Symbol]' = {}
     self.mark_price: 'dict[str, float]' = {}
     self.update_symbols_info()