def test_send(self): async def go(): await utils.send_telegram( 'We have created for you a selection of fun projects, that can show you how to create ' 'application from the blog to the applications related to data science' ) utils.test_async(go())
def test_update_position(self): def update_position(data): print(data) # order = self.nexus.api.put_order(1, 3500) # print(order) self.nexus.update_position = update_position utils.test_async(self.nexus.load())
def test_ohlcv(self): api = utils.ccxt_exchange('bitmex', is_async=True) async def go(symbol, timeframe, limit): m = await api.load_markets() new_data = await api.fetch_ohlcv(symbol=symbol, timeframe=timeframe, limit=limit) print(new_data) await api.close() utils.test_async(go('XBT/USD', '1m', 10))
def test_run(self): self.margin = None self.orders = dict() self.position = None def handle_topic(topic, action, data): print(topic, action, data) if topic == 'margin': if action == 'partial': self.margin = data elif action == 'update': self.margin.update(data) used_margin = self.margin['maintMargin'] avail_margin = self.margin['availableMargin'] logger.debug( f'[Margin] used_margin[{used_margin}], avail_margin[{avail_margin}]' ) elif topic == 'order': # for order in data: if action == 'partial' or action == 'insert': if data: order_id = data['orderID'] self.orders[order_id] = data else: if data and 'orderID' in data: order_id = data['orderID'] working_indicator = data['workingIndicator'] if working_indicator: self.orders[order_id].update(data) else: del self.orders[order_id] print(self.orders) print('--------------------') elif topic == 'position': if action == 'partial': self.position = data else: self.position.update(data) # 필수. currentQty = self.position['currentQty'] currency = self.position['currency'] markPrice = self.position['markPrice'] timestamp = self.position['timestamp'] liquidationPrice = self.position['liquidationPrice'] logger.info('%s %s current_qty[%s]', topic, action, currentQty) req = {'op': 'subscribe', 'args': ['tradeBin1m:XBTUSD']} ws = BitmexWS( 'XBTUSD', api_key=self.api_key, api_secret=self.api_secret, testnet=True, ) async def run(): logger.debug('ws > %s', ws) await ws.connect() """ "affiliate", // Affiliate status, such as total referred users & payout % "execution", // Individual executions; can be multiple per order "order", // Live updates on your orders "margin", // Updates on your current account balance and margin requirements "position", // Updates on your positions "privateNotifications", // Individual notifications - currently not used "transact" // Deposit/Withdrawal updates "wallet" // Bitcoin address balance data, including total deposits & withdrawals """ # req = {'op': 'subscribe', 'args': ['tradeBin1m:XBTUSD', 'order', 'margin', 'position', 'wallet']} # req = {'op': 'subscribe', 'args': ['margin', 'position:XBTUSD', 'quote:XBTUSD', 'orderBook10:XBTUSD']} # req = {'op': 'subscribe', 'args': ['order:XBTUSD', 'position:XBTUSD', 'wallet']} req = {'op': 'subscribe', 'args': ['orderBook10:XBTUSD']} ws.update_orderbook = lambda x: print(x) await ws.listen() utils.test_async(run())
def test_update_order(self): def update_order(data): print(data) self.nexus.update_order = update_order utils.test_async(self.nexus.load())
def test_update_candle(self): def handle_signal(data): print(data) self.nexus.update_candle = handle_signal utils.test_async(self.nexus.load())