#!/usr/bin/env python # coding:utf-8 from PoboAPI import * import datetime import time import numpy as np #开始时间,用于初始化一些参数 def OnStart(context) : print("I\'m starting...") #登录交易账号,需在主页用户管理中设置账号,并把期货测试替换成您的账户名称 context.myacc = None if "回测期货" in context.accounts : print("登录交易账号[回测期货]") if context.accounts["回测期货"].Login() : context.myacc = context.accounts["回测期货"] def OnMarketQuotationInitialEx(context, exchange,daynight): print("当前交易所是%s"%exchange) if exchange != 'SHFE': return #获取主力合约 g.code2 = GetMainContract('CZCE', 'TA', 20) SubscribeQuote([g.code2]) print(g.code2) value = PBObj() value.Rate = 0.09 context.myacc.SetMargin('TA001.CZCE',value) print("保证金率设置成功") def OnBar(context,code,bartype): print("<=====获取到%s得bar事件=====>"%code) cutime = GetCurrentTime() print(cutime) df= GetHisDataByFieldAsDF(code, ["datetime","open", "high", "low", "close"], \ bar_type=BarType.Min30, count=5) print(df) def OnQuote(context,code): dyndata = GetQuote(code) print("%s最新数据:"%code) margin_value = context.accounts["回测期货"].GetMargin(code,BSType.BuyOpen) print("%s的保证金率为:%s"%(code, margin_value.Rate))

图片