def on_message(self, message): print(message) message = json.loads(message) if 'data' in message.keys(): data = message['data'][0] if 'quotes' in data.keys(): data = data['quotes'] for items in data.keys(): try: item = items.replace('.', '_') if item not in self.data.keys(): self.data[item] = data[items] else: for keys in data[items].keys(): self.data[item][keys] = data[items][keys] self.data[item]['instrument_id'] = item self.quoteclient.update_one({'instrument_id': item}, {'$set': self.data[item]}, upsert=True) except Exception as e: print(e) self.ws.send(peek())
def targs(): z = json.loads(str(body, encoding='utf-8')) QA.QA_util_log_info('===================== \n RECEIVE') QA.QA_util_log_info(z) if z['topic'] == 'sendorder': self.ws.send( send_order(z.get('account_cookie'), z.get('order_direction', 'BUY'), z.get('order_offset', 'OPEN'), z.get('volume', 1), z.get('order_id', False), z.get('code', 'rb1905'), z.get('exchange_id', 'SHFE'), z.get('price', 3925))) self.orders_client.insert_one(z) elif z['topic'] == 'peek': self.ws.send(peek()) elif z['topic'] == 'subscribe': self.ws.send(subscribe_quote()) elif z['topic'] == 'cancel_order': self.ws.send(cancel_order(z['account_cookie'], z['order_id'])) elif z['topic'] == 'transfer': self.ws.send( transfer( z['account_cookie'], z.get('capital_password', self.message['capital_password']), z.get('bankid', self.message['bankid']), z.get('bankpassword', self.message['bank_password']), z['amount'])) self.message['banks'][z.get( 'bankid', self.message['bankid'])]['fetch_amount'] = -1 self.ws.send( querybank( z['account_cookie'], z.get('capital_password', self.message['capital_password']), z.get('bankid', self.message['bankid']), z.get('bankpassword', self.message['bank_password']))) elif z['topic'] == 'query_bank': # x = list(self.message['banks'].())[0] # x['fetch_amount'] = -1 self.message['banks'][z.get( 'bankid', self.message['bankid'])]['fetch_amount'] = -1 self.ws.send( querybank( z['account_cookie'], z.get('capital_password', self.message['capital_password']), z.get('bankid', self.message['bankid']), z.get('bankpassword', self.message['bank_password']))) elif z['topic'] == 'kill': self.message['status'] = 500 self.update_account() self.settle() self.ws.close() raise Exception elif z['topic'] == 'query_settlement': self.ws.send(query_settlement(int(z.get('day')))) elif z['topic'] == 'change_password': self.ws.send( change_password(self.message['password'], z['newPass'])) self.tempPass = z['newPass']
def sync(self): self.ws.send(peek())
def on_message(self, message): print(message) #self.ws.send(subscribe_quote('SHFE.rb1910,DCE.j1909')) self.ws.send(peek())
def run(): ws.send(subscribe_quote('SHFE.rb1910,DCE.j909')) ws.send(peek())
def run(): x = login(name=acc, password=password, broker=broker, appid='1') print(x) ws.send(x) ws.send(peek())
def on_message(ws, message): QA.QA_util_log_info(message) ws.send(peek())
def run(): ws.send(peek())