def __init__(self, meta_code, loop): self.contract_type = None self.symbol = None base_currency, market_currency, symbol, contract_type = self.parse_meta( meta_code) super().__init__(base_currency, market_currency, meta_code, cfg.get_float_config(Constants.OKEX_FEE)) self.apikey = cfg.get_config(Constants.OKEX_APIKEY) self.apisec = cfg.get_config(Constants.OKEX_APISEC) self.base_url = Constants.OKEX_FUTURE_WS_BASE # okex市场的websocket接口的URL self.contract_type = contract_type self.symbol = symbol ''' 这个队列是用于存储什么数据? 可以这样理解,websocket是一个异步接口 当想去调用long()同步开多的时候 在long()方法中创建一个请求放到queue中 然后OkexFutureWs市场的线程会从queue中取出请求,处理 然后long会持续等待,直到等待其收到应答 这样就可以达到同步的效果 ''' self.q = queue.Queue() self.websocket = None # 用于和okex市场进行websocket通信 self.depth = None self.trade = None self.update_flags = {"depth": False, 'trade': False} # 更新标志 self.loop = loop # type: AbstractEventLoop # EventLoop ''' 注册静态方法 def static_methods_register(self): self.methods["ok_sub_future_btc_depth_this_week_usd"] = self.update_depth ''' self.static_methods_register()
def __init__(self, meta_code, loop): self.contract_type = None self.symbol = None base_currency, market_currency, symbol, contract_type = self.parse_meta( meta_code) super().__init__(base_currency, market_currency, meta_code, cfg.get_float_config(Constants.OKEX_FEE)) self.apikey = cfg.get_config(Constants.OKEX_APIKEY) self.apisec = cfg.get_config(Constants.OKEX_APISEC) self.base_url = Constants.OKEX_FUTURE_WS_BASE self.contract_type = contract_type self.symbol = symbol self.q = asyncio.Queue() self.websocket = None self.depth = None self.trade = None self.hist_lenth = 10 self.order_type = { 1: 'long', 2: 'short', 3: 'close_long', 4: 'close_short' } self.hist = {'delete': collections.OrderedDict()} for _type_num, _type in self.order_type.items(): self.hist[_type] = collections.OrderedDict() # self.lock = threading.Lock() self.update_flags = {"depth": False} self.loop = loop # type: AbstractEventLoop self.static_methods_register()
def __init__(self, channels): threading.Thread.__init__(self) self.host = cfg.get_config(Constants.REDIS_HOST) self.port = cfg.get_config(Constants.REDIS_PORT) self.redis = redis.Redis(host=self.host, port=self.port) self.pubsub = self.redis.pubsub() self.pubsub.subscribe(channels) self.methods = {'price' : self.price_handler}
def __init__(self, meta_code): base_currency, market_currency, symbol, contract_type = self.parse_meta(meta_code) super().__init__(base_currency, market_currency, meta_code, cfg.get_float_config(Constants.OKEX_FEE)) self.apikey = cfg.get_config(Constants.OKEX_APIKEY) self.apisec = cfg.get_config(Constants.OKEX_APISEC) self.contract_type = contract_type self.symbol = symbol self.base_url = Constants.OKEX_FUTURE_REST_BASE self.timeout = Constants.OK_HTTP_TIMEOUT
def __init__(self, channels): threading.Thread.__init__(self) self.host = cfg.get_config(Constants.REDIS_HOST) self.port = cfg.get_config(Constants.REDIS_PORT) # 连接到redis self.redis = redis.Redis(host=self.host, port=self.port) # 创建一个订阅者发布者对象 self.pubsub = self.redis.pubsub() # channels是一个list,里面存储所有需要订阅的频道 self.pubsub.subscribe(channels) self.methods = {'price': self.price_handler}
def __init__(self, meta_code): base_currency, market_currency, symbol, contract_type = self.parse_meta( meta_code) super().__init__(base_currency, market_currency, meta_code, cfg.get_float_config(Constants.OKEX_FEE)) self.apikey = cfg.get_config(Constants.OKEX_APIKEY) # apikey self.apisec = cfg.get_config(Constants.OKEX_APISEC) # apisec self.contract_type = contract_type # 合约类型? self.symbol = symbol # ?? self.base_url = Constants.OKEX_FUTURE_REST_BASE # okex市场的URL:"https://www.okex.com" self.session = requests.session() # 通过request模块创建一个session self.timeout = Constants.OK_HTTP_TIMEOUT # 超时时间:2000
def __init__(self, meta_code): base_currency, market_currency, symbol = self.parse_meta(meta_code) super().__init__(base_currency, market_currency, meta_code, cfg.get_float_config(Constants.BITMEX_FEE)) self.apikey = cfg.get_config(Constants.BITMEX_APIKEY) self.apisec = cfg.get_config(Constants.BITMEX_APISEC) self.base_url = Constants.BITMEX_FUTURE_WS_BASE self.symbol = symbol self.timeout = Constants.OK_HTTP_TIMEOUT self.update_flags = {"depth": False} self.websocket = None self.session = requests.session()
def __init__(self, meta_code,loop): self.contract_type = None self.symbol = None base_currency, market_currency, symbol, contract_type = self.parse_meta(meta_code) super().__init__(base_currency, market_currency, meta_code, cfg.get_float_config(Constants.OKEX_FEE)) self.apikey = cfg.get_config(Constants.OKEX_APIKEY) # apikey,估计是登录交易所需要的认证凭据 self.apisec = cfg.get_config(Constants.OKEX_APISEC) # apisec,估计是登录交易所需要的认证凭据 # okex市场的websocket异步接口和request同步接口的url是不同的! self.base_url = Constants.OKEX_FUTURE_WS_BASE # "wss://real.okex.com:10440/websocket/okexapi" self.contract_type = contract_type self.symbol = symbol self.q = queue.Queue() self.websocket = None self.depth = None self.trade = None self.update_flags = {"depth": False, 'trade': False} self.loop = loop # type: AbstractEventLoop self.static_methods_register()
def test_get_redis(self): host = cfg.get_config(Constants.REDIS_PORT) port = cfg.get_config(Constants.REDIS_HOST) print(host + port)
def test_get_config(self): val = cfg.get_config("test") self.assertTrue(val == "dev")
def __init__(self): self.host = cfg.get_config(Constants.REDIS_HOST) self.port = cfg.get_config(Constants.REDIS_PORT) self.redis = redis.Redis(host=self.host, port=self.port)