async def asyncAccount(): body = request['body'] future = request['future'] channel = request['channel'] queue = request['queue'] clientRef = body['client_ref'] action = body['action'] account = body['params']['account'] amount = body['params']['amount'] requestId = str(uuid4())[:8] msg = json.dumps({ 'action': action, 'params': { 'account': account, 'amount': amount } }) msg = Message(msg.encode(), delivery_mode=DeliveryMode.PERSISTENT) await channel.default_exchange.publish(msg, routing_key=queue) future.set_result( web.json_response({ 'status': 'OK', 'request_id': requestId, 'client_ref': clientRef }))
async def asyncOrder(): future = request['future'] body = request['body'] channel = request['channel'] queue = request['queue'] clientRef = body['client_ref'] account = body['account'] action = body['action'] stock = body['stock'] price = body['price'] vol = body['vol'] orderId = str(uuid4())[:8] msg = f"{account}|{action}|{stock}.{price}.{vol}.{orderId}" msg = Message(msg.encode(), delivery_mode=DeliveryMode.PERSISTENT) await channel.default_exchange.publish(msg, routing_key=queue) future.set_result( web.json_response({ 'status': 'OK', 'order_id': orderId, 'client_ref': clientRef }))
async def asyncTrade(): msg = json.dumps({ 'action': f"TRADE-{data['action']}", 'params': data }) msg = Message(msg.encode(), delivery_mode=DeliveryMode.PERSISTENT) await self.channel.default_exchange.publish(msg, routing_key='account')