基于 haifengat/centos:8.1, 密码 root/pentakill,支持sshd。
FROM haifengat/centos:8.1
# root:pentakill
# 安装 python 3.6
RUN yum install python3 -y
RUN ln -s /usr/bin/python3.6 /usr/bin/python \
&& ln -s /usr/bin/pip3.6 /usr/bin/pip
COPY ./mq_demo.py /home/
COPY ./td_demo.py /home/
# pip 国内源
RUN mkdir -p ~/.pip/ \
&& echo $'[global]\n\
timeout = 6000\n\
index-url = https://mirrors.aliyun.com/pypi/simple/\n\
trusted-host = mirrors.aliyun.com\n'\
> ~/.pip/pip.conf
# 安装pyctp
RUN pip install py_ctp
Build
docker build -t haifengat/pyctp . && docker push haifengat/pyctp \
&& docker tag haifengat/pyctp haifengat/pyctp:`date '+%m%d'` && docker push haifengat/pyctp:`date '+%m%d'`
docker run -it haifengat/pyctp:2.3.2 python mq_demo.py
docker run -it haifengat/pyctp:2.3.2 python td_demo.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from py_ctp.trade import CtpTrade
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()
if __name__ == "__main__":
front_trade = 'tcp://180.168.146.187:10101'
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(6)
for inst in tt.t.instruments.values():
print(inst)
print(tt.t.account)
input()
tt.release()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from py_ctp.quote import CtpQuote
from py_ctp.enums import *
import time
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 = self.onconnect
self.q.OnUserLogin = self.onrspuserlogin
def run(self):
self.q.ReqConnect(self.front)
def onconnect(self, obj):
print("connected")
self.q.ReqUserLogin(self.investor, self.pwd, self.broker)
def onrspuserlogin(self, obj, info):
print(info)
self.q.ReqSubscribeMarketData('rb2009')
def release(self):
self.q.ReqUserLogout()
if __name__ == "__main__":
front_quote = 'tcp://180.168.146.187:10111'
broker = '9999'
investor = '008105'
pwd = '1'
appid = 'simnow_client_test'
auth_code = '0000000000000000'
if investor == '':
investor = input('invesotr:')
pwd = input('password:')
appid = input('appid:')
auth_code = input('auth code:')
qq = TestQuote(front_quote, broker, investor, pwd)
qq.run()
input()
qq.release()
input()
Content type
Image
Digest
Size
288.9 MB
Last updated
about 6 years ago
docker pull haifengat/pyctp