def initialize(context):
g.security = '000001.XSHE'
set_benchmark('000300.XSHG')
def handle_data(context,data):
security = g.security
order(security, 100)
I want operation this code at 10:00 o'clock, how can write the code?
def initialize(context):
g.security = '000001.XSHE'
set_benchmark('000300.XSHG')
def handle_data(context,data):
security = g.security
order(security, 100)
I want operation this code at 10:00 o'clock, how can write the code?
You can use the sched
module or simply loop through datetime, although as AChampion points out, on a *nix platform, it's easier to use cron.
This stackoverflow question does into more detail about sched and datetime.
Essentially:
from datetime import datetime as dt
while True:
if dt.now().hour == 10: # for 10 o'clock
initialize(context)
handle_data(context,data)
time.sleep(60) # Minimum interval between task executions
else:
time.sleep(10) # The else clause is not necessary but would prevent the program to keep the CPU busy.