Exemplo n.º 1
0
    def test_subscribe_instrument(self):
        ws = BitMexWs()

        def subscribe(x):
            print(x)
            self.complete()

        ws.bind('instrument', subscribe)

        self.wait_complete()
        ws.close()
Exemplo n.º 2
0
    def test_subscribe_margin(self):
        ws = BitMexWs()

        def subscribe(x):
            print(x)
            self.complete()

        ws.bind('margin', subscribe)

        self.wait_complete()
        ws.close()
Exemplo n.º 3
0
    def test_subscribe_margin(self):
        ws = BitMexWs(account=self.account, pair=self.pair)

        def subscribe(x):
            print(x)
            self.complete()

        ws.bind('margin', subscribe)

        self.wait_complete()
        ws.close()
Exemplo n.º 4
0
 def on_update(self, bin_size, strategy):
     """
     戦略の関数を登録する。
     :param strategy:
     """
     self.bin_size = bin_size
     self.strategy = strategy
     if self.is_running:
         self.ws = BitMexWs(test=self.demo)
         self.ws.bind(allowed_range[bin_size][0], self.__update_ohlcv)
         self.ws.bind('instrument', self.__on_update_instrument)
         self.ws.bind('wallet', self.__on_update_wallet)
         self.ws.bind('position', self.__on_update_position)
         self.ws.bind('margin', self.__on_update_margin)
Exemplo n.º 5
0
 def on_update(self, bin_size, strategy):
     """
     Register the strategy function
     bind functions with webosocket data streams        
     :param strategy: strategy
     """       
     self.bin_size = bin_size
     self.strategy = strategy
     if self.is_running:
         self.ws = BitMexWs(account=self.account, pair=self.pair, test=self.demo)
         self.ws.bind(allowed_range[bin_size][0], self.__update_ohlcv)
         self.ws.bind('instrument', self.__on_update_instrument)
         self.ws.bind('wallet', self.__on_update_wallet)
         self.ws.bind('position', self.__on_update_position)
         self.ws.bind('margin', self.__on_update_margin)
         self.ob = OrderBook(self.ws)
Exemplo n.º 6
0
            if action == "partial" or \
                    action == "insert":
                orders[ordId] = v
            elif action == "update" and ordId in orders:
                orders[ordId]["size"] = v['size']
            elif action == "delete" and ordId in orders:
                del orders[ordId]

        bid_prices = sorted([v['price'] for v in self.asks.values()])
        ask_prices = sorted([v['price'] for v in self.bids.values()])

        if len(ask_prices) > 0:
            self.ask_max_price = ask_prices[-1]
        if len(bid_prices) > 0:
            self.bid_min_price = bid_prices[0]
        if len(ask_prices) > 0:
            self.best_bid_price = bid_prices[-1]
        if len(ask_prices) > 0:
            self.best_ask_price = ask_prices[0]

    def get_prices(self):
        return self.best_bid_price, self.best_ask_price


if __name__ == '__main__':
    ws = BitMexWs(account=BitMexWs.account, pair=BitMexWs.pair)
    ob = OrderBook(ws)
    while True:
        sys.stdout.write(f"\r{ob.get_prices()}")
        sys.stdout.flush()
Exemplo n.º 7
0
 def test_setup(self):
     ws = BitMexWs()
     ws.close()
Exemplo n.º 8
0
        for v in values:
            ordId = v['id']
            side = v['side']
            orders = self.asks if side == "Buy" else self.bids
            if action == "partial" or \
                    action == "insert":
                orders[ordId] = v
            elif action == "update" and ordId in orders:
                orders[ordId]["size"] = v['size']
            elif action == "delete" and ordId in orders:
                del orders[ordId]

        ask_prices = sorted([v['price'] for v in self.asks.values()])
        bid_prices = sorted([v['price'] for v in self.bids.values()])

        if len(ask_prices) > 0:
            self.ask_max_price = ask_prices[-1]
        if len(bid_prices) > 0:
            self.bid_min_price = bid_prices[0]

    def get_prices(self):
        return self.bid_min_price, self.ask_max_price

if __name__ == '__main__':
    ws = BitMexWs()
    ob = OrderBook(ws)
    while True:
        sys.stdout.write(f"\r{ob.get_prices()}")
        sys.stdout.flush()
Exemplo n.º 9
0
 def test_setup(self):
     ws = BitMexWs(account=self.account, pair=self.pair)
     ws.close()