Skip to content

Commit 35f92e3

Browse files
committed
Added updateConfig request/response
1 parent 9d1dc6a commit 35f92e3

15 files changed

Lines changed: 724 additions & 10 deletions

client.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6515,3 +6515,34 @@ func (c *EClient) ReqConfigProtoBuf(configRequestProto *protobuf.ConfigRequest)
65156515

65166516
c.reqChan <- me.Bytes()
65176517
}
6518+
6519+
func (c *EClient) UpdateConfigProtoBuf(updateConfigRequestProto *protobuf.UpdateConfigRequest) {
6520+
reqID := NO_VALID_ID
6521+
if updateConfigRequestProto.ReqId != nil {
6522+
reqID = int64(*updateConfigRequestProto.ReqId)
6523+
}
6524+
6525+
if !c.IsConnected() {
6526+
c.wrapper.Error(reqID, currentTimeMillis(), NOT_CONNECTED.Code, NOT_CONNECTED.Msg, "")
6527+
return
6528+
}
6529+
6530+
if c.serverVersion < MIN_SERVER_VER_UPDATE_CONFIG {
6531+
c.wrapper.Error(reqID, currentTimeMillis(), UPDATE_TWS.Code, UPDATE_TWS.Msg+" It does not support update config requests.", "")
6532+
return
6533+
}
6534+
6535+
me := NewMsgEncoder(1, c)
6536+
6537+
me.encodeMsgID(UPDATE_CONFIG + PROTOBUF_MSG_ID)
6538+
6539+
msg, err := proto.Marshal(updateConfigRequestProto)
6540+
if err != nil {
6541+
c.wrapper.Error(reqID, currentTimeMillis(), ERROR_ENCODING_PROTOBUF.Code, ERROR_ENCODING_PROTOBUF.Msg+err.Error(), "")
6542+
return
6543+
}
6544+
6545+
me.encodeProto(msg)
6546+
6547+
c.reqChan <- me.Bytes()
6548+
}

