From 0a2d54e826798b42d429eb6327d5f133ac806877 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Fri, 14 Sep 2018 17:54:02 +0800 Subject: [PATCH] =?UTF-8?q?[Add]=E6=96=B0=E5=A2=9E=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=9B=B8=E5=85=B3=E7=B1=BB=E5=92=8C=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/language/chinese/constant.py | 12 ++++++++- vnpy/trader/language/english/constant.py | 13 +++++++++- vnpy/trader/vtEvent.py | 3 ++- vnpy/trader/vtGateway.py | 12 +++++++++ vnpy/trader/vtObject.py | 32 ++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 3 deletions(-) diff --git a/vnpy/trader/language/chinese/constant.py b/vnpy/trader/language/chinese/constant.py index 08743346..5d14ada9 100644 --- a/vnpy/trader/language/chinese/constant.py +++ b/vnpy/trader/language/chinese/constant.py @@ -110,4 +110,14 @@ GATEWAYTYPE_EQUITY = 'equity' # 股票、ETF、债券 GATEWAYTYPE_FUTURES = 'futures' # 期货、期权、贵金属 GATEWAYTYPE_INTERNATIONAL = 'international' # 外盘 GATEWAYTYPE_BTC = 'btc' # 比特币 -GATEWAYTYPE_DATA = 'data' # 数据(非交易) \ No newline at end of file +GATEWAYTYPE_DATA = 'data' # 数据(非交易) + +# K线周期类型 +INTERVAL_1M = u'1分钟' +INTERVAL_5M = u'5分钟' +INTERVAL_15M = u'15分钟' +INTERVAL_30M = u'30分钟' +INTERVAL_1H = u'1小时' +INTERVAL_4H = u'4小时' +INTERVAL_DAILY = u'日线' +INTERVAL_WEEKLY = u'周线' \ No newline at end of file diff --git a/vnpy/trader/language/english/constant.py b/vnpy/trader/language/english/constant.py index b5caeabe..27c01542 100644 --- a/vnpy/trader/language/english/constant.py +++ b/vnpy/trader/language/english/constant.py @@ -106,4 +106,15 @@ GATEWAYTYPE_EQUITY = 'equity' # 股票、ETF、债券 GATEWAYTYPE_FUTURES = 'futures' # 期货、期权、贵金属 GATEWAYTYPE_INTERNATIONAL = 'international' # 外盘 GATEWAYTYPE_BTC = 'btc' # 比特币 -GATEWAYTYPE_DATA = 'data' # 数据(非交易) \ No newline at end of file +GATEWAYTYPE_DATA = 'data' # 数据(非交易) + + +# K线周期类型 +INTERVAL_1M = u'1-Minute' +INTERVAL_5M = u'5-Minute' +INTERVAL_15M = u'15-Minute' +INTERVAL_30M = u'30-Minute' +INTERVAL_1H = u'1-Hour' +INTERVAL_4H = u'4-Hour' +INTERVAL_DAILY = u'Daily' +INTERVAL_WEEKLY = u'Weekly' \ No newline at end of file diff --git a/vnpy/trader/vtEvent.py b/vnpy/trader/vtEvent.py index 4c5c67ef..14ea8178 100644 --- a/vnpy/trader/vtEvent.py +++ b/vnpy/trader/vtEvent.py @@ -17,4 +17,5 @@ EVENT_ORDER = 'eOrder.' # 报单回报事件 EVENT_POSITION = 'ePosition.' # 持仓回报事件 EVENT_ACCOUNT = 'eAccount.' # 账户回报事件 EVENT_CONTRACT = 'eContract.' # 合约基础信息回报事件 -EVENT_ERROR = 'eError.' # 错误回报事件 \ No newline at end of file +EVENT_ERROR = 'eError.' # 错误回报事件 +EVENT_HISTORY = 'eHistory.' # K线数据查询回报事件 \ No newline at end of file diff --git a/vnpy/trader/vtGateway.py b/vnpy/trader/vtGateway.py index 5e63cc67..0df2366d 100644 --- a/vnpy/trader/vtGateway.py +++ b/vnpy/trader/vtGateway.py @@ -108,6 +108,13 @@ class VtGateway(object): event1.dict_['data'] = contract self.eventEngine.put(event1) + #---------------------------------------------------------------------- + def onHistory(self, history): + """历史数据推送""" + event = Event(EVENT_HISTORY) + event.dict_['data'] = history + self.eventEngine.put(event) + #---------------------------------------------------------------------- def connect(self): """连接""" @@ -138,6 +145,11 @@ class VtGateway(object): """查询持仓""" pass + #---------------------------------------------------------------------- + def qryHistory(self, historyReq): + """查询历史""" + pass + #---------------------------------------------------------------------- def close(self): """关闭""" diff --git a/vnpy/trader/vtObject.py b/vnpy/trader/vtObject.py index 2a3a4cb9..966be5fe 100644 --- a/vnpy/trader/vtObject.py +++ b/vnpy/trader/vtObject.py @@ -265,6 +265,22 @@ class VtContractData(VtBaseData): self.expiryDate = EMPTY_STRING # 到期日 +######################################################################## +class VtHistoryData(object): + """K线时间序列数据""" + + #---------------------------------------------------------------------- + def __init__(self): + """Constructor""" + self.vtSymbol = EMPTY_STRING # vt系统代码 + self.symbol = EMPTY_STRING # 代码 + self.exchange = EMPTY_STRING # 交易所 + + self.interval = EMPTY_UNICODE # K线时间周期 + self.queryID = EMPTY_STRING # 查询号 + self.barList = [] # VtBarData列表 + + ######################################################################## class VtSubscribeReq(object): """订阅行情时传入的对象类""" @@ -327,6 +343,22 @@ class VtCancelOrderReq(object): self.sessionID = EMPTY_STRING # 会话号 +######################################################################## +class VtHistoryReq(object): + """查询历史数据时传入的对象类""" + + #---------------------------------------------------------------------- + def __init__(self): + """Constructor""" + self.symbol = EMPTY_STRING # 代码 + self.exchange = EMPTY_STRING # 交易所 + self.vtSymbol = EMPTY_STRING # VT合约代码 + + self.interval = EMPTY_UNICODE # K线周期 + self.start = None # 起始时间datetime对象 + self.end = None # 结束时间datetime对象 + + ######################################################################## class VtSingleton(type): """