Skip to content

Commit e7b2cb1

Browse files
committed
Added protobuf support for rest of messages (part 3 of 3)
1 parent fb30368 commit e7b2cb1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3629
-68
lines changed

client.go

Lines changed: 344 additions & 0 deletions
Large diffs are not rendered by default.

client_utils.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,3 +1945,107 @@ func createUserInfoRequestProto(reqID int64) *protobuf.UserInfoRequest {
19451945
}
19461946
return req
19471947
}
1948+
1949+
func createIdsRequestProto(numIds int64) *protobuf.IdsRequest {
1950+
req := &protobuf.IdsRequest{}
1951+
if isValidInt64Value(numIds) {
1952+
n := int32(numIds)
1953+
req.NumIds = &n
1954+
}
1955+
return req
1956+
}
1957+
1958+
func createCurrentTimeRequestProto() *protobuf.CurrentTimeRequest {
1959+
return &protobuf.CurrentTimeRequest{}
1960+
}
1961+
1962+
func createCurrentTimeInMillisRequestProto() *protobuf.CurrentTimeInMillisRequest {
1963+
return &protobuf.CurrentTimeInMillisRequest{}
1964+
}
1965+
1966+
func createStartApiRequestProto(clientID int64, optionalCapabilities string) *protobuf.StartApiRequest {
1967+
req := &protobuf.StartApiRequest{}
1968+
if isValidInt64Value(clientID) {
1969+
id := int32(clientID)
1970+
req.ClientId = &id
1971+
}
1972+
if !stringIsEmpty(optionalCapabilities) {
1973+
req.OptionalCapabilities = &optionalCapabilities
1974+
}
1975+
return req
1976+
}
1977+
1978+
func createSetServerLogLevelRequestProto(logLevel int64) *protobuf.SetServerLogLevelRequest {
1979+
req := &protobuf.SetServerLogLevelRequest{}
1980+
if isValidInt64Value(logLevel) {
1981+
level := int32(logLevel)
1982+
req.LogLevel = &level
1983+
}
1984+
return req
1985+
}
1986+
1987+
func createVerifyRequestProto(apiName, apiVersion string) *protobuf.VerifyRequest {
1988+
req := &protobuf.VerifyRequest{}
1989+
if !stringIsEmpty(apiName) {
1990+
req.ApiName = &apiName
1991+
}
1992+
if !stringIsEmpty(apiVersion) {
1993+
req.ApiVersion = &apiVersion
1994+
}
1995+
return req
1996+
}
1997+
1998+
func createVerifyMessageRequestProto(apiData string) *protobuf.VerifyMessageRequest {
1999+
req := &protobuf.VerifyMessageRequest{}
2000+
if !stringIsEmpty(apiData) {
2001+
req.ApiData = &apiData
2002+
}
2003+
return req
2004+
}
2005+
2006+
func createQueryDisplayGroupsRequestProto(reqID int64) *protobuf.QueryDisplayGroupsRequest {
2007+
req := &protobuf.QueryDisplayGroupsRequest{}
2008+
if isValidInt64Value(reqID) {
2009+
id := int32(reqID)
2010+
req.ReqId = &id
2011+
}
2012+
return req
2013+
}
2014+
2015+
func createSubscribeToGroupEventsRequestProto(reqID int64, groupID int64) *protobuf.SubscribeToGroupEventsRequest {
2016+
req := &protobuf.SubscribeToGroupEventsRequest{}
2017+
if isValidInt64Value(reqID) {
2018+
id := int32(reqID)
2019+
req.ReqId = &id
2020+
}
2021+
if isValidInt64Value(groupID) {
2022+
gid := int32(groupID)
2023+
req.GroupId = &gid
2024+
}
2025+
return req
2026+
}
2027+
2028+
func createUpdateDisplayGroupRequestProto(reqID int64, contractInfo string) *protobuf.UpdateDisplayGroupRequest {
2029+
req := &protobuf.UpdateDisplayGroupRequest{}
2030+
if isValidInt64Value(reqID) {
2031+
id := int32(reqID)
2032+
req.ReqId = &id
2033+
}
2034+
if !stringIsEmpty(contractInfo) {
2035+
req.ContractInfo = &contractInfo
2036+
}
2037+
return req
2038+
}
2039+
2040+
func createUnsubscribeFromGroupEventsRequestProto(reqID int64) *protobuf.UnsubscribeFromGroupEventsRequest {
2041+
req := &protobuf.UnsubscribeFromGroupEventsRequest{}
2042+
if isValidInt64Value(reqID) {
2043+
id := int32(reqID)
2044+
req.ReqId = &id
2045+
}
2046+
return req
2047+
}
2048+
2049+
func createMarketDepthExchangesRequestProto() *protobuf.MarketDepthExchangesRequest {
2050+
return &protobuf.MarketDepthExchangesRequest{}
2051+
}

