from tqsdk import TqApi, TqSim, TargetPosTask, BacktestFinished, TqBacktest, TqAccount
from tqsdk.tafunc import ma
import datetime
from tqsdk import tafunc
beg_date = ‘2019-04-08 08:05:00’
end_date = ‘2019-04-15 23:36:20’
acc = TqSim()
api = TqApi(
acc,
backtest=TqBacktest(
start_dt=datetime.datetime.strptime(beg_date, ‘%Y-%m-%d %H:%M:%S’),
end_dt=datetime.datetime.strptime(end_date, ‘%Y-%m-%d %H:%M:%S’))
)
bars = api.get_kline_serial(“CZCE.RM001″,86400, 2)
orders = api.insert_order(symbol=”CZCE.RM001″, direction=”BUY”, offset=”OPEN”, volume=3)
print(‘–> order’, orders)
while True:
api.wait_update()
#if api.is_changing(bars.iloc[-1], “datetime”):
#print(datetime.datetime.fromtimestamp(bars.iloc[-1].datetime / 1e9))
func = lambda x: tafunc.time_to_datetime(x)
bars[‘datetime’] = bars[‘datetime’].apply(func)
print(bars)