예제 #1
0
파일: app.py 프로젝트: 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
예제 #2
0
class MarketClient(_MarketClient):
    exclude_list = [
        'htusdt', 'btcusdt', 'bsvusdt', 'bchusdt', 'etcusdt',
        'ethusdt', 'botusdt','mcousdt','lendusdt','venusdt',
        'yamv2usdt', 'bttusdt', 'dogeusdt'
    ]

    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()

    def exclude(self, infos, base_price) -> 'dict[str, Symbol]':
        return {
            symbol: info
            for symbol, info in infos.items()
            if symbol not in self.exclude_list
            and not re.search('\d', symbol)
            and symbol in base_price
            and base_price[symbol] < 10
        }

    def update_symbols_info(self) -> 'tuple[list[str], list[str]]':
        new_symbols_info = {
            info.symbol: info
            for info in self.generic_client.get_exchange_symbols()
            if info.symbol.endswith('usdt')
        }
        price = self.get_price()
        symbols_info = self.exclude(new_symbols_info, price)
        new_symbols = [symbol for symbol in symbols_info.keys() if symbol not in self.symbols_info]
        removed_symbols = [symbol for symbol in self.symbols_info.keys() if symbol not in symbols_info]
        self.symbols_info = symbols_info
        self.mark_price = price
        return new_symbols, removed_symbols

    @timeout_handle({})
    def get_price(self) -> 'dict[str, float]':
        return {
            pair.symbol: pair.close
            for pair in self.get_market_tickers()
        }
예제 #3
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')
예제 #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
예제 #5
0
from huobi.client.generic import GenericClient
from huobi.utils import *

generic_client = GenericClient()
list_obj = generic_client.get_exchange_info()
LogInfo.output("---- Supported symbols ----")
for symbol in list_obj.symbol_list:
    LogInfo.output(symbol.symbol)

LogInfo.output("---- Supported currencies ----")
for currency in list_obj.currencies:
    LogInfo.output(currency)
예제 #6
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()
from huobi.client.generic import GenericClient
from huobi.utils import *


generic_client = GenericClient()
list_obj = generic_client.get_exchange_symbols()
if len(list_obj):
    for idx, row in enumerate(list_obj):
        LogInfo.output("------- number " + str(idx) + " -------")
        row.print_object()



from huobi.client.generic import GenericClient
from huobi.utils import *

generic_client = GenericClient()

list_obj = generic_client.get_reference_currencies()
LogInfo.output_list(list_obj)

list_obj = generic_client.get_reference_currencies(currency="usdt")
LogInfo.output_list(list_obj)