def main(): txdates = get_date_list("20200101")# ["20200113","20200114","20200115",] tradeapi=api.CThostFtdcTraderApi_CreateFtdcTraderApi() tradespi=CTradeSpi(tradeapi) tradeapi.RegisterSpi(tradespi) tradeapi.SubscribePrivateTopic(api.THOST_TERT_QUICK) tradeapi.SubscribePublicTopic(api.THOST_TERT_QUICK) FrontAddr1="tcp://222.66.192.247:43205"#"tcp://180.168.146.187:10100" Userid ="60039860" tradeapi.RegisterFront(FrontAddr1.encode('ascii', 'ignore')) tradeapi.Init() time.sleep(15) #qryinfofield.TradingDay="20200113" lv_reqid = 40000 txdates = ["20200113","20200117"] for dt in txdates: #print "before" lv_reqid += 1 tradespi.ReqQryHist(dt,lv_reqid) time.sleep(6) #print "after" #print dt time.sleep(30) rst = tradespi.allsettle filehandler = open("./tx1.pkl", 'w') pickle.dump(rst, filehandler)
def main(): tradeapi = api.CThostFtdcTraderApi_CreateFtdcTraderApi() tradespi = CTradeSpi(tradeapi, BROKERID, USERID, PASSWORD, AppID, AuthCode) tradeapi.RegisterFront(FrontAddr) tradeapi.RegisterSpi(tradespi) tradeapi.SubscribePrivateTopic(api.THOST_TERT_QUICK) tradeapi.SubscribePublicTopic(api.THOST_TERT_QUICK) tradeapi.Init() tradeapi.Join()
def main(): tradeapi=api.CThostFtdcTraderApi_CreateFtdcTraderApi() tradespi=CTradeSpi(tradeapi) tradeapi.RegisterFront(FrontAddr) tradeapi.RegisterSpi(tradespi) tradeapi.SubscribePrivateTopic(api.THOST_TERT_QUICK) tradeapi.SubscribePublicTopic(api.THOST_TERT_QUICK) tradeapi.Init() tradeapi.Join()
def __init__(self): tdapi.CThostFtdcTraderSpi.__init__(self) self.api = tdapi.CThostFtdcTraderApi_CreateFtdcTraderApi() self.login = False self.lock = False # 锁机制,用于确保系统前后操作,下单超过1秒废单 self.position = None self.positionCache = {} self.account = {} self.contract = {} self.orderList = []
def main(): tradeapi=api.CThostFtdcTraderApi_CreateFtdcTraderApi() tradespi=CTradeSpi(tradeapi) tradeapi.RegisterFront("tcp://180.168.146.187:10000") #tradeapi.RegisterFront("tcp://180.168.146.187:10030") tradeapi.RegisterSpi(tradespi) tradeapi.SubscribePrivateTopic(api.THOST_TERT_RESUME) tradeapi.SubscribePublicTopic(api.THOST_TERT_RESUME) tradeapi.Init() tradeapi.Join()
def main(): tradeapi = api.CThostFtdcTraderApi_CreateFtdcTraderApi() tradespi = CTradeSpi(tradeapi, BROKERID, USERID, PASSWORD, AppID, AuthCode) tradeapi.RegisterFront(FrontAddr) tradeapi.RegisterSpi(tradespi) tradeapi.SubscribePrivateTopic(api.THOST_TERT_QUICK) tradeapi.SubscribePublicTopic(api.THOST_TERT_QUICK) tradeapi.Init() time.sleep(10) ReqQryInstrument(tradeapi) # ReqQryInvestorPosition(tradeapi, BROKERID, USERID, "IF2012") tradeapi.Join()
def main(): tradeapi = api.CThostFtdcTraderApi_CreateFtdcTraderApi() tradespi = CTradeSpi(tradeapi) loginfield = api.CThostFtdcReqUserLoginField() loginfield.BrokerID = "8000" loginfield.UserID = "000005" loginfield.Password = "******" loginfield.UserProductInfo = "python dll" tradeapi.RegisterFront("tcp://172.19.125.39:39233") tradeapi.RegisterSpi(tradespi) tradeapi.SubscribePrivateTopic(api.THOST_TERT_RESUME) tradeapi.SubscribePublicTopic(api.THOST_TERT_RESUME) tradeapi.Init() time.sleep(2) tradeapi.ReqUserLogin(loginfield, 0) tradeapi.Join()
def main(): reqid = 0 tradeapi=api.CThostFtdcTraderApi_CreateFtdcTraderApi() tradespi=CTradeSpi(tradeapi) tradeapi.RegisterSpi(tradespi) tradeapi.SubscribePrivateTopic(api.THOST_TERT_QUICK) tradeapi.SubscribePublicTopic(api.THOST_TERT_QUICK) tradeapi.RegisterFront(FrontAddr) tradeapi.Init() time.sleep(15) global ct str1 = "" print("hello") for str in ct: str1= str1+str print str1 save_file("./order.txt",u'{}\n'.format(str1))
async def 启动程序(账户data): global CTP用户名对应实例和登陆名,myqueue CTP用户名对应实例和登陆名={} myqueue=janus.Queue() while True: #每个CTP账户实例遍历,建立spi和api实例 for x in 账户data: if 账户data[x] is None: 账户data[x]=[list(x[1:3])+[0]] #登陆交易实例 tradeapi=api.CThostFtdcTraderApi_CreateFtdcTraderApi() BROKERID,USERID,PASSWORD,AppID,AuthCode,FrontAddr=x tradespi=CTradeSpi(tradeapi,BROKERID,USERID,PASSWORD,AppID,AuthCode,myqueue.sync_q) tradeapi.RegisterFront(FrontAddr) tradeapi.RegisterSpi(tradespi) tradeapi.SubscribePrivateTopic(api.THOST_TERT_RESTART) tradeapi.SubscribePublicTopic(api.THOST_TERT_RESTART) tradeapi.Init() while True: if tradespi.init_start is None: time.sleep(1) else: break if x[1] not in CTP用户名对应实例和登陆名: CTP用户名对应实例和登陆名[x[1]]={"td_obj":tradespi,'td_user_pass':账户data[x],"td_websockets":[],"td_api":tradeapi} else: CTP用户名对应实例和登陆名[x[1]]["td_obj"]=tradespi CTP用户名对应实例和登陆名[x[1]]["td_api"]=tradeapi await asyncio.sleep(100) #进行无限延迟,到达重连时间,去释放原来的api while True: await asyncio.sleep(10) if time_to_str(time.time())[11:16] in ("08:35","20:35"): for x in 账户data: CTP用户名对应实例和登陆名[x[1]]["td_api"].Release() break