decoder.go

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,22 @@ func (d *EDecoder) interpret(msgBytes []byte) {
186186
d.processMarketRuleMsgProtoBuf(msgBuf)
187187
case USER_INFO:
188188
d.processUserInfoMsgProtoBuf(msgBuf)
189+
case NEXT_VALID_ID:
190+
d.processNextValidIdMsgProtoBuf(msgBuf)
191+
case CURRENT_TIME:
192+
d.processCurrentTimeMsgProtoBuf(msgBuf)
193+
case CURRENT_TIME_IN_MILLIS:
194+
d.processCurrentTimeInMillisMsgProtoBuf(msgBuf)
195+
case VERIFY_MESSAGE_API:
196+
d.processVerifyMessageApiMsgProtoBuf(msgBuf)
197+
case VERIFY_COMPLETED:
198+
d.processVerifyCompletedMsgProtoBuf(msgBuf)
199+
case DISPLAY_GROUP_LIST:
200+
d.processDisplayGroupListMsgProtoBuf(msgBuf)
201+
case DISPLAY_GROUP_UPDATED:
202+
d.processDisplayGroupUpdatedMsgProtoBuf(msgBuf)
203+
case MKT_DEPTH_EXCHANGES:
204+
d.processMktDepthExchangesMsgProtoBuf(msgBuf)
189205
default:
190206
d.wrapper.Error(msgID, currentTimeMillis(), UNKNOWN_ID.Code, UNKNOWN_ID.Msg, "")
191207
}
@@ -1219,6 +1235,24 @@ func (d *EDecoder) processNextValidIdMsg(msgBuf *MsgBuffer) {
12191235
d.wrapper.NextValidID(reqID)
12201236
}
12211237

