下载当前gateway的所有行情bar数据

import time
from logging import INFO
from vnpy.event import EventEngine
from vnpy.trader.setting import SETTINGS
from vnpy.trader.engine import MainEngine
from vnpy_okex import OkexGateway
from vnpy_ctabacktester import CtaBacktesterApp

SETTINGS["log.active"] = True
SETTINGS["log.level"] = INFO
SETTINGS["log.console"] = True
SETTINGS["log.file"] = True

okex_setting = {
    "API Key": "",
    "Secret Key": "",
    "Passphrase": "",
    "会话数": 30,
    "代理地址": "127.0.0.1",
    "代理端口": "1087",
    "服务器": "REAL"
}

def time_str2int(timestring):
    return time.mktime(time.strptime(timestring, '%Y-%m-%d %H:%M:%S'))

def time_int2str(timestamp):
    return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp))

def main():
    event_engine = EventEngine()
    main_engine = MainEngine(event_engine)
    main_engine.add_gateway(OkexGateway)
    main_engine.connect(okex_setting, "OKEX")

    time.sleep(3)

    start = '2000-01-01 00:00:00+08:00'
    end = time_int2str(int(time.time())) +'+08:00'
    all_contracts = main_engine.get_all_contracts()
    ctaback_engine = main_engine.add_app(CtaBacktesterApp)

    # CTA BACK
    ctaback_engine.init_engine()
    main_engine.write_log("CTA BACK数据下载开始")

    #ctaback_engine.run_downloading_all("2021-09-20 00:00:00+08:00", "2021-09-27 00:00:00+08:00")

    for contracts in all_contracts:
        vt_symbol = contracts.name + '.' + contracts.gateway_name
        vt_intervals = ["d", "1h", "1m"]
        for vt_interval in vt_intervals:
            ctaback_engine.run_downloading(vt_symbol,vt_interval,start,end)

    main_engine.write_log("CTA BACK数据下载完成")
    ctaback_engine.close()
    main_engine.close()


if __name__ == '__main__':
    time_t = 28800
    # main()
    try:
        main()
    except:
        print('异常退出')
        # sendemail('异常退出', '行情下载异常: ' + time_int2str(int(time.time())))