Merge branch 'dev' of https://github.com/vnpy/vnpy into okexv3

This commit is contained in:
nanoric 2018-10-23 21:33:52 -04:00
commit 3fd5d398a8
10 changed files with 227 additions and 22 deletions

6
.gitignore vendored
View File

@ -59,6 +59,8 @@ build/Makefile
.gitignore
temp/
# setup.py install 临时文件
dist
*.egg
*.egg-info

64
docker/gui/Dockerfile Normal file
View File

@ -0,0 +1,64 @@
FROM ubuntu:16.04
LABEL name="vnpy"
LABEL maintainer="joans321 <xjq9296@gmail.com>"
ARG user=vnpyuser
ARG group=vnpyuser
ARG uid=1000
ARG gid=1000
ARG ANACONDA=Anaconda2-4.0.0-Linux-x86_64.sh
ENV HOME /home/${user}
RUN groupadd -g ${gid} ${group}
RUN useradd -d $HOME -u ${uid} -g ${gid} -m -s /bin/bash ${user}
RUN apt-get update
RUN apt-get install -y gcc make cmake
RUN apt-get install -y build-essential
RUN apt-get install -y ccache
RUN apt-get install -y libssl-dev
RUN apt-get install -y wget curl git
RUN apt-get install -y gawk sed bison flex
RUN apt-get install -y bc libelf-dev
RUN apt-get install -y vim
RUN apt-get install -y net-tools gdb
RUN apt-get install -y iputils-ping
RUN apt-get install -y libncurses-dev
RUN apt-get install -y cpio
RUN apt-get install -y python-dev
RUN apt-get install -y mongodb
RUN apt-get install -y libboost-all-dev
RUN apt-get install -y libsnappy-dev python-snappy
RUN apt-get install -y qt4-dev-tools
RUN apt-get install -y qtbase5-dev
RUN apt-get install -y python-pyqt5
RUN apt-get install -y python3
RUN apt-get install -y python3-pyqt5
RUN apt-get install -y fonts-wqy-zenhei
### Install Anaconda
RUN curl https://repo.continuum.io/archive/${ANACONDA} -o ${ANACONDA} && \
/bin/bash ${ANACONDA} -b -p /opt/conda && \
echo "export PATH=/opt/conda/bin:\$PATH" >> /etc/bash.bashrc && \
rm ${ANACONDA}
### Install ta-lib
RUN curl -L -O http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz && \
tar -zxf ta-lib-0.4.0-src.tar.gz && \
cd ta-lib && \
./configure --prefix=/usr && \
make && make install
RUN rm -rf /ta-lib-0.4.0-src.tar.gz /ta-lib
RUN chown ${user} -R /opt
ENV QT_X11_NO_MITSHM=1
WORKDIR /

73
docker/gui/README.md Normal file
View File

@ -0,0 +1,73 @@
# VNPY GUI Docker 镜像
该镜像提供编译及运行 vnpy 的环境。
# 编译镜像
~~~sh
$ docker build . -t vnpy
~~~
# 运行镜像
执行 [run.sh](./run.sh) 以 vnpyuser 用户启动容器并且把 vnpy 项目目录挂载到容器的 /srv/vnpy 目录。
~~~sh
$ ./run.sh
vnpyuser@e6ad42871a34$ cd /srv/vnpy
vnpyuser@e6ad42871a34:/srv/vnpy$ bash ./install.sh
vnpyuser@e6ad42871a34:/srv/vnpy$ cd examples/VnTrader/
vnpyuser@4abb3834d129:/srv/vnpy/examples/VnTrader$ python run.py
~~~
# Mongodb 支持
// TODO : 数据保存到本地磁盘
* 容器内启动方法
~~~sh
$ docker exec -u 0 -it vnpy /bin/bash
$ mongod --smallfiles --config /etc/mongodb.conf
~~~
# Windows 支持
Windows 使用 [Xming](http://www.straightrunning.com/XmingNotes/) 作为 X11 服务器,安装配置网络连接之后启动 docker 容器。
# OS X 支持
由于 OS X 没有自带 X11 服务器,需要手动安装后并配置允许网络客户端连接.
* 安装 xquartz 作为 X11 服务器
~~~sh
$ brew cask install xquartz
~~~
* 打开 xquartz 并配置允许网络连接
![xquartz config](xquartz_preferences.png)
* 执行脚本启动 docker
~~~sh
$ ./run.sh
~~~
参考博客 [docker-for-mac-and-gui-applications](https://fredrikaverpil.github.io/2016/07/31/docker-for-mac-and-gui-applications/)

4
docker/gui/build.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
docker build . -t vnpy

51
docker/gui/run.sh Executable file
View File

@ -0,0 +1,51 @@
#!/bin/bash
THIS_DIR=$(cd `dirname $0`; pwd -P)
TOPDIR=${THIS_DIR}/../..
id=vnpyuser
ostype=Linux
display=
volume="-v ${TOPDIR}:/srv/vnpy"
timezone="-e TZ=UTC-8"
function os_detect() {
osname=`uname -s`
case "${osname}" in
Linux*) ostype=Linux;;
Darwin*) ostype=Mac;;
CYGWIN*) ostype=Cywin;;
MINGW*) ostype=Mingw;;
*) ostype="Unknown-${osname}"
esac
echo "Your system is : ${ostype}"
}
function osx_ip() {
ip=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
if [ -z "$ip" ]; then
ip=$(ifconfig en1 | grep inet | awk '$1=="inet" {print $2}')
fi
}
os_detect
if [ "${ostype}" = "Linux" ]; then
display="-v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY"
elif [ "${ostype}" = "Mac" ]; then
osx_ip
display_number=`ps -ef | grep "Xquartz :\d" | grep -v xinit | awk '{ print $9; }'`
display="-v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=${ip}${display_number}"
xhost + $ip
elif [ "${ostype}" = "Cywin" ]; then
elif [ "${ostype}" = "Mingw" ]; then
fi
docker_args="-u $id $display $volume $timezone"
docker run -it -d --name vnpy $docker_args vnpy /bin/bash

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

