156156"""
157157BarSizeType = c_long
158158
159+ SizeType = c_int
160+
159161"""
160162连接状态枚举
161163"""
@@ -579,91 +581,63 @@ class RspUserLoginField(Structure):
579581 ]
580582
581583
582- # 深度行情
583- class DepthMarketDataField (Structure ):
584+ # 深度行情N档
585+ class DepthMarketDataNField (Structure ):
584586 _fields_ = [
587+ # 占用总字节大小
588+ ("Size" , SizeType ),
585589 # 交易所时间
590+ # 交易日,用于给数据接收器划分到同一文件使用,基本没啥别的用处
586591 ("TradingDay" , DateIntType ),
587- # 交易日,用于给数据接收器划分到同一文件使用,基本没啥别的用处
588592 ("ActionDay" , DateIntType ),
589593 ("UpdateTime" , TimeIntType ),
590594 ("UpdateMillisec" , TimeIntType ),
591- # 最新价
595+ # 交易所代码
596+ ("Exchange" , ExchangeType ),
597+ #唯一符号
598+ ("Symbol" , SymbolType ),
599+ #合约代码
600+ ("InstrumentID" , InstrumentIDType ),
601+ #最新价
592602 ("LastPrice" , PriceType ),
593- # 数量
603+ #数量
594604 ("Volume" , LargeVolumeType ),
595- # 成交金额
605+ #成交金额
596606 ("Turnover" , MoneyType ),
597- # 持仓量
607+ #持仓量
598608 ("OpenInterest" , LargeVolumeType ),
599- # 当日均价
609+ #当日均价
600610 ("AveragePrice" , PriceType ),
601- # 今开盘
611+ #今开盘
602612 ("OpenPrice" , PriceType ),
603- # 最高价
613+ #最高价
604614 ("HighestPrice" , PriceType ),
605- # 最低价
615+ #最低价
606616 ("LowestPrice" , PriceType ),
607- # 今收盘
617+ #今收盘
608618 ("ClosePrice" , PriceType ),
609- # 本次结算价
619+ #本次结算价
610620 ("SettlementPrice" , PriceType ),
611- # 涨停板价
621+ #涨停板价
612622 ("UpperLimitPrice" , PriceType ),
613- # 跌停板价
623+ #跌停板价
614624 ("LowerLimitPrice" , PriceType ),
615- # 昨收盘
625+ #昨收盘
616626 ("PreClosePrice" , PriceType ),
617- # 上次结算价
627+ #上次结算价
618628 ("PreSettlementPrice" , PriceType ),
619- # 昨持仓量
629+ #昨持仓量
620630 ("PreOpenInterest" , LargeVolumeType ),
621- # 申买价一
622- ("BidPrice1" , PriceType ),
623- # 申买量一
624- ("BidVolume1" , VolumeType ),
625- # 申卖价一
626- ("AskPrice1" , PriceType ),
627- # 申卖量一
628- ("AskVolume1" , VolumeType ),
629- # 申买价二
630- ("BidPrice2" , PriceType ),
631- # 申买量二
632- ("BidVolume2" , VolumeType ),
633- # 申卖价二
634- ("AskPrice2" , PriceType ),
635- # 申卖量二
636- ("AskVolume2" , VolumeType ),
637- # 申买价三
638- ("BidPrice3" , PriceType ),
639- # 申买量三
640- ("BidVolume3" , VolumeType ),
641- # 申卖价三
642- ("AskPrice3" , PriceType ),
643- # 申卖量三
644- ("AskVolume3" , VolumeType ),
645- # 申买价四
646- ("BidPrice4" , PriceType ),
647- # 申买量四
648- ("BidVolume4" , VolumeType ),
649- # 申卖价四
650- ("AskPrice4" , PriceType ),
651- # 申卖量四
652- ("AskVolume4" , VolumeType ),
653- # 申买价五
654- ("BidPrice5" , PriceType ),
655- # 申买量五
656- ("BidVolume5" , VolumeType ),
657- # 申卖价五
658- ("AskPrice5" , PriceType ),
659- # 申卖量五
660- ("AskVolume5" , VolumeType ),
661- # 交易所代码
662- ("Exchange" , ExchangeType ),
663- # 唯一符号
664- ("Symbol" , SymbolType ),
665- # 合约代码
666- ("InstrumentID" , InstrumentIDType ),
631+ #买档个数
632+ ("BidCount" , SizeType )
633+ ]
634+
635+
636+ class DepthField (Structure ):
637+ _fields_ = [
638+ ("Price" , PriceType ),
639+ ("Size" , VolumeType ),
640+ ("Count" , VolumeType )
667641 ]
668642
669643
@@ -749,6 +723,8 @@ class InstrumentField(Structure):
749723 ("InstrumentID" , InstrumentIDType ),
750724 # 交易所代码
751725 ("ExchangeID" , ExchangeIDType ),
726+ # 产品代码
727+ ("ProductID" , InstrumentIDType ),
752728 # 合约名称
753729 ("InstrumentName" , InstrumentNameType ),
754730 # 基础商品代码
@@ -940,4 +916,95 @@ class HistoricalDataRequestField(Structure):
940916
941917# function
942918fnOnRespone = WINFUNCTYPE (None , c_char , c_void_p , c_void_p , c_double , c_double , c_void_p , c_int , c_void_p , c_int ,
943- c_void_p , c_int )
919+ c_void_p , c_int )
920+
921+
922+ def get_depth_market_data (p_market_data ):
923+ """
924+ 指针转换为行情数据
925+ :param p_market_data:
926+ :return:
927+ """
928+ market_data = cast (p_market_data , POINTER (DepthMarketDataNField )).contents
929+ return market_data
930+
931+
932+ def get_bid_count (p_market_data ):
933+ """
934+ Bid Count
935+ :param p_market_data:
936+ :return:
937+ """
938+ market_data = get_depth_market_data (p_market_data )
939+ return market_data .BidCount
940+
941+
942+ def get_ask_count (p_market_data ):
943+ """
944+ Ask Count
945+ :param p_market_data:
946+ :return:
947+ """
948+ market_data = get_depth_market_data (p_market_data )
949+ size = market_data .Size
950+ bid_count = market_data .BidCount
951+ count = (size - sizeof (DepthMarketDataNField )) / sizeof (DepthField )
952+ return count - bid_count
953+
954+
955+ def get_bid (p_market_data , pos ):
956+ """
957+ 获取买档,pos=1表示买1
958+ :param p_market_data:
959+ :param pos:
960+ :return:
961+ """
962+ bid_count = get_bid_count (p_market_data )
963+ if pos <= 0 or pos > bid_count :
964+ return None
965+ p = p_market_data + sizeof (DepthMarketDataNField ) + sizeof (DepthField ) * (pos - 1 )
966+ return cast (p , POINTER (DepthField )).contents
967+
968+
969+ def get_ask (p_market_data , pos ):
970+ """
971+ 获取卖档,pos=1表示卖1
972+ :param p_market_data:
973+ :param pos:
974+ :return:
975+ """
976+ ask_count = get_ask_count (p_market_data )
977+ if pos <= 0 or pos > ask_count :
978+ return None
979+ p = p_market_data + sizeof (DepthMarketDataNField ) + sizeof (DepthField ) * (
980+ get_bid_count (p_market_data ) + pos - 1 )
981+ return cast (p , POINTER (DepthField )).contents
982+
983+
984+ def get_all_bids (p_market_data ):
985+ """
986+ 获取所有买档数据
987+ :param p_market_data:
988+ :return:
989+ """
990+ total = get_bid_count (p_market_data )
991+ bids = []
992+ for i in range (0 , total ):
993+ p = p_market_data + sizeof (DepthMarketDataNField ) + sizeof (DepthField ) * i
994+ bids .append (cast (p , POINTER (DepthField )).contents )
995+ return bids
996+
997+
998+ def get_all_asks (p_market_data ):
999+ """
1000+ 获取所有卖档数据
1001+ :param p_market_data:
1002+ :return:
1003+ """
1004+ bid_count = get_bid_count (p_market_data )
1005+ total = get_ask_count (p_market_data ) + bid_count
1006+ asks = []
1007+ for i in range (bid_count , total ):
1008+ p = p_market_data + sizeof (DepthMarketDataNField ) + sizeof (DepthField ) * i
1009+ asks .append (cast (p , POINTER (DepthField )).contents )
1010+ return asks
0 commit comments