Skip to content

Commit

Permalink
#
Browse files Browse the repository at this point in the history
  • Loading branch information
yutiansut committed Jul 10, 2019
1 parent 74758dd commit 43584e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions QATRADER/__init__.py
Expand Up @@ -13,7 +13,8 @@
@click.option('--portfolio', default='default')
@click.option('--bank_password', default=None)
@click.option('--capital_password', default=None)
def single_trade(acc, pwd, wsuri, broker, trade_host, ping_gap, taskid, portfolio, bank_password, capital_password):
@click.option('--appid', default=None)
def single_trade(acc, pwd, wsuri, broker, trade_host, ping_gap, taskid, portfolio, bank_password, capital_password, appid):
QA_TRADER(str(acc), str(pwd), wsuri=wsuri, trade_host=trade_host, portfolio=portfolio, bank_password=bank_password, capital_password=capital_password,
broker_name=broker, ping_gap=ping_gap, taskid=taskid).start()
appid=appid, broker_name=broker, ping_gap=ping_gap, taskid=taskid).start()

13 changes: 9 additions & 4 deletions QATRADER/trader.py
Expand Up @@ -39,7 +39,7 @@ class QA_TRADER(QA_Thread):

def __init__(self, account_cookie, password, wsuri, broker_name='simnow', portfolio='default',
trade_host='localhost', trade_port='5672', pub_host='localhost', pub_port='5672', sig=True, ping_gap=1,
bank_password=None, capital_password=None,
bank_password=None, capital_password=None, appid= None,
if_restart=True, taskid=None, database=pymongo.MongoClient()):

super().__init__(name='QATRADER_{}'.format(account_cookie))
Expand Down Expand Up @@ -70,6 +70,7 @@ def __init__(self, account_cookie, password, wsuri, broker_name='simnow', portfo
self.bank_password = bank_password
self.capital_password = capital_password
self.tempPass = ''
self.appid = appid

self.sub = consumer.subscriber_routing(host=trade_host, port=trade_port, user=trade_server_user, password=trade_server_password,
exchange=trade_server_order_exchange, routing_key=self.account_cookie)
Expand All @@ -90,7 +91,7 @@ def on_message(self, message):
message, dict) else json.loads(str(message))
#print(message)
message = fix_dict(message)
#print(message)
print(message)
self.pub.pub(json.dumps(message), routing_key=self.account_cookie)
"""需要在这里维持实时账户逻辑
Expand Down Expand Up @@ -199,8 +200,12 @@ def generate_websocket(self,):

def _onopen(ws):
def run():
ws.send(login(
name=self.account_cookie, password=self.password, broker=self.broker_name))
if self.appid is None:
ws.send(login(
name=self.account_cookie, password=self.password, broker=self.broker_name))
else:
ws.send(login(
name=self.account_cookie, password=self.password, broker=self.broker_name, appid=self.appid))
threading.Thread(target=run, daemon=False).start()
ws.on_open = _onopen
return ws
Expand Down

0 comments on commit 43584e9

Please sign in to comment.