userlist=download_data_from_db(f'select Distinct Account_name from trade_instruction where ID_Order = "{order_id}" and Intranet_IP ="{Intranat_ip}"','user_center')['Account_name'].tolist()
returnuserlist
deftrade_instruction_monitor(last_order:int=0):
'''
交易监控
Returns
-------
None.
'''
iflast_order==0:
last_order_id=str(
int(download_data_from_db(f'select max(ID_Order) from trade_instruction','user_center').values.tolist()[0][0]))
eliflast_order==1:
last_order_id='-1'
whileTrue:
order_id=str(
int(download_data_from_db(f'select max(ID_Order) from trade_instruction','user_center').values.tolist()[0][0]))
iforder_id==last_order_id:
time.sleep(10)
pass
elifint(order_id)-int(last_order_id)>1:
order_id=str(int(last_order_id)+1)
ip=get_host_ip()
message=time.strftime("%Y-%m-%d%H:%M:%S",time.localtime())+''+str(ip)+''+order_id+' begin trade'
# send_email('自动交易提醒', message)
time.sleep(10)
op=str(download_data_from_db(f'select Trade_Type from trade_instruction where ID_Order="{order_id}"','user_center').values.tolist()[0][0])
op=str(download_data_from_db(f'select Trade_Type from trade_instruction where ID_Order="{order_id}"',
'user_center').values.tolist()[0][0])
userlist=get_userlist(order_id)
trade_main=auto_trade(userlist,op,order_id)
trade_main.trades()
last_order_id=order_id
else:
pass
defall_check():
instruction=pd.read_sql(
fr'select Account_Number Account_name,Ticker,Buy_Or_Sell Operate,Shares Number_transactions from trade_retail.trade_instruction_stock_retail where Trade_Date like "{today}%%"',
fr'select * from user_center.trading_users where update_time = (select max(update_time) from user_center.trading_users) and Broker ="华泰证券" or Broker = "长城证券" or Broker = "国泰君安"',
engine)
# print(trading_users)
user_list=trading_users['Account_Name'].tolist()
trade_list=pd.read_sql(fr'select * from user_center.trade_instruction where As_Of_Date like "{today}%%"',engine)