Beispiel #1
0
 def __init__(self, apiKey, apiSecret, isTestNet=True, loglevel='debug', logfile=None):
     
     self.logger = generate_logger('bitmexREST', loglevel, logfile)
     
     self.apiKey = apiKey
     self.apiSecret = apiSecret
     self.isTestNet = isTestNet
     
     self.base_url = 'https://testnet.bitmex.com/api/v1/' if self.isTestNet else 'https://www.bitmex.com/api/v1/'
     self.clientOrderID = 0
Beispiel #2
0
 def __init__(self, *args, **kwargs):
     """
     self.symbols:
     {
       'XBTUSD': Snapshot(last_price, bid1, ask1, bid1vol, ask1vol, 
                           last_price_ts, orderbook_ts,
                           last_price_receiveTime, orderbook_receiveTime)
     }
     """
     super().__init__(*args, **kwargs)
     self.logger = generate_logger('bitmexWS_Market')
     self.symbols = {}
Beispiel #3
0
 def __init__(self, apiKey=None, apiSecret=None, isTestNet=True, loglevel='debug', logfile=None):
     
     self.logger = generate_logger('bitmexWS', loglevel, logfile)
     
     self.apiKey = apiKey
     self.apiSecret = apiSecret
     self.shouldAuth = apiKey is not None and apiSecret is not None
     
     self.isTestNet = isTestNet
     self.ws_url = 'wss://testnet.bitmex.com/realtime' if self.isTestNet else 'wss://www.bitmex.com/realtime'
     
     self.ws = None
     self.wst = None
     self.ping_td = None
     self.connected = False
    def __init__(self, g, account_settings, symbols):

        # 全局设置
        self.g = g
        self.logger = generate_logger('bitmexTargetPositionExecutor',
                                      self.g.loglevel, self.g.logfile)

        # 账户配置
        self.account_settings = account_settings

        # 目标仓位
        self.target_position = {}  # {symbol: pos}

        # 标的
        self.symbols = symbols  # 订阅哪些标的的持仓信息

        # data_handler
        self.data_handler = None

        # event engine
        self.event_engine = None

        # websocket-trading
        self.bm_ws_trading = bitmexWSTrading(self.account_settings.apiKey,
                                             self.account_settings.apiSecret,
                                             self.account_settings.isTestNet)
        self.bm_ws_trading.connect()
        self.bm_ws_trading.subscribe(self.symbols)
        self.bm_ws_trading.wait_for_initial_status()  # 等待的初始信息

        self.actual_position = self.bm_ws_trading.actual_position  # 由websocket接收的信息计算出的实际仓位 `position`
        self.unfilled_qty = self.bm_ws_trading.unfilled_qty  # 由websocket接收的信息计算出的未成交委托  `order`

        # rest
        self.bm_rest = bitmexREST(self.account_settings.apiKey,
                                  self.account_settings.apiSecret)
    def __init__(self, g, account_settings):

        self.g = g  # 全局设置
        self.logger = generate_logger('DataHandler', g.loglevel,
                                      g.logfile)  # 日志

        self.account_settings = account_settings  # 账户设置
        self.symbols = None  # 订阅的标的  ['XBTUSD', ...]

        self.market_data_q = queue.Queue()  # MarketData队列(带数据)
        self.td_run = None  # __run()函数线程
        self.active = False

        self.tick = {}  # {symbol: Tick}            # 最新的last_price信息
        self.orderbook = {}  # {symbol: Orderbook}       # 最新的orderbook信息

        self.registered_tick_events = {
        }  # {'XBTUSD': True}      # todo BITMEX_TICK_BATCH
        self.registered_orderbook_events = {
        }  # {'XBTUSD': BITMEX_ORDERBOOK_TOP}   # todo: consts.py 不同的orderbook类型

        self.registered_bar_events = {}  # {'XBTUSD': ['1m', '30s'], ...}
        self.bar = {}  # {'XBTUSD': {'1m': Bar, '30s': Bar}, ...}
        self.prev_bar = {}  # {'XBTUSD': {'1m': Bar, '30s': Bar}, ...}
Beispiel #6
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.logger = generate_logger('bitmexWS_Trading')