Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16981

How to place orders using a broker ID within my Kucoin order monitoring code (Python, CCXT)

$
0
0

My Python code currently uses the CCXT library to monitor my Kucoin order stream. I would like to modify it to also place orders directly through the exchange. Importantly, I want to be able to specify my broker ID within the order placement process.Note: if there is any other individual solution that is welcome.Here's my existing order_stream function:

```  async def order_stream(self):        while self.info.userStreamActive and len(self.watch) != 0:            try:                ws = await self.ccxt.ws_connect('wss://ws-api-spot.kucoin.com/?', {'apiKey': self.ccxt.apiKey,'secret': self.ccxt.secret,'passphrase': self.ccxt.password,                })                msg = await ws.recv()                msg = json.loads(msg)                if 'data' in msg and 'subject' in msg['data'] and msg['data']['subject'] == 'trade.order':                    order = msg['data']['data']                    order_id = str(order['orderId'])                    status = order['status']                    symbol = str(order['symbol']).replace('-', '').lower()                    data = kucoin_order_stream(order)                    logging.debug('Order Stream:', data)                    order = self.orders.update(order_id, data)                    if '_id' in order:                        logging.warning(                            f"kucoin order stream: {order['symbol']} - {order['status']} - {order['orderId']}")                        await db.update_one(MONGO_METRONIX_ORDERS, {'_id': order['_id']}, {'status': order['status']})            except Exception as err:                logging.warning(                    f'kucoin user data msg websocket error (outer) - {str(err)}')            await asyncio.sleep(30)```

Viewing all articles
Browse latest Browse all 16981

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>