| 136 | |
| 137 | |
| 138 | class Decoder(Object): |
| 139 | def __init__(self, wrapper, serverVersion): |
| 140 | self.wrapper = wrapper |
| 141 | self.serverVersion = serverVersion |
| 142 | self.discoverParams() |
| 143 | |
| 144 | def processTickPriceMsg(self, fields): |
| 145 | decode(int, fields) |
| 146 | |
| 147 | reqId = decode(int, fields) |
| 148 | tickType = decode(int, fields) |
| 149 | price = decode(float, fields) |
| 150 | size = decode(Decimal, fields) # ver 2 field |
| 151 | attrMask = decode(int, fields) # ver 3 field |
| 152 | |
| 153 | attrib = TickAttrib() |
| 154 | |
| 155 | attrib.canAutoExecute = attrMask == 1 |
| 156 | |
| 157 | if self.serverVersion >= MIN_SERVER_VER_PAST_LIMIT: |
| 158 | attrib.canAutoExecute = attrMask & 1 != 0 |
| 159 | attrib.pastLimit = attrMask & 2 != 0 |
| 160 | if self.serverVersion >= MIN_SERVER_VER_PRE_OPEN_BID_ASK: |
| 161 | attrib.preOpen = attrMask & 4 != 0 |
| 162 | |
| 163 | self.wrapper.tickPrice(reqId, tickType, price, attrib) |
| 164 | |
| 165 | # process ver 2 fields |
| 166 | sizeTickType = TickTypeEnum.NOT_SET |
| 167 | if TickTypeEnum.BID == tickType: |
| 168 | sizeTickType = TickTypeEnum.BID_SIZE |
| 169 | elif TickTypeEnum.ASK == tickType: |
| 170 | sizeTickType = TickTypeEnum.ASK_SIZE |
| 171 | elif TickTypeEnum.LAST == tickType: |
| 172 | sizeTickType = TickTypeEnum.LAST_SIZE |
| 173 | elif TickTypeEnum.DELAYED_BID == tickType: |
| 174 | sizeTickType = TickTypeEnum.DELAYED_BID_SIZE |
| 175 | elif TickTypeEnum.DELAYED_ASK == tickType: |
| 176 | sizeTickType = TickTypeEnum.DELAYED_ASK_SIZE |
| 177 | elif TickTypeEnum.DELAYED_LAST == tickType: |
| 178 | sizeTickType = TickTypeEnum.DELAYED_LAST_SIZE |
| 179 | |
| 180 | if sizeTickType != TickTypeEnum.NOT_SET: |
| 181 | self.wrapper.tickSize(reqId, sizeTickType, size) |
| 182 | |
| 183 | def processTickPriceMsgProtoBuf(self, protobuf): |
| 184 | tickPriceProto = TickPriceProto() |
| 185 | tickPriceProto.ParseFromString(protobuf) |
| 186 | |
| 187 | self.wrapper.tickPriceProtoBuf(tickPriceProto) |
| 188 | |
| 189 | reqId = tickPriceProto.reqId if tickPriceProto.HasField('reqId') else NO_VALID_ID |
| 190 | tickType = tickPriceProto.tickType if tickPriceProto.HasField('tickType') else UNSET_INTEGER |
| 191 | price = tickPriceProto.price if tickPriceProto.HasField('price') else UNSET_DOUBLE |
| 192 | size = Decimal(tickPriceProto.size) if tickPriceProto.HasField('size') else UNSET_DECIMAL |
| 193 | attrMask = tickPriceProto.attrMask if tickPriceProto.HasField('attrMask') else UNSET_INTEGER |
| 194 | attrib = TickAttrib() |
| 195 | attrib.canAutoExecute = attrMask & 1 != 0 |