如果我看一下这里:https://docs.python.org/2/library/struct.html在第7.3.2.2节。对于Python类型,格式的整型字符没有6个。我试过“6p”甚至“3H”,但这不起作用,例如:
import struct
struct.calcsize('!6p')
抱歉,如果这听起来很蠢。。。我正在学习如何第一次将字符串转换为压缩的二进制数据,对于长度为6且值为整数的字符串消息。那么,对于一个整数来说,得到标准大小6的正确字母格式是什么呢?在
我的任务是转换^{ 因此,例如,如果您查看第4.1节:系统事件消息(第3页),我将转换类型为“S”的消息,如下所示: 我得到这个错误: 所以我假设我的错误与'6p'有关,因为我找不到任何标准大小为6的整数。在 更新2 因此,我使用以下建议,即使用 我得到这个错误: 这很奇怪,因为 谢谢大家的帮助!在struct.error: unpack requires a string argument of length 11
6s
而不是6p
,对于文档第4.6节:净订单不平衡指示符(NOII)消息中的以下消息类型“I”,我确实:class NoiiMessage(ITCH41MarketMessage):
type = 'I'
description = "NOII Message"
message_size = struct.calcsize("!HH6sQQc8sIIIcc") + 1
def __init__(self, message):
(self.locate,self.tracking,self.timestamp, self.pairedShares, self.imbalance,
self.imbalanceDirection, self.stock, self.farPrice, self.nearPrice,
self.currentRefPrice, self.crossType, self.priceVariationbsindicator
) = struct.unpack("!HH6sQQc8sIIIcc", message[1:])
def pack(self):
return struct.pack("!cHH6sQQc8sIIIcc", self.type,self.locate,
self.tracking, self.timestamp,
self.pairedShares, self.imbalance,
self.imbalanceDirection, self.stock,
self.farPrice, self.nearPrice,
self.currentRefPrice, self.crossType,
self.priceVariationbsindicator)
struct.error: unpack requires a string argument of length 49
!HH6sQQc8sIIIcc
的长度是49。。。在
NASDAQ TotalView-ITCH 5.0
为了得到
NASDAQ_Timestamp
,在掩模中使用
6B
或char[]
6s
只有在消费者方面需要时,才将它们后置处理成
int()
这会延迟延迟延迟和解除阻塞。在+还可以享受Python7.3.2.1。使用“!”进行BigEndian/network订购时的注意事项掩码前缀
^{pr2}$
在更新2中添加另一个问题
其中:
struct
是为处理C结构而设计的。这就是为什么它只有股票C类型。 “6字节整数”不是一个普通的C类型——你不能写一些像struct s { int6 timestamp; }
这样的东西来马上得到一个可用的整数。这就是为什么它在这里也不起作用。在那么,在C语言中,你将如何解决这个问题呢?你可能会的
unsigned char ts_data[6];
现在,我们所要做的就是用Python表达相同的内容:
相关问题 更多 >
编程相关推荐