Skip to content

Commit

Permalink
Merge pull request #6 from noranhe/main
Browse files Browse the repository at this point in the history
[Mod] 补充类型声明 + replace pytz + 更新版本号至2.0.1.3 + 增加Linux支持
  • Loading branch information
vnpy authored Aug 1, 2022
2 parents 4763f84 + ed56577 commit 927ce86
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 23 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 2.0.1.3版本

1. 修复打包文件缺少lib的问题
2. 使用zoneinfo替换pytz库
3. 调整安装脚本setup.cfg,添加Python版本限制
4. 增加Linux支持

# 2.0.1.2版本

1. 调整安装脚本setup.py,支持Windows下安装时根据Python版本进行编译
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</p>

<p align="center">
<img src ="https://img.shields.io/badge/version-2.0.1.2-blueviolet.svg"/>
<img src ="https://img.shields.io/badge/platform-windows-yellow.svg"/>
<img src ="https://img.shields.io/badge/version-2.0.1.3-blueviolet.svg"/>
<img src ="https://img.shields.io/badge/platform-windows|linux-yellow.svg"/>
<img src ="https://img.shields.io/badge/python-3.7|3.8|3.9|3.10-blue.svg" />
<img src ="https://img.shields.io/github/license/vnpy/vnpy.svg?color=orange"/>
</p>
Expand All @@ -17,7 +17,7 @@

## 安装

安装环境推荐基于3.0.0版本以上的【[**VeighNa Studio**](https://www.vnpy.com)】。
安装环境推荐基于3.3.0版本以上的【[**VeighNa Studio**](https://www.vnpy.com)】。

直接使用pip命令:

Expand Down
6 changes: 4 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = vnpy_ost
version = 2.0.1.2
version = 2.0.1.3
url = https://www.vnpy.com
license = MIT
author = Xiaoyou Chen
Expand All @@ -17,6 +17,7 @@ keywords =
classifiers =
Development Status :: 5 - Production/Stable
Operating System :: Microsoft :: Windows
Operating System :: POSIX :: Linux
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Expand All @@ -31,7 +32,8 @@ classifiers =
packages = find:
include_package_data = True
zip_safe = False
install_requires =
python_requires = >=3.7
install_requires =
importlib_metadata

[options.package_data]
Expand Down
24 changes: 18 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@
def get_ext_modules() -> list:
"""
获取三方模块
Windos需要编译使用
Linux暂未支持
Linux和Windows需要编译封装接口
Mac由于缺乏二进制库支持无法使用
"""

extra_compile_flags = ["-O2", "-MT"]
extra_link_args = []
runtime_library_dirs = []
if platform.system() == "Linux":
extra_compile_flags = [
"-std=c++17",
"-O3",
"-Wno-delete-incomplete",
"-Wno-sign-compare",
]
extra_link_args = ["-lstdc++"]
runtime_library_dirs = ["$ORIGIN"]

elif platform.system() == "Windows":
extra_compile_flags = ["-O2", "-MT"]
extra_link_args = []
runtime_library_dirs = []

else:
return []

vnostmd = Extension(
name="vnpy_ost.api.vnostmd",
Expand Down
22 changes: 10 additions & 12 deletions vnpy_ost/gateway/ost_gateway.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytz
from datetime import datetime
from typing import Dict, List, Tuple, Any
from pathlib import Path
Expand All @@ -12,7 +11,6 @@
Status
)
from vnpy.trader.gateway import BaseGateway

from vnpy.trader.object import (
TickData,
OrderData,
Expand All @@ -24,8 +22,9 @@
CancelRequest,
SubscribeRequest,
)
from vnpy.trader.utility import get_folder_path
from vnpy.trader.utility import get_folder_path, ZoneInfo
from vnpy.trader.event import EVENT_TIMER

from ..api import MdApi, TdApi

# 委托状态映射
Expand Down Expand Up @@ -70,15 +69,15 @@
}

# 中国时区
CHINA_TZ = pytz.timezone("Asia/Shanghai")
CHINA_TZ = ZoneInfo("Asia/Shanghai")

# 合约数据全局缓存字典
symbol_contract_map: Dict[str, ContractData] = {}


class OstGateway(BaseGateway):
"""
vn.py用于对接东方证券OST的交易接口
VeighNa用于对接东方证券OST的交易接口
"""

default_name: str = "OST"
Expand Down Expand Up @@ -213,7 +212,7 @@ def onRtnL2MarketData(self, data: dict) -> None:

timestamp: str = f"{self.current_date}{data['OrigTime']}"
dt: datetime = datetime.strptime(timestamp, "%Y%m%d%H%M%S")
dt: datetime = CHINA_TZ.localize(dt)
dt: datetime = dt.replace(tzinfo=CHINA_TZ)

tick: TickData = TickData(
symbol=symbol,
Expand Down Expand Up @@ -428,7 +427,6 @@ def onRspQryInstrument(self, data: dict, error: dict, reqid: int, last: bool) ->
)

self.gateway.on_contract(contract)

symbol_contract_map[contract.symbol] = contract

if last:
Expand Down Expand Up @@ -459,9 +457,9 @@ def onRtnOrder(self, data: dict) -> None:

timestamp: str = f"{data['TradingDay']} {data['InsertTime']}"
dt: datetime = datetime.strptime(timestamp, "%Y%m%d %H%M%S%f")
dt: datetime = CHINA_TZ.localize(dt)
dt: datetime = dt.replace(tzinfo=CHINA_TZ)

tp = (data["OrderPriceType"], data["TimeCondition"], data["VolumeCondition"])
tp: tuple = (data["OrderPriceType"], data["TimeCondition"], data["VolumeCondition"])

order: OrderData = OrderData(
symbol=symbol,
Expand Down Expand Up @@ -496,7 +494,7 @@ def onRtnTrade(self, data: dict) -> None:

timestamp: str = f"{data['TradeDate']} {data['TradeTime']}"
dt: datetime = datetime.strptime(timestamp, "%Y%m%d %H%M%S%f")
dt: datetime = CHINA_TZ.localize(dt)
dt: datetime = dt.replace(tzinfo=CHINA_TZ)

trade: TradeData = TradeData(
symbol=symbol,
Expand Down Expand Up @@ -551,12 +549,12 @@ def send_order(self, req: OrderRequest) -> str:
return ""

if not req.direction:
self.gateway.write_log(f"请选择买卖方向")
self.gateway.write_log("请选择买卖方向")
return ""

self.order_ref += 1

tp = ORDERTYPE_VT2OST[req.type]
tp: tuple = ORDERTYPE_VT2OST[req.type]
price_type, time_condition, volume_condition = tp

ost_req: dict = {
Expand Down

0 comments on commit 927ce86

Please sign in to comment.