diff --git a/README.md b/README.md index 8928a784..8de194af 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,12 @@ # vn.py - 基于python的开源交易平台开发框架 +### 论坛 + +新的论坛[维恩的派](http://www.vnpie.com)已经上线(感谢量衍投资对vn.py项目的支持)。 + +如果你在使用vn.py的过程中有任何疑问想求助或者经验想分享,欢迎到维恩的派上面发帖,项目作者和其他主要贡献者也会每天阅帖,保证回复的效率。 + + --- ### Quick Start diff --git a/vn.lts/vnltstd/test/tdtest.py b/vn.lts/vnltstd/test/tdtest.py index d198f4f6..2c375f0e 100644 --- a/vn.lts/vnltstd/test/tdtest.py +++ b/vn.lts/vnltstd/test/tdtest.py @@ -330,7 +330,7 @@ def main(): api.subscribePublicTopic(1) # 注册前置机地址,测试通过 - api.registerFront("tcp://211.144.195.163:34505") + api.registerFront("tcp://211.144.195.163:54505") # 初始化api,连接前置机,测试通过 api.init() @@ -367,30 +367,30 @@ def main(): #sleep(0.5) ############################################### - # 发单测试, 测试通过 - reqid = reqid + 1 - req = {} - req['InvestorID'] = api.userID - req['UserID'] = api.userID - req['BrokerID'] = api.brokerID - req['InstrumentID'] = '510050' - req['ExchangeID'] = 'SSE' - req['OrderPriceType'] = defineDict['SECURITY_FTDC_OPT_LimitPrice'] - req['LimitPrice'] = '0.1850' - req['VolumeTotalOriginal'] = 1 - req['Direction'] = defineDict['SECURITY_FTDC_D_Buy'] - req['CombOffsetFlag'] = defineDict['SECURITY_FTDC_OF_Open'] - req['OrderRef'] = '10' - req['CombHedgeFlag'] = defineDict['SECURITY_FTDC_HF_Speculation'] - req['ContingentCondition'] = defineDict['SECURITY_FTDC_CC_Immediately'] - req['ForceCloseReason'] = defineDict['SECURITY_FTDC_FCC_NotForceClose'] - req['IsAutoSuspend'] = 0 - req['UserForceClose'] = 0 - req['TimeCondition'] = defineDict['SECURITY_FTDC_TC_GFD'] - req['VolumeCondition'] = defineDict['SECURITY_FTDC_VC_AV'] - req['MinVolume'] = 1 - i = api.reqOrderInsert(req, reqid) - sleep(1.0) + # # 发单测试, 测试通过 + # reqid = reqid + 1 + # req = {} + # req['InvestorID'] = api.userID + # req['UserID'] = api.userID + # req['BrokerID'] = api.brokerID + # req['InstrumentID'] = '510050' + # req['ExchangeID'] = 'SSE' + # req['OrderPriceType'] = defineDict['SECURITY_FTDC_OPT_LimitPrice'] + # req['LimitPrice'] = '0.1850' + # req['VolumeTotalOriginal'] = 1 + # req['Direction'] = defineDict['SECURITY_FTDC_D_Buy'] + # req['CombOffsetFlag'] = defineDict['SECURITY_FTDC_OF_Open'] + # req['OrderRef'] = '10' + # req['CombHedgeFlag'] = defineDict['SECURITY_FTDC_HF_Speculation'] + # req['ContingentCondition'] = defineDict['SECURITY_FTDC_CC_Immediately'] + # req['ForceCloseReason'] = defineDict['SECURITY_FTDC_FCC_NotForceClose'] + # req['IsAutoSuspend'] = 0 + # req['UserForceClose'] = 0 + # req['TimeCondition'] = defineDict['SECURITY_FTDC_TC_GFD'] + # req['VolumeCondition'] = defineDict['SECURITY_FTDC_VC_AV'] + # req['MinVolume'] = 1 + # i = api.reqOrderInsert(req, reqid) + # sleep(1.0) # 撤单测试,测试通过 #reqid = reqid + 1 diff --git a/vn.okcoin/README.md b/vn.okcoin/README.md new file mode 100644 index 00000000..cd8a1ee5 --- /dev/null +++ b/vn.okcoin/README.md @@ -0,0 +1,36 @@ +# vn.okcoin + +贡献者:量衍投资 + +### 简介 +OkCoin的比特币交易接口,基于Websocket API开发,实现了以下功能: + +1. 发送、撤销委托 + +2. 查询委托、持仓、资金、成交历史 + +3. 实时行情、成交、资金更新的推送 + +### 特点 +相比较于[OkCoin官方](http://github.com/OKCoin/websocket/tree/master/python)给出的Python API实现,vn.okcoin的一些特点: + +1. 同时支持OkCoin的中国站和国际站交易,根据用户连接的站点会在内部自动切换结算货币(CNY、USD) + +2. 采用面向对象的接口设计模式,接近国内CTP接口的风格,并对主动函数的调用参数做了大幅简化 + +3. 数据解包和签名生成两个热点函数使用了更加高效的实现方式 + +### 参数命名 +函数的参数命名针对金融领域用户的习惯做了一些修改,具体对应如下: + +* expiry:原生命名的contract_type +* order: 原生命名的match_price +* leverage:原生命名的lever_rate +* page:原生命名的current_page +* length:原生命名的page_length + +### API版本 +日期:2016-06-29 + +链接:[http://www.okcoin.com/about/ws_getStarted.do](http://www.okcoin.com/about/ws_getStarted.do) + diff --git a/vn.okcoin/test.py b/vn.okcoin/test.py new file mode 100644 index 00000000..41863684 --- /dev/null +++ b/vn.okcoin/test.py @@ -0,0 +1,47 @@ +# encoding: UTF-8 + +from vnokcoin import * + +# 在OkCoin网站申请这两个Key,分别对应用户名和密码 +apiKey = '' +secretKey = '' + +# 创建API对象 +api = OkCoinApi() + +# 连接服务器,并等待1秒 +api.connect(OKCOIN_USD, apiKey, secretKey, True) + +sleep(1) + +# 测试现货行情API +#api.subscribeSpotTicker(SYMBOL_BTC) +#api.subscribeSpotTradeData(SYMBOL_BTC) +api.subscribeSpotDepth(SYMBOL_BTC, DEPTH_20) +#api.subscribeSpotKline(SYMBOL_BTC, INTERVAL_1M) + +# 测试现货交易API +#api.subscribeSpotTrades() +#api.subscribeSpotUserInfo() +#api.spotUserInfo() +#api.spotTrade(symbol, type_, price, amount) +#api.spotCancelOrder(symbol, orderid) +#api.spotOrderInfo(symbol, orderid) + +# 测试期货行情API +#api.subscribeFutureTicker(SYMBOL_BTC, FUTURE_EXPIRY_THIS_WEEK) +#api.subscribeFutureTradeData(SYMBOL_BTC, FUTURE_EXPIRY_THIS_WEEK) +#api.subscribeFutureDepth(SYMBOL_BTC, FUTURE_EXPIRY_THIS_WEEK, DEPTH_20) +#api.subscribeFutureKline(SYMBOL_BTC, FUTURE_EXPIRY_THIS_WEEK, INTERVAL_1M) +#api.subscribeFutureIndex(SYMBOL_BTC) + +# 测试期货交易API +#api.subscribeFutureTrades() +#api.subscribeFutureUserInfo() +#api.subscribeFuturePositions() +#api.futureUserInfo() +#api.futureTrade(symbol, expiry, type_, price, amount, order, leverage) +#api.futureCancelOrder(symbol, expiry, orderid) +#api.futureOrderInfo(symbol, expiry, orderid, status, page, length) + +raw_input() \ No newline at end of file diff --git a/vn.okcoin/vnokcoin.py b/vn.okcoin/vnokcoin.py new file mode 100644 index 00000000..b5da6789 --- /dev/null +++ b/vn.okcoin/vnokcoin.py @@ -0,0 +1,382 @@ +# encoding: UTF-8 + +import hashlib +import zlib +import json +from time import sleep +from threading import Thread + +import websocket + + +# OKCOIN网站 +OKCOIN_CNY = 'wss://real.okcoin.cn:10440/websocket/okcoinapi' +OKCOIN_USD = 'wss://real.okcoin.com:10440/websocket/okcoinapi' + +# 账户货币代码 +CURRENCY_CNY = 'cny' +CURRENCY_USD = 'usd' + +# 电子货币代码 +SYMBOL_BTC = 'btc' +SYMBOL_LTC = 'ltc' + +# 行情深度 +DEPTH_20 = 20 +DEPTH_60 = 60 + +# K线时间区间 +INTERVAL_1M = '1min' +INTERVAL_3M = '3min' +INTERVAL_5M = '5min' +INTERVAL_15M = '15min' +INTERVAL_30M = '30min' +INTERVAL_1H = '1hour' +INTERVAL_2H = '2hour' +INTERVAL_4H = '4hour' +INTERVAL_6H = '6hour' +INTERVAL_1D = 'day' +INTERVAL_3D = '3day' +INTERVAL_1W = 'week' + +# 交易代码,需要后缀货币名才能完整 +TRADING_SYMBOL_BTC = 'btc_' +TRADING_SYMBOL_LTC = 'ltc_' + +# 委托类型 +TYPE_BUY = 'buy' +TYPE_SELL = 'sell' +TYPE_BUY_MARKET = 'buy_market' +TYPE_SELL_MARKET = 'sell_market' + +# 期货合约到期类型 +FUTURE_EXPIRY_THIS_WEEK = 'this_week' +FUTURE_EXPIRY_NEXT_WEEK = 'next_week' +FUTURE_EXPIRY_QUARTER = 'quarter' + +# 期货委托类型 +FUTURE_TYPE_LONG = 1 +FUTURE_TYPE_SHORT = 2 +FUTURE_TYPE_SELL = 3 +FUTURE_TYPE_COVER = 4 + +# 期货是否用现价 +FUTURE_ORDER_MARKET = 1 +FUTURE_ORDER_LIMIT = 0 + +# 期货杠杆 +FUTURE_LEVERAGE_10 = 10 +FUTURE_LEVERAGE_20 = 20 + +# 委托状态 +ORDER_STATUS_NOTTRADED = 0 +ORDER_STATUS_PARTTRADED = 1 +ORDER_STATUS_ALLTRADED = 2 +ORDER_STATUS_CANCELLED = -1 +ORDER_STATUS_CANCELLING = 4 + + +######################################################################## +class OkCoinApi(object): + """基于Websocket的API对象""" + + #---------------------------------------------------------------------- + def __init__(self): + """Constructor""" + self.apiKey = '' # 用户名 + self.secretKey = '' # 密码 + self.host = '' # 服务器地址 + + self.currency = '' # 货币类型(usd或者cny) + + self.ws = None # websocket应用对象 + self.thread = None # 工作线程 + + ####################### + ## 通用函数 + ####################### + + #---------------------------------------------------------------------- + def readData(self, evt): + """解压缩推送收到的数据""" + # 创建解压器 + decompress = zlib.decompressobj(-zlib.MAX_WBITS) + + # 将原始数据解压成字符串 + inflated = decompress.decompress(evt) + decompress.flush() + + # 通过json解析字符串 + data = json.loads(inflated) + + return data + + #---------------------------------------------------------------------- + def generateSign(self, params): + """生成签名""" + l = [] + for key in sorted(params.keys()): + l.append('%s=%s' %(key, params[key])) + l.append('secret_key=%s' %self.secretKey) + sign = '&'.join(l) + return hashlib.md5(sign.encode('utf-8')).hexdigest().upper() + + #---------------------------------------------------------------------- + def onMessage(self, ws, evt): + """信息推送""" + print 'onMessage' + data = self.readData(evt) + print data + + #---------------------------------------------------------------------- + def onError(self, ws, evt): + """错误推送""" + print 'onError' + print evt + + #---------------------------------------------------------------------- + def onClose(self, ws): + """接口断开""" + print 'onClose' + + #---------------------------------------------------------------------- + def onOpen(self, ws): + """接口打开""" + print 'onOpen' + + #---------------------------------------------------------------------- + def connect(self, host, apiKey, secretKey, trace=False): + """连接服务器""" + self.host = host + self.apiKey = apiKey + self.secretKey = secretKey + + if self.host == OKCOIN_CNY: + self.currency = CURRENCY_CNY + else: + self.currency = CURRENCY_USD + + websocket.enableTrace(trace) + + self.ws = websocket.WebSocketApp(host, + on_message=self.onMessage, + on_error=self.onError, + on_close=self.onClose, + on_open=self.onOpen) + + self.thread = Thread(target=self.ws.run_forever) + self.thread.start() + + #---------------------------------------------------------------------- + def sendMarketDataRequest(self, channel): + """发送行情请求""" + # 生成请求 + d = {} + d['event'] = 'addChannel' + d['binary'] = True + d['channel'] = channel + + # 使用json打包并发送 + j = json.dumps(d) + self.ws.send(j) + + #---------------------------------------------------------------------- + def sendTradingRequest(self, channel, params): + """发送交易请求""" + # 在参数字典中加上api_key和签名字段 + params['api_key'] = self.apiKey + params['sign'] = self.generateSign(params) + + # 生成请求 + d = {} + d['event'] = 'addChannel' + d['binary'] = True + d['channel'] = channel + d['parameters'] = params + + # 使用json打包并发送 + j = json.dumps(d) + self.ws.send(j) + + ####################### + ## 现货相关 + ####################### + + #---------------------------------------------------------------------- + def subscribeSpotTicker(self, symbol): + """订阅现货普通报价""" + self.sendMarketDataRequest('ok_sub_spot%s_%s_ticker' %(self.currency, symbol)) + + #---------------------------------------------------------------------- + def subscribeSpotDepth(self, symbol, depth): + """订阅现货深度报价""" + self.sendMarketDataRequest('ok_sub_spot%s_%s_depth_%s' %(self.currency, symbol, depth)) + + #---------------------------------------------------------------------- + def subscribeSpotTradeData(self, symbol): + """订阅现货成交记录""" + self.sendMarketDataRequest('ok_sub_spot%s_%s_trades' %(self.currency, symbol)) + + #---------------------------------------------------------------------- + def subscribeSpotKline(self, symbol, interval): + """订阅现货K线""" + self.sendMarketDataRequest('ok_sub_spot%s_%s_kline_%s' %(self.currency, symbol, interval)) + + #---------------------------------------------------------------------- + def spotTrade(self, symbol, type_, price, amount): + """现货委托""" + params = {} + params['symbol'] = str(symbol+self.currency) + params['type'] = str(type_) + params['price'] = str(price) + params['amount'] = str(amount) + + channel = 'ok_spot%s_trade' %(self.currency) + + self.sendTradingRequest(channel, params) + + #---------------------------------------------------------------------- + def spotCancelOrder(self, symbol, orderid): + """现货撤单""" + params = {} + params['symbol'] = str(symbol+self.currency) + params['order_id'] = str(orderid) + + channel = 'ok_spot%s_cancel_order' %(self.currency) + + self.sendTradingRequest(channel, params) + + #---------------------------------------------------------------------- + def spotUserInfo(self): + """查询现货账户""" + channel = 'ok_spot%s_userinfo' %(self.currency) + + self.sendTradingRequest(channel, {}) + + #---------------------------------------------------------------------- + def spotOrderInfo(self, symbol, orderid): + """查询现货委托信息""" + params = {} + params['symbol'] = str(symbol+self.currency) + params['order_id'] = str(orderid) + + channel = 'ok_spot%s_orderinfo' %(self.currency) + + self.sendTradingRequest(channel, params) + + #---------------------------------------------------------------------- + def subscribeSpotTrades(self): + """订阅现货成交信息""" + channel = 'ok_sub_spot%s_trades' %(self.currency) + + self.sendTradingRequest(channel, {}) + + #---------------------------------------------------------------------- + def subscribeSpotUserInfo(self): + """订阅现货账户信息""" + channel = 'ok_sub_spot%s_userinfo' %(self.currency) + + self.sendTradingRequest(channel, {}) + + ####################### + ## 期货相关 + ####################### + + #---------------------------------------------------------------------- + def subscribeFutureTicker(self, symbol, expiry): + """订阅期货普通报价""" + self.sendMarketDataRequest('ok_sub_future%s_%s_ticker_%s' %(self.currency, symbol, expiry)) + + #---------------------------------------------------------------------- + def subscribeFutureDepth(self, symbol, expiry, depth): + """订阅期货深度报价""" + self.sendMarketDataRequest('ok_sub_future%s_%s_depth_%s_%s' %(self.currency, symbol, + expiry, depth)) + + #---------------------------------------------------------------------- + def subscribeFutureTradeData(self, symbol, expiry): + """订阅期货成交记录""" + self.sendMarketDataRequest('ok_sub_future%s_%s_trade_%s' %(self.currency, symbol, expiry)) + + #---------------------------------------------------------------------- + def subscribeFutureKline(self, symbol, expiry, interval): + """订阅期货K线""" + self.sendMarketDataRequest('ok_sub_future%s_%s_kline_%s_%s' %(self.currency, symbol, + expiry, interval)) + + #---------------------------------------------------------------------- + def subscribeFutureIndex(self, symbol): + """订阅期货指数""" + self.sendMarketDataRequest('ok_sub_future%s_%s_index' %(self.currency, symbol)) + + #---------------------------------------------------------------------- + def futureTrade(self, symbol, expiry, type_, price, amount, order, leverage): + """期货委托""" + params = {} + params['symbol'] = str(symbol+self.currency) + params['type'] = str(type_) + params['price'] = str(price) + params['amount'] = str(amount) + params['contract_type'] = str(expiry) + params['match_price'] = str(order) + params['lever_rate'] = str(leverage) + + channel = 'ok_future%s_trade' %(self.currency) + + self.sendTradingRequest(channel, params) + + #---------------------------------------------------------------------- + def futureCancelOrder(self, symbol, expiry, orderid): + """期货撤单""" + params = {} + params['symbol'] = str(symbol+self.currency) + params['order_id'] = str(orderid) + params['contract_type'] = str(expiry) + + channel = 'ok_future%s_cancel_order' %(self.currency) + + self.sendTradingRequest(channel, params) + + #---------------------------------------------------------------------- + def futureUserInfo(self): + """查询期货账户""" + channel = 'ok_future%s_userinfo' %(self.currency) + + self.sendTradingRequest(channel, {}) + + #---------------------------------------------------------------------- + def futureOrderInfo(self, symbol, expiry, orderid, status, page, length): + """查询期货委托信息""" + params = {} + params['symbol'] = str(symbol+self.currency) + params['order_id'] = str(orderid) + params['contract_type'] = expiry + params['status'] = status + params['current_page'] = page + params['page_length'] = length + + channel = 'ok_future%s_orderinfo' + + self.sendTradingRequest(channel, params) + + #---------------------------------------------------------------------- + def subscribeFutureTrades(self): + """订阅期货成交信息""" + channel = 'ok_sub_future%s_trades' %(self.currency) + + self.sendTradingRequest(channel, {}) + + #---------------------------------------------------------------------- + def subscribeFutureUserInfo(self): + """订阅期货账户信息""" + channel = 'ok_sub_future%s_userinfo' %(self.currency) + + self.sendTradingRequest(channel, {}) + + #---------------------------------------------------------------------- + def subscribeFuturePositions(self): + """订阅期货持仓信息""" + channel = 'ok_sub_future%s_positions' %(self.currency) + + self.sendTradingRequest(channel, {}) + + diff --git a/vn.trader/ctaAlgo/ctaBacktesting.py b/vn.trader/ctaAlgo/ctaBacktesting.py index 35220f1b..d82b6636 100644 --- a/vn.trader/ctaAlgo/ctaBacktesting.py +++ b/vn.trader/ctaAlgo/ctaBacktesting.py @@ -4,9 +4,11 @@ 本文件中包含的是CTA模块的回测引擎,回测引擎的API和CTA引擎一致, 可以使用和实盘相同的代码进行回测。 ''' +from __future__ import division from datetime import datetime, timedelta from collections import OrderedDict +from itertools import product import pymongo from ctaBase import * @@ -40,6 +42,9 @@ class BacktestingEngine(object): self.stopOrderDict = {} # 停止单撤销后不会从本字典中删除 self.workingStopOrderDict = {} # 停止单撤销后会从本字典中删除 + # 引擎类型为回测 + self.engineType = ENGINETYPE_BACKTESTING + # 回测相关 self.strategy = None # 回测策略 self.mode = self.BAR_MODE # 回测模式,默认为K线 @@ -55,6 +60,9 @@ class BacktestingEngine(object): self.initData = [] # 初始化用的数据 #self.backtestingData = [] # 回测用的数据 + self.dbName = '' # 回测数据库名 + self.symbol = '' # 回测集合名 + self.dataStartDate = None # 回测数据开始日期,datetime对象 self.dataEndDate = None # 回测数据结束日期,datetime对象 self.strategyStartDate = None # 策略启动日期(即前面的数据用于初始化),datetime对象 @@ -91,14 +99,20 @@ class BacktestingEngine(object): def setBacktestingMode(self, mode): """设置回测模式""" self.mode = mode - + #---------------------------------------------------------------------- - def loadHistoryData(self, dbName, symbol): + def setDatabase(self, dbName, symbol): + """设置历史数据所用的数据库""" + self.dbName = dbName + self.symbol = symbol + + #---------------------------------------------------------------------- + def loadHistoryData(self): """载入历史数据""" host, port = loadMongoSetting() self.dbClient = pymongo.MongoClient(host, port) - collection = self.dbClient[dbName][symbol] + collection = self.dbClient[self.dbName][self.symbol] self.output(u'开始载入数据') @@ -134,6 +148,9 @@ class BacktestingEngine(object): #---------------------------------------------------------------------- def runBacktesting(self): """运行回测""" + # 载入历史数据 + self.loadHistoryData() + # 首先根据回测模式,确认要使用的数据类 if self.mode == self.BAR_MODE: dataClass = CtaBarData @@ -279,13 +296,15 @@ class BacktestingEngine(object): """基于最新数据撮合限价单""" # 先确定会撮合成交的价格 if self.mode == self.BAR_MODE: - buyCrossPrice = self.bar.low # 若买入方向限价单价格高于该价格,则会成交 - sellCrossPrice = self.bar.high # 若卖出方向限价单价格低于该价格,则会成交 - bestCrossPrice = self.bar.open # 在当前时间点前发出的委托可能的最优成交价 + buyCrossPrice = self.bar.low # 若买入方向限价单价格高于该价格,则会成交 + sellCrossPrice = self.bar.high # 若卖出方向限价单价格低于该价格,则会成交 + buyBestCrossPrice = self.bar.open # 在当前时间点前发出的买入委托可能的最优成交价 + sellBestCrossPrice = self.bar.open # 在当前时间点前发出的卖出委托可能的最优成交价 else: - buyCrossPrice = self.tick.lastPrice - sellCrossPrice = self.tick.lastPrice - bestCrossPrice = self.tick.lastPrice + buyCrossPrice = self.tick.askPrice1 + sellCrossPrice = self.tick.bidPrice1 + buyBestCrossPrice = self.tick.askPrice1 + sellBestCrossPrice = self.tick.bidPrice1 # 遍历限价单字典中的所有限价单 for orderID, order in self.workingLimitOrderDict.items(): @@ -312,10 +331,10 @@ class BacktestingEngine(object): # 2. 假设在上一根K线结束(也是当前K线开始)的时刻,策略发出的委托为限价105 # 3. 则在实际中的成交价会是100而不是105,因为委托发出时市场的最优价格是100 if buyCross: - trade.price = min(order.price, bestCrossPrice) + trade.price = min(order.price, buyBestCrossPrice) self.strategy.pos += order.totalVolume else: - trade.price = max(order.price, bestCrossPrice) + trade.price = max(order.price, sellBestCrossPrice) self.strategy.pos -= order.totalVolume trade.volume = order.totalVolume @@ -429,23 +448,21 @@ class BacktestingEngine(object): #---------------------------------------------------------------------- def output(self, content): """输出内容""" - print content - + print str(datetime.now()) + "\t" + content + #---------------------------------------------------------------------- - def showBacktestingResult(self): + def calculateBacktestingResult(self): """ - 显示回测结果 + 计算回测结果 """ - self.output(u'显示回测结果') + self.output(u'计算回测结果') # 首先基于回测后的成交记录,计算每笔交易的盈亏 - pnlDict = OrderedDict() # 每笔盈亏的记录 + resultList = [] # 交易结果列表 + longTrade = [] # 未平仓的多头交易 shortTrade = [] # 未平仓的空头交易 - # 计算滑点,一个来回包括两次 - totalSlippage = self.slippage * 2 - for trade in self.tradeDict.values(): # 多头交易 if trade.direction == DIRECTION_LONG: @@ -454,71 +471,191 @@ class BacktestingEngine(object): longTrade.append(trade) # 当前多头交易为平空 else: - entryTrade = shortTrade.pop(0) - # 计算比例佣金 - commission = (trade.price+entryTrade.price) * self.rate - # 计算盈亏 - pnl = ((trade.price - entryTrade.price)*(-1) - totalSlippage - commission) \ - * trade.volume * self.size - pnlDict[trade.dt] = pnl + while True: + entryTrade = shortTrade[0] + exitTrade = trade + + # 清算开平仓交易 + closedVolume = min(exitTrade.volume, entryTrade.volume) + result = TradingResult(entryTrade.price, entryTrade.dt, + exitTrade.price, exitTrade.dt, + -closedVolume, self.rate, self.slippage, self.size) + resultList.append(result) + + # 计算未清算部分 + entryTrade.volume -= closedVolume + exitTrade.volume -= closedVolume + + # 如果开仓交易已经全部清算,则从列表中移除 + if not entryTrade.volume: + shortTrade.pop(0) + + # 如果平仓交易已经全部清算,则退出循环 + if not exitTrade.volume: + break + + # 如果平仓交易未全部清算, + if exitTrade.volume: + # 且开仓交易已经全部清算完,则平仓交易剩余的部分 + # 等于新的反向开仓交易,添加到队列中 + if not shortTrade: + longTrade.append(exitTrade) + break + # 如果开仓交易还有剩余,则进入下一轮循环 + else: + pass + # 空头交易 else: # 如果尚无多头交易 if not longTrade: shortTrade.append(trade) # 当前空头交易为平多 - else: - entryTrade = longTrade.pop(0) - # 计算比例佣金 - commission = (trade.price+entryTrade.price) * self.rate - # 计算盈亏 - pnl = ((trade.price - entryTrade.price) - totalSlippage - commission) \ - * trade.volume * self.size - pnlDict[trade.dt] = pnl + else: + while True: + entryTrade = longTrade[0] + exitTrade = trade + + # 清算开平仓交易 + closedVolume = min(exitTrade.volume, entryTrade.volume) + result = TradingResult(entryTrade.price, entryTrade.dt, + exitTrade.price, exitTrade.dt, + closedVolume, self.rate, self.slippage, self.size) + resultList.append(result) + + # 计算未清算部分 + entryTrade.volume -= closedVolume + exitTrade.volume -= closedVolume + + # 如果开仓交易已经全部清算,则从列表中移除 + if not entryTrade.volume: + longTrade.pop(0) + + # 如果平仓交易已经全部清算,则退出循环 + if not exitTrade.volume: + break + + # 如果平仓交易未全部清算, + if exitTrade.volume: + # 且开仓交易已经全部清算完,则平仓交易剩余的部分 + # 等于新的反向开仓交易,添加到队列中 + if not longTrade: + shortTrade.append(exitTrade) + break + # 如果开仓交易还有剩余,则进入下一轮循环 + else: + pass + + # 检查是否有交易 + if not resultList: + self.output(u'无交易结果') + return {} - # 然后基于每笔交易的结果,我们可以计算具体的盈亏曲线和最大回撤等 - timeList = pnlDict.keys() - pnlList = pnlDict.values() + # 然后基于每笔交易的结果,我们可以计算具体的盈亏曲线和最大回撤等 + capital = 0 # 资金 + maxCapital = 0 # 资金最高净值 + drawdown = 0 # 回撤 - capital = 0 - maxCapital = 0 - drawdown = 0 + totalResult = 0 # 总成交数量 + totalTurnover = 0 # 总成交金额(合约面值) + totalCommission = 0 # 总手续费 + totalSlippage = 0 # 总滑点 + timeList = [] # 时间序列 + pnlList = [] # 每笔盈亏序列 capitalList = [] # 盈亏汇总的时间序列 - maxCapitalList = [] # 最高盈利的时间序列 drawdownList = [] # 回撤的时间序列 - for pnl in pnlList: - capital += pnl + winningResult = 0 # 盈利次数 + losingResult = 0 # 亏损次数 + totalWinning = 0 # 总盈利金额 + totalLosing = 0 # 总亏损金额 + + for result in resultList: + capital += result.pnl maxCapital = max(capital, maxCapital) drawdown = capital - maxCapital + pnlList.append(result.pnl) + timeList.append(result.exitDt) # 交易的时间戳使用平仓时间 capitalList.append(capital) - maxCapitalList.append(maxCapital) drawdownList.append(drawdown) - # 输出 - self.output('-' * 50) - self.output(u'第一笔交易时间:%s' % timeList[0]) - self.output(u'最后一笔交易时间:%s' % timeList[-1]) - self.output(u'总交易次数:%s' % len(pnlList)) - self.output(u'总盈亏:%s' % capitalList[-1]) - self.output(u'最大回撤: %s' % min(drawdownList)) + totalResult += 1 + totalTurnover += result.turnover + totalCommission += result.commission + totalSlippage += result.slippage + if result.pnl >= 0: + winningResult += 1 + totalWinning += result.pnl + else: + losingResult += 1 + totalLosing += result.pnl + + # 计算盈亏相关数据 + winningRate = winningResult/totalResult*100 # 胜率 + averageWinning = totalWinning/winningResult # 平均每笔盈利 + averageLosing = totalLosing/losingResult # 平均每笔亏损 + profitLossRatio = -averageWinning/averageLosing # 盈亏比 + + # 返回回测结果 + d = {} + d['capital'] = capital + d['maxCapital'] = maxCapital + d['drawdown'] = drawdown + d['totalResult'] = totalResult + d['totalTurnover'] = totalTurnover + d['totalCommission'] = totalCommission + d['totalSlippage'] = totalSlippage + d['timeList'] = timeList + d['pnlList'] = pnlList + d['capitalList'] = capitalList + d['drawdownList'] = drawdownList + d['winningRate'] = winningRate + d['averageWinning'] = averageWinning + d['averageLosing'] = averageLosing + d['profitLossRatio'] = profitLossRatio + + return d + + #---------------------------------------------------------------------- + def showBacktestingResult(self): + """显示回测结果""" + d = self.calculateBacktestingResult() + + # 输出 + self.output('-' * 30) + self.output(u'第一笔交易:\t%s' % d['timeList'][0]) + self.output(u'最后一笔交易:\t%s' % d['timeList'][-1]) + + self.output(u'总交易次数:\t%s' % formatNumber(d['totalResult'])) + self.output(u'总盈亏:\t%s' % formatNumber(d['capital'])) + self.output(u'最大回撤: \t%s' % formatNumber(min(d['drawdownList']))) + + self.output(u'平均每笔盈利:\t%s' %formatNumber(d['capital']/d['totalResult'])) + self.output(u'平均每笔滑点:\t%s' %formatNumber(d['totalSlippage']/d['totalResult'])) + self.output(u'平均每笔佣金:\t%s' %formatNumber(d['totalCommission']/d['totalResult'])) + + self.output(u'胜率\t\t%s%%' %formatNumber(d['winningRate'])) + self.output(u'平均每笔盈利\t%s' %formatNumber(d['averageWinning'])) + self.output(u'平均每笔亏损\t%s' %formatNumber(d['averageLosing'])) + self.output(u'盈亏比:\t%s' %formatNumber(d['profitLossRatio'])) + # 绘图 import matplotlib.pyplot as plt pCapital = plt.subplot(3, 1, 1) pCapital.set_ylabel("capital") - pCapital.plot(capitalList) + pCapital.plot(d['capitalList']) pDD = plt.subplot(3, 1, 2) pDD.set_ylabel("DD") - pDD.bar(range(len(drawdownList)), drawdownList) + pDD.bar(range(len(d['drawdownList'])), d['drawdownList']) pPnl = plt.subplot(3, 1, 3) pPnl.set_ylabel("pnl") - pPnl.hist(pnlList, bins=20) + pPnl.hist(d['pnlList'], bins=50) plt.show() @@ -529,7 +666,7 @@ class BacktestingEngine(object): #---------------------------------------------------------------------- def setSlippage(self, slippage): - """设置滑点""" + """设置滑点点数""" self.slippage = slippage #---------------------------------------------------------------------- @@ -542,6 +679,142 @@ class BacktestingEngine(object): """设置佣金比例""" self.rate = rate + #---------------------------------------------------------------------- + def runOptimization(self, strategyClass, optimizationSetting): + """优化参数""" + # 获取优化设置 + settingList = optimizationSetting.generateSetting() + targetName = optimizationSetting.optimizeTarget + + # 检查参数设置问题 + if not settingList or not targetName: + self.output(u'优化设置有问题,请检查') + + # 遍历优化 + resultList = [] + for setting in settingList: + self.clearBacktestingResult() + self.output('-' * 30) + self.output('setting: %s' %str(setting)) + self.initStrategy(strategyClass, setting) + self.runBacktesting() + d = self.calculateBacktestingResult() + try: + targetValue = d[targetName] + except KeyError: + targetValue = 0 + resultList.append(([str(setting)], targetValue)) + + # 显示结果 + resultList.sort(reverse=True, key=lambda result:result[1]) + self.output('-' * 30) + self.output(u'优化结果:') + for result in resultList: + self.output(u'%s: %s' %(result[0], result[1])) + + #---------------------------------------------------------------------- + def clearBacktestingResult(self): + """清空之前回测的结果""" + # 清空限价单相关 + self.limitOrderCount = 0 + self.limitOrderDict.clear() + self.workingLimitOrderDict.clear() + + # 清空停止单相关 + self.stopOrderCount = 0 + self.stopOrderDict.clear() + self.workingStopOrderDict.clear() + + # 清空成交相关 + self.tradeCount = 0 + self.tradeDict.clear() + + +######################################################################## +class TradingResult(object): + """每笔交易的结果""" + + #---------------------------------------------------------------------- + def __init__(self, entryPrice, entryDt, exitPrice, + exitDt, volume, rate, slippage, size): + """Constructor""" + self.entryPrice = entryPrice # 开仓价格 + self.exitPrice = exitPrice # 平仓价格 + + self.entryDt = entryDt # 开仓时间datetime + self.exitDt = exitDt # 平仓时间 + + self.volume = volume # 交易数量(+/-代表方向) + + self.turnover = (self.entryPrice+self.exitPrice)*size*abs(volume) # 成交金额 + self.commission = self.turnover*rate # 手续费成本 + self.slippage = slippage*2*size*abs(volume) # 滑点成本 + self.pnl = ((self.exitPrice - self.entryPrice) * volume * size + - self.commission - self.slippage) # 净盈亏 + + +######################################################################## +class OptimizationSetting(object): + """优化设置""" + + #---------------------------------------------------------------------- + def __init__(self): + """Constructor""" + self.paramDict = OrderedDict() + + self.optimizeTarget = '' # 优化目标字段 + + #---------------------------------------------------------------------- + def addParameter(self, name, start, end, step): + """增加优化参数""" + if end <= start: + print u'参数起始点必须小于终止点' + return + + if step <= 0: + print u'参数布进必须大于0' + return + + l = [] + param = start + + while param <= end: + l.append(param) + param += step + + self.paramDict[name] = l + + #---------------------------------------------------------------------- + def generateSetting(self): + """生成优化参数组合""" + # 参数名的列表 + nameList = self.paramDict.keys() + paramList = self.paramDict.values() + + # 使用迭代工具生产参数对组合 + productList = list(product(*paramList)) + + # 把参数对组合打包到一个个字典组成的列表中 + settingList = [] + for p in productList: + d = dict(zip(nameList, p)) + settingList.append(d) + + return settingList + + #---------------------------------------------------------------------- + def setOptimizeTarget(self, target): + """设置优化目标字段""" + self.optimizeTarget = target + + +#---------------------------------------------------------------------- +def formatNumber(n): + """格式化数字到字符串""" + n = round(n, 2) # 保留两位小数 + return format(n, ',') # 加上千分符 + + if __name__ == '__main__': @@ -560,7 +833,7 @@ if __name__ == '__main__': engine.setStartDate('20110101') # 载入历史数据到引擎中 - engine.loadHistoryData(MINUTE_DB_NAME, 'IF0000') + engine.setDatabase(MINUTE_DB_NAME, 'IF0000') # 设置产品相关参数 engine.setSlippage(0.2) # 股指1跳 diff --git a/vn.trader/ctaAlgo/ctaBase.py b/vn.trader/ctaAlgo/ctaBase.py index f0fffbca..8060b6a3 100644 --- a/vn.trader/ctaAlgo/ctaBase.py +++ b/vn.trader/ctaAlgo/ctaBase.py @@ -33,6 +33,9 @@ TICK_DB_NAME = 'VnTrader_Tick_Db' DAILY_DB_NAME = 'VnTrader_Daily_Db' MINUTE_DB_NAME = 'VnTrader_1Min_Db' +# 引擎类型,用于区分当前策略的运行环境 +ENGINETYPE_BACKTESTING = 'backtesting' # 回测 +ENGINETYPE_TRADING = 'trading' # 实盘 # CTA引擎中涉及的数据类定义 from vtConstant import EMPTY_UNICODE, EMPTY_STRING, EMPTY_FLOAT, EMPTY_INT diff --git a/vn.trader/ctaAlgo/ctaDemo.py b/vn.trader/ctaAlgo/ctaDemo.py index 4391fb21..747be12a 100644 --- a/vn.trader/ctaAlgo/ctaDemo.py +++ b/vn.trader/ctaAlgo/ctaDemo.py @@ -61,6 +61,13 @@ class DoubleEmaDemo(CtaTemplate): """Constructor""" super(DoubleEmaDemo, self).__init__(ctaEngine, setting) + # 注意策略类中的可变对象属性(通常是list和dict等),在策略初始化时需要重新创建, + # 否则会出现多个策略实例之间数据共享的情况,有可能导致潜在的策略逻辑错误风险, + # 策略类中的这些可变对象属性可以选择不写,全都放在__init__下面,写主要是为了阅读 + # 策略时方便(更多是个编程习惯的选择) + self.fastMa = [] + self.slowMa = [] + #---------------------------------------------------------------------- def onInit(self): """初始化策略(必须由用户继承实现)""" diff --git a/vn.trader/ctaAlgo/ctaEngine.py b/vn.trader/ctaAlgo/ctaEngine.py index e4649580..17f2c020 100644 --- a/vn.trader/ctaAlgo/ctaEngine.py +++ b/vn.trader/ctaAlgo/ctaEngine.py @@ -70,6 +70,9 @@ class CtaEngine(object): # key为vtSymbol,value为PositionBuffer对象 self.posBufferDict = {} + # 引擎类型为实盘 + self.engineType = ENGINETYPE_TRADING + # 注册事件监听 self.registerEvent() diff --git a/vn.trader/ctaAlgo/ctaHistoryData.py b/vn.trader/ctaAlgo/ctaHistoryData.py index 18304301..5039adee 100644 --- a/vn.trader/ctaAlgo/ctaHistoryData.py +++ b/vn.trader/ctaAlgo/ctaHistoryData.py @@ -278,7 +278,7 @@ class HistoryDataEngine(object): params = {} params['ticker'] = symbol if last: - params['startDate'] = last['date'] + params['beginDate'] = last['date'] data = self.datayesClient.downloadData(path, params) diff --git a/vn.trader/ctaAlgo/ctaSetting.py b/vn.trader/ctaAlgo/ctaSetting.py index 81816b76..9115e9d2 100644 --- a/vn.trader/ctaAlgo/ctaSetting.py +++ b/vn.trader/ctaAlgo/ctaSetting.py @@ -8,9 +8,7 @@ 在CTA_setting.json中写入具体每个策略对象的类和合约设置。 ''' -from ctaTemplate import DataRecorder from ctaDemo import DoubleEmaDemo STRATEGY_CLASS = {} -STRATEGY_CLASS['DataRecorder'] = DataRecorder STRATEGY_CLASS['DoubleEmaDemo'] = DoubleEmaDemo \ No newline at end of file diff --git a/vn.trader/ctaAlgo/ctaTemplate.py b/vn.trader/ctaAlgo/ctaTemplate.py index 6689b08f..2e4f57d4 100644 --- a/vn.trader/ctaAlgo/ctaTemplate.py +++ b/vn.trader/ctaAlgo/ctaTemplate.py @@ -120,11 +120,16 @@ class CtaTemplate(object): vtOrderID = self.ctaEngine.sendOrder(self.vtSymbol, orderType, price, volume, self) return vtOrderID else: - return None + # 交易停止时发单返回空字符串 + return '' #---------------------------------------------------------------------- def cancelOrder(self, vtOrderID): """撤单""" + # 如果发单号为空字符串,则不进行后续操作 + if not vtOrderID: + return + if STOPORDERPREFIX in vtOrderID: self.ctaEngine.cancelStopOrder(vtOrderID) else: @@ -160,112 +165,9 @@ class CtaTemplate(object): def putEvent(self): """发出策略状态变化事件""" self.ctaEngine.putStrategyEvent(self.name) - - -######################################################################## -class DataRecorder(CtaTemplate): - """ - 纯粹用来记录历史数据的工具(基于CTA策略), - 建议运行在实际交易程序外的一个vn.trader实例中, - 本工具会记录Tick和1分钟K线数据。 - """ - className = 'DataRecorder' - author = u'用Python的交易员' - - # 策略的基本参数 - name = EMPTY_UNICODE # 策略实例名称 - vtSymbol = EMPTY_STRING # 交易的合约vt系统代码 - - # 策略的变量 - bar = None # K线数据对象 - barMinute = EMPTY_STRING # 当前的分钟,初始化设为-1 - - # 变量列表,保存了变量的名称 - varList = ['inited', - 'trading', - 'pos', - 'barMinute'] - - #---------------------------------------------------------------------- - def __init__(self, ctaEngine, setting): - """Constructor""" - super(DataRecorder, self).__init__(ctaEngine, setting) - - #---------------------------------------------------------------------- - def onInit(self): - """初始化""" - self.writeCtaLog(u'数据记录工具初始化') #---------------------------------------------------------------------- - def onStart(self): - """启动策略(必须由用户继承实现)""" - self.writeCtaLog(u'数据记录工具启动') - self.putEvent() + def getEngineType(self): + """查询当前运行的环境""" + return self.ctaEngine.engineType - #---------------------------------------------------------------------- - def onStop(self): - """停止策略(必须由用户继承实现)""" - self.writeCtaLog(u'数据记录工具停止') - self.putEvent() - - #---------------------------------------------------------------------- - def onTick(self, tick): - """收到行情TICK推送""" - # 收到Tick后,首先插入到数据库里 - self.insertTick(tick) - - # 计算K线 - tickMinute = tick.datetime.minute - - if tickMinute != self.barMinute: # 如果分钟变了,则把旧的K线插入数据库,并生成新的K线 - if self.bar: - self.onBar(self.bar) - - bar = CtaBarData() # 创建新的K线,目的在于防止之前K线对象在插入Mongo中被再次修改,导致出错 - bar.vtSymbol = tick.vtSymbol - bar.symbol = tick.symbol - bar.exchange = tick.exchange - - bar.open = tick.lastPrice - bar.high = tick.lastPrice - bar.low = tick.lastPrice - bar.close = tick.lastPrice - - bar.date = tick.date - bar.time = tick.time - bar.datetime = tick.datetime # K线的时间设为第一个Tick的时间 - - bar.volume = tick.volume - bar.openInterest = tick.openInterest - - self.bar = bar # 这种写法为了减少一层访问,加快速度 - self.barMinute = tickMinute # 更新当前的分钟 - - else: # 否则继续累加新的K线 - bar = self.bar # 写法同样为了加快速度 - - bar.high = max(bar.high, tick.lastPrice) - bar.low = min(bar.low, tick.lastPrice) - bar.close = tick.lastPrice - - bar.volume = bar.volume + tick.volume # 成交量是累加的 - bar.openInterest = tick.openInterest # 持仓量直接更新 - - #---------------------------------------------------------------------- - def onOrder(self, order): - """收到委托变化推送""" - pass - - #---------------------------------------------------------------------- - def onTrade(self, trade): - """收到成交推送""" - pass - - #---------------------------------------------------------------------- - def onBar(self, bar): - """收到Bar推送""" - self.insertBar(bar) - - - - \ No newline at end of file diff --git a/vn.trader/ctaAlgo/strategyAtrRsi.py b/vn.trader/ctaAlgo/strategyAtrRsi.py index 74aabc6f..70029941 100644 --- a/vn.trader/ctaAlgo/strategyAtrRsi.py +++ b/vn.trader/ctaAlgo/strategyAtrRsi.py @@ -80,6 +80,11 @@ class AtrRsiStrategy(CtaTemplate): def __init__(self, ctaEngine, setting): """Constructor""" super(AtrRsiStrategy, self).__init__(ctaEngine, setting) + + # 注意策略类中的可变对象属性(通常是list和dict等),在策略初始化时需要重新创建, + # 否则会出现多个策略实例之间数据共享的情况,有可能导致潜在的策略逻辑错误风险, + # 策略类中的这些可变对象属性可以选择不写,全都放在__init__下面,写主要是为了阅读 + # 策略时方便(更多是个编程习惯的选择) #---------------------------------------------------------------------- def onInit(self): @@ -194,14 +199,12 @@ class AtrRsiStrategy(CtaTemplate): if self.rsiValue > self.rsiBuy: # 这里为了保证成交,选择超价5个整指数点下单 self.buy(bar.close+5, 1) - return - if self.rsiValue < self.rsiSell: + elif self.rsiValue < self.rsiSell: self.short(bar.close-5, 1) - return # 持有多头仓位 - if self.pos == 1: + elif self.pos > 0: # 计算多头持有期内的最高价,以及重置最低价 self.intraTradeHigh = max(self.intraTradeHigh, bar.high) self.intraTradeLow = bar.low @@ -210,17 +213,15 @@ class AtrRsiStrategy(CtaTemplate): # 发出本地止损委托,并且把委托号记录下来,用于后续撤单 orderID = self.sell(longStop, 1, stop=True) self.orderList.append(orderID) - return # 持有空头仓位 - if self.pos == -1: + elif self.pos < 0: self.intraTradeLow = min(self.intraTradeLow, bar.low) self.intraTradeHigh = bar.high shortStop = self.intraTradeLow * (1+self.trailingPercent/100) orderID = self.cover(shortStop, 1, stop=True) self.orderList.append(orderID) - return # 发出状态更新事件 self.putEvent() @@ -250,16 +251,17 @@ if __name__ == '__main__': # 设置回测用的数据起始日期 engine.setStartDate('20120101') - # 载入历史数据到引擎中 - engine.loadHistoryData(MINUTE_DB_NAME, 'IF0000') - # 设置产品相关参数 engine.setSlippage(0.2) # 股指1跳 engine.setRate(0.3/10000) # 万0.3 - engine.setSize(300) # 股指合约大小 + engine.setSize(300) # 股指合约大小 + + # 设置使用的历史数据库 + engine.setDatabase(MINUTE_DB_NAME, 'IF0000') # 在引擎中创建策略对象 - engine.initStrategy(AtrRsiStrategy, {}) + d = {'atrLength': 11} + engine.initStrategy(AtrRsiStrategy, d) # 开始跑回测 engine.runBacktesting() @@ -267,4 +269,11 @@ if __name__ == '__main__': # 显示回测结果 engine.showBacktestingResult() + ## 跑优化 + #setting = OptimizationSetting() # 新建一个优化任务设置对象 + #setting.setOptimizeTarget('capital') # 设置优化排序的目标是策略净盈利 + #setting.addParameter('atrLength', 11, 12, 1) # 增加第一个优化参数atrLength,起始11,结束12,步进1 + #setting.addParameter('atrMa', 20, 30, 5) # 增加第二个优化参数atrMa,起始20,结束30,步进1 + #engine.runOptimization(AtrRsiStrategy, setting) # 运行优化函数,自动输出结果 + \ No newline at end of file diff --git a/vn.trader/ctpGateway/ctpDataType.py b/vn.trader/ctpGateway/ctpDataType.py index 9b7a4ecf..13033f68 100644 --- a/vn.trader/ctpGateway/ctpDataType.py +++ b/vn.trader/ctpGateway/ctpDataType.py @@ -74,6 +74,11 @@ typedefDict["TThostFtdcClientIDType"] = "string" #////////////////////////////////////////////////////////////////////// typedefDict["TThostFtdcInstrumentIDType"] = "string" +#////////////////////////////////////////////////////////////////////// +#TFtdcInstrumentCodeType是一个合约标识码类型 +#////////////////////////////////////////////////////////////////////// +typedefDict["TThostFtdcInstrumentCodeType"] = "string" + #////////////////////////////////////////////////////////////////////// #TFtdcMarketIDType是一个市场代码类型 #////////////////////////////////////////////////////////////////////// @@ -122,7 +127,7 @@ defineDict["THOST_FTDC_EXP_Normal"] = '0' #根据成交生成报单 defineDict["THOST_FTDC_EXP_GenOrderByTrade"] = '1' -typedefDict["TThostFtdcExchangePropertyType"] = "string" +typedefDict["TThostFtdcExchangePropertyType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcDateType是一个日期类型 @@ -238,10 +243,12 @@ defineDict["THOST_FTDC_ICT_LocalID"] = 'G' defineDict["THOST_FTDC_ICT_BusinessRegistration"] = 'H' #港澳永久性居民身份证 defineDict["THOST_FTDC_ICT_HKMCIDCard"] = 'I' +#人行开户许可证 +defineDict["THOST_FTDC_ICT_AccountsPermits"] = 'J' #其他证件 defineDict["THOST_FTDC_ICT_OtherCard"] = 'x' -typedefDict["TThostFtdcIdCardTypeType"] = "string" +typedefDict["TThostFtdcIdCardTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcOrderLocalIDType是一个本地报单编号类型 @@ -293,7 +300,7 @@ defineDict["THOST_FTDC_IR_Group"] = '2' #单一投资者 defineDict["THOST_FTDC_IR_Single"] = '3' -typedefDict["TThostFtdcInvestorRangeType"] = "string" +typedefDict["TThostFtdcInvestorRangeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcDepartmentRangeType是一个投资者范围类型 @@ -305,7 +312,7 @@ defineDict["THOST_FTDC_DR_Group"] = '2' #单一投资者 defineDict["THOST_FTDC_DR_Single"] = '3' -typedefDict["TThostFtdcDepartmentRangeType"] = "string" +typedefDict["TThostFtdcDepartmentRangeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcDataSyncStatusType是一个数据同步状态类型 @@ -317,7 +324,7 @@ defineDict["THOST_FTDC_DS_Synchronizing"] = '2' #已同步 defineDict["THOST_FTDC_DS_Synchronized"] = '3' -typedefDict["TThostFtdcDataSyncStatusType"] = "string" +typedefDict["TThostFtdcDataSyncStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBrokerDataSyncStatusType是一个经纪公司数据同步状态类型 @@ -327,7 +334,7 @@ defineDict["THOST_FTDC_BDS_Synchronized"] = '1' #同步中 defineDict["THOST_FTDC_BDS_Synchronizing"] = '2' -typedefDict["TThostFtdcBrokerDataSyncStatusType"] = "string" +typedefDict["TThostFtdcBrokerDataSyncStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcExchangeConnectStatusType是一个交易所连接状态类型 @@ -339,7 +346,7 @@ defineDict["THOST_FTDC_ECS_QryInstrumentSent"] = '2' #已经获取信息 defineDict["THOST_FTDC_ECS_GotInformation"] = '9' -typedefDict["TThostFtdcExchangeConnectStatusType"] = "string" +typedefDict["TThostFtdcExchangeConnectStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcTraderConnectStatusType是一个交易所交易员连接状态类型 @@ -353,7 +360,7 @@ defineDict["THOST_FTDC_TCS_QryInstrumentSent"] = '3' #订阅私有流 defineDict["THOST_FTDC_TCS_SubPrivateFlow"] = '4' -typedefDict["TThostFtdcTraderConnectStatusType"] = "string" +typedefDict["TThostFtdcTraderConnectStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFunctionCodeType是一个功能代码类型 @@ -389,7 +396,7 @@ defineDict["THOST_FTDC_FC_SyncOTP"] = 'E' #删除未知单 defineDict["THOST_FTDC_FC_DeleteOrder"] = 'F' -typedefDict["TThostFtdcFunctionCodeType"] = "string" +typedefDict["TThostFtdcFunctionCodeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBrokerFunctionCodeType是一个经纪公司功能代码类型 @@ -483,7 +490,7 @@ defineDict["THOST_FTDC_BFC_ParkedOrderInsert"] = 'K' #预埋报单操作 defineDict["THOST_FTDC_BFC_ParkedOrderAction"] = 'L' -typedefDict["TThostFtdcBrokerFunctionCodeType"] = "string" +typedefDict["TThostFtdcBrokerFunctionCodeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcOrderActionStatusType是一个报单操作状态类型 @@ -495,7 +502,7 @@ defineDict["THOST_FTDC_OAS_Accepted"] = 'b' #已经被拒绝 defineDict["THOST_FTDC_OAS_Rejected"] = 'c' -typedefDict["TThostFtdcOrderActionStatusType"] = "string" +typedefDict["TThostFtdcOrderActionStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcOrderStatusType是一个报单状态类型 @@ -519,7 +526,7 @@ defineDict["THOST_FTDC_OST_NotTouched"] = 'b' #已触发 defineDict["THOST_FTDC_OST_Touched"] = 'c' -typedefDict["TThostFtdcOrderStatusType"] = "string" +typedefDict["TThostFtdcOrderStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcOrderSubmitStatusType是一个报单提交状态类型 @@ -539,7 +546,7 @@ defineDict["THOST_FTDC_OSS_CancelRejected"] = '5' #改单已经被拒绝 defineDict["THOST_FTDC_OSS_ModifyRejected"] = '6' -typedefDict["TThostFtdcOrderSubmitStatusType"] = "string" +typedefDict["TThostFtdcOrderSubmitStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcPositionDateType是一个持仓日期类型 @@ -549,7 +556,7 @@ defineDict["THOST_FTDC_PSD_Today"] = '1' #历史持仓 defineDict["THOST_FTDC_PSD_History"] = '2' -typedefDict["TThostFtdcPositionDateType"] = "string" +typedefDict["TThostFtdcPositionDateType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcPositionDateTypeType是一个持仓日期类型类型 @@ -559,7 +566,7 @@ defineDict["THOST_FTDC_PDT_UseHistory"] = '1' #不使用历史持仓 defineDict["THOST_FTDC_PDT_NoUseHistory"] = '2' -typedefDict["TThostFtdcPositionDateTypeType"] = "string" +typedefDict["TThostFtdcPositionDateTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcTradingRoleType是一个交易角色类型 @@ -571,7 +578,7 @@ defineDict["THOST_FTDC_ER_Host"] = '2' #做市商 defineDict["THOST_FTDC_ER_Maker"] = '3' -typedefDict["TThostFtdcTradingRoleType"] = "string" +typedefDict["TThostFtdcTradingRoleType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcProductClassType是一个产品类型类型 @@ -588,8 +595,12 @@ defineDict["THOST_FTDC_PC_Spot"] = '4' defineDict["THOST_FTDC_PC_EFP"] = '5' #现货期权 defineDict["THOST_FTDC_PC_SpotOption"] = '6' +#个股期权 +defineDict["THOST_FTDC_PC_ETFOption"] = '7' +#证券 +defineDict["THOST_FTDC_PC_Stock"] = '8' -typedefDict["TThostFtdcProductClassType"] = "string" +typedefDict["TThostFtdcProductClassType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcInstLifePhaseType是一个合约生命周期状态类型 @@ -603,7 +614,7 @@ defineDict["THOST_FTDC_IP_Pause"] = '2' #到期 defineDict["THOST_FTDC_IP_Expired"] = '3' -typedefDict["TThostFtdcInstLifePhaseType"] = "string" +typedefDict["TThostFtdcInstLifePhaseType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcDirectionType是一个买卖方向类型 @@ -613,7 +624,7 @@ defineDict["THOST_FTDC_D_Buy"] = '0' #卖 defineDict["THOST_FTDC_D_Sell"] = '1' -typedefDict["TThostFtdcDirectionType"] = "string" +typedefDict["TThostFtdcDirectionType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcPositionTypeType是一个持仓类型类型 @@ -623,7 +634,7 @@ defineDict["THOST_FTDC_PT_Net"] = '1' #综合持仓 defineDict["THOST_FTDC_PT_Gross"] = '2' -typedefDict["TThostFtdcPositionTypeType"] = "string" +typedefDict["TThostFtdcPositionTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcPosiDirectionType是一个持仓多空方向类型 @@ -635,7 +646,7 @@ defineDict["THOST_FTDC_PD_Long"] = '2' #空头 defineDict["THOST_FTDC_PD_Short"] = '3' -typedefDict["TThostFtdcPosiDirectionType"] = "string" +typedefDict["TThostFtdcPosiDirectionType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSysSettlementStatusType是一个系统结算状态类型 @@ -651,7 +662,7 @@ defineDict["THOST_FTDC_SS_Settlement"] = '4' #结算完成 defineDict["THOST_FTDC_SS_SettlementFinished"] = '5' -typedefDict["TThostFtdcSysSettlementStatusType"] = "string" +typedefDict["TThostFtdcSysSettlementStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcRatioAttrType是一个费率属性类型 @@ -661,7 +672,7 @@ defineDict["THOST_FTDC_RA_Trade"] = '0' #结算费率 defineDict["THOST_FTDC_RA_Settlement"] = '1' -typedefDict["TThostFtdcRatioAttrType"] = "string" +typedefDict["TThostFtdcRatioAttrType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcHedgeFlagType是一个投机套保标志类型 @@ -672,8 +683,10 @@ defineDict["THOST_FTDC_HF_Speculation"] = '1' defineDict["THOST_FTDC_HF_Arbitrage"] = '2' #套保 defineDict["THOST_FTDC_HF_Hedge"] = '3' +#备兑 +defineDict["THOST_FTDC_HF_Covered"] = '4' -typedefDict["TThostFtdcHedgeFlagType"] = "string" +typedefDict["TThostFtdcHedgeFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBillHedgeFlagType是一个投机套保标志类型 @@ -685,7 +698,7 @@ defineDict["THOST_FTDC_BHF_Arbitrage"] = '2' #套保 defineDict["THOST_FTDC_BHF_Hedge"] = '3' -typedefDict["TThostFtdcBillHedgeFlagType"] = "string" +typedefDict["TThostFtdcBillHedgeFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcClientIDTypeType是一个交易编码类型类型 @@ -697,7 +710,7 @@ defineDict["THOST_FTDC_CIDT_Arbitrage"] = '2' #套保 defineDict["THOST_FTDC_CIDT_Hedge"] = '3' -typedefDict["TThostFtdcClientIDTypeType"] = "string" +typedefDict["TThostFtdcClientIDTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcOrderPriceTypeType是一个报单价格条件类型 @@ -732,8 +745,12 @@ defineDict["THOST_FTDC_OPT_BidPrice1PlusOneTicks"] = 'D' defineDict["THOST_FTDC_OPT_BidPrice1PlusTwoTicks"] = 'E' #买一价浮动上浮3个ticks defineDict["THOST_FTDC_OPT_BidPrice1PlusThreeTicks"] = 'F' +#五档价 +defineDict["THOST_FTDC_OPT_FiveLevelPrice"] = 'G' +#本方最优价 +defineDict["THOST_FTDC_OPT_BestPriceThisSide"] = 'H' -typedefDict["TThostFtdcOrderPriceTypeType"] = "string" +typedefDict["TThostFtdcOrderPriceTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcOffsetFlagType是一个开平标志类型 @@ -753,7 +770,7 @@ defineDict["THOST_FTDC_OF_ForceOff"] = '5' #本地强平 defineDict["THOST_FTDC_OF_LocalForceClose"] = '6' -typedefDict["TThostFtdcOffsetFlagType"] = "string" +typedefDict["TThostFtdcOffsetFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcForceCloseReasonType是一个强平原因类型 @@ -775,7 +792,7 @@ defineDict["THOST_FTDC_FCC_Other"] = '6' #自然人临近交割 defineDict["THOST_FTDC_FCC_PersonDeliv"] = '7' -typedefDict["TThostFtdcForceCloseReasonType"] = "string" +typedefDict["TThostFtdcForceCloseReasonType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcOrderTypeType是一个报单类型类型 @@ -793,7 +810,7 @@ defineDict["THOST_FTDC_ORDT_ConditionalOrder"] = '4' #互换单 defineDict["THOST_FTDC_ORDT_Swap"] = '5' -typedefDict["TThostFtdcOrderTypeType"] = "string" +typedefDict["TThostFtdcOrderTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcTimeConditionType是一个有效期类型类型 @@ -811,7 +828,7 @@ defineDict["THOST_FTDC_TC_GTC"] = '5' #集合竞价有效 defineDict["THOST_FTDC_TC_GFA"] = '6' -typedefDict["TThostFtdcTimeConditionType"] = "string" +typedefDict["TThostFtdcTimeConditionType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcVolumeConditionType是一个成交量类型类型 @@ -823,7 +840,7 @@ defineDict["THOST_FTDC_VC_MV"] = '2' #全部数量 defineDict["THOST_FTDC_VC_CV"] = '3' -typedefDict["TThostFtdcVolumeConditionType"] = "string" +typedefDict["TThostFtdcVolumeConditionType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcContingentConditionType是一个触发条件类型 @@ -861,7 +878,7 @@ defineDict["THOST_FTDC_CC_BidPriceLesserThanStopPrice"] = 'F' #买一价小于等于条件价 defineDict["THOST_FTDC_CC_BidPriceLesserEqualStopPrice"] = 'H' -typedefDict["TThostFtdcContingentConditionType"] = "string" +typedefDict["TThostFtdcContingentConditionType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcActionFlagType是一个操作标志类型 @@ -871,7 +888,7 @@ defineDict["THOST_FTDC_AF_Delete"] = '0' #修改 defineDict["THOST_FTDC_AF_Modify"] = '3' -typedefDict["TThostFtdcActionFlagType"] = "string" +typedefDict["TThostFtdcActionFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcTradingRightType是一个交易权限类型 @@ -883,7 +900,7 @@ defineDict["THOST_FTDC_TR_CloseOnly"] = '1' #不能交易 defineDict["THOST_FTDC_TR_Forbidden"] = '2' -typedefDict["TThostFtdcTradingRightType"] = "string" +typedefDict["TThostFtdcTradingRightType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcOrderSourceType是一个报单来源类型 @@ -893,7 +910,7 @@ defineDict["THOST_FTDC_OSRC_Participant"] = '0' #来自管理员 defineDict["THOST_FTDC_OSRC_Administrator"] = '1' -typedefDict["TThostFtdcOrderSourceType"] = "string" +typedefDict["TThostFtdcOrderSourceType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcTradeTypeType是一个成交类型类型 @@ -911,7 +928,7 @@ defineDict["THOST_FTDC_TRDT_EFPDerived"] = '3' #组合衍生成交 defineDict["THOST_FTDC_TRDT_CombinationDerived"] = '4' -typedefDict["TThostFtdcTradeTypeType"] = "string" +typedefDict["TThostFtdcTradeTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcPriceSourceType是一个成交价来源类型 @@ -923,7 +940,7 @@ defineDict["THOST_FTDC_PSRC_Buy"] = '1' #卖委托价 defineDict["THOST_FTDC_PSRC_Sell"] = '2' -typedefDict["TThostFtdcPriceSourceType"] = "string" +typedefDict["TThostFtdcPriceSourceType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcInstrumentStatusType是一个合约交易状态类型 @@ -943,7 +960,7 @@ defineDict["THOST_FTDC_IS_AuctionMatch"] = '5' #收盘 defineDict["THOST_FTDC_IS_Closed"] = '6' -typedefDict["TThostFtdcInstrumentStatusType"] = "string" +typedefDict["TThostFtdcInstrumentStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcInstStatusEnterReasonType是一个品种进入交易状态原因类型 @@ -955,7 +972,7 @@ defineDict["THOST_FTDC_IER_Manual"] = '2' #熔断 defineDict["THOST_FTDC_IER_Fuse"] = '3' -typedefDict["TThostFtdcInstStatusEnterReasonType"] = "string" +typedefDict["TThostFtdcInstStatusEnterReasonType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcOrderActionRefType是一个报单操作引用类型 @@ -1177,7 +1194,7 @@ defineDict["THOST_FTDC_BS_Uploaded"] = '2' #审核失败 defineDict["THOST_FTDC_BS_Failed"] = '3' -typedefDict["TThostFtdcBatchStatusType"] = "string" +typedefDict["TThostFtdcBatchStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcPropertyIDType是一个属性代码类型 @@ -1222,7 +1239,7 @@ defineDict["THOST_FTDC_RS_All"] = '1' #按品种 defineDict["THOST_FTDC_RS_ByProduct"] = '2' -typedefDict["TThostFtdcReturnStyleType"] = "string" +typedefDict["TThostFtdcReturnStyleType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcReturnPatternType是一个返还模式类型 @@ -1232,7 +1249,7 @@ defineDict["THOST_FTDC_RP_ByVolume"] = '1' #按留存手续费 defineDict["THOST_FTDC_RP_ByFeeOnHand"] = '2' -typedefDict["TThostFtdcReturnPatternType"] = "string" +typedefDict["TThostFtdcReturnPatternType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcReturnLevelType是一个返还级别类型 @@ -1256,7 +1273,7 @@ defineDict["THOST_FTDC_RL_Level8"] = '8' #级别9 defineDict["THOST_FTDC_RL_Level9"] = '9' -typedefDict["TThostFtdcReturnLevelType"] = "string" +typedefDict["TThostFtdcReturnLevelType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcReturnStandardType是一个返还标准类型 @@ -1266,7 +1283,7 @@ defineDict["THOST_FTDC_RSD_ByPeriod"] = '1' #按某一标准 defineDict["THOST_FTDC_RSD_ByStandard"] = '2' -typedefDict["TThostFtdcReturnStandardType"] = "string" +typedefDict["TThostFtdcReturnStandardType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcMortgageTypeType是一个质押类型类型 @@ -1276,7 +1293,7 @@ defineDict["THOST_FTDC_MT_Out"] = '0' #质入 defineDict["THOST_FTDC_MT_In"] = '1' -typedefDict["TThostFtdcMortgageTypeType"] = "string" +typedefDict["TThostFtdcMortgageTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcInvestorSettlementParamIDType是一个投资者结算参数代码类型 @@ -1288,7 +1305,7 @@ defineDict["THOST_FTDC_ISPI_MarginWay"] = '5' #结算单结存是否包含质押 defineDict["THOST_FTDC_ISPI_BillDeposit"] = '9' -typedefDict["TThostFtdcInvestorSettlementParamIDType"] = "string" +typedefDict["TThostFtdcInvestorSettlementParamIDType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcExchangeSettlementParamIDType是一个交易所结算参数代码类型 @@ -1316,7 +1333,7 @@ defineDict["THOST_FTDC_ESPI_OptOutDisCountRate"] = 'a' #最低保障系数 defineDict["THOST_FTDC_ESPI_OptMiniGuarantee"] = 'b' -typedefDict["TThostFtdcExchangeSettlementParamIDType"] = "string" +typedefDict["TThostFtdcExchangeSettlementParamIDType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSystemParamIDType是一个系统参数代码类型 @@ -1368,7 +1385,7 @@ defineDict["THOST_FTDC_SPI_IsStandardFreeze"] = 'X' #郑商所是否开放所有品种套保交易 defineDict["THOST_FTDC_SPI_CZCENormalProductHedge"] = 'B' -typedefDict["TThostFtdcSystemParamIDType"] = "string" +typedefDict["TThostFtdcSystemParamIDType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcTradeParamIDType是一个交易系统参数代码类型 @@ -1389,8 +1406,14 @@ defineDict["THOST_FTDC_TPID_SingleUserSessionMaxNum"] = 'S' defineDict["THOST_FTDC_TPID_LoginFailMaxNum"] = 'L' #是否强制认证 defineDict["THOST_FTDC_TPID_IsAuthForce"] = 'A' +#是否冻结证券持仓 +defineDict["THOST_FTDC_TPID_IsPosiFreeze"] = 'F' +#是否限仓 +defineDict["THOST_FTDC_TPID_IsPosiLimit"] = 'M' +#郑商所询价时间间隔 +defineDict["THOST_FTDC_TPID_ForQuoteTimeInterval"] = 'Q' -typedefDict["TThostFtdcTradeParamIDType"] = "string" +typedefDict["TThostFtdcTradeParamIDType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSettlementParamValueType是一个参数代码值类型 @@ -1480,7 +1503,7 @@ defineDict["THOST_FTDC_FI_SettlementPriceComparison"] = 'M' #上期所非持仓变动明细 defineDict["THOST_FTDC_FI_NonTradePosChange"] = 'B' -typedefDict["TThostFtdcFileIDType"] = "string" +typedefDict["TThostFtdcFileIDType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFileNameType是一个文件名称类型 @@ -1495,7 +1518,7 @@ defineDict["THOST_FTDC_FUT_Settlement"] = '0' #核对 defineDict["THOST_FTDC_FUT_Check"] = '1' -typedefDict["TThostFtdcFileTypeType"] = "string" +typedefDict["TThostFtdcFileTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFileFormatType是一个文件格式类型 @@ -1507,7 +1530,7 @@ defineDict["THOST_FTDC_FFT_Zip"] = '1' #DBF文件(.dbf) defineDict["THOST_FTDC_FFT_DBF"] = '2' -typedefDict["TThostFtdcFileFormatType"] = "string" +typedefDict["TThostFtdcFileFormatType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFileUploadStatusType是一个文件状态类型 @@ -1523,7 +1546,7 @@ defineDict["THOST_FTDC_FUS_PartSucceedLoad"] = '4' #导入失败 defineDict["THOST_FTDC_FUS_FailedLoad"] = '5' -typedefDict["TThostFtdcFileUploadStatusType"] = "string" +typedefDict["TThostFtdcFileUploadStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcTransferDirectionType是一个移仓方向类型 @@ -1533,7 +1556,7 @@ defineDict["THOST_FTDC_TD_Out"] = '0' #移入 defineDict["THOST_FTDC_TD_In"] = '1' -typedefDict["TThostFtdcTransferDirectionType"] = "string" +typedefDict["TThostFtdcTransferDirectionType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcUploadModeType是一个上传文件类型类型 @@ -1613,7 +1636,7 @@ defineDict["THOST_FTDC_SC_NoSpecialRule"] = '0' #不包含春节 defineDict["THOST_FTDC_SC_NoSpringFestival"] = '1' -typedefDict["TThostFtdcSpecialCreateRuleType"] = "string" +typedefDict["TThostFtdcSpecialCreateRuleType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBasisPriceTypeType是一个挂牌基准价类型类型 @@ -1623,7 +1646,7 @@ defineDict["THOST_FTDC_IPT_LastSettlement"] = '1' #上一合约收盘价 defineDict["THOST_FTDC_IPT_LaseClose"] = '2' -typedefDict["TThostFtdcBasisPriceTypeType"] = "string" +typedefDict["TThostFtdcBasisPriceTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcProductLifePhaseType是一个产品生命周期状态类型 @@ -1635,7 +1658,7 @@ defineDict["THOST_FTDC_PLP_NonActive"] = '2' #注销 defineDict["THOST_FTDC_PLP_Canceled"] = '3' -typedefDict["TThostFtdcProductLifePhaseType"] = "string" +typedefDict["TThostFtdcProductLifePhaseType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcDeliveryModeType是一个交割方式类型 @@ -1645,7 +1668,7 @@ defineDict["THOST_FTDC_DM_CashDeliv"] = '1' #实物交割 defineDict["THOST_FTDC_DM_CommodityDeliv"] = '2' -typedefDict["TThostFtdcDeliveryModeType"] = "string" +typedefDict["TThostFtdcDeliveryModeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcLogLevelType是一个日志级别类型 @@ -1672,7 +1695,7 @@ defineDict["THOST_FTDC_FIOT_Transfer"] = '2' #银期换汇 defineDict["THOST_FTDC_FIOT_SwapCurrency"] = '3' -typedefDict["TThostFtdcFundIOTypeType"] = "string" +typedefDict["TThostFtdcFundIOTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFundTypeType是一个资金类型类型 @@ -1686,7 +1709,7 @@ defineDict["THOST_FTDC_FT_Company"] = '3' #资金内转 defineDict["THOST_FTDC_FT_InnerTransfer"] = '4' -typedefDict["TThostFtdcFundTypeType"] = "string" +typedefDict["TThostFtdcFundTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFundDirectionType是一个出入金方向类型 @@ -1696,7 +1719,7 @@ defineDict["THOST_FTDC_FD_In"] = '1' #出金 defineDict["THOST_FTDC_FD_Out"] = '2' -typedefDict["TThostFtdcFundDirectionType"] = "string" +typedefDict["TThostFtdcFundDirectionType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFundStatusType是一个资金状态类型 @@ -1708,7 +1731,7 @@ defineDict["THOST_FTDC_FS_Check"] = '2' #已冲销 defineDict["THOST_FTDC_FS_Charge"] = '3' -typedefDict["TThostFtdcFundStatusType"] = "string" +typedefDict["TThostFtdcFundStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBillNoType是一个票据号类型 @@ -1730,7 +1753,7 @@ defineDict["THOST_FTDC_PS_Publishing"] = '2' #已发布 defineDict["THOST_FTDC_PS_Published"] = '3' -typedefDict["TThostFtdcPublishStatusType"] = "string" +typedefDict["TThostFtdcPublishStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcEnumValueIDType是一个枚举值代码类型 @@ -1770,7 +1793,7 @@ defineDict["THOST_FTDC_ES_Closed"] = '6' #结算 defineDict["THOST_FTDC_ES_Settlement"] = '7' -typedefDict["TThostFtdcSystemStatusType"] = "string" +typedefDict["TThostFtdcSystemStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSettlementStatusType是一个结算状态类型 @@ -1784,7 +1807,7 @@ defineDict["THOST_FTDC_STS_Settlemented"] = '2' #结算完成 defineDict["THOST_FTDC_STS_Finished"] = '3' -typedefDict["TThostFtdcSettlementStatusType"] = "string" +typedefDict["TThostFtdcSettlementStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcRangeIntTypeType是一个限定值类型类型 @@ -1855,7 +1878,7 @@ defineDict["THOST_FTDC_CT_SpecialOrgan"] = '3' #资管户 defineDict["THOST_FTDC_CT_Asset"] = '4' -typedefDict["TThostFtdcInvestorTypeType"] = "string" +typedefDict["TThostFtdcInvestorTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBrokerTypeType是一个经纪公司类型类型 @@ -1865,7 +1888,7 @@ defineDict["THOST_FTDC_BT_Trade"] = '0' #交易结算会员 defineDict["THOST_FTDC_BT_TradeSettle"] = '1' -typedefDict["TThostFtdcBrokerTypeType"] = "string" +typedefDict["TThostFtdcBrokerTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcRiskLevelType是一个风险等级类型 @@ -1879,7 +1902,7 @@ defineDict["THOST_FTDC_FAS_Focus"] = '3' #风险客户 defineDict["THOST_FTDC_FAS_Risk"] = '4' -typedefDict["TThostFtdcRiskLevelType"] = "string" +typedefDict["TThostFtdcRiskLevelType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFeeAcceptStyleType是一个手续费收取方式类型 @@ -1893,7 +1916,7 @@ defineDict["THOST_FTDC_FAS_None"] = '3' #按指定手续费收取 defineDict["THOST_FTDC_FAS_FixFee"] = '4' -typedefDict["TThostFtdcFeeAcceptStyleType"] = "string" +typedefDict["TThostFtdcFeeAcceptStyleType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcPasswordTypeType是一个密码类型类型 @@ -1903,7 +1926,7 @@ defineDict["THOST_FTDC_PWDT_Trade"] = '1' #资金密码 defineDict["THOST_FTDC_PWDT_Account"] = '2' -typedefDict["TThostFtdcPasswordTypeType"] = "string" +typedefDict["TThostFtdcPasswordTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcAlgorithmType是一个盈亏算法类型 @@ -1917,7 +1940,7 @@ defineDict["THOST_FTDC_AG_OnlyGain"] = '3' #浮盈浮亏都不计算 defineDict["THOST_FTDC_AG_None"] = '4' -typedefDict["TThostFtdcAlgorithmType"] = "string" +typedefDict["TThostFtdcAlgorithmType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcIncludeCloseProfitType是一个是否包含平仓盈利类型 @@ -1927,7 +1950,7 @@ defineDict["THOST_FTDC_ICP_Include"] = '0' #不包含平仓盈利 defineDict["THOST_FTDC_ICP_NotInclude"] = '2' -typedefDict["TThostFtdcIncludeCloseProfitType"] = "string" +typedefDict["TThostFtdcIncludeCloseProfitType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcAllWithoutTradeType是一个是否受可提比例限制类型 @@ -1939,7 +1962,7 @@ defineDict["THOST_FTDC_AWT_Disable"] = '2' #无仓不受可提比例限制 defineDict["THOST_FTDC_AWT_NoHoldEnable"] = '3' -typedefDict["TThostFtdcAllWithoutTradeType"] = "string" +typedefDict["TThostFtdcAllWithoutTradeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCommentType是一个盈亏算法说明类型 @@ -2024,7 +2047,7 @@ defineDict["THOST_FTDC_FPWD_UnCheck"] = '0' #核对 defineDict["THOST_FTDC_FPWD_Check"] = '1' -typedefDict["TThostFtdcFuturePwdFlagType"] = "string" +typedefDict["TThostFtdcFuturePwdFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcTransferTypeType是一个银期转账类型类型 @@ -2034,7 +2057,7 @@ defineDict["THOST_FTDC_TT_BankToFuture"] = '0' #期货转银行 defineDict["THOST_FTDC_TT_FutureToBank"] = '1' -typedefDict["TThostFtdcTransferTypeType"] = "string" +typedefDict["TThostFtdcTransferTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFutureAccPwdType是一个期货资金密码类型 @@ -2081,7 +2104,7 @@ defineDict["THOST_FTDC_TVF_Valid"] = '1' #冲正 defineDict["THOST_FTDC_TVF_Reverse"] = '2' -typedefDict["TThostFtdcTransferValidFlagType"] = "string" +typedefDict["TThostFtdcTransferValidFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCertCodeType是一个证件号码类型 @@ -2098,7 +2121,7 @@ defineDict["THOST_FTDC_RN_ZT"] = '1' #其它 defineDict["THOST_FTDC_RN_QT"] = '2' -typedefDict["TThostFtdcReasonType"] = "string" +typedefDict["TThostFtdcReasonType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFundProjectIDType是一个资金项目编号类型 @@ -2115,7 +2138,7 @@ defineDict["THOST_FTDC_SEX_Man"] = '1' #女 defineDict["THOST_FTDC_SEX_Woman"] = '2' -typedefDict["TThostFtdcSexType"] = "string" +typedefDict["TThostFtdcSexType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcProfessionType是一个职业类型 @@ -2172,7 +2195,12 @@ defineDict["THOST_FTDC_UT_Operator"] = '1' #管理员 defineDict["THOST_FTDC_UT_SuperUser"] = '2' -typedefDict["TThostFtdcUserTypeType"] = "string" +typedefDict["TThostFtdcUserTypeType"] = "char" + +#////////////////////////////////////////////////////////////////////// +#TFtdcBranchIDType是一个营业部编号类型 +#////////////////////////////////////////////////////////////////////// +typedefDict["TThostFtdcBranchIDType"] = "string" #////////////////////////////////////////////////////////////////////// #TFtdcRateTypeType是一个费率类型类型 @@ -2180,7 +2208,7 @@ typedefDict["TThostFtdcUserTypeType"] = "string" #保证金率 defineDict["THOST_FTDC_RATETYPE_MarginRate"] = '2' -typedefDict["TThostFtdcRateTypeType"] = "string" +typedefDict["TThostFtdcRateTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcNoteTypeType是一个通知类型类型 @@ -2198,7 +2226,7 @@ defineDict["THOST_FTDC_NOTETYPE_TradeNotes"] = '5' #交割通知书 defineDict["THOST_FTDC_NOTETYPE_DelivNotes"] = '6' -typedefDict["TThostFtdcNoteTypeType"] = "string" +typedefDict["TThostFtdcNoteTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSettlementStyleType是一个结算单方式类型 @@ -2208,7 +2236,7 @@ defineDict["THOST_FTDC_SBS_Day"] = '1' #逐笔对冲 defineDict["THOST_FTDC_SBS_Volume"] = '2' -typedefDict["TThostFtdcSettlementStyleType"] = "string" +typedefDict["TThostFtdcSettlementStyleType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBrokerDNSType是一个域名类型 @@ -2228,7 +2256,7 @@ defineDict["THOST_FTDC_ST_Day"] = '0' #月报 defineDict["THOST_FTDC_ST_Month"] = '1' -typedefDict["TThostFtdcSettlementBillTypeType"] = "string" +typedefDict["TThostFtdcSettlementBillTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcUserRightTypeType是一个客户权限类型类型 @@ -2244,7 +2272,7 @@ defineDict["THOST_FTDC_URT_Fax"] = '4' #条件单 defineDict["THOST_FTDC_URT_ConditionOrder"] = '5' -typedefDict["TThostFtdcUserRightTypeType"] = "string" +typedefDict["TThostFtdcUserRightTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcMarginPriceTypeType是一个保证金价格类型类型 @@ -2258,7 +2286,7 @@ defineDict["THOST_FTDC_MPT_AveragePrice"] = '3' #开仓价 defineDict["THOST_FTDC_MPT_OpenPrice"] = '4' -typedefDict["TThostFtdcMarginPriceTypeType"] = "string" +typedefDict["TThostFtdcMarginPriceTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBillGenStatusType是一个结算单生成状态类型 @@ -2270,7 +2298,7 @@ defineDict["THOST_FTDC_BGS_NoGenerated"] = '1' #已生成 defineDict["THOST_FTDC_BGS_Generated"] = '2' -typedefDict["TThostFtdcBillGenStatusType"] = "string" +typedefDict["TThostFtdcBillGenStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcAlgoTypeType是一个算法类型类型 @@ -2280,7 +2308,7 @@ defineDict["THOST_FTDC_AT_HandlePositionAlgo"] = '1' #寻找保证金率算法 defineDict["THOST_FTDC_AT_FindMarginRateAlgo"] = '2' -typedefDict["TThostFtdcAlgoTypeType"] = "string" +typedefDict["TThostFtdcAlgoTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcHandlePositionAlgoIDType是一个持仓处理算法编号类型 @@ -2292,7 +2320,7 @@ defineDict["THOST_FTDC_HPA_DCE"] = '2' #郑州商品交易所 defineDict["THOST_FTDC_HPA_CZCE"] = '3' -typedefDict["TThostFtdcHandlePositionAlgoIDType"] = "string" +typedefDict["TThostFtdcHandlePositionAlgoIDType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFindMarginRateAlgoIDType是一个寻找保证金率算法编号类型 @@ -2304,7 +2332,7 @@ defineDict["THOST_FTDC_FMRA_DCE"] = '2' #郑州商品交易所 defineDict["THOST_FTDC_FMRA_CZCE"] = '3' -typedefDict["TThostFtdcFindMarginRateAlgoIDType"] = "string" +typedefDict["TThostFtdcFindMarginRateAlgoIDType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcHandleTradingAccountAlgoIDType是一个资金处理算法编号类型 @@ -2316,7 +2344,7 @@ defineDict["THOST_FTDC_HTAA_DCE"] = '2' #郑州商品交易所 defineDict["THOST_FTDC_HTAA_CZCE"] = '3' -typedefDict["TThostFtdcHandleTradingAccountAlgoIDType"] = "string" +typedefDict["TThostFtdcHandleTradingAccountAlgoIDType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcPersonTypeType是一个联系人类型类型 @@ -2350,7 +2378,7 @@ defineDict["THOST_FTDC_PST_ForeignerRefer"] = 'D' #法人代表参考证件 defineDict["THOST_FTDC_PST_CorporationRefer"] = 'E' -typedefDict["TThostFtdcPersonTypeType"] = "string" +typedefDict["TThostFtdcPersonTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcQueryInvestorRangeType是一个查询范围类型 @@ -2362,7 +2390,7 @@ defineDict["THOST_FTDC_QIR_Group"] = '2' #单一投资者 defineDict["THOST_FTDC_QIR_Single"] = '3' -typedefDict["TThostFtdcQueryInvestorRangeType"] = "string" +typedefDict["TThostFtdcQueryInvestorRangeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcInvestorRiskStatusType是一个投资者风险状态类型 @@ -2378,7 +2406,7 @@ defineDict["THOST_FTDC_IRS_Force"] = '4' #异常 defineDict["THOST_FTDC_IRS_Exception"] = '5' -typedefDict["TThostFtdcInvestorRiskStatusType"] = "string" +typedefDict["TThostFtdcInvestorRiskStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcLegIDType是一个单腿编号类型 @@ -2428,7 +2456,7 @@ defineDict["THOST_FTDC_UET_Authenticate"] = '6' #其他 defineDict["THOST_FTDC_UET_Other"] = '9' -typedefDict["TThostFtdcUserEventTypeType"] = "string" +typedefDict["TThostFtdcUserEventTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcUserEventInfoType是一个用户事件信息类型 @@ -2443,7 +2471,7 @@ defineDict["THOST_FTDC_ICS_Close"] = '0' #先平今再平昨 defineDict["THOST_FTDC_ICS_CloseToday"] = '1' -typedefDict["TThostFtdcCloseStyleType"] = "string" +typedefDict["TThostFtdcCloseStyleType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcStatModeType是一个统计方式类型 @@ -2457,7 +2485,7 @@ defineDict["THOST_FTDC_SM_Product"] = '2' #按投资者统计 defineDict["THOST_FTDC_SM_Investor"] = '3' -typedefDict["TThostFtdcStatModeType"] = "string" +typedefDict["TThostFtdcStatModeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcParkedOrderStatusType是一个预埋单状态类型 @@ -2469,7 +2497,7 @@ defineDict["THOST_FTDC_PAOS_Send"] = '2' #已删除 defineDict["THOST_FTDC_PAOS_Deleted"] = '3' -typedefDict["TThostFtdcParkedOrderStatusType"] = "string" +typedefDict["TThostFtdcParkedOrderStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcParkedOrderIDType是一个预埋报单编号类型 @@ -2489,7 +2517,7 @@ defineDict["THOST_FTDC_VDS_Dealing"] = '1' #处理成功 defineDict["THOST_FTDC_VDS_DeaclSucceed"] = '2' -typedefDict["TThostFtdcVirDealStatusType"] = "string" +typedefDict["TThostFtdcVirDealStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcOrgSystemIDType是一个原有系统代码类型 @@ -2501,7 +2529,7 @@ defineDict["THOST_FTDC_ORGS_ESunny"] = '1' #金仕达V6系统 defineDict["THOST_FTDC_ORGS_KingStarV6"] = '2' -typedefDict["TThostFtdcOrgSystemIDType"] = "string" +typedefDict["TThostFtdcOrgSystemIDType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcVirTradeStatusType是一个交易状态类型 @@ -2521,7 +2549,7 @@ defineDict["THOST_FTDC_VTS_MesException"] = '5' #系统出错,请人工处理 defineDict["THOST_FTDC_VTS_SysException"] = '6' -typedefDict["TThostFtdcVirTradeStatusType"] = "string" +typedefDict["TThostFtdcVirTradeStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcVirBankAccTypeType是一个银行帐户类型类型 @@ -2533,7 +2561,7 @@ defineDict["THOST_FTDC_VBAT_BankCard"] = '2' #信用卡 defineDict["THOST_FTDC_VBAT_CreditCard"] = '3' -typedefDict["TThostFtdcVirBankAccTypeType"] = "string" +typedefDict["TThostFtdcVirBankAccTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcVirementStatusType是一个银行帐户类型类型 @@ -2543,7 +2571,7 @@ defineDict["THOST_FTDC_VMS_Natural"] = '0' #销户 defineDict["THOST_FTDC_VMS_Canceled"] = '9' -typedefDict["TThostFtdcVirementStatusType"] = "string" +typedefDict["TThostFtdcVirementStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcVirementAvailAbilityType是一个有效标志类型 @@ -2555,7 +2583,7 @@ defineDict["THOST_FTDC_VAA_AvailAbility"] = '1' #冲正 defineDict["THOST_FTDC_VAA_Repeal"] = '2' -typedefDict["TThostFtdcVirementAvailAbilityType"] = "string" +typedefDict["TThostFtdcVirementAvailAbilityType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcVirementTradeCodeType是一个交易代码类型 @@ -2569,7 +2597,7 @@ defineDict["THOST_FTDC_VTC_FutureBankToFuture"] = '202001' #期货发起期货资金转银行 defineDict["THOST_FTDC_VTC_FutureFutureToBank"] = '202002' -typedefDict["TThostFtdcVirementTradeCodeType"] = "string" +typedefDict["TThostFtdcVirementTradeCodeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcPhotoTypeNameType是一个影像类型名称类型 @@ -2719,7 +2747,7 @@ defineDict["THOST_FTDC_GEN_Program"] = '0' #人工生成 defineDict["THOST_FTDC_GEN_HandWork"] = '1' -typedefDict["TThostFtdcAMLGenStatusType"] = "string" +typedefDict["TThostFtdcAMLGenStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcAMLSeqCodeType是一个业务标识号类型 @@ -2746,6 +2774,11 @@ typedefDict["TThostFtdcAMLFileAmountType"] = "int" #////////////////////////////////////////////////////////////////////// typedefDict["TThostFtdcCFMMCKeyType"] = "string" +#////////////////////////////////////////////////////////////////////// +#TFtdcCFMMCTokenType是一个令牌类型(保证金监管)类型 +#////////////////////////////////////////////////////////////////////// +typedefDict["TThostFtdcCFMMCTokenType"] = "string" + #////////////////////////////////////////////////////////////////////// #TFtdcCFMMCKeyKindType是一个动态密钥类别(保证金监管)类型 #////////////////////////////////////////////////////////////////////// @@ -2756,13 +2789,38 @@ defineDict["THOST_FTDC_CFMMCKK_AUTO"] = 'A' #CFMMC手动更新 defineDict["THOST_FTDC_CFMMCKK_MANUAL"] = 'M' -typedefDict["TThostFtdcCFMMCKeyKindType"] = "string" +typedefDict["TThostFtdcCFMMCKeyKindType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcAMLReportNameType是一个报文名称类型 #////////////////////////////////////////////////////////////////////// typedefDict["TThostFtdcAMLReportNameType"] = "string" +#////////////////////////////////////////////////////////////////////// +#TFtdcDBFComdTypeType是一个DBF命令类型类型 +#////////////////////////////////////////////////////////////////////// +typedefDict["TThostFtdcDBFComdTypeType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcDBFComTimeType是一个DBF时间类型类型 +#////////////////////////////////////////////////////////////////////// +typedefDict["TThostFtdcDBFComTimeType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcDBFComNoType是一个DBF流水号类型类型 +#////////////////////////////////////////////////////////////////////// +typedefDict["TThostFtdcDBFComNoType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcDBFFdNameType是一个DBF字段类型类型 +#////////////////////////////////////////////////////////////////////// +typedefDict["TThostFtdcDBFFdNameType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcDBFFdContentType是一个DBF字段内容类型类型 +#////////////////////////////////////////////////////////////////////// +typedefDict["TThostFtdcDBFFdContentType"] = "string" + #////////////////////////////////////////////////////////////////////// #TFtdcIndividualNameType是一个个人姓名类型 #////////////////////////////////////////////////////////////////////// @@ -3091,7 +3149,7 @@ defineDict["THOST_FTDC_CFT_OtherCard"] = 'x' #主管部门批文 defineDict["THOST_FTDC_CFT_SuperDepAgree"] = 'a' -typedefDict["TThostFtdcCertificationTypeType"] = "string" +typedefDict["TThostFtdcCertificationTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFileBusinessCodeType是一个文件业务功能类型 @@ -3129,7 +3187,7 @@ defineDict["THOST_FTDC_FBC_PreparationMoney"] = 'e' #协办存管银行资金监管数据 defineDict["THOST_FTDC_FBC_BankMoneyMonitorData"] = 'f' -typedefDict["TThostFtdcFileBusinessCodeType"] = "string" +typedefDict["TThostFtdcFileBusinessCodeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCashExchangeCodeType是一个汇钞标志类型 @@ -3139,7 +3197,7 @@ defineDict["THOST_FTDC_CEC_Exchange"] = '1' #钞 defineDict["THOST_FTDC_CEC_Cash"] = '2' -typedefDict["TThostFtdcCashExchangeCodeType"] = "string" +typedefDict["TThostFtdcCashExchangeCodeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcYesNoIndicatorType是一个是或否标识类型 @@ -3149,7 +3207,7 @@ defineDict["THOST_FTDC_YNI_Yes"] = '0' #否 defineDict["THOST_FTDC_YNI_No"] = '1' -typedefDict["TThostFtdcYesNoIndicatorType"] = "string" +typedefDict["TThostFtdcYesNoIndicatorType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBanlanceTypeType是一个余额类型类型 @@ -3163,7 +3221,7 @@ defineDict["THOST_FTDC_BLT_FetchableMoney"] = '2' #冻结余额 defineDict["THOST_FTDC_BLT_FreezeMoney"] = '3' -typedefDict["TThostFtdcBanlanceTypeType"] = "string" +typedefDict["TThostFtdcBanlanceTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcGenderType是一个性别类型 @@ -3175,7 +3233,7 @@ defineDict["THOST_FTDC_GD_Male"] = '1' #女 defineDict["THOST_FTDC_GD_Female"] = '2' -typedefDict["TThostFtdcGenderType"] = "string" +typedefDict["TThostFtdcGenderType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFeePayFlagType是一个费用支付标志类型 @@ -3187,7 +3245,7 @@ defineDict["THOST_FTDC_FPF_OUR"] = '1' #由发送方支付发起的费用,受益方支付接受的费用 defineDict["THOST_FTDC_FPF_SHA"] = '2' -typedefDict["TThostFtdcFeePayFlagType"] = "string" +typedefDict["TThostFtdcFeePayFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcPassWordKeyTypeType是一个密钥类型类型 @@ -3201,7 +3259,7 @@ defineDict["THOST_FTDC_PWKT_MACKey"] = '2' #报文密钥 defineDict["THOST_FTDC_PWKT_MessageKey"] = '3' -typedefDict["TThostFtdcPassWordKeyTypeType"] = "string" +typedefDict["TThostFtdcPassWordKeyTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFBTPassWordTypeType是一个密码类型类型 @@ -3215,7 +3273,7 @@ defineDict["THOST_FTDC_PWT_Transfer"] = '2' #交易 defineDict["THOST_FTDC_PWT_Trade"] = '3' -typedefDict["TThostFtdcFBTPassWordTypeType"] = "string" +typedefDict["TThostFtdcFBTPassWordTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFBTEncryModeType是一个加密方式类型 @@ -3227,7 +3285,7 @@ defineDict["THOST_FTDC_EM_DES"] = '1' #3DES defineDict["THOST_FTDC_EM_3DES"] = '2' -typedefDict["TThostFtdcFBTEncryModeType"] = "string" +typedefDict["TThostFtdcFBTEncryModeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBankRepealFlagType是一个银行冲正标志类型 @@ -3239,7 +3297,7 @@ defineDict["THOST_FTDC_BRF_BankWaitingRepeal"] = '1' #银行已自动冲正 defineDict["THOST_FTDC_BRF_BankBeenRepealed"] = '2' -typedefDict["TThostFtdcBankRepealFlagType"] = "string" +typedefDict["TThostFtdcBankRepealFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBrokerRepealFlagType是一个期商冲正标志类型 @@ -3251,7 +3309,7 @@ defineDict["THOST_FTDC_BRORF_BrokerWaitingRepeal"] = '1' #期商已自动冲正 defineDict["THOST_FTDC_BRORF_BrokerBeenRepealed"] = '2' -typedefDict["TThostFtdcBrokerRepealFlagType"] = "string" +typedefDict["TThostFtdcBrokerRepealFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcInstitutionTypeType是一个机构类别类型 @@ -3263,7 +3321,7 @@ defineDict["THOST_FTDC_TS_Future"] = '1' #券商 defineDict["THOST_FTDC_TS_Store"] = '2' -typedefDict["TThostFtdcInstitutionTypeType"] = "string" +typedefDict["TThostFtdcInstitutionTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcLastFragmentType是一个最后分片标志类型 @@ -3273,7 +3331,7 @@ defineDict["THOST_FTDC_LF_Yes"] = '0' #不是最后分片 defineDict["THOST_FTDC_LF_No"] = '1' -typedefDict["TThostFtdcLastFragmentType"] = "string" +typedefDict["TThostFtdcLastFragmentType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBankAccStatusType是一个银行账户状态类型 @@ -3285,7 +3343,7 @@ defineDict["THOST_FTDC_BAS_Freeze"] = '1' #挂失 defineDict["THOST_FTDC_BAS_ReportLoss"] = '2' -typedefDict["TThostFtdcBankAccStatusType"] = "string" +typedefDict["TThostFtdcBankAccStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcMoneyAccountStatusType是一个资金账户状态类型 @@ -3295,7 +3353,7 @@ defineDict["THOST_FTDC_MAS_Normal"] = '0' #销户 defineDict["THOST_FTDC_MAS_Cancel"] = '1' -typedefDict["TThostFtdcMoneyAccountStatusType"] = "string" +typedefDict["TThostFtdcMoneyAccountStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcManageStatusType是一个存管状态类型 @@ -3307,7 +3365,7 @@ defineDict["THOST_FTDC_MSS_PrePoint"] = '1' #撤销指定 defineDict["THOST_FTDC_MSS_CancelPoint"] = '2' -typedefDict["TThostFtdcManageStatusType"] = "string" +typedefDict["TThostFtdcManageStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSystemTypeType是一个应用系统类型类型 @@ -3319,7 +3377,7 @@ defineDict["THOST_FTDC_SYT_StockBankTransfer"] = '1' #第三方存管 defineDict["THOST_FTDC_SYT_TheThirdPartStore"] = '2' -typedefDict["TThostFtdcSystemTypeType"] = "string" +typedefDict["TThostFtdcSystemTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcTxnEndFlagType是一个银期转帐划转结果标志类型 @@ -3339,7 +3397,7 @@ defineDict["THOST_FTDC_TEF_CommuFailedNeedManualProcess"] = '5' #系统出错,请人工处理 defineDict["THOST_FTDC_TEF_SysErrorNeedManualProcess"] = '6' -typedefDict["TThostFtdcTxnEndFlagType"] = "string" +typedefDict["TThostFtdcTxnEndFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcProcessStatusType是一个银期转帐服务处理状态类型 @@ -3351,7 +3409,7 @@ defineDict["THOST_FTDC_PSS_StartProcess"] = '1' #处理完成 defineDict["THOST_FTDC_PSS_Finished"] = '2' -typedefDict["TThostFtdcProcessStatusType"] = "string" +typedefDict["TThostFtdcProcessStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCustTypeType是一个客户类型类型 @@ -3361,7 +3419,7 @@ defineDict["THOST_FTDC_CUSTT_Person"] = '0' #机构户 defineDict["THOST_FTDC_CUSTT_Institution"] = '1' -typedefDict["TThostFtdcCustTypeType"] = "string" +typedefDict["TThostFtdcCustTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFBTTransferDirectionType是一个银期转帐方向类型 @@ -3371,7 +3429,7 @@ defineDict["THOST_FTDC_FBTTD_FromBankToFuture"] = '1' #出金,期货转银行 defineDict["THOST_FTDC_FBTTD_FromFutureToBank"] = '2' -typedefDict["TThostFtdcFBTTransferDirectionType"] = "string" +typedefDict["TThostFtdcFBTTransferDirectionType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcOpenOrDestroyType是一个开销户类别类型 @@ -3381,7 +3439,7 @@ defineDict["THOST_FTDC_OOD_Open"] = '1' #销户 defineDict["THOST_FTDC_OOD_Destroy"] = '0' -typedefDict["TThostFtdcOpenOrDestroyType"] = "string" +typedefDict["TThostFtdcOpenOrDestroyType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcAvailabilityFlagType是一个有效标志类型 @@ -3393,7 +3451,7 @@ defineDict["THOST_FTDC_AVAF_Valid"] = '1' #冲正 defineDict["THOST_FTDC_AVAF_Repeal"] = '2' -typedefDict["TThostFtdcAvailabilityFlagType"] = "string" +typedefDict["TThostFtdcAvailabilityFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcOrganTypeType是一个机构类型类型 @@ -3405,7 +3463,7 @@ defineDict["THOST_FTDC_OT_Future"] = '2' #银期转帐平台管理 defineDict["THOST_FTDC_OT_PlateForm"] = '9' -typedefDict["TThostFtdcOrganTypeType"] = "string" +typedefDict["TThostFtdcOrganTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcOrganLevelType是一个机构级别类型 @@ -3415,7 +3473,7 @@ defineDict["THOST_FTDC_OL_HeadQuarters"] = '1' #银行分中心或期货公司营业部 defineDict["THOST_FTDC_OL_Branch"] = '2' -typedefDict["TThostFtdcOrganLevelType"] = "string" +typedefDict["TThostFtdcOrganLevelType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcProtocalIDType是一个协议类型类型 @@ -3435,7 +3493,7 @@ defineDict["THOST_FTDC_PID_BOCOMProtocal"] = '5' #银期转帐平台协议 defineDict["THOST_FTDC_PID_FBTPlateFormProtocal"] = 'X' -typedefDict["TThostFtdcProtocalIDType"] = "string" +typedefDict["TThostFtdcProtocalIDType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcConnectModeType是一个套接字连接方式类型 @@ -3445,7 +3503,7 @@ defineDict["THOST_FTDC_CM_ShortConnect"] = '0' #长连接 defineDict["THOST_FTDC_CM_LongConnect"] = '1' -typedefDict["TThostFtdcConnectModeType"] = "string" +typedefDict["TThostFtdcConnectModeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSyncModeType是一个套接字通信方式类型 @@ -3455,7 +3513,7 @@ defineDict["THOST_FTDC_SRM_ASync"] = '0' #同步 defineDict["THOST_FTDC_SRM_Sync"] = '1' -typedefDict["TThostFtdcSyncModeType"] = "string" +typedefDict["TThostFtdcSyncModeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBankAccTypeType是一个银行帐号类型类型 @@ -3467,7 +3525,7 @@ defineDict["THOST_FTDC_BAT_SavingCard"] = '2' #信用卡 defineDict["THOST_FTDC_BAT_CreditCard"] = '3' -typedefDict["TThostFtdcBankAccTypeType"] = "string" +typedefDict["TThostFtdcBankAccTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFutureAccTypeType是一个期货公司帐号类型类型 @@ -3479,7 +3537,7 @@ defineDict["THOST_FTDC_FAT_SavingCard"] = '2' #信用卡 defineDict["THOST_FTDC_FAT_CreditCard"] = '3' -typedefDict["TThostFtdcFutureAccTypeType"] = "string" +typedefDict["TThostFtdcFutureAccTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcOrganStatusType是一个接入机构状态类型 @@ -3499,7 +3557,7 @@ defineDict["THOST_FTDC_OS_DayEndClean"] = '5' #注销 defineDict["THOST_FTDC_OS_Invalid"] = '9' -typedefDict["TThostFtdcOrganStatusType"] = "string" +typedefDict["TThostFtdcOrganStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCCBFeeModeType是一个建行收费模式类型 @@ -3509,7 +3567,7 @@ defineDict["THOST_FTDC_CCBFM_ByAmount"] = '1' #按月扣收 defineDict["THOST_FTDC_CCBFM_ByMonth"] = '2' -typedefDict["TThostFtdcCCBFeeModeType"] = "string" +typedefDict["TThostFtdcCCBFeeModeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCommApiTypeType是一个通讯API类型类型 @@ -3521,7 +3579,7 @@ defineDict["THOST_FTDC_CAPIT_Server"] = '2' #交易系统的UserApi defineDict["THOST_FTDC_CAPIT_UserApi"] = '3' -typedefDict["TThostFtdcCommApiTypeType"] = "string" +typedefDict["TThostFtdcCommApiTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcServiceIDType是一个服务编号类型 @@ -3546,7 +3604,7 @@ defineDict["THOST_FTDC_LS_Connected"] = '1' #没有连接 defineDict["THOST_FTDC_LS_Disconnected"] = '2' -typedefDict["TThostFtdcLinkStatusType"] = "string" +typedefDict["TThostFtdcLinkStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCommApiPointerType是一个通讯API指针类型 @@ -3563,7 +3621,7 @@ defineDict["THOST_FTDC_BPWDF_BlankCheck"] = '1' #密文核对 defineDict["THOST_FTDC_BPWDF_EncryptCheck"] = '2' -typedefDict["TThostFtdcPwdFlagType"] = "string" +typedefDict["TThostFtdcPwdFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSecuAccTypeType是一个期货帐号类型类型 @@ -3577,7 +3635,7 @@ defineDict["THOST_FTDC_SAT_SHStockholderID"] = '3' #深圳股东帐号 defineDict["THOST_FTDC_SAT_SZStockholderID"] = '4' -typedefDict["TThostFtdcSecuAccTypeType"] = "string" +typedefDict["TThostFtdcSecuAccTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcTransferStatusType是一个转账交易状态类型 @@ -3587,7 +3645,7 @@ defineDict["THOST_FTDC_TRFS_Normal"] = '0' #被冲正 defineDict["THOST_FTDC_TRFS_Repealed"] = '1' -typedefDict["TThostFtdcTransferStatusType"] = "string" +typedefDict["TThostFtdcTransferStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSponsorTypeType是一个发起方类型 @@ -3597,7 +3655,7 @@ defineDict["THOST_FTDC_SPTYPE_Broker"] = '0' #银行 defineDict["THOST_FTDC_SPTYPE_Bank"] = '1' -typedefDict["TThostFtdcSponsorTypeType"] = "string" +typedefDict["TThostFtdcSponsorTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcReqRspTypeType是一个请求响应类别类型 @@ -3607,7 +3665,7 @@ defineDict["THOST_FTDC_REQRSP_Request"] = '0' #响应 defineDict["THOST_FTDC_REQRSP_Response"] = '1' -typedefDict["TThostFtdcReqRspTypeType"] = "string" +typedefDict["TThostFtdcReqRspTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFBTUserEventTypeType是一个银期转帐用户事件类型类型 @@ -3639,7 +3697,7 @@ defineDict["THOST_FTDC_FBTUET_SyncKey"] = 'B' #其他 defineDict["THOST_FTDC_FBTUET_Other"] = 'Z' -typedefDict["TThostFtdcFBTUserEventTypeType"] = "string" +typedefDict["TThostFtdcFBTUserEventTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBankIDByBankType是一个银行自己的编码类型 @@ -3686,7 +3744,7 @@ defineDict["THOST_FTDC_DBOP_Update"] = '1' #删除 defineDict["THOST_FTDC_DBOP_Delete"] = '2' -typedefDict["TThostFtdcDBOperationType"] = "string" +typedefDict["TThostFtdcDBOperationType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSyncFlagType是一个同步标记类型 @@ -3696,7 +3754,7 @@ defineDict["THOST_FTDC_SYNF_Yes"] = '0' #未同步 defineDict["THOST_FTDC_SYNF_No"] = '1' -typedefDict["TThostFtdcSyncFlagType"] = "string" +typedefDict["TThostFtdcSyncFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcTargetIDType是一个同步目标编号类型 @@ -3713,7 +3771,7 @@ defineDict["THOST_FTDC_SYNT_TimerSync"] = '1' #定时完全同步 defineDict["THOST_FTDC_SYNT_TimerFullSync"] = '2' -typedefDict["TThostFtdcSyncTypeType"] = "string" +typedefDict["TThostFtdcSyncTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFBETimeType是一个各种换汇时间类型 @@ -3738,7 +3796,7 @@ defineDict["THOST_FTDC_FBEDIR_Settlement"] = '0' #售汇 defineDict["THOST_FTDC_FBEDIR_Sale"] = '1' -typedefDict["TThostFtdcExDirectionType"] = "string" +typedefDict["TThostFtdcExDirectionType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFBEBankAccountType是一个换汇银行账户类型 @@ -3787,7 +3845,7 @@ defineDict["THOST_FTDC_FBERES_UnknownTrading"] = '8' #失败 defineDict["THOST_FTDC_FBERES_Fail"] = 'x' -typedefDict["TThostFtdcFBEResultFlagType"] = "string" +typedefDict["TThostFtdcFBEResultFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFBERtnMsgType是一个换汇返回信息类型 @@ -3822,7 +3880,7 @@ defineDict["THOST_FTDC_FBEES_Normal"] = '0' #交易重发 defineDict["THOST_FTDC_FBEES_ReExchange"] = '1' -typedefDict["TThostFtdcFBEExchStatusType"] = "string" +typedefDict["TThostFtdcFBEExchStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFBEFileFlagType是一个换汇文件标志类型 @@ -3832,7 +3890,7 @@ defineDict["THOST_FTDC_FBEFG_DataPackage"] = '0' #文件 defineDict["THOST_FTDC_FBEFG_File"] = '1' -typedefDict["TThostFtdcFBEFileFlagType"] = "string" +typedefDict["TThostFtdcFBEFileFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFBEAlreadyTradeType是一个换汇已交易标志类型 @@ -3842,7 +3900,7 @@ defineDict["THOST_FTDC_FBEAT_NotTrade"] = '0' #已交易 defineDict["THOST_FTDC_FBEAT_Trade"] = '1' -typedefDict["TThostFtdcFBEAlreadyTradeType"] = "string" +typedefDict["TThostFtdcFBEAlreadyTradeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFBEOpenBankType是一个换汇账户开户行类型 @@ -3873,7 +3931,7 @@ defineDict["THOST_FTDC_FBEUET_SignOut"] = '8' #其他 defineDict["THOST_FTDC_FBEUET_Other"] = 'Z' -typedefDict["TThostFtdcFBEUserEventTypeType"] = "string" +typedefDict["TThostFtdcFBEUserEventTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFBEFileNameType是一个换汇相关文件名类型 @@ -3899,7 +3957,7 @@ defineDict["THOST_FTDC_FBERF_SendFailed"] = '3' #等待重发 defineDict["THOST_FTDC_FBERF_WaitReSend"] = '4' -typedefDict["TThostFtdcFBEReqFlagType"] = "string" +typedefDict["TThostFtdcFBEReqFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcNotifyClassType是一个风险通知类型类型 @@ -3917,7 +3975,7 @@ defineDict["THOST_FTDC_NC_CHUANCANG"] = '4' #异常 defineDict["THOST_FTDC_NC_Exception"] = '5' -typedefDict["TThostFtdcNotifyClassType"] = "string" +typedefDict["TThostFtdcNotifyClassType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcRiskNofityInfoType是一个客户风险通知消息类型 @@ -3939,7 +3997,7 @@ defineDict["THOST_FTDC_FCT_Single"] = '1' #批量投资者辅助强平 defineDict["THOST_FTDC_FCT_Group"] = '2' -typedefDict["TThostFtdcForceCloseTypeType"] = "string" +typedefDict["TThostFtdcForceCloseTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcInstrumentIDsType是一个多个产品代码,用+分隔,如cu+zn类型 @@ -3958,7 +4016,7 @@ defineDict["THOST_FTDC_RNM_EMail"] = '2' #人工通知 defineDict["THOST_FTDC_RNM_Manual"] = '3' -typedefDict["TThostFtdcRiskNotifyMethodType"] = "string" +typedefDict["TThostFtdcRiskNotifyMethodType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcRiskNotifyStatusType是一个风险通知状态类型 @@ -3976,7 +4034,7 @@ defineDict["THOST_FTDC_RNS_Received"] = '4' #已确认 defineDict["THOST_FTDC_RNS_Confirmed"] = '5' -typedefDict["TThostFtdcRiskNotifyStatusType"] = "string" +typedefDict["TThostFtdcRiskNotifyStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcRiskUserEventType是一个风控用户操作事件类型 @@ -3984,7 +4042,7 @@ typedefDict["TThostFtdcRiskNotifyStatusType"] = "string" #导出数据 defineDict["THOST_FTDC_RUE_ExportData"] = '0' -typedefDict["TThostFtdcRiskUserEventType"] = "string" +typedefDict["TThostFtdcRiskUserEventType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcParamIDType是一个参数代码类型 @@ -4017,7 +4075,7 @@ defineDict["THOST_FTDC_COST_BidPriceAsc"] = '4' #使用买价降序 defineDict["THOST_FTDC_COST_BidPriceDesc"] = '5' -typedefDict["TThostFtdcConditionalOrderSortTypeType"] = "string" +typedefDict["TThostFtdcConditionalOrderSortTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSendTypeType是一个报送状态类型 @@ -4037,7 +4095,7 @@ defineDict["THOST_FTDC_UOAST_Fail"] = '5' #取消报送 defineDict["THOST_FTDC_UOAST_Cancel"] = '6' -typedefDict["TThostFtdcSendTypeType"] = "string" +typedefDict["TThostFtdcSendTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcClientIDStatusType是一个交易编码状态类型 @@ -4055,7 +4113,7 @@ defineDict["THOST_FTDC_UOACS_Refuse"] = '5' #已撤销编码 defineDict["THOST_FTDC_UOACS_Cancel"] = '6' -typedefDict["TThostFtdcClientIDStatusType"] = "string" +typedefDict["TThostFtdcClientIDStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcIndustryIDType是一个行业编码类型 @@ -4092,7 +4150,7 @@ defineDict["THOST_FTDC_QT_Option"] = '2' #填空 defineDict["THOST_FTDC_QT_Blank"] = '3' -typedefDict["TThostFtdcQuestionTypeType"] = "string" +typedefDict["TThostFtdcQuestionTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcProcessIDType是一个业务流水号类型 @@ -4124,7 +4182,7 @@ defineDict["THOST_FTDC_BT_Response"] = '2' #通知 defineDict["THOST_FTDC_BT_Notice"] = '3' -typedefDict["TThostFtdcBusinessTypeType"] = "string" +typedefDict["TThostFtdcBusinessTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCfmmcReturnCodeType是一个监控中心返回码类型 @@ -4140,7 +4198,7 @@ defineDict["THOST_FTDC_CRC_IDCardFail"] = '3' #其他错误 defineDict["THOST_FTDC_CRC_OtherFail"] = '4' -typedefDict["TThostFtdcCfmmcReturnCodeType"] = "string" +typedefDict["TThostFtdcCfmmcReturnCodeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcExReturnCodeType是一个交易所返回码类型 @@ -4163,7 +4221,7 @@ defineDict["THOST_FTDC_CfMMCCT_SpecialOrgan"] = '4' #资管户 defineDict["THOST_FTDC_CfMMCCT_Asset"] = '5' -typedefDict["TThostFtdcClientTypeType"] = "string" +typedefDict["TThostFtdcClientTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcExchangeIDTypeType是一个交易所编号类型 @@ -4178,8 +4236,12 @@ defineDict["THOST_FTDC_EIDT_DCE"] = 'D' defineDict["THOST_FTDC_EIDT_CFFEX"] = 'J' #上海国际能源交易中心股份有限公司 defineDict["THOST_FTDC_EIDT_INE"] = 'N' +#上海证券交易所 +defineDict["THOST_FTDC_EIDT_SSE"] = 'A' +#深圳证券交易所 +defineDict["THOST_FTDC_EIDT_SZSE"] = 'E' -typedefDict["TThostFtdcExchangeIDTypeType"] = "string" +typedefDict["TThostFtdcExchangeIDTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcExClientIDTypeType是一个交易编码类型类型 @@ -4191,7 +4253,7 @@ defineDict["THOST_FTDC_ECIDT_Arbitrage"] = '2' #投机 defineDict["THOST_FTDC_ECIDT_Speculation"] = '3' -typedefDict["TThostFtdcExClientIDTypeType"] = "string" +typedefDict["TThostFtdcExClientIDTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcClientClassifyType是一个客户分类码类型 @@ -4249,7 +4311,7 @@ defineDict["THOST_FTDC_UF_TCFail"] = '4' #已丢弃 defineDict["THOST_FTDC_UF_Cancel"] = '5' -typedefDict["TThostFtdcUpdateFlagType"] = "string" +typedefDict["TThostFtdcUpdateFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcApplyOperateIDType是一个申请动作类型 @@ -4271,7 +4333,7 @@ defineDict["THOST_FTDC_AOID_FreezeAccount"] = '8' #激活休眠账户 defineDict["THOST_FTDC_AOID_ActiveFreezeAccount"] = '9' -typedefDict["TThostFtdcApplyOperateIDType"] = "string" +typedefDict["TThostFtdcApplyOperateIDType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcApplyStatusIDType是一个申请状态类型 @@ -4287,7 +4349,7 @@ defineDict["THOST_FTDC_ASID_Refused"] = '4' #已删除 defineDict["THOST_FTDC_ASID_Deleted"] = '5' -typedefDict["TThostFtdcApplyStatusIDType"] = "string" +typedefDict["TThostFtdcApplyStatusIDType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSendMethodType是一个发送方式类型 @@ -4297,7 +4359,7 @@ defineDict["THOST_FTDC_UOASM_ByAPI"] = '1' #电子发送 defineDict["THOST_FTDC_UOASM_ByFile"] = '2' -typedefDict["TThostFtdcSendMethodType"] = "string" +typedefDict["TThostFtdcSendMethodType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcEventTypeType是一个业务操作类型类型 @@ -4322,7 +4384,7 @@ defineDict["THOST_FTDC_EvM_CANCEL"] = '6' #冲销 defineDict["THOST_FTDC_EvM_Reverse"] = '7' -typedefDict["TThostFtdcEventModeType"] = "string" +typedefDict["TThostFtdcEventModeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcUOAAutoSendType是一个统一开户申请自动发送类型 @@ -4336,7 +4398,7 @@ defineDict["THOST_FTDC_UOAA_NSAR"] = '3' #不自动发送,也不自动接收 defineDict["THOST_FTDC_UOAA_NSR"] = '4' -typedefDict["TThostFtdcUOAAutoSendType"] = "string" +typedefDict["TThostFtdcUOAAutoSendType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcQueryDepthType是一个查询深度类型 @@ -4358,7 +4420,7 @@ defineDict["THOST_FTDC_EvM_InvestorRate"] = '2' #投资者手续费率模板关系设置 defineDict["THOST_FTDC_EvM_InvestorCommRateModel"] = '3' -typedefDict["TThostFtdcFlowIDType"] = "string" +typedefDict["TThostFtdcFlowIDType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCheckLevelType是一个复核级别类型 @@ -4370,7 +4432,7 @@ defineDict["THOST_FTDC_CL_One"] = '1' #二级复核 defineDict["THOST_FTDC_CL_Two"] = '2' -typedefDict["TThostFtdcCheckLevelType"] = "string" +typedefDict["TThostFtdcCheckLevelType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCheckNoType是一个操作次数类型 @@ -4391,7 +4453,7 @@ defineDict["THOST_FTDC_CHS_Refuse"] = '3' #作废 defineDict["THOST_FTDC_CHS_Cancel"] = '4' -typedefDict["TThostFtdcCheckStatusType"] = "string" +typedefDict["TThostFtdcCheckStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcUsedStatusType是一个生效状态类型 @@ -4403,7 +4465,7 @@ defineDict["THOST_FTDC_CHU_Used"] = '1' #生效失败 defineDict["THOST_FTDC_CHU_Fail"] = '2' -typedefDict["TThostFtdcUsedStatusType"] = "string" +typedefDict["TThostFtdcUsedStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcRateTemplateNameType是一个模型名称类型 @@ -4423,7 +4485,7 @@ defineDict["THOST_FTDC_BAO_ByAccProperty"] = '0' #银期转账 defineDict["THOST_FTDC_BAO_ByFBTransfer"] = '1' -typedefDict["TThostFtdcBankAcountOriginType"] = "string" +typedefDict["TThostFtdcBankAcountOriginType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcMonthBillTradeSumType是一个结算单月报成交汇总方式类型 @@ -4435,7 +4497,7 @@ defineDict["THOST_FTDC_MBTS_ByDayInsPrc"] = '1' #同合约 defineDict["THOST_FTDC_MBTS_ByDayIns"] = '2' -typedefDict["TThostFtdcMonthBillTradeSumType"] = "string" +typedefDict["TThostFtdcMonthBillTradeSumType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFBTTradeCodeEnumType是一个银期交易代码枚举类型 @@ -4449,7 +4511,7 @@ defineDict["THOST_FTDC_FTC_BankLaunchBrokerToBank"] = '102002' #期货发起期货转银行 defineDict["THOST_FTDC_FTC_BrokerLaunchBrokerToBank"] = '202002' -typedefDict["TThostFtdcFBTTradeCodeEnumType"] = "string" +typedefDict["TThostFtdcFBTTradeCodeEnumType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcRateTemplateIDType是一个模型代码类型 @@ -4504,7 +4566,7 @@ defineDict["THOST_FTDC_OTP_NONE"] = '0' #时间令牌 defineDict["THOST_FTDC_OTP_TOTP"] = '1' -typedefDict["TThostFtdcOTPTypeType"] = "string" +typedefDict["TThostFtdcOTPTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcOTPVendorsIDType是一个动态令牌提供商类型 @@ -4526,7 +4588,7 @@ defineDict["THOST_FTDC_OTPS_Used"] = '1' #注销 defineDict["THOST_FTDC_OTPS_Disuse"] = '2' -typedefDict["TThostFtdcOTPStatusType"] = "string" +typedefDict["TThostFtdcOTPStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBrokerUserTypeType是一个经济公司用户类型类型 @@ -4536,7 +4598,7 @@ defineDict["THOST_FTDC_BUT_Investor"] = '1' #操作员 defineDict["THOST_FTDC_BUT_BrokerUser"] = '2' -typedefDict["TThostFtdcBrokerUserTypeType"] = "string" +typedefDict["TThostFtdcBrokerUserTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFutureTypeType是一个期货类型类型 @@ -4546,7 +4608,7 @@ defineDict["THOST_FTDC_FUTT_Commodity"] = '1' #金融期货 defineDict["THOST_FTDC_FUTT_Financial"] = '2' -typedefDict["TThostFtdcFutureTypeType"] = "string" +typedefDict["TThostFtdcFutureTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFundEventTypeType是一个资金管理操作类型类型 @@ -4570,7 +4632,7 @@ defineDict["THOST_FTDC_FET_ExchangeFundIO"] = '7' #投资者出入金 defineDict["THOST_FTDC_FET_InvestorFundIO"] = '8' -typedefDict["TThostFtdcFundEventTypeType"] = "string" +typedefDict["TThostFtdcFundEventTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcAccountSourceTypeType是一个资金账户来源类型 @@ -4580,7 +4642,7 @@ defineDict["THOST_FTDC_AST_FBTransfer"] = '0' #手工录入 defineDict["THOST_FTDC_AST_ManualEntry"] = '1' -typedefDict["TThostFtdcAccountSourceTypeType"] = "string" +typedefDict["TThostFtdcAccountSourceTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCodeSourceTypeType是一个交易编码来源类型 @@ -4590,7 +4652,7 @@ defineDict["THOST_FTDC_CST_UnifyAccount"] = '0' #手工录入(未规范) defineDict["THOST_FTDC_CST_ManualEntry"] = '1' -typedefDict["TThostFtdcCodeSourceTypeType"] = "string" +typedefDict["TThostFtdcCodeSourceTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcUserRangeType是一个操作员范围类型 @@ -4600,7 +4662,7 @@ defineDict["THOST_FTDC_UR_All"] = '0' #单一操作员 defineDict["THOST_FTDC_UR_Single"] = '1' -typedefDict["TThostFtdcUserRangeType"] = "string" +typedefDict["TThostFtdcUserRangeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcTimeSpanType是一个时间跨度类型 @@ -4620,7 +4682,7 @@ defineDict["THOST_FTDC_BG_Investor"] = '2' #按类统计 defineDict["THOST_FTDC_BG_Group"] = '1' -typedefDict["TThostFtdcByGroupType"] = "string" +typedefDict["TThostFtdcByGroupType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcTradeSumStatModeType是一个交易统计表按范围统计方式类型 @@ -4632,7 +4694,7 @@ defineDict["THOST_FTDC_TSSM_Product"] = '2' #按交易所统计 defineDict["THOST_FTDC_TSSM_Exchange"] = '3' -typedefDict["TThostFtdcTradeSumStatModeType"] = "string" +typedefDict["TThostFtdcTradeSumStatModeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcComTypeType是一个组合成交类型类型 @@ -4787,7 +4849,7 @@ defineDict["THOST_FTDC_ESM_Relative"] = '1' #典型设置 defineDict["THOST_FTDC_ESM_Typical"] = '2' -typedefDict["TThostFtdcExprSetModeType"] = "string" +typedefDict["TThostFtdcExprSetModeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcRateInvestorRangeType是一个投资者范围类型 @@ -4799,7 +4861,7 @@ defineDict["THOST_FTDC_RIR_Model"] = '2' #单一投资者 defineDict["THOST_FTDC_RIR_Single"] = '3' -typedefDict["TThostFtdcRateInvestorRangeType"] = "string" +typedefDict["TThostFtdcRateInvestorRangeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcAgentBrokerIDType是一个代理经纪公司代码类型 @@ -4831,7 +4893,7 @@ defineDict["THOST_FTDC_SDS_Settlementing"] = '1' #已同步 defineDict["THOST_FTDC_SDS_Settlemented"] = '2' -typedefDict["TThostFtdcSyncDataStatusType"] = "string" +typedefDict["TThostFtdcSyncDataStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcTradeSourceType是一个成交来源类型 @@ -4841,7 +4903,7 @@ defineDict["THOST_FTDC_TSRC_NORMAL"] = '0' #来自查询 defineDict["THOST_FTDC_TSRC_QUERY"] = '1' -typedefDict["TThostFtdcTradeSourceType"] = "string" +typedefDict["TThostFtdcTradeSourceType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFlexStatModeType是一个产品合约统计方式类型 @@ -4853,7 +4915,7 @@ defineDict["THOST_FTDC_FSM_Exchange"] = '2' #统计所有 defineDict["THOST_FTDC_FSM_All"] = '3' -typedefDict["TThostFtdcFlexStatModeType"] = "string" +typedefDict["TThostFtdcFlexStatModeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcByInvestorRangeType是一个投资者范围统计方式类型 @@ -4863,7 +4925,7 @@ defineDict["THOST_FTDC_BIR_Property"] = '1' #统计所有 defineDict["THOST_FTDC_BIR_All"] = '2' -typedefDict["TThostFtdcByInvestorRangeType"] = "string" +typedefDict["TThostFtdcByInvestorRangeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSRiskRateType是一个风险度类型 @@ -4885,7 +4947,7 @@ defineDict["THOST_FTDC_PIR_Property"] = '2' #单一投资者 defineDict["THOST_FTDC_PIR_Single"] = '3' -typedefDict["TThostFtdcPropertyInvestorRangeType"] = "string" +typedefDict["TThostFtdcPropertyInvestorRangeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFileStatusType是一个文件状态类型 @@ -4897,7 +4959,7 @@ defineDict["THOST_FTDC_FIS_Created"] = '1' #生成失败 defineDict["THOST_FTDC_FIS_Failed"] = '2' -typedefDict["TThostFtdcFileStatusType"] = "string" +typedefDict["TThostFtdcFileStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFileGenStyleType是一个文件生成方式类型 @@ -4907,7 +4969,7 @@ defineDict["THOST_FTDC_FGS_FileTransmit"] = '0' #生成 defineDict["THOST_FTDC_FGS_FileGen"] = '1' -typedefDict["TThostFtdcFileGenStyleType"] = "string" +typedefDict["TThostFtdcFileGenStyleType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSysOperModeType是一个系统日志操作方法类型 @@ -4927,7 +4989,7 @@ defineDict["THOST_FTDC_SoM_CanCel"] = '6' #重置 defineDict["THOST_FTDC_SoM_ReSet"] = '7' -typedefDict["TThostFtdcSysOperModeType"] = "string" +typedefDict["TThostFtdcSysOperModeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSysOperTypeType是一个系统日志操作类型类型 @@ -4965,7 +5027,7 @@ defineDict["THOST_FTDC_SoT_ReSetInvestorPasswd"] = 'E' #投资者个性信息维护 defineDict["THOST_FTDC_SoT_InvestorPersonalityInfo"] = 'F' -typedefDict["TThostFtdcSysOperTypeType"] = "string" +typedefDict["TThostFtdcSysOperTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCSRCDataQueyTypeType是一个上报数据查询类型类型 @@ -4975,7 +5037,7 @@ defineDict["THOST_FTDC_CSRCQ_Current"] = '0' #查询历史报送的代理经纪公司的数据 defineDict["THOST_FTDC_CSRCQ_History"] = '1' -typedefDict["TThostFtdcCSRCDataQueyTypeType"] = "string" +typedefDict["TThostFtdcCSRCDataQueyTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFreezeStatusType是一个休眠状态类型 @@ -4985,7 +5047,7 @@ defineDict["THOST_FTDC_FRS_Normal"] = '1' #休眠 defineDict["THOST_FTDC_FRS_Freeze"] = '0' -typedefDict["TThostFtdcFreezeStatusType"] = "string" +typedefDict["TThostFtdcFreezeStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcStandardStatusType是一个规范状态类型 @@ -4995,7 +5057,7 @@ defineDict["THOST_FTDC_STST_Standard"] = '0' #未规范 defineDict["THOST_FTDC_STST_NonStandard"] = '1' -typedefDict["TThostFtdcStandardStatusType"] = "string" +typedefDict["TThostFtdcStandardStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCSRCFreezeStatusType是一个休眠状态类型 @@ -5014,7 +5076,7 @@ defineDict["THOST_FTDC_RPT_OpenLimit"] = '3' #解除开仓权限限制 defineDict["THOST_FTDC_RPT_RelieveOpenLimit"] = '4' -typedefDict["TThostFtdcRightParamTypeType"] = "string" +typedefDict["TThostFtdcRightParamTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcRightTemplateIDType是一个模板代码类型 @@ -5034,7 +5096,7 @@ defineDict["THOST_FTDC_AMLDS_Normal"] = '0' #已删除 defineDict["THOST_FTDC_AMLDS_Deleted"] = '1' -typedefDict["TThostFtdcDataStatusType"] = "string" +typedefDict["TThostFtdcDataStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcAMLCheckStatusType是一个审核状态类型 @@ -5048,7 +5110,7 @@ defineDict["THOST_FTDC_AMLCHS_Checked"] = '2' #拒绝上报 defineDict["THOST_FTDC_AMLCHS_RefuseReport"] = '3' -typedefDict["TThostFtdcAMLCheckStatusType"] = "string" +typedefDict["TThostFtdcAMLCheckStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcAmlDateTypeType是一个日期类型类型 @@ -5058,7 +5120,7 @@ defineDict["THOST_FTDC_AMLDT_DrawDay"] = '0' #发生日期 defineDict["THOST_FTDC_AMLDT_TouchDay"] = '1' -typedefDict["TThostFtdcAmlDateTypeType"] = "string" +typedefDict["TThostFtdcAmlDateTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcAmlCheckLevelType是一个审核级别类型 @@ -5072,7 +5134,7 @@ defineDict["THOST_FTDC_AMLCL_CheckLevel2"] = '2' #三级审核 defineDict["THOST_FTDC_AMLCL_CheckLevel3"] = '3' -typedefDict["TThostFtdcAmlCheckLevelType"] = "string" +typedefDict["TThostFtdcAmlCheckLevelType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcAmlCheckFlowType是一个反洗钱数据抽取审核流程类型 @@ -5094,7 +5156,7 @@ defineDict["THOST_FTDC_EFT_EXCEL"] = '1' #DBF defineDict["THOST_FTDC_EFT_DBF"] = '2' -typedefDict["TThostFtdcExportFileTypeType"] = "string" +typedefDict["TThostFtdcExportFileTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSettleManagerTypeType是一个结算配置类型类型 @@ -5108,7 +5170,7 @@ defineDict["THOST_FTDC_SMT_After"] = '3' #结算后处理 defineDict["THOST_FTDC_SMT_Settlemented"] = '4' -typedefDict["TThostFtdcSettleManagerTypeType"] = "string" +typedefDict["TThostFtdcSettleManagerTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSettleManagerIDType是一个结算配置代码类型 @@ -5132,7 +5194,7 @@ defineDict["THOST_FTDC_SML_Prompt"] = '3' #不检查 defineDict["THOST_FTDC_SML_Ignore"] = '4' -typedefDict["TThostFtdcSettleManagerLevelType"] = "string" +typedefDict["TThostFtdcSettleManagerLevelType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSettleManagerGroupType是一个模块分组类型 @@ -5144,7 +5206,7 @@ defineDict["THOST_FTDC_SMG_ASP"] = '2' #上报数据核对 defineDict["THOST_FTDC_SMG_CSRC"] = '3' -typedefDict["TThostFtdcSettleManagerGroupType"] = "string" +typedefDict["TThostFtdcSettleManagerGroupType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCheckResultMemoType是一个核对结果说明类型 @@ -5174,7 +5236,7 @@ defineDict["THOST_FTDC_LUT_Repeatable"] = '1' #不可重复使用 defineDict["THOST_FTDC_LUT_Unrepeatable"] = '2' -typedefDict["TThostFtdcLimitUseTypeType"] = "string" +typedefDict["TThostFtdcLimitUseTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcDataResourceType是一个数据来源类型 @@ -5186,7 +5248,7 @@ defineDict["THOST_FTDC_DAR_Exchange"] = '2' #报送数据 defineDict["THOST_FTDC_DAR_CSRC"] = '3' -typedefDict["TThostFtdcDataResourceType"] = "string" +typedefDict["TThostFtdcDataResourceType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcMarginTypeType是一个保证金类型类型 @@ -5198,7 +5260,7 @@ defineDict["THOST_FTDC_MGT_InstrMarginRate"] = '1' #投资者交易保证金率 defineDict["THOST_FTDC_MGT_InstrMarginRateTrade"] = '2' -typedefDict["TThostFtdcMarginTypeType"] = "string" +typedefDict["TThostFtdcMarginTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcActiveTypeType是一个生效类型类型 @@ -5208,7 +5270,7 @@ defineDict["THOST_FTDC_ACT_Intraday"] = '1' #长期生效 defineDict["THOST_FTDC_ACT_Long"] = '2' -typedefDict["TThostFtdcActiveTypeType"] = "string" +typedefDict["TThostFtdcActiveTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcMarginRateTypeType是一个冲突保证金率类型类型 @@ -5220,7 +5282,7 @@ defineDict["THOST_FTDC_MRT_Investor"] = '2' #投资者交易保证金率 defineDict["THOST_FTDC_MRT_InvestorTrade"] = '3' -typedefDict["TThostFtdcMarginRateTypeType"] = "string" +typedefDict["TThostFtdcMarginRateTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBackUpStatusType是一个备份数据状态类型 @@ -5234,7 +5296,7 @@ defineDict["THOST_FTDC_BUS_BakUped"] = '2' #备份数据失败 defineDict["THOST_FTDC_BUS_BakFail"] = '3' -typedefDict["TThostFtdcBackUpStatusType"] = "string" +typedefDict["TThostFtdcBackUpStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcInitSettlementType是一个结算初始化状态类型 @@ -5246,7 +5308,7 @@ defineDict["THOST_FTDC_SIS_Initialize"] = '1' #结算初始化完成 defineDict["THOST_FTDC_SIS_Initialized"] = '2' -typedefDict["TThostFtdcInitSettlementType"] = "string" +typedefDict["TThostFtdcInitSettlementType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcReportStatusType是一个报表数据生成状态类型 @@ -5260,7 +5322,7 @@ defineDict["THOST_FTDC_SRS_Created"] = '2' #生成报表数据失败 defineDict["THOST_FTDC_SRS_CreateFail"] = '3' -typedefDict["TThostFtdcReportStatusType"] = "string" +typedefDict["TThostFtdcReportStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSaveStatusType是一个数据归档状态类型 @@ -5270,7 +5332,7 @@ defineDict["THOST_FTDC_SSS_UnSaveData"] = '0' #归档完成 defineDict["THOST_FTDC_SSS_SaveDatad"] = '1' -typedefDict["TThostFtdcSaveStatusType"] = "string" +typedefDict["TThostFtdcSaveStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSettArchiveStatusType是一个结算确认数据归档状态类型 @@ -5284,7 +5346,7 @@ defineDict["THOST_FTDC_SAS_Archived"] = '2' #归档数据失败 defineDict["THOST_FTDC_SAS_ArchiveFail"] = '3' -typedefDict["TThostFtdcSettArchiveStatusType"] = "string" +typedefDict["TThostFtdcSettArchiveStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCTPTypeType是一个CTP交易系统类型类型 @@ -5296,7 +5358,7 @@ defineDict["THOST_FTDC_CTPT_MainCenter"] = '1' #备中心 defineDict["THOST_FTDC_CTPT_BackUp"] = '2' -typedefDict["TThostFtdcCTPTypeType"] = "string" +typedefDict["TThostFtdcCTPTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcToolIDType是一个工具代码类型 @@ -5316,7 +5378,7 @@ defineDict["THOST_FTDC_CDT_Normal"] = '0' #投机平仓优先 defineDict["THOST_FTDC_CDT_SpecFirst"] = '1' -typedefDict["TThostFtdcCloseDealTypeType"] = "string" +typedefDict["TThostFtdcCloseDealTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcMortgageFundUseRangeType是一个货币质押资金可用范围类型 @@ -5328,7 +5390,7 @@ defineDict["THOST_FTDC_MFUR_Margin"] = '1' #用于手续费、盈亏、保证金 defineDict["THOST_FTDC_MFUR_All"] = '2' -typedefDict["TThostFtdcMortgageFundUseRangeType"] = "string" +typedefDict["TThostFtdcMortgageFundUseRangeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCurrencyUnitType是一个币种单位数量类型 @@ -5350,7 +5412,7 @@ defineDict["THOST_FTDC_SPT_IneForeignCurrency"] = '2' #大连短线开平仓产品 defineDict["THOST_FTDC_SPT_DceOpenClose"] = '3' -typedefDict["TThostFtdcSpecProductTypeType"] = "string" +typedefDict["TThostFtdcSpecProductTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFundMortgageTypeType是一个货币质押类型类型 @@ -5360,7 +5422,7 @@ defineDict["THOST_FTDC_FMT_Mortgage"] = '1' #解质 defineDict["THOST_FTDC_FMT_Redemption"] = '2' -typedefDict["TThostFtdcFundMortgageTypeType"] = "string" +typedefDict["TThostFtdcFundMortgageTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcAccountSettlementParamIDType是一个投资者账户结算参数代码类型 @@ -5370,7 +5432,7 @@ defineDict["THOST_FTDC_ASPI_BaseMargin"] = '1' #最低权益标准 defineDict["THOST_FTDC_ASPI_LowestInterest"] = '2' -typedefDict["TThostFtdcAccountSettlementParamIDType"] = "string" +typedefDict["TThostFtdcAccountSettlementParamIDType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCurrencyNameType是一个币种名称类型 @@ -5390,7 +5452,7 @@ defineDict["THOST_FTDC_FMD_In"] = '1' #货币质出 defineDict["THOST_FTDC_FMD_Out"] = '2' -typedefDict["TThostFtdcFundMortDirectionType"] = "string" +typedefDict["TThostFtdcFundMortDirectionType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBusinessClassType是一个换汇类别类型 @@ -5402,7 +5464,7 @@ defineDict["THOST_FTDC_BT_Loss"] = '1' #其他 defineDict["THOST_FTDC_BT_Other"] = 'Z' -typedefDict["TThostFtdcBusinessClassType"] = "string" +typedefDict["TThostFtdcBusinessClassType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSwapSourceTypeType是一个换汇数据来源类型 @@ -5412,7 +5474,7 @@ defineDict["THOST_FTDC_SST_Manual"] = '0' #自动生成 defineDict["THOST_FTDC_SST_Automatic"] = '1' -typedefDict["TThostFtdcSwapSourceTypeType"] = "string" +typedefDict["TThostFtdcSwapSourceTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCurrExDirectionType是一个换汇类型类型 @@ -5422,7 +5484,7 @@ defineDict["THOST_FTDC_CED_Settlement"] = '0' #售汇 defineDict["THOST_FTDC_CED_Sale"] = '1' -typedefDict["TThostFtdcCurrExDirectionType"] = "string" +typedefDict["TThostFtdcCurrExDirectionType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCurrencySwapStatusType是一个申请状态类型 @@ -5442,7 +5504,7 @@ defineDict["THOST_FTDC_CSS_Success"] = '6' #换汇失败 defineDict["THOST_FTDC_CSS_Failure"] = '7' -typedefDict["TThostFtdcCurrencySwapStatusType"] = "string" +typedefDict["TThostFtdcCurrencySwapStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCurrExchCertNoType是一个凭证号类型 @@ -5466,7 +5528,7 @@ defineDict["THOST_FTDC_REQF_SendFailed"] = '2' #等待重发 defineDict["THOST_FTDC_REQF_WaitReSend"] = '3' -typedefDict["TThostFtdcReqFlagType"] = "string" +typedefDict["TThostFtdcReqFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcResFlagType是一个换汇返回成功标志类型 @@ -5478,7 +5540,7 @@ defineDict["THOST_FTDC_RESF_InsuffiCient"] = '1' #交易结果未知 defineDict["THOST_FTDC_RESF_UnKnown"] = '8' -typedefDict["TThostFtdcResFlagType"] = "string" +typedefDict["TThostFtdcResFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcPageControlType是一个换汇页面控制类型 @@ -5503,7 +5565,7 @@ defineDict["THOST_FTDC_EXS_Before"] = '0' #修改后 defineDict["THOST_FTDC_EXS_After"] = '1' -typedefDict["TThostFtdcExStatusType"] = "string" +typedefDict["TThostFtdcExStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcClientRegionType是一个开户客户地域类型 @@ -5515,7 +5577,7 @@ defineDict["THOST_FTDC_CR_GMT"] = '2' #国外客户 defineDict["THOST_FTDC_CR_Foreign"] = '3' -typedefDict["TThostFtdcClientRegionType"] = "string" +typedefDict["TThostFtdcClientRegionType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcWorkPlaceType是一个工作单位类型 @@ -5580,7 +5642,7 @@ defineDict["THOST_FTDC_HB_No"] = '0' #有 defineDict["THOST_FTDC_HB_Yes"] = '1' -typedefDict["TThostFtdcHasBoardType"] = "string" +typedefDict["TThostFtdcHasBoardType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcStartModeType是一个启动模式类型 @@ -5592,7 +5654,7 @@ defineDict["THOST_FTDC_SM_Emerge"] = '2' #恢复 defineDict["THOST_FTDC_SM_Restore"] = '3' -typedefDict["TThostFtdcStartModeType"] = "string" +typedefDict["TThostFtdcStartModeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcTemplateTypeType是一个模型类型类型 @@ -5604,7 +5666,7 @@ defineDict["THOST_FTDC_TPT_Increment"] = '2' #备份 defineDict["THOST_FTDC_TPT_BackUp"] = '3' -typedefDict["TThostFtdcTemplateTypeType"] = "string" +typedefDict["TThostFtdcTemplateTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcLoginModeType是一个登录模式类型 @@ -5614,7 +5676,7 @@ defineDict["THOST_FTDC_LM_Trade"] = '0' #转账 defineDict["THOST_FTDC_LM_Transfer"] = '1' -typedefDict["TThostFtdcLoginModeType"] = "string" +typedefDict["TThostFtdcLoginModeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcPromptTypeType是一个日历提示类型类型 @@ -5624,7 +5686,7 @@ defineDict["THOST_FTDC_CPT_Instrument"] = '1' #保证金分段生效 defineDict["THOST_FTDC_CPT_Margin"] = '2' -typedefDict["TThostFtdcPromptTypeType"] = "string" +typedefDict["TThostFtdcPromptTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcLedgerManageIDType是一个分户管理资产编码类型 @@ -5664,7 +5726,7 @@ defineDict["THOST_FTDC_HT_Yes"] = '1' #没有 defineDict["THOST_FTDC_HT_No"] = '0' -typedefDict["TThostFtdcHasTrusteeType"] = "string" +typedefDict["TThostFtdcHasTrusteeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCSRCMemo1Type是一个说明类型 @@ -5702,7 +5764,7 @@ defineDict["THOST_FTDC_AMT_Trust"] = '5' #其他 defineDict["THOST_FTDC_AMT_Other"] = '9' -typedefDict["TThostFtdcAmTypeType"] = "string" +typedefDict["TThostFtdcAmTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCSRCAmTypeType是一个机构类型类型 @@ -5717,7 +5779,7 @@ defineDict["THOST_FTDC_CFIOT_FundIO"] = '0' #银期换汇 defineDict["THOST_FTDC_CFIOT_SwapCurrency"] = '1' -typedefDict["TThostFtdcCSRCFundIOTypeType"] = "string" +typedefDict["TThostFtdcCSRCFundIOTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCusAccountTypeType是一个结算账户类型类型 @@ -5731,7 +5793,7 @@ defineDict["THOST_FTDC_CAT_AssetmgrTrustee"] = '3' #综合类资管业务下的资金中转账户 defineDict["THOST_FTDC_CAT_AssetmgrTransfer"] = '4' -typedefDict["TThostFtdcCusAccountTypeType"] = "string" +typedefDict["TThostFtdcCusAccountTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCSRCNationalType是一个国籍类型 @@ -5751,7 +5813,7 @@ defineDict["THOST_FTDC_LT_Chinese"] = '1' #英文 defineDict["THOST_FTDC_LT_English"] = '2' -typedefDict["TThostFtdcLanguageTypeType"] = "string" +typedefDict["TThostFtdcLanguageTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcAmAccountType是一个投资账户类型 @@ -5768,7 +5830,7 @@ defineDict["THOST_FTDC_AMCT_Organ"] = '2' #特殊单位资管客户 defineDict["THOST_FTDC_AMCT_SpecialOrgan"] = '4' -typedefDict["TThostFtdcAssetmgrClientTypeType"] = "string" +typedefDict["TThostFtdcAssetmgrClientTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcAssetmgrTypeType是一个投资类型类型 @@ -5778,7 +5840,7 @@ defineDict["THOST_FTDC_ASST_Futures"] = '3' #综合类 defineDict["THOST_FTDC_ASST_SpecialOrgan"] = '4' -typedefDict["TThostFtdcAssetmgrTypeType"] = "string" +typedefDict["TThostFtdcAssetmgrTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcUOMType是一个计量单位类型 @@ -5815,7 +5877,7 @@ defineDict["THOST_FTDC_CIT_HasATP"] = '1' #合约比较不一致 defineDict["THOST_FTDC_CIT_HasDiff"] = '2' -typedefDict["TThostFtdcCheckInstrTypeType"] = "string" +typedefDict["TThostFtdcCheckInstrTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcDeliveryTypeType是一个交割类型类型 @@ -5825,7 +5887,7 @@ defineDict["THOST_FTDC_DT_HandDeliv"] = '1' #到期交割 defineDict["THOST_FTDC_DT_PersonDeliv"] = '2' -typedefDict["TThostFtdcDeliveryTypeType"] = "string" +typedefDict["TThostFtdcDeliveryTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBigMoneyType是一个资金类型 @@ -5840,7 +5902,7 @@ defineDict["THOST_FTDC_MMSA_NO"] = '0' #使用大额单边保证金算法 defineDict["THOST_FTDC_MMSA_YES"] = '1' -typedefDict["TThostFtdcMaxMarginSideAlgorithmType"] = "string" +typedefDict["TThostFtdcMaxMarginSideAlgorithmType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcDAClientTypeType是一个资产管理客户类型类型 @@ -5852,7 +5914,7 @@ defineDict["THOST_FTDC_CACT_Company"] = '1' #其他 defineDict["THOST_FTDC_CACT_Other"] = '2' -typedefDict["TThostFtdcDAClientTypeType"] = "string" +typedefDict["TThostFtdcDAClientTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCombinInstrIDType是一个套利合约代码类型 @@ -5887,7 +5949,7 @@ defineDict["THOST_FTDC_UOAAT_Futures"] = '1' #综合类 defineDict["THOST_FTDC_UOAAT_SpecialOrgan"] = '2' -typedefDict["TThostFtdcUOAAssetmgrTypeType"] = "string" +typedefDict["TThostFtdcUOAAssetmgrTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcDirectionEnType是一个买卖方向类型 @@ -5897,7 +5959,7 @@ defineDict["THOST_FTDC_DEN_Buy"] = '0' #Sell defineDict["THOST_FTDC_DEN_Sell"] = '1' -typedefDict["TThostFtdcDirectionEnType"] = "string" +typedefDict["TThostFtdcDirectionEnType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcOffsetFlagEnType是一个开平标志类型 @@ -5917,7 +5979,7 @@ defineDict["THOST_FTDC_OFEN_ForceOff"] = '5' #Local Forced Liquidation defineDict["THOST_FTDC_OFEN_LocalForceClose"] = '6' -typedefDict["TThostFtdcOffsetFlagEnType"] = "string" +typedefDict["TThostFtdcOffsetFlagEnType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcHedgeFlagEnType是一个投机套保标志类型 @@ -5929,7 +5991,7 @@ defineDict["THOST_FTDC_HFEN_Arbitrage"] = '2' #Hedge defineDict["THOST_FTDC_HFEN_Hedge"] = '3' -typedefDict["TThostFtdcHedgeFlagEnType"] = "string" +typedefDict["TThostFtdcHedgeFlagEnType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFundIOTypeEnType是一个出入金类型类型 @@ -5941,7 +6003,7 @@ defineDict["THOST_FTDC_FIOTEN_Transfer"] = '2' #Bank-Futures FX Exchange defineDict["THOST_FTDC_FIOTEN_SwapCurrency"] = '3' -typedefDict["TThostFtdcFundIOTypeEnType"] = "string" +typedefDict["TThostFtdcFundIOTypeEnType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFundTypeEnType是一个资金类型类型 @@ -5955,7 +6017,7 @@ defineDict["THOST_FTDC_FTEN_Company"] = '3' #Internal Transfer defineDict["THOST_FTDC_FTEN_InnerTransfer"] = '4' -typedefDict["TThostFtdcFundTypeEnType"] = "string" +typedefDict["TThostFtdcFundTypeEnType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFundDirectionEnType是一个出入金方向类型 @@ -5965,7 +6027,7 @@ defineDict["THOST_FTDC_FDEN_In"] = '1' #Withdrawal defineDict["THOST_FTDC_FDEN_Out"] = '2' -typedefDict["TThostFtdcFundDirectionEnType"] = "string" +typedefDict["TThostFtdcFundDirectionEnType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcFundMortDirectionEnType是一个货币质押方向类型 @@ -5975,7 +6037,7 @@ defineDict["THOST_FTDC_FMDEN_In"] = '1' #Redemption defineDict["THOST_FTDC_FMDEN_Out"] = '2' -typedefDict["TThostFtdcFundMortDirectionEnType"] = "string" +typedefDict["TThostFtdcFundMortDirectionEnType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSwapBusinessTypeType是一个换汇业务种类类型 @@ -5990,7 +6052,7 @@ defineDict["THOST_FTDC_CP_CallOptions"] = '1' #看跌 defineDict["THOST_FTDC_CP_PutOptions"] = '2' -typedefDict["TThostFtdcOptionsTypeType"] = "string" +typedefDict["TThostFtdcOptionsTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcStrikeModeType是一个执行方式类型 @@ -6002,7 +6064,7 @@ defineDict["THOST_FTDC_STM_American"] = '1' #百慕大 defineDict["THOST_FTDC_STM_Bermuda"] = '2' -typedefDict["TThostFtdcStrikeModeType"] = "string" +typedefDict["TThostFtdcStrikeModeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcStrikeTypeType是一个执行类型类型 @@ -6012,7 +6074,7 @@ defineDict["THOST_FTDC_STT_Hedge"] = '0' #匹配执行 defineDict["THOST_FTDC_STT_Match"] = '1' -typedefDict["TThostFtdcStrikeTypeType"] = "string" +typedefDict["TThostFtdcStrikeTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcApplyTypeType是一个中金所期权放弃执行申请类型类型 @@ -6020,7 +6082,7 @@ typedefDict["TThostFtdcStrikeTypeType"] = "string" #不执行数量 defineDict["THOST_FTDC_APPT_NotStrikeNum"] = '4' -typedefDict["TThostFtdcApplyTypeType"] = "string" +typedefDict["TThostFtdcApplyTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcGiveUpDataSourceType是一个放弃执行申请数据来源类型 @@ -6030,7 +6092,7 @@ defineDict["THOST_FTDC_GUDS_Gen"] = '0' #手工添加 defineDict["THOST_FTDC_GUDS_Hand"] = '1' -typedefDict["TThostFtdcGiveUpDataSourceType"] = "string" +typedefDict["TThostFtdcGiveUpDataSourceType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcExecOrderSysIDType是一个执行宣告系统编号类型 @@ -6065,7 +6127,7 @@ defineDict["THOST_FTDC_OER_NoEnoughHistoryTrade"] = '9' #未知 defineDict["THOST_FTDC_OER_Unknown"] = 'a' -typedefDict["TThostFtdcExecResultType"] = "string" +typedefDict["TThostFtdcExecResultType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcStrikeSequenceType是一个执行序号类型 @@ -6092,8 +6154,10 @@ defineDict["THOST_FTDC_COMBT_STD"] = '3' defineDict["THOST_FTDC_COMBT_STG"] = '4' #备兑组合 defineDict["THOST_FTDC_COMBT_PRT"] = '5' +#时间价差组合 +defineDict["THOST_FTDC_COMBT_CLD"] = '6' -typedefDict["TThostFtdcCombinationTypeType"] = "string" +typedefDict["TThostFtdcCombinationTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcOptionRoyaltyPriceTypeType是一个期权权利金价格类型类型 @@ -6103,7 +6167,7 @@ defineDict["THOST_FTDC_ORPT_PreSettlementPrice"] = '1' #开仓价 defineDict["THOST_FTDC_ORPT_OpenPrice"] = '4' -typedefDict["TThostFtdcOptionRoyaltyPriceTypeType"] = "string" +typedefDict["TThostFtdcOptionRoyaltyPriceTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcBalanceAlgorithmType是一个权益算法类型 @@ -6113,7 +6177,7 @@ defineDict["THOST_FTDC_BLAG_Default"] = '1' #计算期权市值亏损 defineDict["THOST_FTDC_BLAG_IncludeOptValLost"] = '2' -typedefDict["TThostFtdcBalanceAlgorithmType"] = "string" +typedefDict["TThostFtdcBalanceAlgorithmType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcActionTypeType是一个执行类型类型 @@ -6123,7 +6187,7 @@ defineDict["THOST_FTDC_ACTP_Exec"] = '1' #放弃 defineDict["THOST_FTDC_ACTP_Abandon"] = '2' -typedefDict["TThostFtdcActionTypeType"] = "string" +typedefDict["TThostFtdcActionTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcForQuoteStatusType是一个询价状态类型 @@ -6135,19 +6199,7 @@ defineDict["THOST_FTDC_FQST_Accepted"] = 'b' #已经被拒绝 defineDict["THOST_FTDC_FQST_Rejected"] = 'c' -typedefDict["TThostFtdcForQuoteStatusType"] = "string" - -#////////////////////////////////////////////////////////////////////// -#TFtdcQuotStatusType是一个报价状态类型 -#////////////////////////////////////////////////////////////////////// -#未知 -defineDict["THOST_FTDC_QTST_Unknown"] = 'a' -#已经接受 -defineDict["THOST_FTDC_QTST_Accepted"] = 'b' -#已经撤销 -defineDict["THOST_FTDC_QTST_Canceled"] = 'c' - -typedefDict["TThostFtdcQuotStatusType"] = "string" +typedefDict["TThostFtdcForQuoteStatusType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcValueMethodType是一个取值方式类型 @@ -6157,7 +6209,7 @@ defineDict["THOST_FTDC_VM_Absolute"] = '0' #按比率 defineDict["THOST_FTDC_VM_Ratio"] = '1' -typedefDict["TThostFtdcValueMethodType"] = "string" +typedefDict["TThostFtdcValueMethodType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcExecOrderPositionFlagType是一个期权行权后是否保留期货头寸的标记类型 @@ -6167,7 +6219,7 @@ defineDict["THOST_FTDC_EOPF_Reserve"] = '0' #不保留 defineDict["THOST_FTDC_EOPF_UnReserve"] = '1' -typedefDict["TThostFtdcExecOrderPositionFlagType"] = "string" +typedefDict["TThostFtdcExecOrderPositionFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcExecOrderCloseFlagType是一个期权行权后生成的头寸是否自动平仓类型 @@ -6177,7 +6229,7 @@ defineDict["THOST_FTDC_EOCF_AutoClose"] = '0' #免于自动平仓 defineDict["THOST_FTDC_EOCF_NotToClose"] = '1' -typedefDict["TThostFtdcExecOrderCloseFlagType"] = "string" +typedefDict["TThostFtdcExecOrderCloseFlagType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcProductTypeType是一个产品类型类型 @@ -6187,7 +6239,7 @@ defineDict["THOST_FTDC_PTE_Futures"] = '1' #期权 defineDict["THOST_FTDC_PTE_Options"] = '2' -typedefDict["TThostFtdcProductTypeType"] = "string" +typedefDict["TThostFtdcProductTypeType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCZCEUploadFileNameType是一个郑商所结算文件名类型 @@ -6209,7 +6261,7 @@ defineDict["THOST_FTDC_CUFN_CUFN_C"] = 'C' #^\d{8}保证金参数表 defineDict["THOST_FTDC_CUFN_CUFN_M"] = 'M' -typedefDict["TThostFtdcCZCEUploadFileNameType"] = "string" +typedefDict["TThostFtdcCZCEUploadFileNameType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcDCEUploadFileNameType是一个大商所结算文件名类型 @@ -6231,7 +6283,7 @@ defineDict["THOST_FTDC_DUFN_DUFN_M"] = 'M' #^\d{8}_期权执行表 defineDict["THOST_FTDC_DUFN_DUFN_S"] = 'S' -typedefDict["TThostFtdcDCEUploadFileNameType"] = "string" +typedefDict["TThostFtdcDCEUploadFileNameType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcSHFEUploadFileNameType是一个上期所结算文件名类型 @@ -6245,7 +6297,7 @@ defineDict["THOST_FTDC_SUFN_SUFN_P"] = 'P' #^\d{4}_\d{8}_\d{8}_Capital defineDict["THOST_FTDC_SUFN_SUFN_F"] = 'F' -typedefDict["TThostFtdcSHFEUploadFileNameType"] = "string" +typedefDict["TThostFtdcSHFEUploadFileNameType"] = "char" #////////////////////////////////////////////////////////////////////// #TFtdcCFFEXUploadFileNameType是一个中金所结算文件名类型 @@ -6259,5 +6311,146 @@ defineDict["THOST_FTDC_CFUFN_SUFN_F"] = 'F' #^\d{4}_SG\d{1}_\d{8}_\d{1}_OptionExec defineDict["THOST_FTDC_CFUFN_SUFN_S"] = 'S' -typedefDict["TThostFtdcCFFEXUploadFileNameType"] = "string" +typedefDict["TThostFtdcCFFEXUploadFileNameType"] = "char" + +#////////////////////////////////////////////////////////////////////// +#TFtdcCombDirectionType是一个组合指令方向类型 +#////////////////////////////////////////////////////////////////////// +#申请组合 +defineDict["THOST_FTDC_CMDR_Comb"] = '0' +#申请拆分 +defineDict["THOST_FTDC_CMDR_UnComb"] = '1' + +typedefDict["TThostFtdcCombDirectionType"] = "char" + +#////////////////////////////////////////////////////////////////////// +#TFtdcLockTypeType是一个锁定方向类型 +#////////////////////////////////////////////////////////////////////// +#锁定 +defineDict["THOST_FTDC_LCKT_Lock"] = '1' +#解锁 +defineDict["THOST_FTDC_LCKT_Unlock"] = '2' + +typedefDict["TThostFtdcLockTypeType"] = "char" + +#////////////////////////////////////////////////////////////////////// +#TFtdcBizTypeType是一个业务类型类型 +#////////////////////////////////////////////////////////////////////// +#期货 +defineDict["THOST_FTDC_BZTP_Future"] = '1' +#证券 +defineDict["THOST_FTDC_BZTP_Stock"] = '2' + +typedefDict["TThostFtdcBizTypeType"] = "char" + +#////////////////////////////////////////////////////////////////////// +#TFtdcDesignateTypeType是一个指定类型类型 +#////////////////////////////////////////////////////////////////////// +#指定登记 +defineDict["THOST_FTDC_DSTP_Register"] = '1' +#指定撤销 +defineDict["THOST_FTDC_DSTP_Cancel"] = '2' + +typedefDict["TThostFtdcDesignateTypeType"] = "char" + +#////////////////////////////////////////////////////////////////////// +#TFtdcFreezeReasonTypeType是一个冻结原因类型 +#////////////////////////////////////////////////////////////////////// +#初始化 +defineDict["THOST_FTDC_FRTP_Init"] = '1' +#锁定 +defineDict["THOST_FTDC_FRTP_Lock"] = '2' +#执行 +defineDict["THOST_FTDC_FRTP_Exec"] = '3' +#仓位校验 +defineDict["THOST_FTDC_FRTP_Check"] = '4' +#E+1日执行冻结 +defineDict["THOST_FTDC_FRTP_ExecFreeze"] = '5' + +typedefDict["TThostFtdcFreezeReasonTypeType"] = "char" + +#////////////////////////////////////////////////////////////////////// +#TFtdcFreezeTypeType是一个冻结类型类型 +#////////////////////////////////////////////////////////////////////// +#冻结 +defineDict["THOST_FTDC_FZTP_Freeze"] = '1' +#解冻 +defineDict["THOST_FTDC_FZTP_Unfreeze"] = '2' +#强制执行 +defineDict["THOST_FTDC_FZTP_Force"] = '3' + +typedefDict["TThostFtdcFreezeTypeType"] = "char" + +#////////////////////////////////////////////////////////////////////// +#TFtdcTradeSystemTypeType是一个交易系统类型类型 +#////////////////////////////////////////////////////////////////////// +#未知系统 +defineDict["THOST_FTDC_TSTP_Unknow"] = '0' +#期货系统 +defineDict["THOST_FTDC_TSTP_Future"] = '1' +#个股系统 +defineDict["THOST_FTDC_TSTP_IShare"] = '2' + +typedefDict["TThostFtdcTradeSystemTypeType"] = "char" + +#////////////////////////////////////////////////////////////////////// +#TFtdcStockDisposalTypeType是一个证券处置方向类型 +#////////////////////////////////////////////////////////////////////// +#划入经纪公司账户 +defineDict["THOST_FTDC_STPT_ToBroker"] = '1' +#划入投资者账户 +defineDict["THOST_FTDC_STPT_ToInvestor"] = '2' + +typedefDict["TThostFtdcStockDisposalTypeType"] = "char" + +#////////////////////////////////////////////////////////////////////// +#TFtdcStockDisposalSysIDType是一个证券处置编号类型 +#////////////////////////////////////////////////////////////////////// +typedefDict["TThostFtdcStockDisposalSysIDType"] = "string" + +#////////////////////////////////////////////////////////////////////// +#TFtdcStockDisposalStatusType是一个证券处置状态类型 +#////////////////////////////////////////////////////////////////////// +#已经提交 +defineDict["THOST_FTDC_SDPS_Submitted"] = 'a' +#已经接受 +defineDict["THOST_FTDC_SDPS_Accepted"] = 'b' +#已经被拒绝 +defineDict["THOST_FTDC_SDPS_Rejected"] = 'c' +#已经被撤销 +defineDict["THOST_FTDC_SDPS_Cancelled"] = 'd' + +typedefDict["TThostFtdcStockDisposalStatusType"] = "char" + +#////////////////////////////////////////////////////////////////////// +#TFtdcInstructionRightTypeType是一个指令权限类型类型 +#////////////////////////////////////////////////////////////////////// +#限价单 +defineDict["THOST_FTDC_ISTR_Limit"] = '1' +#限价全额成交否则取消 +defineDict["THOST_FTDC_ISTR_Limit_FOK"] = '2' +#市价订单剩余转限价 +defineDict["THOST_FTDC_ISTR_Market_RemainLimit"] = '3' +#市价订单剩余撤销 +defineDict["THOST_FTDC_ISTR_Market_FAK"] = '4' +#市价全额成交否则取消 +defineDict["THOST_FTDC_ISTR_Market_FOK"] = '5' +#证券锁定 +defineDict["THOST_FTDC_ISTR_Lock"] = '6' +#证券解锁 +defineDict["THOST_FTDC_ISTR_Unlock"] = '7' + +typedefDict["TThostFtdcInstructionRightTypeType"] = "char" + +#////////////////////////////////////////////////////////////////////// +#TFtdcLevelTypeType是一个投资者分级类型类型 +#////////////////////////////////////////////////////////////////////// +#一级投资者 +defineDict["THOST_FTDC_IVLV_FirstLevel"] = '1' +#二级投资者 +defineDict["THOST_FTDC_IVLV_SecondLevel"] = '2' +#三级投资者 +defineDict["THOST_FTDC_IVLV_ThirdLevel"] = '3' + +typedefDict["TThostFtdcLevelTypeType"] = "char" diff --git a/vn.trader/ctpGateway/ctpGateway.py b/vn.trader/ctpGateway/ctpGateway.py index dcd444ff..731ab5f3 100644 --- a/vn.trader/ctpGateway/ctpGateway.py +++ b/vn.trader/ctpGateway/ctpGateway.py @@ -41,14 +41,11 @@ offsetMapReverse = {v:k for k,v in offsetMap.items()} # 交易所类型映射 exchangeMap = {} -#exchangeMap[EXCHANGE_CFFEX] = defineDict['THOST_FTDC_EIDT_CFFEX'] -#exchangeMap[EXCHANGE_SHFE] = defineDict['THOST_FTDC_EIDT_SHFE'] -#exchangeMap[EXCHANGE_CZCE] = defineDict['THOST_FTDC_EIDT_CZCE'] -#exchangeMap[EXCHANGE_DCE] = defineDict['THOST_FTDC_EIDT_DCE'] exchangeMap[EXCHANGE_CFFEX] = 'CFFEX' exchangeMap[EXCHANGE_SHFE] = 'SHFE' exchangeMap[EXCHANGE_CZCE] = 'CZCE' exchangeMap[EXCHANGE_DCE] = 'DCE' +exchangeMap[EXCHANGE_SSE] = 'SSE' exchangeMap[EXCHANGE_UNKNOWN] = '' exchangeMapReverse = {v:k for k,v in exchangeMap.items()} @@ -59,6 +56,14 @@ posiDirectionMap[DIRECTION_LONG] = defineDict["THOST_FTDC_PD_Long"] posiDirectionMap[DIRECTION_SHORT] = defineDict["THOST_FTDC_PD_Short"] posiDirectionMapReverse = {v:k for k,v in posiDirectionMap.items()} +# 产品类型映射 +productClassMap = {} +productClassMap[PRODUCT_FUTURES] = defineDict["THOST_FTDC_PC_Futures"] +productClassMap[PRODUCT_OPTION] = defineDict["THOST_FTDC_PC_Options"] +productClassMap[PRODUCT_COMBINATION] = defineDict["THOST_FTDC_PC_Combination"] +productClassMapReverse = {v:k for k,v in productClassMap.items()} + + ######################################################################## class CtpGateway(VtGateway): @@ -284,7 +289,7 @@ class CtpMdApi(MdApi): # 如果登出成功,推送日志信息 if error['ErrorID'] == 0: self.loginStatus = False - self.gateway.tdConnected = False + self.gateway.mdConnected = False log = VtLogData() log.gatewayName = self.gatewayName @@ -439,41 +444,43 @@ class CtpTdApi(TdApi): self.sessionID = EMPTY_INT # 会话编号 self.posBufferDict = {} # 缓存持仓数据的字典 + self.symbolExchangeDict = {} # 保存合约代码和交易所的印射关系 + self.symbolSizeDict = {} # 保存合约代码和合约大小的印射关系 #---------------------------------------------------------------------- def onFrontConnected(self): """服务器连接""" self.connectionStatus = True - + log = VtLogData() log.gatewayName = self.gatewayName log.logContent = u'交易服务器连接成功' self.gateway.onLog(log) - - self.login() + self.login() + #---------------------------------------------------------------------- def onFrontDisconnected(self, n): """服务器断开""" self.connectionStatus = False self.loginStatus = False self.gateway.tdConnected = False - + log = VtLogData() log.gatewayName = self.gatewayName log.logContent = u'交易服务器连接断开' - self.gateway.onLog(log) - + self.gateway.onLog(log) + #---------------------------------------------------------------------- def onHeartBeatWarning(self, n): """""" pass - + #---------------------------------------------------------------------- def onRspAuthenticate(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspUserLogin(self, data, error, n, last): """登陆回报""" @@ -482,7 +489,7 @@ class CtpTdApi(TdApi): self.frontID = str(data['FrontID']) self.sessionID = str(data['SessionID']) self.loginStatus = True - self.gateway.mdConnected = True + self.gateway.tdConnected = True log = VtLogData() log.gatewayName = self.gatewayName @@ -503,7 +510,7 @@ class CtpTdApi(TdApi): err.errorID = error['ErrorID'] err.errorMsg = error['ErrorMsg'].decode('gbk') self.gateway.onError(err) - + #---------------------------------------------------------------------- def onRspUserLogout(self, data, error, n, last): """登出回报""" @@ -524,17 +531,17 @@ class CtpTdApi(TdApi): err.errorID = error['ErrorID'] err.errorMsg = error['ErrorMsg'].decode('gbk') self.gateway.onError(err) - + #---------------------------------------------------------------------- def onRspUserPasswordUpdate(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspTradingAccountPasswordUpdate(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspOrderInsert(self, data, error, n, last): """发单错误(柜台)""" @@ -543,17 +550,17 @@ class CtpTdApi(TdApi): err.errorID = error['ErrorID'] err.errorMsg = error['ErrorMsg'].decode('gbk') self.gateway.onError(err) - + #---------------------------------------------------------------------- def onRspParkedOrderInsert(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspParkedOrderAction(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspOrderAction(self, data, error, n, last): """撤单错误(柜台)""" @@ -562,12 +569,12 @@ class CtpTdApi(TdApi): err.errorID = error['ErrorID'] err.errorMsg = error['ErrorMsg'].decode('gbk') self.gateway.onError(err) - + #---------------------------------------------------------------------- def onRspQueryMaxOrderVolume(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspSettlementInfoConfirm(self, data, error, n, last): """确认结算信息回报""" @@ -575,7 +582,7 @@ class CtpTdApi(TdApi): log.gatewayName = self.gatewayName log.logContent = u'结算信息确认完成' self.gateway.onLog(log) - + # 查询合约代码 self.reqID += 1 self.reqQryInstrument({}, self.reqID) @@ -584,47 +591,57 @@ class CtpTdApi(TdApi): def onRspRemoveParkedOrder(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspRemoveParkedOrderAction(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspExecOrderInsert(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspExecOrderAction(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspForQuoteInsert(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQuoteInsert(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQuoteAction(self, data, error, n, last): """""" pass - + + #---------------------------------------------------------------------- + def onRspLockInsert(self, data, error, n, last): + """""" + pass + + #---------------------------------------------------------------------- + def onRspCombActionInsert(self, data, error, n, last): + """""" + pass + #---------------------------------------------------------------------- def onRspQryOrder(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryTrade(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryInvestorPosition(self, data, error, n, last): """持仓查询回报""" @@ -638,19 +655,24 @@ class CtpTdApi(TdApi): self.posBufferDict[positionName] = posBuffer # 更新持仓缓存,并获取VT系统中持仓对象的返回值 - pos = posBuffer.updateBuffer(data) + exchange = self.symbolExchangeDict.get(data['InstrumentID'], EXCHANGE_UNKNOWN) + size = self.symbolSizeDict.get(data['InstrumentID'], 1) + if exchange == EXCHANGE_SHFE: + pos = posBuffer.updateShfeBuffer(data, size) + else: + pos = posBuffer.updateBuffer(data, size) self.gateway.onPosition(pos) - + #---------------------------------------------------------------------- def onRspQryTradingAccount(self, data, error, n, last): """资金账户查询回报""" account = VtAccountData() account.gatewayName = self.gatewayName - + # 账户代码 account.accountID = data['AccountID'] account.vtAccountID = '.'.join([self.gatewayName, account.accountID]) - + # 数值相关 account.preBalance = data['PreBalance'] account.available = data['Available'] @@ -658,46 +680,46 @@ class CtpTdApi(TdApi): account.margin = data['CurrMargin'] account.closeProfit = data['CloseProfit'] account.positionProfit = data['PositionProfit'] - + # 这里的balance和快期中的账户不确定是否一样,需要测试 account.balance = (data['PreBalance'] - data['PreCredit'] - data['PreMortgage'] + data['Mortgage'] - data['Withdraw'] + data['Deposit'] + data['CloseProfit'] + data['PositionProfit'] + data['CashIn'] - data['Commission']) - + # 推送 self.gateway.onAccount(account) - + #---------------------------------------------------------------------- def onRspQryInvestor(self, data, error, n, last): - """投资者查询回报""" + """""" pass - + #---------------------------------------------------------------------- def onRspQryTradingCode(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryInstrumentMarginRate(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryInstrumentCommissionRate(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryExchange(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryProduct(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryInstrument(self, data, error, n, last): """合约查询回报""" @@ -708,143 +730,179 @@ class CtpTdApi(TdApi): contract.exchange = exchangeMapReverse[data['ExchangeID']] contract.vtSymbol = contract.symbol #'.'.join([contract.symbol, contract.exchange]) contract.name = data['InstrumentName'].decode('GBK') - + # 合约数值 contract.size = data['VolumeMultiple'] contract.priceTick = data['PriceTick'] contract.strikePrice = data['StrikePrice'] contract.underlyingSymbol = data['UnderlyingInstrID'] - - # 合约类型 - if data['ProductClass'] == '1': - contract.productClass = PRODUCT_FUTURES - elif data['ProductClass'] == '2': - contract.productClass = PRODUCT_OPTION - elif data['ProductClass'] == '3': - contract.productClass = PRODUCT_COMBINATION - else: - contract.productClass = PRODUCT_UNKNOWN - + + contract.productClass = productClassMapReverse.get(data['ProductClass'], PRODUCT_UNKNOWN) + # 期权类型 if data['OptionsType'] == '1': contract.optionType = OPTION_CALL elif data['OptionsType'] == '2': contract.optionType = OPTION_PUT - + + # 缓存代码和交易所的印射关系 + self.symbolExchangeDict[contract.symbol] = contract.exchange + self.symbolSizeDict[contract.symbol] = contract.size + # 推送 self.gateway.onContract(contract) - + if last: log = VtLogData() log.gatewayName = self.gatewayName log.logContent = u'交易合约信息获取完成' self.gateway.onLog(log) - + #---------------------------------------------------------------------- def onRspQryDepthMarketData(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQrySettlementInfo(self, data, error, n, last): - """查询结算信息回报""" + """""" pass - + #---------------------------------------------------------------------- def onRspQryTransferBank(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryInvestorPositionDetail(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryNotice(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQrySettlementInfoConfirm(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryInvestorPositionCombineDetail(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryCFMMCTradingAccountKey(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryEWarrantOffset(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryInvestorProductGroupMargin(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryExchangeMarginRate(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryExchangeMarginRateAdjust(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryExchangeRate(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQrySecAgentACIDMap(self, data, error, n, last): """""" pass - + + #---------------------------------------------------------------------- + def onRspQryProductExchRate(self, data, error, n, last): + """""" + pass + + #---------------------------------------------------------------------- + def onRspQryProductGroup(self, data, error, n, last): + """""" + pass + #---------------------------------------------------------------------- def onRspQryOptionInstrTradeCost(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryOptionInstrCommRate(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryExecOrder(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryForQuote(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryQuote(self, data, error, n, last): """""" pass - + + #---------------------------------------------------------------------- + def onRspQryLock(self, data, error, n, last): + """""" + pass + + #---------------------------------------------------------------------- + def onRspQryLockPosition(self, data, error, n, last): + """""" + pass + + #---------------------------------------------------------------------- + def onRspQryInvestorLevel(self, data, error, n, last): + """""" + pass + + #---------------------------------------------------------------------- + def onRspQryExecFreeze(self, data, error, n, last): + """""" + pass + + #---------------------------------------------------------------------- + def onRspQryCombInstrumentGuard(self, data, error, n, last): + """""" + pass + + #---------------------------------------------------------------------- + def onRspQryCombAction(self, data, error, n, last): + """""" + pass + #---------------------------------------------------------------------- def onRspQryTransferSerial(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryAccountregister(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspError(self, error, n, last): """错误回报""" @@ -853,7 +911,7 @@ class CtpTdApi(TdApi): err.errorID = error['ErrorID'] err.errorMsg = error['ErrorMsg'].decode('gbk') self.gateway.onError(err) - + #---------------------------------------------------------------------- def onRtnOrder(self, data): """报单回报""" @@ -917,7 +975,7 @@ class CtpTdApi(TdApi): # 推送 self.gateway.onOrder(order) - + #---------------------------------------------------------------------- def onRtnTrade(self, data): """成交回报""" @@ -949,7 +1007,7 @@ class CtpTdApi(TdApi): # 推送 self.gateway.onTrade(trade) - + #---------------------------------------------------------------------- def onErrRtnOrderInsert(self, data, error): """发单错误回报(交易所)""" @@ -958,7 +1016,7 @@ class CtpTdApi(TdApi): err.errorID = error['ErrorID'] err.errorMsg = error['ErrorMsg'].decode('gbk') self.gateway.onError(err) - + #---------------------------------------------------------------------- def onErrRtnOrderAction(self, data, error): """撤单错误回报(交易所)""" @@ -967,202 +1025,233 @@ class CtpTdApi(TdApi): err.errorID = error['ErrorID'] err.errorMsg = error['ErrorMsg'].decode('gbk') self.gateway.onError(err) - + #---------------------------------------------------------------------- def onRtnInstrumentStatus(self, data): """""" pass - + #---------------------------------------------------------------------- def onRtnTradingNotice(self, data): """""" pass - + #---------------------------------------------------------------------- def onRtnErrorConditionalOrder(self, data): """""" pass - + #---------------------------------------------------------------------- def onRtnExecOrder(self, data): """""" pass - + #---------------------------------------------------------------------- def onErrRtnExecOrderInsert(self, data, error): """""" pass - + #---------------------------------------------------------------------- def onErrRtnExecOrderAction(self, data, error): """""" pass - + #---------------------------------------------------------------------- def onErrRtnForQuoteInsert(self, data, error): """""" pass - + #---------------------------------------------------------------------- def onRtnQuote(self, data): """""" pass - + #---------------------------------------------------------------------- def onErrRtnQuoteInsert(self, data, error): """""" pass - + #---------------------------------------------------------------------- def onErrRtnQuoteAction(self, data, error): """""" pass - + #---------------------------------------------------------------------- def onRtnForQuoteRsp(self, data): """""" pass - + + #---------------------------------------------------------------------- + def onRtnCFMMCTradingAccountToken(self, data): + """""" + pass + + #---------------------------------------------------------------------- + def onRtnLock(self, data): + """""" + pass + + #---------------------------------------------------------------------- + def onErrRtnLockInsert(self, data, error): + """""" + pass + + #---------------------------------------------------------------------- + def onRtnCombAction(self, data): + """""" + pass + + #---------------------------------------------------------------------- + def onErrRtnCombActionInsert(self, data, error): + """""" + pass + #---------------------------------------------------------------------- def onRspQryContractBank(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryParkedOrder(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryParkedOrderAction(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryTradingNotice(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryBrokerTradingParams(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQryBrokerTradingAlgos(self, data, error, n, last): """""" pass - + + #---------------------------------------------------------------------- + def onRspQueryCFMMCTradingAccountToken(self, data, error, n, last): + """""" + pass + #---------------------------------------------------------------------- def onRtnFromBankToFutureByBank(self, data): """""" pass - + #---------------------------------------------------------------------- def onRtnFromFutureToBankByBank(self, data): """""" pass - + #---------------------------------------------------------------------- def onRtnRepealFromBankToFutureByBank(self, data): """""" pass - + #---------------------------------------------------------------------- def onRtnRepealFromFutureToBankByBank(self, data): """""" pass - + #---------------------------------------------------------------------- def onRtnFromBankToFutureByFuture(self, data): """""" pass - + #---------------------------------------------------------------------- def onRtnFromFutureToBankByFuture(self, data): """""" pass - + #---------------------------------------------------------------------- def onRtnRepealFromBankToFutureByFutureManual(self, data): """""" pass - + #---------------------------------------------------------------------- def onRtnRepealFromFutureToBankByFutureManual(self, data): """""" pass - + #---------------------------------------------------------------------- def onRtnQueryBankBalanceByFuture(self, data): """""" pass - + #---------------------------------------------------------------------- def onErrRtnBankToFutureByFuture(self, data, error): """""" pass - + #---------------------------------------------------------------------- def onErrRtnFutureToBankByFuture(self, data, error): """""" pass - + #---------------------------------------------------------------------- def onErrRtnRepealBankToFutureByFutureManual(self, data, error): """""" pass - + #---------------------------------------------------------------------- def onErrRtnRepealFutureToBankByFutureManual(self, data, error): """""" pass - + #---------------------------------------------------------------------- def onErrRtnQueryBankBalanceByFuture(self, data, error): """""" pass - + #---------------------------------------------------------------------- def onRtnRepealFromBankToFutureByFuture(self, data): """""" pass - + #---------------------------------------------------------------------- def onRtnRepealFromFutureToBankByFuture(self, data): """""" pass - + #---------------------------------------------------------------------- def onRspFromBankToFutureByFuture(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspFromFutureToBankByFuture(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspQueryBankAccountMoneyByFuture(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRtnOpenAccountByBank(self, data): """""" pass - + #---------------------------------------------------------------------- def onRtnCancelAccountByBank(self, data): """""" pass - + #---------------------------------------------------------------------- def onRtnChangeAccountByBank(self, data): """""" pass - + + #---------------------------------------------------------------------- def connect(self, userID, password, brokerID, address): """初始化连接""" @@ -1313,15 +1402,16 @@ class PositionBuffer(object): self.pos = pos #---------------------------------------------------------------------- - def updateBuffer(self, data): - """更新缓存,返回更新后的持仓数据""" + def updateShfeBuffer(self, data, size): + """更新上期所缓存,返回更新后的持仓数据""" # 昨仓和今仓的数据更新是分在两条记录里的,因此需要判断检查该条记录对应仓位 - if data['TodayPosition']: - self.todayPosition = data['Position'] - self.todayPositionCost = data['PositionCost'] - elif data['YdPosition']: + # 因为今仓字段TodayPosition可能变为0(被全部平仓),因此分辨今昨仓需要用YdPosition字段 + if data['YdPosition']: self.ydPosition = data['Position'] - self.ydPositionCost = data['PositionCost'] + self.ydPositionCost = data['PositionCost'] + else: + self.todayPosition = data['Position'] + self.todayPositionCost = data['PositionCost'] # 持仓的昨仓和今仓相加后为总持仓 self.pos.position = self.todayPosition + self.ydPosition @@ -1330,12 +1420,27 @@ class PositionBuffer(object): # 如果手头还有持仓,则通过加权平均方式计算持仓均价 if self.todayPosition or self.ydPosition: self.pos.price = ((self.todayPositionCost + self.ydPositionCost)/ - (self.todayPosition + self.ydPosition)) + ((self.todayPosition + self.ydPosition) * size)) # 否则价格为0 else: self.pos.price = 0 return copy(self.pos) + + #---------------------------------------------------------------------- + def updateBuffer(self, data, size): + """更新其他交易所的缓存,返回更新后的持仓数据""" + # 其他交易所并不区分今昨,因此只关心总仓位,昨仓设为0 + self.pos.position = data['Position'] + self.pos.ydPosition = 0 + + if data['Position']: + self.pos.price = data['PositionCost'] / (data['Position'] * size) + else: + self.pos.price = 0 + + return copy(self.pos) + #---------------------------------------------------------------------- def test(): diff --git a/vn.trader/dataRecorder/DR_setting.json b/vn.trader/dataRecorder/DR_setting.json index 38c4dd35..f7c297c5 100644 --- a/vn.trader/dataRecorder/DR_setting.json +++ b/vn.trader/dataRecorder/DR_setting.json @@ -3,7 +3,7 @@ "tick": [ - ["IF1605", "SGIT"], + ["m1609", "XSPEED"], ["IF1606", "SGIT"], ["IH1606", "SGIT"], ["IH1606", "SGIT"], diff --git a/vn.trader/dataRecorder/drEngine.py b/vn.trader/dataRecorder/drEngine.py index 644dc0da..76ea1df1 100644 --- a/vn.trader/dataRecorder/drEngine.py +++ b/vn.trader/dataRecorder/drEngine.py @@ -11,6 +11,8 @@ import os import copy from collections import OrderedDict from datetime import datetime, timedelta +from Queue import Queue +from threading import Thread from eventEngine import * from vtGateway import VtSubscribeReq, VtLogData @@ -43,6 +45,11 @@ class DrEngine(object): # K线对象字典 self.barDict = {} + # 负责执行数据库插入的单独线程相关 + self.active = False # 工作状态 + self.queue = Queue() # 队列 + self.thread = Thread(target=self.run) # 线程 + # 载入设置,订阅行情 self.loadSetting() @@ -111,9 +118,12 @@ class DrEngine(object): # 注意这里的vtSymbol对于IB和LTS接口,应该后缀.交易所 for activeSymbol, vtSymbol in d.items(): self.activeSymbolDict[vtSymbol] = activeSymbol - + + # 启动数据插入线程 + self.start() + # 注册事件监听 - self.registerEvent() + self.registerEvent() #---------------------------------------------------------------------- def procecssTickEvent(self, event): @@ -187,7 +197,29 @@ class DrEngine(object): #---------------------------------------------------------------------- def insertData(self, dbName, collectionName, data): """插入数据到数据库(这里的data可以是CtaTickData或者CtaBarData)""" - self.mainEngine.dbInsert(dbName, collectionName, data.__dict__) + self.queue.put((dbName, collectionName, data.__dict__)) + + #---------------------------------------------------------------------- + def run(self): + """运行插入线程""" + while self.active: + try: + dbName, collectionName, d = self.queue.get(block=True, timeout=1) + self.mainEngine.dbInsert(dbName, collectionName, d) + except Empty: + pass + #---------------------------------------------------------------------- + def start(self): + """启动""" + self.active = True + self.thread.start() + + #---------------------------------------------------------------------- + def stop(self): + """退出""" + if self.active: + self.active = False + self.thread.join() #---------------------------------------------------------------------- def writeDrLog(self, content): diff --git a/vn.trader/ltsGateway/ltsGateway.py b/vn.trader/ltsGateway/ltsGateway.py index d3fa3ea3..77eccdc9 100644 --- a/vn.trader/ltsGateway/ltsGateway.py +++ b/vn.trader/ltsGateway/ltsGateway.py @@ -193,7 +193,7 @@ class LtsGateway(VtGateway): ######################################################################## -class LtsMdApi(MdApi): +class LtsMdApi(MdApi): """Lts行情API实现""" #---------------------------------------------------------------------- @@ -733,6 +733,10 @@ class LtsTdApi(TdApi): os.makedirs(path) self.createFtdcTraderApi(path) + # 设置数据同步模式为推送从今日开始所有数据 + self.subscribePrivateTopic(0) + self.subscribePublicTopic(0) + # 注册服务器地址 self.registerFront(self.address) @@ -1153,7 +1157,7 @@ class LtsQryApi(QryApi): # 持仓均价 if pos.position: - pos.price = data['PositionCost'] / pos.position + pos.price = data['OpenCost'] / pos.position # VT系统持仓名 pos.vtPositionName = '.'.join([pos.vtSymbol, pos.direction]) diff --git a/vn.trader/okcoinGateway/OKCOIN_connect.json b/vn.trader/okcoinGateway/OKCOIN_connect.json new file mode 100644 index 00000000..8240e55e --- /dev/null +++ b/vn.trader/okcoinGateway/OKCOIN_connect.json @@ -0,0 +1,7 @@ +{ + "host": "CNY", + "apiKey": "OKCOIN网站申请", + "secretKey": "OKCOIN网站申请", + "trace": false, + "leverage": 20 +} \ No newline at end of file diff --git a/vn.trader/okcoinGateway/__init__.py b/vn.trader/okcoinGateway/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/vn.trader/okcoinGateway/okcoinGateway.py b/vn.trader/okcoinGateway/okcoinGateway.py new file mode 100644 index 00000000..ee1d86aa --- /dev/null +++ b/vn.trader/okcoinGateway/okcoinGateway.py @@ -0,0 +1,657 @@ +# encoding: UTF-8 + +''' +vn.okcoin的gateway接入 + +注意: +1. 该接口尚处于测试阶段,用于实盘请谨慎 +2. 目前仅支持USD和CNY的现货交易,USD的期货合约交易暂不支持 +''' + + +import os +import json +from datetime import datetime +from copy import copy +from threading import Condition + +import vnokcoin +from vtGateway import * + +# 价格类型映射 +priceTypeMap = {} +priceTypeMap['buy'] = (DIRECTION_LONG, PRICETYPE_LIMITPRICE) +priceTypeMap['buy_market'] = (DIRECTION_LONG, PRICETYPE_MARKETPRICE) +priceTypeMap['sell'] = (DIRECTION_SHORT, PRICETYPE_LIMITPRICE) +priceTypeMap['sell_market'] = (DIRECTION_SHORT, PRICETYPE_MARKETPRICE) +priceTypeMapReverse = {v: k for k, v in priceTypeMap.items()} + +# 方向类型映射 +directionMap = {} +directionMapReverse = {v: k for k, v in directionMap.items()} + +# 委托状态印射 +statusMap = {} +statusMap[-1] = STATUS_CANCELLED +statusMap[0] = STATUS_NOTTRADED +statusMap[1] = STATUS_PARTTRADED +statusMap[2] = STATUS_ALLTRADED +statusMap[4] = STATUS_UNKNOWN + +############################################ +## 交易合约代码 +############################################ + +# USD +BTC_USD_SPOT = 'BTC_USD_SPOT' +BTC_USD_THISWEEK = 'BTC_USD_THISWEEK' +BTC_USD_NEXTWEEK = 'BTC_USD_NEXTWEEK' +BTC_USD_QUARTER = 'BTC_USD_QUARTER' + +LTC_USD_SPOT = 'LTC_USD_SPOT' +LTC_USD_THISWEEK = 'LTC_USD_THISWEEK' +LTC_USD_NEXTWEEK = 'LTC_USD_NEXTWEEK' +LTC_USD_QUARTER = 'LTC_USD_QUARTER' + +# CNY +BTC_CNY_SPOT = 'BTC_CNY_SPOT' +LTC_CNY_SPOT = 'LTC_CNY_SPOT' + +# 印射字典 +spotSymbolMap = {} +spotSymbolMap['ltc_usd'] = LTC_USD_SPOT +spotSymbolMap['btc_usd'] = BTC_USD_SPOT +spotSymbolMap['ltc_cny'] = LTC_CNY_SPOT +spotSymbolMap['btc_cny'] = BTC_CNY_SPOT +spotSymbolMapReverse = {v: k for k, v in spotSymbolMap.items()} + + +############################################ +## Channel和Symbol的印射 +############################################ +channelSymbolMap = {} + +# USD +channelSymbolMap['ok_sub_spotusd_btc_ticker'] = BTC_USD_SPOT +channelSymbolMap['ok_sub_spotusd_ltc_ticker'] = LTC_USD_SPOT + +channelSymbolMap['ok_sub_spotusd_btc_depth_20'] = BTC_USD_SPOT +channelSymbolMap['ok_sub_spotusd_ltc_depth_20'] = LTC_USD_SPOT + +# CNY +channelSymbolMap['ok_sub_spotcny_btc_ticker'] = BTC_CNY_SPOT +channelSymbolMap['ok_sub_spotcny_ltc_ticker'] = LTC_CNY_SPOT + +channelSymbolMap['ok_sub_spotcny_btc_depth_20'] = BTC_CNY_SPOT +channelSymbolMap['ok_sub_spotcny_ltc_depth_20'] = LTC_CNY_SPOT + + + + +######################################################################## +class OkcoinGateway(VtGateway): + """OkCoin接口""" + + #---------------------------------------------------------------------- + def __init__(self, eventEngine, gatewayName='OKCOIN'): + """Constructor""" + super(OkcoinGateway, self).__init__(eventEngine, gatewayName) + + self.api = Api(self) + + self.leverage = 0 + self.connected = False + + #---------------------------------------------------------------------- + def connect(self): + """连接""" + # 载入json文件 + fileName = self.gatewayName + '_connect.json' + fileName = os.getcwd() + '/okcoinGateway/' + fileName + + try: + f = file(fileName) + except IOError: + log = VtLogData() + log.gatewayName = self.gatewayName + log.logContent = u'读取连接配置出错,请检查' + self.onLog(log) + return + + # 解析json文件 + setting = json.load(f) + try: + host = str(setting['host']) + apiKey = str(setting['apiKey']) + secretKey = str(setting['secretKey']) + trace = setting['trace'] + leverage = setting['leverage'] + except KeyError: + log = VtLogData() + log.gatewayName = self.gatewayName + log.logContent = u'连接配置缺少字段,请检查' + self.onLog(log) + return + + # 初始化接口 + self.leverage = leverage + + if host == 'CNY': + host = vnokcoin.OKCOIN_CNY + else: + host = vnokcoin.OKCOIN_USD + + self.api.connect(host, apiKey, secretKey, trace) + + log = VtLogData() + log.gatewayName = self.gatewayName + log.logContent = u'接口初始化成功' + self.onLog(log) + + # 启动查询 + self.initQuery() + self.startQuery() + + #---------------------------------------------------------------------- + def subscribe(self, subscribeReq): + """订阅行情""" + pass + + #---------------------------------------------------------------------- + def sendOrder(self, orderReq): + """发单""" + return self.api.spotSendOrder(orderReq) + + #---------------------------------------------------------------------- + def cancelOrder(self, cancelOrderReq): + """撤单""" + self.api.spotCancel(cancelOrderReq) + + #---------------------------------------------------------------------- + def qryAccount(self): + """查询账户资金""" + self.api.spotUserInfo() + + #---------------------------------------------------------------------- + def qryPosition(self): + """查询持仓""" + pass + + #---------------------------------------------------------------------- + def close(self): + """关闭""" + pass + + #---------------------------------------------------------------------- + def initQuery(self): + """初始化连续查询""" + if self.qryEnabled: + # 需要循环的查询函数列表 + self.qryFunctionList = [self.qryAccount] + + self.qryCount = 0 # 查询触发倒计时 + self.qryTrigger = 2 # 查询触发点 + self.qryNextFunction = 0 # 上次运行的查询函数索引 + + self.startQuery() + + #---------------------------------------------------------------------- + def query(self, event): + """注册到事件处理引擎上的查询函数""" + self.qryCount += 1 + + if self.qryCount > self.qryTrigger: + # 清空倒计时 + self.qryCount = 0 + + # 执行查询函数 + function = self.qryFunctionList[self.qryNextFunction] + function() + + # 计算下次查询函数的索引,如果超过了列表长度,则重新设为0 + self.qryNextFunction += 1 + if self.qryNextFunction == len(self.qryFunctionList): + self.qryNextFunction = 0 + + #---------------------------------------------------------------------- + def startQuery(self): + """启动连续查询""" + self.eventEngine.register(EVENT_TIMER, self.query) + + #---------------------------------------------------------------------- + def setQryEnabled(self, qryEnabled): + """设置是否要启动循环查询""" + self.qryEnabled = qryEnabled + + + +######################################################################## +class Api(vnokcoin.OkCoinApi): + """OkCoin的API实现""" + + #---------------------------------------------------------------------- + def __init__(self, gateway): + """Constructor""" + super(Api, self).__init__() + + self.gateway = gateway # gateway对象 + self.gatewayName = gateway.gatewayName # gateway对象名称 + + self.cbDict = {} + self.tickDict = {} + self.orderDict = {} + + self.lastOrderID = '' + self.orderCondition = Condition() + + self.initCallback() + + #---------------------------------------------------------------------- + def onMessage(self, ws, evt): + """信息推送""" + data = self.readData(evt)[0] + channel = data['channel'] + callback = self.cbDict[channel] + callback(data) + + #---------------------------------------------------------------------- + def onError(self, ws, evt): + """错误推送""" + error = VtErrorData() + error.gatewayName = self.gatewayName + error.errorMsg = str(evt) + self.gateway.onError(error) + + #---------------------------------------------------------------------- + def onClose(self, ws): + """接口断开""" + self.gateway.connected = True + self.writeLog(u'服务器连接断开') + + #---------------------------------------------------------------------- + def onOpen(self, ws): + self.gateway.connected = True + self.writeLog(u'服务器连接成功') + + # 连接后查询账户和委托数据 + self.spotUserInfo() + + self.spotOrderInfo(vnokcoin.TRADING_SYMBOL_LTC, '-1') + self.spotOrderInfo(vnokcoin.TRADING_SYMBOL_BTC, '-1') + + # 连接后订阅现货的成交和账户数据 + self.subscribeSpotTrades() + self.subscribeSpotUserInfo() + + self.subscribeSpotTicker(vnokcoin.SYMBOL_BTC) + self.subscribeSpotTicker(vnokcoin.SYMBOL_LTC) + + self.subscribeSpotDepth(vnokcoin.SYMBOL_BTC, vnokcoin.DEPTH_20) + self.subscribeSpotDepth(vnokcoin.SYMBOL_LTC, vnokcoin.DEPTH_20) + + # 如果连接的是USD网站则订阅期货相关回报数据 + if self.currency == vnokcoin.CURRENCY_USD: + self.subscribeFutureTrades() + self.subscribeFutureUserInfo() + self.subscribeFuturePositions() + + # 返回合约信息 + if self.currency == vnokcoin.CURRENCY_CNY: + l = self.generateCnyContract() + else: + l = self.generateUsdContract() + + for contract in l: + contract.gatewayName = self.gatewayName + self.gateway.onContract(contract) + + #---------------------------------------------------------------------- + def writeLog(self, content): + """快速记录日志""" + log = VtLogData() + log.gatewayName = self.gatewayName + log.logContent = content + self.gateway.onLog(log) + + #---------------------------------------------------------------------- + def initCallback(self): + """初始化回调函数""" + # USD_SPOT + self.cbDict['ok_sub_spotusd_btc_ticker'] = self.onTicker + self.cbDict['ok_sub_spotusd_ltc_ticker'] = self.onTicker + + self.cbDict['ok_sub_spotusd_btc_depth_20'] = self.onDepth + self.cbDict['ok_sub_spotusd_ltc_depth_20'] = self.onDepth + + self.cbDict['ok_spotusd_userinfo'] = self.onSpotUserInfo + self.cbDict['ok_spotusd_orderinfo'] = self.onSpotOrderInfo + + self.cbDict['ok_sub_spotusd_userinfo'] = self.onSpotSubUserInfo + self.cbDict['ok_sub_spotusd_trades'] = self.onSpotSubTrades + + self.cbDict['ok_spotusd_trade'] = self.onSpotTrade + self.cbDict['ok_spotusd_cancel_order'] = self.onSpotCancelOrder + + # CNY_SPOT + self.cbDict['ok_sub_spotcny_btc_ticker'] = self.onTicker + self.cbDict['ok_sub_spotcny_ltc_ticker'] = self.onTicker + + self.cbDict['ok_sub_spotcny_btc_depth_20'] = self.onDepth + self.cbDict['ok_sub_spotcny_ltc_depth_20'] = self.onDepth + + self.cbDict['ok_spotcny_userinfo'] = self.onSpotUserInfo + self.cbDict['ok_spotcny_orderinfo'] = self.onSpotOrderInfo + + self.cbDict['ok_sub_spotcny_userinfo'] = self.onSpotSubUserInfo + self.cbDict['ok_sub_spotcny_trades'] = self.onSpotSubTrades + + self.cbDict['ok_spotcny_trade'] = self.onSpotTrade + self.cbDict['ok_spotcny_cancel_order'] = self.onSpotCancelOrder + + # USD_FUTURES + + #---------------------------------------------------------------------- + def onTicker(self, data): + """""" + if 'data' not in data: + return + + channel = data['channel'] + symbol = channelSymbolMap[channel] + + if symbol not in self.tickDict: + tick = VtTickData() + tick.symbol = symbol + tick.vtSymbol = symbol + tick.gatewayName = self.gatewayName + self.tickDict[symbol] = tick + else: + tick = self.tickDict[symbol] + + rawData = data['data'] + tick.highPrice = float(rawData['high']) + tick.lowPrice = float(rawData['low']) + tick.lastPrice = float(rawData['last']) + tick.volume = float(rawData['vol'].replace(',', '')) + tick.date, tick.time = generateDateTime(rawData['timestamp']) + + newtick = copy(tick) + self.gateway.onTick(newtick) + + #---------------------------------------------------------------------- + def onDepth(self, data): + """""" + if 'data' not in data: + return + + channel = data['channel'] + symbol = channelSymbolMap[channel] + + if symbol not in self.tickDict: + tick = VtTickData() + tick.symbol = symbol + tick.vtSymbol = symbol + tick.gatewayName = self.gatewayName + self.tickDict[symbol] = tick + else: + tick = self.tickDict[symbol] + + if 'data' not in data: + return + rawData = data['data'] + + tick.bidPrice1, tick.bidVolume1 = rawData['bids'][0] + tick.bidPrice2, tick.bidVolume2 = rawData['bids'][1] + tick.bidPrice3, tick.bidVolume3 = rawData['bids'][2] + tick.bidPrice4, tick.bidVolume4 = rawData['bids'][3] + tick.bidPrice5, tick.bidVolume5 = rawData['bids'][4] + + tick.askPrice1, tick.askVolume1 = rawData['asks'][0] + tick.askPrice2, tick.askVolume2 = rawData['asks'][1] + tick.askPrice3, tick.askVolume3 = rawData['asks'][2] + tick.askPrice4, tick.askVolume4 = rawData['asks'][3] + tick.askPrice5, tick.askVolume5 = rawData['asks'][4] + + newtick = copy(tick) + self.gateway.onTick(newtick) + + #---------------------------------------------------------------------- + def onSpotUserInfo(self, data): + """现货账户资金推送""" + rawData = data['data'] + info = rawData['info'] + funds = rawData['info']['funds'] + + # 持仓信息 + for symbol in ['btc', 'ltc', self.currency]: + if symbol in funds['free']: + pos = VtPositionData() + pos.gatewayName = self.gatewayName + + pos.symbol = symbol + pos.vtSymbol = symbol + pos.vtPositionName = symbol + pos.direction = DIRECTION_NET + + pos.frozen = float(funds['freezed'][symbol]) + pos.position = pos.frozen + float(funds['free'][symbol]) + + self.gateway.onPosition(pos) + + # 账户资金 + account = VtAccountData() + account.gatewayName = self.gatewayName + account.accountID = self.gatewayName + account.vtAccountID = account.accountID + account.balance = float(funds['asset']['net']) + self.gateway.onAccount(account) + + #---------------------------------------------------------------------- + def onSpotSubUserInfo(self, data): + """现货账户资金推送""" + if 'data' not in data: + return + + rawData = data['data'] + info = rawData['info'] + + # 持仓信息 + for symbol in ['btc', 'ltc', self.currency]: + if symbol in info['free']: + pos = VtPositionData() + pos.gatewayName = self.gatewayName + + pos.symbol = symbol + pos.vtSymbol = symbol + pos.vtPositionName = symbol + pos.direction = DIRECTION_NET + + pos.frozen = float(info['freezed'][symbol]) + pos.position = pos.frozen + float(info['free'][symbol]) + + self.gateway.onPosition(pos) + + #---------------------------------------------------------------------- + def onSpotSubTrades(self, data): + """成交和委托推送""" + if 'data' not in data: + return + rawData = data['data'] + + # 委托信息 + orderID = str(rawData['orderId']) + if orderID not in self.orderDict: + order = VtOrderData() + order.gatewayName = self.gatewayName + + order.symbol = spotSymbolMap[rawData['symbol']] + order.vtSymbol = order.symbol + + order.orderID = str(rawData['orderId']) + order.vtOrderID = '.'.join([self.gatewayName, order.orderID]) + + order.price = float(rawData['tradeUnitPrice']) + order.totalVolume = float(rawData['tradeAmount']) + order.direction, priceType = priceTypeMap[rawData['tradeType']] + + self.orderDict[orderID] = order + else: + order = self.orderDict[orderID] + + order.tradedVolume = float(rawData['completedTradeAmount']) + order.status = statusMap[rawData['status']] + + self.gateway.onOrder(copy(order)) + + # 成交信息 + if 'sigTradeAmount' in rawData and float(rawData['sigTradeAmount'])>0: + trade = VtTradeData() + trade.gatewayName = self.gatewayName + + trade.symbol = spotSymbolMap[rawData['symbol']] + trade.vtSymbol = order.symbol + + trade.tradeID = str(rawData['id']) + trade.vtTradeID = '.'.join([self.gatewayName, trade.tradeID]) + + trade.orderID = str(rawData['orderId']) + trade.vtOrderID = '.'.join([self.gatewayName, trade.orderID]) + + trade.price = float(rawData['sigTradePrice']) + trade.volume = float(rawData['sigTradeAmount']) + + trade.direction, priceType = priceTypeMap[rawData['tradeType']] + + trade.tradeTime = datetime.now().strftime('%H:%M:%S') + + self.gateway.onTrade(trade) + + #---------------------------------------------------------------------- + def onSpotOrderInfo(self, data): + """委托信息查询回调""" + rawData = data['data'] + + for d in rawData['orders']: + orderID = str(d['order_id']) + + if orderID not in self.orderDict: + order = VtOrderData() + order.gatewayName = self.gatewayName + + order.symbol = spotSymbolMap[d['symbol']] + order.vtSymbol = order.symbol + + order.orderID = str(d['order_id']) + order.vtOrderID = '.'.join([self.gatewayName, order.orderID]) + + order.price = d['price'] + order.totalVolume = d['amount'] + order.direction, priceType = priceTypeMap[d['type']] + + self.orderDict[orderID] = order + else: + order = self.orderDict[orderID] + + order.tradedVolume = d['deal_amount'] + order.status = statusMap[d['status']] + + self.gateway.onOrder(copy(order)) + + #---------------------------------------------------------------------- + def generateSpecificContract(self, contract, symbol): + """生成合约""" + new = copy(contract) + new.symbol = symbol + new.vtSymbol = symbol + new.name = symbol + return new + + #---------------------------------------------------------------------- + def generateCnyContract(self): + """生成CNY合约信息""" + contractList = [] + + contract = VtContractData() + contract.exchange = EXCHANGE_OKCOIN + contract.productClass = PRODUCT_SPOT + contract.size = 1 + contract.priceTick = 0.01 + + contractList.append(self.generateSpecificContract(contract, BTC_CNY_SPOT)) + contractList.append(self.generateSpecificContract(contract, LTC_CNY_SPOT)) + + return contractList + + #---------------------------------------------------------------------- + def generateUsdContract(self): + """生成USD合约信息""" + contractList = [] + + # 现货 + contract = VtContractData() + contract.exchange = EXCHANGE_OKCOIN + contract.productClass = PRODUCT_SPOT + contract.size = 1 + contract.priceTick = 0.01 + + contractList.append(self.generateSpecificContract(contract, BTC_USD_SPOT)) + contractList.append(self.generateSpecificContract(contract, LTC_USD_SPOT)) + + # 期货 + contract.productClass = PRODUCT_FUTURES + + contractList.append(self.generateSpecificContract(contract, BTC_USD_THISWEEK)) + contractList.append(self.generateSpecificContract(contract, BTC_USD_NEXTWEEK)) + contractList.append(self.generateSpecificContract(contract, BTC_USD_QUARTER)) + contractList.append(self.generateSpecificContract(contract, LTC_USD_THISWEEK)) + contractList.append(self.generateSpecificContract(contract, LTC_USD_NEXTWEEK)) + contractList.append(self.generateSpecificContract(contract, LTC_USD_QUARTER)) + + return contractList + + #---------------------------------------------------------------------- + def onSpotTrade(self, data): + """委托回报""" + rawData = data['data'] + self.lastOrderID = rawData['order_id'] + + # 收到委托号后,通知发送委托的线程返回委托号 + self.orderCondition.acquire() + self.orderCondition.notify() + self.orderCondition.release() + + #---------------------------------------------------------------------- + def onSpotCancelOrder(self, data): + """撤单回报""" + pass + + #---------------------------------------------------------------------- + def spotSendOrder(self, req): + """发单""" + symbol = spotSymbolMapReverse[req.symbol][:4] + type_ = priceTypeMapReverse[(req.direction, req.priceType)] + self.spotTrade(symbol, type_, str(req.price), str(req.volume)) + + # 等待发单回调推送委托号信息 + self.orderCondition.acquire() + self.orderCondition.wait() + self.orderCondition.release() + + vtOrderID = '.'.join([self.gatewayName, self.lastOrderID]) + self.lastOrderID = '' + return vtOrderID + + #---------------------------------------------------------------------- + def spotCancel(self, req): + """撤单""" + symbol = spotSymbolMapReverse[req.symbol][:4] + self.spotCancelOrder(symbol, req.orderID) + + +#---------------------------------------------------------------------- +def generateDateTime(s): + """生成时间""" + dt = datetime.fromtimestamp(float(s)/1e3) + time = dt.strftime("%H:%M:%S.%f") + date = dt.strftime("%Y%m%d") + return date, time \ No newline at end of file diff --git a/vn.trader/okcoinGateway/vnokcoin.py b/vn.trader/okcoinGateway/vnokcoin.py new file mode 100644 index 00000000..b5da6789 --- /dev/null +++ b/vn.trader/okcoinGateway/vnokcoin.py @@ -0,0 +1,382 @@ +# encoding: UTF-8 + +import hashlib +import zlib +import json +from time import sleep +from threading import Thread + +import websocket + + +# OKCOIN网站 +OKCOIN_CNY = 'wss://real.okcoin.cn:10440/websocket/okcoinapi' +OKCOIN_USD = 'wss://real.okcoin.com:10440/websocket/okcoinapi' + +# 账户货币代码 +CURRENCY_CNY = 'cny' +CURRENCY_USD = 'usd' + +# 电子货币代码 +SYMBOL_BTC = 'btc' +SYMBOL_LTC = 'ltc' + +# 行情深度 +DEPTH_20 = 20 +DEPTH_60 = 60 + +# K线时间区间 +INTERVAL_1M = '1min' +INTERVAL_3M = '3min' +INTERVAL_5M = '5min' +INTERVAL_15M = '15min' +INTERVAL_30M = '30min' +INTERVAL_1H = '1hour' +INTERVAL_2H = '2hour' +INTERVAL_4H = '4hour' +INTERVAL_6H = '6hour' +INTERVAL_1D = 'day' +INTERVAL_3D = '3day' +INTERVAL_1W = 'week' + +# 交易代码,需要后缀货币名才能完整 +TRADING_SYMBOL_BTC = 'btc_' +TRADING_SYMBOL_LTC = 'ltc_' + +# 委托类型 +TYPE_BUY = 'buy' +TYPE_SELL = 'sell' +TYPE_BUY_MARKET = 'buy_market' +TYPE_SELL_MARKET = 'sell_market' + +# 期货合约到期类型 +FUTURE_EXPIRY_THIS_WEEK = 'this_week' +FUTURE_EXPIRY_NEXT_WEEK = 'next_week' +FUTURE_EXPIRY_QUARTER = 'quarter' + +# 期货委托类型 +FUTURE_TYPE_LONG = 1 +FUTURE_TYPE_SHORT = 2 +FUTURE_TYPE_SELL = 3 +FUTURE_TYPE_COVER = 4 + +# 期货是否用现价 +FUTURE_ORDER_MARKET = 1 +FUTURE_ORDER_LIMIT = 0 + +# 期货杠杆 +FUTURE_LEVERAGE_10 = 10 +FUTURE_LEVERAGE_20 = 20 + +# 委托状态 +ORDER_STATUS_NOTTRADED = 0 +ORDER_STATUS_PARTTRADED = 1 +ORDER_STATUS_ALLTRADED = 2 +ORDER_STATUS_CANCELLED = -1 +ORDER_STATUS_CANCELLING = 4 + + +######################################################################## +class OkCoinApi(object): + """基于Websocket的API对象""" + + #---------------------------------------------------------------------- + def __init__(self): + """Constructor""" + self.apiKey = '' # 用户名 + self.secretKey = '' # 密码 + self.host = '' # 服务器地址 + + self.currency = '' # 货币类型(usd或者cny) + + self.ws = None # websocket应用对象 + self.thread = None # 工作线程 + + ####################### + ## 通用函数 + ####################### + + #---------------------------------------------------------------------- + def readData(self, evt): + """解压缩推送收到的数据""" + # 创建解压器 + decompress = zlib.decompressobj(-zlib.MAX_WBITS) + + # 将原始数据解压成字符串 + inflated = decompress.decompress(evt) + decompress.flush() + + # 通过json解析字符串 + data = json.loads(inflated) + + return data + + #---------------------------------------------------------------------- + def generateSign(self, params): + """生成签名""" + l = [] + for key in sorted(params.keys()): + l.append('%s=%s' %(key, params[key])) + l.append('secret_key=%s' %self.secretKey) + sign = '&'.join(l) + return hashlib.md5(sign.encode('utf-8')).hexdigest().upper() + + #---------------------------------------------------------------------- + def onMessage(self, ws, evt): + """信息推送""" + print 'onMessage' + data = self.readData(evt) + print data + + #---------------------------------------------------------------------- + def onError(self, ws, evt): + """错误推送""" + print 'onError' + print evt + + #---------------------------------------------------------------------- + def onClose(self, ws): + """接口断开""" + print 'onClose' + + #---------------------------------------------------------------------- + def onOpen(self, ws): + """接口打开""" + print 'onOpen' + + #---------------------------------------------------------------------- + def connect(self, host, apiKey, secretKey, trace=False): + """连接服务器""" + self.host = host + self.apiKey = apiKey + self.secretKey = secretKey + + if self.host == OKCOIN_CNY: + self.currency = CURRENCY_CNY + else: + self.currency = CURRENCY_USD + + websocket.enableTrace(trace) + + self.ws = websocket.WebSocketApp(host, + on_message=self.onMessage, + on_error=self.onError, + on_close=self.onClose, + on_open=self.onOpen) + + self.thread = Thread(target=self.ws.run_forever) + self.thread.start() + + #---------------------------------------------------------------------- + def sendMarketDataRequest(self, channel): + """发送行情请求""" + # 生成请求 + d = {} + d['event'] = 'addChannel' + d['binary'] = True + d['channel'] = channel + + # 使用json打包并发送 + j = json.dumps(d) + self.ws.send(j) + + #---------------------------------------------------------------------- + def sendTradingRequest(self, channel, params): + """发送交易请求""" + # 在参数字典中加上api_key和签名字段 + params['api_key'] = self.apiKey + params['sign'] = self.generateSign(params) + + # 生成请求 + d = {} + d['event'] = 'addChannel' + d['binary'] = True + d['channel'] = channel + d['parameters'] = params + + # 使用json打包并发送 + j = json.dumps(d) + self.ws.send(j) + + ####################### + ## 现货相关 + ####################### + + #---------------------------------------------------------------------- + def subscribeSpotTicker(self, symbol): + """订阅现货普通报价""" + self.sendMarketDataRequest('ok_sub_spot%s_%s_ticker' %(self.currency, symbol)) + + #---------------------------------------------------------------------- + def subscribeSpotDepth(self, symbol, depth): + """订阅现货深度报价""" + self.sendMarketDataRequest('ok_sub_spot%s_%s_depth_%s' %(self.currency, symbol, depth)) + + #---------------------------------------------------------------------- + def subscribeSpotTradeData(self, symbol): + """订阅现货成交记录""" + self.sendMarketDataRequest('ok_sub_spot%s_%s_trades' %(self.currency, symbol)) + + #---------------------------------------------------------------------- + def subscribeSpotKline(self, symbol, interval): + """订阅现货K线""" + self.sendMarketDataRequest('ok_sub_spot%s_%s_kline_%s' %(self.currency, symbol, interval)) + + #---------------------------------------------------------------------- + def spotTrade(self, symbol, type_, price, amount): + """现货委托""" + params = {} + params['symbol'] = str(symbol+self.currency) + params['type'] = str(type_) + params['price'] = str(price) + params['amount'] = str(amount) + + channel = 'ok_spot%s_trade' %(self.currency) + + self.sendTradingRequest(channel, params) + + #---------------------------------------------------------------------- + def spotCancelOrder(self, symbol, orderid): + """现货撤单""" + params = {} + params['symbol'] = str(symbol+self.currency) + params['order_id'] = str(orderid) + + channel = 'ok_spot%s_cancel_order' %(self.currency) + + self.sendTradingRequest(channel, params) + + #---------------------------------------------------------------------- + def spotUserInfo(self): + """查询现货账户""" + channel = 'ok_spot%s_userinfo' %(self.currency) + + self.sendTradingRequest(channel, {}) + + #---------------------------------------------------------------------- + def spotOrderInfo(self, symbol, orderid): + """查询现货委托信息""" + params = {} + params['symbol'] = str(symbol+self.currency) + params['order_id'] = str(orderid) + + channel = 'ok_spot%s_orderinfo' %(self.currency) + + self.sendTradingRequest(channel, params) + + #---------------------------------------------------------------------- + def subscribeSpotTrades(self): + """订阅现货成交信息""" + channel = 'ok_sub_spot%s_trades' %(self.currency) + + self.sendTradingRequest(channel, {}) + + #---------------------------------------------------------------------- + def subscribeSpotUserInfo(self): + """订阅现货账户信息""" + channel = 'ok_sub_spot%s_userinfo' %(self.currency) + + self.sendTradingRequest(channel, {}) + + ####################### + ## 期货相关 + ####################### + + #---------------------------------------------------------------------- + def subscribeFutureTicker(self, symbol, expiry): + """订阅期货普通报价""" + self.sendMarketDataRequest('ok_sub_future%s_%s_ticker_%s' %(self.currency, symbol, expiry)) + + #---------------------------------------------------------------------- + def subscribeFutureDepth(self, symbol, expiry, depth): + """订阅期货深度报价""" + self.sendMarketDataRequest('ok_sub_future%s_%s_depth_%s_%s' %(self.currency, symbol, + expiry, depth)) + + #---------------------------------------------------------------------- + def subscribeFutureTradeData(self, symbol, expiry): + """订阅期货成交记录""" + self.sendMarketDataRequest('ok_sub_future%s_%s_trade_%s' %(self.currency, symbol, expiry)) + + #---------------------------------------------------------------------- + def subscribeFutureKline(self, symbol, expiry, interval): + """订阅期货K线""" + self.sendMarketDataRequest('ok_sub_future%s_%s_kline_%s_%s' %(self.currency, symbol, + expiry, interval)) + + #---------------------------------------------------------------------- + def subscribeFutureIndex(self, symbol): + """订阅期货指数""" + self.sendMarketDataRequest('ok_sub_future%s_%s_index' %(self.currency, symbol)) + + #---------------------------------------------------------------------- + def futureTrade(self, symbol, expiry, type_, price, amount, order, leverage): + """期货委托""" + params = {} + params['symbol'] = str(symbol+self.currency) + params['type'] = str(type_) + params['price'] = str(price) + params['amount'] = str(amount) + params['contract_type'] = str(expiry) + params['match_price'] = str(order) + params['lever_rate'] = str(leverage) + + channel = 'ok_future%s_trade' %(self.currency) + + self.sendTradingRequest(channel, params) + + #---------------------------------------------------------------------- + def futureCancelOrder(self, symbol, expiry, orderid): + """期货撤单""" + params = {} + params['symbol'] = str(symbol+self.currency) + params['order_id'] = str(orderid) + params['contract_type'] = str(expiry) + + channel = 'ok_future%s_cancel_order' %(self.currency) + + self.sendTradingRequest(channel, params) + + #---------------------------------------------------------------------- + def futureUserInfo(self): + """查询期货账户""" + channel = 'ok_future%s_userinfo' %(self.currency) + + self.sendTradingRequest(channel, {}) + + #---------------------------------------------------------------------- + def futureOrderInfo(self, symbol, expiry, orderid, status, page, length): + """查询期货委托信息""" + params = {} + params['symbol'] = str(symbol+self.currency) + params['order_id'] = str(orderid) + params['contract_type'] = expiry + params['status'] = status + params['current_page'] = page + params['page_length'] = length + + channel = 'ok_future%s_orderinfo' + + self.sendTradingRequest(channel, params) + + #---------------------------------------------------------------------- + def subscribeFutureTrades(self): + """订阅期货成交信息""" + channel = 'ok_sub_future%s_trades' %(self.currency) + + self.sendTradingRequest(channel, {}) + + #---------------------------------------------------------------------- + def subscribeFutureUserInfo(self): + """订阅期货账户信息""" + channel = 'ok_sub_future%s_userinfo' %(self.currency) + + self.sendTradingRequest(channel, {}) + + #---------------------------------------------------------------------- + def subscribeFuturePositions(self): + """订阅期货持仓信息""" + channel = 'ok_sub_future%s_positions' %(self.currency) + + self.sendTradingRequest(channel, {}) + + diff --git a/vn.trader/uiBasicWidget.py b/vn.trader/uiBasicWidget.py index 7fe68f35..f67e4bd4 100644 --- a/vn.trader/uiBasicWidget.py +++ b/vn.trader/uiBasicWidget.py @@ -70,24 +70,6 @@ class DirectionCell(QtGui.QTableWidgetItem): self.setText(text) -######################################################################## -class NameCell(QtGui.QTableWidgetItem): - """用来显示合约中文名的单元格""" - - #---------------------------------------------------------------------- - def __init__(self, text=None, mainEngine=None): - """Constructor""" - super(NameCell, self).__init__() - self.data = None - if text: - self.setContent(text) - - #---------------------------------------------------------------------- - def setContent(self, text): - """设置内容""" - self.setText(text) - - ######################################################################## class NameCell(QtGui.QTableWidgetItem): """用来显示合约中文的单元格""" @@ -458,7 +440,8 @@ class ErrorMonitor(BasicMonitor): """Constructor""" super(ErrorMonitor, self).__init__(mainEngine, eventEngine, parent) - d = OrderedDict() + d = OrderedDict() + d['errorTime'] = {'chinese':u'错误时间', 'cellType':BasicCell} d['errorID'] = {'chinese':u'错误代码', 'cellType':BasicCell} d['errorMsg'] = {'chinese':u'错误信息', 'cellType':BasicCell} d['additionalInfo'] = {'chinese':u'补充信息', 'cellType':BasicCell} diff --git a/vn.trader/uiMainWindow.py b/vn.trader/uiMainWindow.py index 32de7b33..6e77699c 100644 --- a/vn.trader/uiMainWindow.py +++ b/vn.trader/uiMainWindow.py @@ -10,6 +10,7 @@ from riskManager.uiRmWidget import RmEngineManager ######################################################################## class MainWindow(QtGui.QMainWindow): """主窗口""" + signalStatusBar = QtCore.pyqtSignal(type(Event())) #---------------------------------------------------------------------- def __init__(self, mainEngine, eventEngine): @@ -88,6 +89,9 @@ class MainWindow(QtGui.QMainWindow): connectOandaAction = QtGui.QAction(u'连接OANDA', self) connectOandaAction.triggered.connect(self.connectOanda) + connectOkcoinAction = QtGui.QAction(u'连接OKCOIN', self) + connectOkcoinAction.triggered.connect(self.connectOkcoin) + connectDbAction = QtGui.QAction(u'连接数据库', self) connectDbAction.triggered.connect(self.mainEngine.dbConnect) @@ -136,6 +140,8 @@ class MainWindow(QtGui.QMainWindow): sysMenu.addAction(connectIbAction) if 'OANDA' in self.mainEngine.gatewayDict: sysMenu.addAction(connectOandaAction) + if 'OKCOIN' in self.mainEngine.gatewayDict: + sysMenu.addAction(connectOkcoinAction) sysMenu.addSeparator() if 'Wind' in self.mainEngine.gatewayDict: sysMenu.addAction(connectWindAction) @@ -169,7 +175,8 @@ class MainWindow(QtGui.QMainWindow): self.sbCount = 0 self.sbTrigger = 10 # 10秒刷新一次 - self.eventEngine.register(EVENT_TIMER, self.updateStatusBar) + self.signalStatusBar.connect(self.updateStatusBar) + self.eventEngine.register(EVENT_TIMER, self.signalStatusBar.emit) #---------------------------------------------------------------------- def updateStatusBar(self, event): @@ -237,6 +244,11 @@ class MainWindow(QtGui.QMainWindow): """连接OANDA""" self.mainEngine.connect('OANDA') + #---------------------------------------------------------------------- + def connectOkcoin(self): + """连接OKCOIN""" + self.mainEngine.connect('OKCOIN') + #---------------------------------------------------------------------- def test(self): """测试按钮用的函数""" @@ -327,8 +339,17 @@ class MainWindow(QtGui.QMainWindow): def loadWindowSettings(self): """载入窗口设置""" settings = QtCore.QSettings('vn.py', 'vn.trader') - self.restoreState(settings.value('state').toByteArray()) - self.restoreGeometry(settings.value('geometry').toByteArray()) + # 这里由于PyQt4的版本不同,settings.value('state')调用返回的结果可能是: + # 1. None(初次调用,注册表里无相应记录,因此为空) + # 2. QByteArray(比较新的PyQt4) + # 3. QVariant(以下代码正确执行所需的返回结果) + # 所以为了兼容考虑,这里加了一个try...except,如果是1、2的情况就pass + # 可能导致主界面的设置无法载入(每次退出时的保存其实是成功了) + try: + self.restoreState(settings.value('state').toByteArray()) + self.restoreGeometry(settings.value('geometry').toByteArray()) + except AttributeError: + pass ######################################################################## diff --git a/vn.trader/vtConstant.py b/vn.trader/vtConstant.py index d8ed868a..380a158c 100644 --- a/vn.trader/vtConstant.py +++ b/vn.trader/vtConstant.py @@ -69,6 +69,7 @@ EXCHANGE_GLOBEX = 'GLOBEX' # CME电子交易平台 EXCHANGE_IDEALPRO = 'IDEALPRO' # IB外汇ECN EXCHANGE_OANDA = 'OANDA' # OANDA外汇做市商 +EXCHANGE_OKCOIN = 'OKCOIN' # OKCOIN比特币交易所 # 货币类型 CURRENCY_USD = 'USD' # 美元 diff --git a/vn.trader/vtEngine.py b/vn.trader/vtEngine.py index 4f9fe850..583d4fc9 100644 --- a/vn.trader/vtEngine.py +++ b/vn.trader/vtEngine.py @@ -114,6 +114,13 @@ class MainEngine(object): self.gatewayDict['OANDA'].setQryEnabled(True) except Exception, e: print e + + try: + from okcoinGateway.okcoinGateway import OkcoinGateway + self.addGateway(OkcoinGateway, 'OKCOIN') + self.gatewayDict['OKCOIN'].setQryEnabled(True) + except Exception, e: + print e #---------------------------------------------------------------------- def addGateway(self, gateway, gatewayName=None): @@ -165,7 +172,7 @@ class MainEngine(object): """查询特定接口的账户""" if gatewayName in self.gatewayDict: gateway = self.gatewayDict[gatewayName] - gateway.getAccount() + gateway.qryAccount() else: self.writeLog(u'接口不存在:%s' %gatewayName) @@ -174,7 +181,7 @@ class MainEngine(object): """查询特定接口的持仓""" if gatewayName in self.gatewayDict: gateway = self.gatewayDict[gatewayName] - gateway.getPosition() + gateway.qryPosition() else: self.writeLog(u'接口不存在:%s' %gatewayName) @@ -188,6 +195,9 @@ class MainEngine(object): # 停止事件引擎 self.eventEngine.stop() + # 停止数据记录引擎 + self.drEngine.stop() + # 保存数据引擎里的合约数据到硬盘 self.dataEngine.saveContracts() diff --git a/vn.trader/vtGateway.py b/vn.trader/vtGateway.py index 7a590964..3967c1a6 100644 --- a/vn.trader/vtGateway.py +++ b/vn.trader/vtGateway.py @@ -331,6 +331,8 @@ class VtErrorData(VtBaseData): self.errorID = EMPTY_STRING # 错误代码 self.errorMsg = EMPTY_UNICODE # 错误信息 self.additionalInfo = EMPTY_UNICODE # 补充信息 + + self.errorTime = time.strftime('%X', time.localtime()) # 错误生成时间 ######################################################################## @@ -353,7 +355,7 @@ class VtContractData(VtBaseData): #---------------------------------------------------------------------- def __init__(self): """Constructor""" - super(VtBaseData, self).__init__() + super(VtContractData, self).__init__() self.symbol = EMPTY_STRING # 代码 self.exchange = EMPTY_STRING # 交易所代码