View File

@ -1,20 +1,33 @@
#!/bin/bash
function check_result() {
if [ $? -ne 0 ]; then
echo " "
echo "do command failed for $1 !!!"
echo " "
exit 1
fi
}
#Build ctp/lts/ib api
pushd vnpy/api/ctp
bash build.sh
check_result "build api.ctp"
popd
pushd vnpy/api/lts
bash build.sh
check_result "build api.lts"
popd
pushd vnpy/api/xtp
bash build.sh
check_result "build api.xtp"
popd
pushd vnpy/api/ib
bash build.sh
check_result "build api.ib"
popd
#Install Python Modules

View File

@ -13,3 +13,7 @@ gevent-websocket
pyjwt
ccxt
pyqtgraph
qtpy
psutil
ta-lib

View File

@ -19,22 +19,11 @@ other financial markets.
import os
from setuptools import setup
from setuptools import setup, find_packages
import vnpy
def getSubpackages(name):
"""获取该模块下所有的子模块名称"""
splist = []
for dirpath, _dirnames, _filenames in os.walk(name):
if os.path.isfile(os.path.join(dirpath, '__init__.py')):
splist.append(".".join(dirpath.split(os.sep)))
return splist
setup(
name='vnpy',
version=vnpy.__version__,
@ -55,7 +44,7 @@ setup(
'Topic :: Office/Business :: Financial :: Investment',
'Programming Language :: Python :: Implementation :: CPython',
'License :: OSI Approved :: MIT License'],
packages=getSubpackages('vnpy'),
packages=find_packages(),
package_data={'': ['*.json', '*.md', '*.ico',
'*.h', '*.cpp', '*.bash', '*.txt',
'*.dll', '*.lib', '*.so', '*.pyd',

View File

@ -92,7 +92,7 @@ class BitmexGateway(VtGateway):
#----------------------------------------------------------------------
def subscribe(self, subscribeReq):
"""订阅行情"""
pass
self.wsApi.subscribeMarketData(subscribeReq.symbol)
#----------------------------------------------------------------------
def sendOrder(self, orderReq):
@ -274,15 +274,20 @@ class WebsocketApi(BitmexWebsocketApi):
self.apiSecret = apiSecret
for symbol in symbols:
tick = VtTickData()
tick.gatewayName = self.gatewayName
tick.symbol = symbol
tick.exchange = EXCHANGE_BITMEX
tick.vtSymbol = '.'.join([tick.symbol, tick.exchange])
self.tickDict[symbol] = tick
self.subscribeMarketData(symbol)
self.start(testnet)
#----------------------------------------------------------------------
def subscribeMarketData(self, symbol):
"""订阅行情"""
tick = VtTickData()
tick.gatewayName = self.gatewayName
tick.symbol = symbol
tick.exchange = EXCHANGE_BITMEX
tick.vtSymbol = '.'.join([tick.symbol, tick.exchange])
self.tickDict[symbol] = tick
#----------------------------------------------------------------------
def onConnect(self):
"""连接回调"""