代码拉取完成,页面将自动刷新
同步操作将从 海风/pyctp 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__title__ = 'test py ctp of se'
__author__ = 'HaiFeng'
__mtime__ = '20190506'
from py_ctp.trade import CtpTrade
from py_ctp.quote import CtpQuote
from py_ctp.enums import *
import time
class TestTrade(object):
def __init__(self, addr: str, broker: str, investor: str, pwd: str, appid: str, auth_code: str, proc: str):
self.front = addr
self.broker = broker
self.investor = investor
self.pwd = pwd
self.appid = appid
self.authcode = auth_code
self.proc = proc
self.t = CtpTrade()
self.t.OnConnected = self.on_connect
self.t.OnUserLogin = lambda o, x: print('Trade logon:', x)
self.t.OnDisConnected = lambda o, x: print(x)
self.t.OnRtnNotice = lambda obj, time, msg: print(f'OnNotice: {time}:{msg}')
self.t.OnErrRtnQuote = lambda obj, quote, info: None
self.t.OnErrRtnQuoteInsert = lambda obj, o: None
self.t.OnOrder = lambda obj, o: print(o)
self.t.OnErrOrder = lambda obj, f, info: print(info)
self.t.OnTrade = lambda obj, o: print(o)
self.t.OnInstrumentStatus = lambda obj, inst, stat: None
def on_connect(self, obj):
self.t.ReqUserLogin(self.investor, self.pwd, self.broker, self.proc, self.appid, self.authcode)
def run(self):
self.t.ReqConnect(self.front)
# self.t.ReqConnect('tcp://192.168.52.4:41205')
def release(self):
self.t.ReqUserLogout()
class TestQuote(object):
"""TestQuote"""
def __init__(self, addr: str, broker: str, investor: str, pwd: str):
""""""
self.front = addr
self.broker = broker
self.investor = investor
self.pwd = pwd
self.q = CtpQuote()
self.q.OnConnected = lambda x: self.q.ReqUserLogin(self.investor, self.pwd, self.broker)
self.q.OnUserLogin = lambda o, i: self.q.ReqSubscribeMarketData('rb1910')
def run(self):
self.q.ReqConnect(self.front)
def release(self):
self.q.ReqUserLogout()
if __name__ == "__main__":
front_trade = 'tcp://180.168.146.187:10101'
front_quote = 'tcp://180.168.146.187:10111'
broker = '9999'
investor = '008105'
pwd = '1'
appid = 'simnow_client_test'
auth_code = '0000000000000000'
proc = ''
if investor == '':
investor = input('invesotr:')
pwd = input('password:')
appid = input('appid:')
auth_code = input('auth code:')
proc = input('product info:')
tt = TestTrade(front_trade, broker, investor, pwd, appid, auth_code, proc)
tt.run()
time.sleep(5)
# tt.t.ReqOrderInsert('rb2001', DirectType.Buy, OffsetType.Open, 4000, 3)
qq = TestQuote(front_quote, broker, investor, pwd)
qq.run()
#
time.sleep(6)
for inst in tt.t.instruments.values():
print(inst)
print(tt.t.account)
input()
tt.release()
qq.release()
input()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。