1238+
func (d *EDecoder) processNextValidIdMsgProtoBuf(msgBuf *MsgBuffer) {
1239+
1240+
var protoMsg protobuf.NextValidId
1241+
if err := proto.Unmarshal(msgBuf.bs, &protoMsg); err != nil {
1242+
log.Error().Err(err).Msg("failed to unmarshal NextValidId")
1243+
return
1244+
}
1245+
1246+
d.wrapper.NextValidIdProtoBuf(&protoMsg)
1247+
1248+
id := NO_VALID_ID
1249+
if protoMsg.OrderId != nil {
1250+
id = int64(protoMsg.GetOrderId())
1251+
}
1252+
1253+
d.wrapper.NextValidID(id)
1254+
}
1255+
12221256
func (d *EDecoder) processContractDataMsg(msgBuf *MsgBuffer) {
12231257

12241258
var version int64 = 8
@@ -2031,6 +2065,24 @@ func (d *EDecoder) processCurrentTimeMsg(msgBuf *MsgBuffer) {
20312065
d.wrapper.CurrentTime(t)
20322066
}
20332067

2068+
func (d *EDecoder) processCurrentTimeMsgProtoBuf(msgBuf *MsgBuffer) {
2069+
2070+
var protoMsg protobuf.CurrentTime
2071+
if err := proto.Unmarshal(msgBuf.bs, &protoMsg); err != nil {
2072+
log.Error().Err(err).Msg("failed to unmarshal CurrentTime")
2073+
return
2074+
}
2075+
2076+
d.wrapper.CurrentTimeProtoBuf(&protoMsg)
2077+
2078+
ts := int64(0)
2079+
if protoMsg.CurrentTime != nil {
2080+
ts = protoMsg.GetCurrentTime()
2081+
}
2082+
2083+
d.wrapper.CurrentTime(ts)
2084+
}
2085+
20342086
func (d *EDecoder) processRealTimeBarsMsg(msgBuf *MsgBuffer) {
20352087

20362088
msgBuf.decode() // version
@@ -2546,6 +2598,24 @@ func (d *EDecoder) processVerifyMessageApiMsg(msgBuf *MsgBuffer) {
25462598
d.wrapper.VerifyMessageAPI(apiData)
25472599
}
25482600

2601+
func (d *EDecoder) processVerifyMessageApiMsgProtoBuf(msgBuf *MsgBuffer) {
2602+
2603+
var protoMsg protobuf.VerifyMessageApi
2604+
if err := proto.Unmarshal(msgBuf.bs, &protoMsg); err != nil {
2605+
log.Error().Err(err).Msg("failed to unmarshal VerifyMessageApi")
2606+
return
2607+
}
2608+
2609+
d.wrapper.VerifyMessageApiProtoBuf(&protoMsg)
2610+
2611+
data := ""
2612+
if protoMsg.ApiData != nil {
2613+
data = protoMsg.GetApiData()
2614+
}
2615+
2616+
d.wrapper.VerifyMessageAPI(data)
2617+
}
2618+
25492619
func (d *EDecoder) processVerifyCompletedMsg(msgBuf *MsgBuffer) {
25502620

25512621
msgBuf.decode() // version
@@ -2556,6 +2626,27 @@ func (d *EDecoder) processVerifyCompletedMsg(msgBuf *MsgBuffer) {
25562626
d.wrapper.VerifyCompleted(isSuccessful, errorText)
25572627
}
25582628

2629+
func (d *EDecoder) processVerifyCompletedMsgProtoBuf(msgBuf *MsgBuffer) {
2630+
2631+
var protoMsg protobuf.VerifyCompleted
2632+
if err := proto.Unmarshal(msgBuf.bs, &protoMsg); err != nil {
2633+
log.Error().Err(err).Msg("failed to unmarshal VerifyCompleted")
2634+
return
2635+
}
2636+
2637+
d.wrapper.VerifyCompletedProtoBuf(&protoMsg)
2638+
2639+
ok := false
2640+
if protoMsg.IsSuccessful != nil {
2641+
ok = protoMsg.GetIsSuccessful()
2642+
}
2643+
errText := ""
2644+
if protoMsg.ErrorText != nil {
2645+
errText = protoMsg.GetErrorText()
2646+
}
2647+
d.wrapper.VerifyCompleted(ok, errText)
2648+
}
2649+
25592650
func (d *EDecoder) processDisplayGroupListMsg(msgBuf *MsgBuffer) {
25602651

25612652
msgBuf.decode() // version
@@ -2566,6 +2657,28 @@ func (d *EDecoder) processDisplayGroupListMsg(msgBuf *MsgBuffer) {
25662657
d.wrapper.DisplayGroupList(reqID, groups)
25672658
}
25682659

2660+
func (d *EDecoder) processDisplayGroupListMsgProtoBuf(msgBuf *MsgBuffer) {
2661+
2662+
var protoMsg protobuf.DisplayGroupList
2663+
if err := proto.Unmarshal(msgBuf.bs, &protoMsg); err != nil {
2664+
log.Error().Err(err).Msg("failed to unmarshal DisplayGroupList")
2665+
return
2666+
}
2667+
2668+
d.wrapper.DisplayGroupListProtoBuf(&protoMsg)
2669+
2670+
reqID := NO_VALID_ID
2671+
if protoMsg.ReqId != nil {
2672+
reqID = int64(protoMsg.GetReqId())
2673+
}
2674+
groups := ""
2675+
if protoMsg.Groups != nil {
2676+
groups = protoMsg.GetGroups()
2677+
}
2678+
2679+
d.wrapper.DisplayGroupList(reqID, groups)
2680+
}
2681+
25692682
func (d *EDecoder) processDisplayGroupUpdatedMsg(msgBuf *MsgBuffer) {
25702683

25712684
msgBuf.decode() // version
@@ -2576,6 +2689,28 @@ func (d *EDecoder) processDisplayGroupUpdatedMsg(msgBuf *MsgBuffer) {
25762689
d.wrapper.DisplayGroupUpdated(reqID, contractInfo)
25772690
}
25782691

2692+
func (d *EDecoder) processDisplayGroupUpdatedMsgProtoBuf(msgBuf *MsgBuffer) {
2693+
2694+
var protoMsg protobuf.DisplayGroupUpdated
2695+
if err := proto.Unmarshal(msgBuf.bs, &protoMsg); err != nil {
2696+
log.Error().Err(err).Msg("failed to unmarshal DisplayGroupUpdated")
2697+
return
2698+
}
2699+
2700+
d.wrapper.DisplayGroupUpdatedProtoBuf(&protoMsg)
2701+
2702+
reqID := NO_VALID_ID
2703+
if protoMsg.ReqId != nil {
2704+
reqID = int64(protoMsg.GetReqId())
2705+
}
2706+
contractInfo := ""
2707+
if protoMsg.ContractInfo != nil {
2708+
contractInfo = protoMsg.GetContractInfo()
2709+
}
2710+
2711+
d.wrapper.DisplayGroupUpdated(reqID, contractInfo)
2712+
}
2713+
25792714
func (d *EDecoder) processVerifyAndAuthMessageApiMsg(msgBuf *MsgBuffer) {
25802715

25812716
msgBuf.decode() // version
@@ -3031,6 +3166,23 @@ func (d *EDecoder) processMktDepthExchangesMsg(msgBuf *MsgBuffer) {
30313166
d.wrapper.MktDepthExchanges(depthMktDataDescriptions)
30323167
}
30333168

3169+
func (d *EDecoder) processMktDepthExchangesMsgProtoBuf(msgBuf *MsgBuffer) {
3170+
3171+
var protoMsg protobuf.MarketDepthExchanges
3172+
if err := proto.Unmarshal(msgBuf.bs, &protoMsg); err != nil {
3173+
log.Error().Err(err).Msg("failed to unmarshal MarketDepthExchanges")
3174+
return
3175+
}
3176+
3177+
d.wrapper.MarketDepthExchangesProtoBuf(&protoMsg)
3178+
3179+
descs := make([]DepthMktDataDescription, 0, len(protoMsg.GetDepthMarketDataDescriptions()))
3180+
for _, dd := range protoMsg.GetDepthMarketDataDescriptions() {
3181+
descs = append(descs, *decodeDepthMarketDataDescription(dd))
3182+
}
3183+
d.wrapper.MktDepthExchanges(descs)
3184+
}
3185+
30343186
func (d *EDecoder) processTickNewsMsg(msgBuf *MsgBuffer) {
30353187

30363188
tickerID := msgBuf.decodeInt64()
@@ -4237,6 +4389,24 @@ func (d *EDecoder) processCurrentTimeInMillisMsg(msgBuf *MsgBuffer) {
42374389
d.wrapper.CurrentTimeInMillis(timeInMillis)
42384390
}
42394391

4392+
func (d *EDecoder) processCurrentTimeInMillisMsgProtoBuf(msgBuf *MsgBuffer) {
4393+
4394+
var protoMsg protobuf.CurrentTimeInMillis
4395+
if err := proto.Unmarshal(msgBuf.bs, &protoMsg); err != nil {
4396+
log.Error().Err(err).Msg("failed to unmarshal CurrentTimeMillis")
4397+
return
4398+
}
4399+
4400+
d.wrapper.CurrentTimeInMillisProtoBuf(&protoMsg)
4401+
4402+
ms := int64(0)
4403+
if protoMsg.CurrentTimeInMillis != nil {
4404+
ms = protoMsg.GetCurrentTimeInMillis()
4405+
}
4406+
4407+
d.wrapper.CurrentTimeInMillis(ms)
4408+
}
4409+
42404410
//
42414411
// Helpers
42424412
//

decoder_utils.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,3 +1314,24 @@ func decodePriceIncrement(proto *protobuf.PriceIncrement) *PriceIncrement {
13141314
}
13151315
return priceIncrement
13161316
}
1317+
1318+
// decodeDepthMarketDataDescription translates protobuf DepthMarketDataDescription to Go DepthMktDataDescription
1319+
func decodeDepthMarketDataDescription(proto *protobuf.DepthMarketDataDescription) *DepthMktDataDescription {
1320+
depthMktDataDescription := &DepthMktDataDescription{}
1321+
if proto.Exchange != nil {
1322+
depthMktDataDescription.Exchange = proto.GetExchange()
1323+
}
1324+
if proto.SecType != nil {
1325+
depthMktDataDescription.SecType = proto.GetSecType()
1326+
}
1327+
if proto.ListingExch != nil {
1328+
depthMktDataDescription.ListingExch = proto.GetListingExch()
1329+
}
1330+
if proto.ServiceDataType != nil {
1331+
depthMktDataDescription.ServiceDataType = proto.GetServiceDataType()
1332+
}
1333+
if proto.AggGroup != nil {
1334+
depthMktDataDescription.AggGroup = int64(proto.GetAggGroup())
1335+
}
1336+
return depthMktDataDescription
1337+
}

0 commit comments

Comments
 (0)