def callback(self, a, b, c, data): data = json.loads(data) if data['topic'] == 'subscribe': new_ins = data['code'].replace('_', '.').split(',') import copy old = len(self.subscribe_list) self.subscribe_list.extend(new_ins) self.subscribe_list = list(set(self.subscribe_list)) if old < len(self.subscribe_list): self.ws.send(subscribe_quote(','.join(self.subscribe_list)))
def app(acc, password, wsuri, broker, bankid, bankpassword, capitalpassword): ws = websocket.WebSocketApp(wsuri, on_pong=on_pong, on_message=on_message, on_error=on_error, on_close=on_close) def _onopen(ws): def run(): x = login(name=acc, password=password, broker=broker, appid='1') print(x) ws.send(x) ws.send(peek()) # ws.send(querybank(account_cookie=acc, password=capitalpassword, # bankid=bankid, bankpassword=bankpassword)) threading.Thread(target=run, daemon=False).start() ws.on_open = _onopen threading.Thread(target=ws.run_forever, name='sub_websock {}'.format(acc), daemon=False).start() time.sleep(1) # x1 = query_settlement('20190617') # x2 = query_settlement('20190618') ws.send(subscribe_quote('SHFE.rb1910,DCE.j1909')) #x3 = query_settlement(20190619) #ws.send(query_settlement('20190619')) for i in range(10): ws.sock.ping('QUANTAXIS') time.sleep(1) ws.send(subscribe_quote('SHFE.rb1910,DCE.j1909')) ws.close()
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 run(): ws.send(subscribe_quote('SHFE.rb1910,DCE.j909')) ws.send(peek())
def run(self): time.sleep(2) self.ws.send(subscribe_quote('SHFE.rb1910,DCE.j1909')) while True: time.sleep(1)