client_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,12 @@ func TestWshCalendarOperations(t *testing.T) {
790790
func TestConfigOperations(t *testing.T) {
791791
ib := setupIBClient(t)
792792
var configRequestProto protobuf.ConfigRequest
793-
// reqID := int32(20001)
794-
// configRequestProto.ReqId = &reqID
793+
reqID := int32(20001)
794+
configRequestProto.ReqId = &reqID
795795
ib.ReqConfigProtoBuf(&configRequestProto)
796+
ib.UpdateConfigProtoBuf(UpdateConfigAPISettings(20002))
797+
ib.UpdateConfigProtoBuf(UpdateOrdersConfig(20003))
798+
ib.UpdateConfigProtoBuf(UpdateMessageConfigConfirmMandatoryCapPriceAccepted(20004))
799+
ib.UpdateConfigProtoBuf(UpdateConfigOrderIDReset(20005))
796800
time.Sleep(2 * time.Second)
797801
}

config_samples.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package ibapi
2+
3+
import (
4+
"github.com/scmhub/ibapi/protobuf"
5+
"google.golang.org/protobuf/proto"
6+
)
7+
8+
// UpdateConfigAPISettings .
9+
func UpdateConfigAPISettings(reqID int32) *protobuf.UpdateConfigRequest {
10+
settings := &protobuf.ApiSettingsConfig{
11+
TotalQuantityForMutualFunds: proto.Bool(true),
12+
DownloadOpenOrdersOnConnection: proto.Bool(true),
13+
IncludeVirtualFxPositions: proto.Bool(true),
14+
PrepareDailyPnL: proto.Bool(true),
15+
SendStatusUpdatesForVolatilityOrders: proto.Bool(true),
16+
EncodeApiMessages: proto.String("osCodePage"),
17+
SocketPort: proto.Int32(7497),
18+
UseNegativeAutoRange: proto.Bool(true),
19+
CreateApiMessageLogFile: proto.Bool(true),
20+
IncludeMarketDataInLogFile: proto.Bool(true),
21+
ExposeTradingScheduleToApi: proto.Bool(true),
22+
SplitInsuredDepositFromCashBalance: proto.Bool(true),
23+
SendZeroPositionsForTodayOnly: proto.Bool(true),
24+
UseAccountGroupsWithAllocationMethods: proto.Bool(true),
25+
LoggingLevel: proto.String("error"),
26+
MasterClientId: proto.Int32(3),
27+
BulkDataTimeout: proto.Int32(25),
28+
ComponentExchSeparator: proto.String("#"),
29+
RoundAccountValuesToNearestWholeNumber: proto.Bool(true),
30+
ShowAdvancedOrderRejectInUi: proto.Bool(true),
31+
RejectMessagesAboveMaxRate: proto.Bool(true),
32+
MaintainConnectionOnIncorrectFields: proto.Bool(true),
33+
CompatibilityModeNasdaqStocks: proto.Bool(true),
34+
SendInstrumentTimezone: proto.String("utc"),
35+
SendForexDataInCompatibilityMode: proto.Bool(true),
36+
MaintainAndResubmitOrdersOnReconnect: proto.Bool(true),
37+
HistoricalDataMaxSize: proto.Int32(4),
38+
AutoReportNettingEventContractTrades: proto.Bool(true),
39+
OptionExerciseRequestType: proto.String("final"),
40+
TrustedIPs: []string{"127.0.0.1"},
41+
}
42+
43+
return &protobuf.UpdateConfigRequest{
44+
ReqId: proto.Int32(reqID),
45+
Api: &protobuf.ApiConfig{
46+
Settings: settings,
47+
},
48+
}
49+
}
50+
51+
// UpdateOrdersConfig .
52+
func UpdateOrdersConfig(reqID int32) *protobuf.UpdateConfigRequest {
53+
orders := &protobuf.OrdersConfig{
54+
SmartRouting: &protobuf.OrdersSmartRoutingConfig{
55+
SeekPriceImprovement: proto.Bool(true),
56+
DoNotRouteToDarkPools: proto.Bool(true),
57+
},
58+
}
59+
60+
return &protobuf.UpdateConfigRequest{
61+
ReqId: proto.Int32(reqID),
62+
Orders: orders,
63+
}
64+
}
65+
66+
// UpdateMessageConfigConfirmMandatoryCapPriceAccepted .
67+
func UpdateMessageConfigConfirmMandatoryCapPriceAccepted(reqID int32) *protobuf.UpdateConfigRequest {
68+
messageID := proto.Int32(131)
69+
messageConfig := &protobuf.MessageConfig{
70+
Id: messageID,
71+
Enabled: proto.Bool(false),
72+
}
73+
warning := &protobuf.UpdateConfigWarning{MessageId: messageID}
74+
75+
return &protobuf.UpdateConfigRequest{
76+
ReqId: proto.Int32(reqID),
77+
Messages: []*protobuf.MessageConfig{messageConfig},
78+
AcceptedWarnings: []*protobuf.UpdateConfigWarning{warning},
79+
}
80+
}
81+
82+
// UpdateConfigOrderIDReset .
83+
func UpdateConfigOrderIDReset(reqID int32) *protobuf.UpdateConfigRequest {
84+
return &protobuf.UpdateConfigRequest{
85+
ReqId: proto.Int32(reqID),
86+
ResetAPIOrderSequence: proto.Bool(true),
87+
}
88+
}

decoder.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ func (d *EDecoder) parseAndProcessMsg(msgBytes []byte) {
204204
d.processMktDepthExchangesMsgProtoBuf(msgBuf)
205205
case CONFIG_RESPONSE:
206206
d.processConfigResponseMsgProtoBuf(msgBuf)
207+
case UPDATE_CONFIG_RESPONSE:
208+
d.processUpdateConfigResponseMsgProtoBuf(msgBuf)
207209
default:
208210
d.wrapper.Error(msgID, currentTimeMillis(), UNKNOWN_ID.Code, UNKNOWN_ID.Msg, "")
209211
}
@@ -4420,6 +4422,17 @@ func (d *EDecoder) processConfigResponseMsgProtoBuf(msgBuf *MsgBuffer) {
44204422
d.wrapper.ConfigResponseProtoBuf(&protoMsg)
44214423
}
44224424

4425+
func (d *EDecoder) processUpdateConfigResponseMsgProtoBuf(msgBuf *MsgBuffer) {
4426+
4427+
var protoMsg protobuf.UpdateConfigResponse
4428+
if err := proto.Unmarshal(msgBuf.bs, &protoMsg); err != nil {
4429+
log.Error().Err(err).Msg("failed to unmarshal UpdateConfigResponse")
4430+
return
4431+
}
4432+
4433+
d.wrapper.UpdateConfigResponseProtoBuf(&protoMsg)
4434+
}
4435+
44234436
//
44244437
// Helpers
44254438
//

message.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ const (
9393
HISTORICAL_DATA_END IN = 108
9494
CURRENT_TIME_IN_MILLIS IN = 109
9595
CONFIG_RESPONSE IN = 110
96+
UPDATE_CONFIG_RESPONSE IN = 111
9697
)
9798

9899
// OUT is the outgoing msg id's.
@@ -183,6 +184,7 @@ const (
183184
CANCEL_CONTRACT_DATA OUT = 106
184185
CANCEL_HISTORICAL_TICKS OUT = 107
185186
REQ_CONFIG OUT = 108
187+
UPDATE_CONFIG OUT = 109
186188
)
187189

188190
// TWS New Bulletins constants

proto/TickByTickData.proto

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ syntax = "proto3";
22

33
package protobuf;
44

5-
import "HistoricalTickLast.proto";
6-
import "HistoricalTickBidAsk.proto";
75
import "HistoricalTick.proto";
8-
9-
6+
import "HistoricalTickBidAsk.proto";
7+
import "HistoricalTickLast.proto";
108

119
option go_package = ".;protobuf";
1210

proto/UpdateConfigRequest.proto

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
syntax = "proto3";
2+
3+
package protobuf;
4+
5+
import "LockAndExitConfig.proto";
6+
import "MessageConfig.proto";
7+
import "ApiConfig.proto";
8+
import "OrdersConfig.proto";
9+
import "UpdateConfigWarning.proto";
10+
11+
option go_package = ".;protobuf";
12+
13+
message UpdateConfigRequest {
14+
optional int32 reqId = 1;
15+
optional LockAndExitConfig lockAndExit = 2;
16+
repeated MessageConfig messages = 3;
17+
optional ApiConfig api = 4;
18+
optional OrdersConfig orders = 5;
19+
repeated UpdateConfigWarning acceptedWarnings = 6;
20+
optional bool resetAPIOrderSequence = 7;
21+
}

proto/UpdateConfigResponse.proto

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
syntax = "proto3";
2+
3+
package protobuf;
4+
5+
import "UpdateConfigWarning.proto";
6+
7+
option go_package = ".;protobuf";
8+
9+
message UpdateConfigResponse {
10+
optional int32 reqId = 1;
11+
optional string status = 2;
12+
optional string message = 3;
13+
repeated string changedFields = 4;
14+
repeated string errors = 5;
15+
repeated UpdateConfigWarning warnings = 6;
16+
}

proto/UpdateConfigWarning.proto

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
syntax = "proto3";
2+
3+
package protobuf;
4+
5+
option go_package = ".;protobuf";
6+
7+
message UpdateConfigWarning {
8+
optional int32 messageId = 1;
9+
optional string title = 2;
10+
optional string message = 3;
11+
}

protobuf/TickByTickData.pb.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)