import json chart = { ‘__isStock’: True, ‘title’: { ‘text’: '测试API :Chart({…}) ’ }, ‘yAxis’: { ‘plotLines’: [{ ‘value’: 4520, ‘color’: ‘red’, ‘width’: 2, ‘label’: { ‘text’: ‘line1’, ‘align’: ‘center’ }, }, { ‘value’: 4500, ‘color’: ‘green’, ‘width’: 2, ‘label’: { ‘text’: ‘line2’, ‘align’: ‘center’ }, }] }, ‘series’: [{ ‘type’: ‘candlestick’, ‘name’: ‘当前周期’, ‘id’: ‘primary’, ‘data’: [] }] }
preTime = 0
def main(): global chart # 记得 引用全局 Log(exchange.GetAccount()) exchange.SetContractType(‘rb000’) exchange.SetRate(1) records = None ChartObj = Chart(chart) #ChartObj = ext.GetCfg()
records = exchange.GetRecords()
while((records is None) or len(records) < 30):
records = exchange.GetRecords()
LogStatus("records.length:", len(records))
Sleep(1000)
ext.PlotRecords(records, 'OK期货');
ext.PlotLine('dif', 0, records[len(records) - 1].Time)
ext.PlotLine('dea', 0, records[len(records) - 1].Time)
chart = ext.PlotLine('macd', 0, records[len(records)- 1].Time)
# 修改指标线 坐标轴Y轴
for key in ChartObj.series:
if(ChartObj.series[key].name == 'dif' or ChartObj.series[key].name == 'dea' or ChartObj.series[key].name == 'macd'):
ChartObj.series[key].yAxis = 1
chart.update(ChartObj)
chart.reset()
while(true):
records = exchange.GetRecords()
if(len(records) > 50):
ext.PlotRecords(records, 'OK期货')
MACD = TA.MACD(records)
dif = MACD[0]
dea = MACD[1]
macd = MACD[2]
if preTime != records[records.length - 1].Time:
ext.PlotLine('dif', dif[dif.length - 2], records[records.length - 2].Time)
ext.PlotLine('dea', dea[dea.length - 2], records[records.length - 2].Time)
ext.PlotLine('macd', macd[macd.length - 2], records[records.length - 2].Time)
ext.PlotLine('dif', dif[dif.length - 1], records[records.length - 1].Time)
ext.PlotLine('dea', dea[dea.length - 1], records[records.length - 1].Time)
ext.PlotLine('macd', macd[macd.length - 1], records[records.length - 1].Time)
preTime = records[records.length - 1].Time
else:
ext.PlotLine('dif', dif[dif.length - 1], records[records.length - 1].Time)
ext.PlotLine('dea', dea[dea.length - 1], records[records.length - 1].Time)
ext.PlotLine('macd', macd[macd.length - 1], records[records.length - 1].Time)
LogStatus("records.length:", records.length, records[records.length - 1])
Sleep(1000)
小草 错误信息贴出来