Skip to content

Commit d8e50aa

Browse files
committed
Added cancelContractData and cancelHistoricalTicks requests.
1 parent b1b6b69 commit d8e50aa

File tree

9 files changed

+371
-3
lines changed

9 files changed

+371
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
**We will do our best to keep it in sync** with the official API releases to ensure compatibility and feature parity, but users should be aware that this is a community-driven project and may lag behind the official versions at times.
99

1010
> [!CAUTION]
11-
> This package is in the **beta phase**. While functional, it may still have bugs or incomplete features. Please test extensively in non-production environments.
11+
> Please test extensively in non-production environments before relying on it for live trading.
1212
1313
## Getting Started
1414

@@ -83,7 +83,7 @@ For more information on how to use this package, please refer to the [GoDoc](htt
8383
## Notice of Non-Affiliation and Disclaimer
8484

8585
> [!CAUTION]
86-
> This project is in the **beta phase** and is still undergoing testing and development. Users are advised to thoroughly test the software in non-production environments before relying on it for live trading. Features may be incomplete, and bugs may exist. Use at your own risk.
86+
> Users are advised to thoroughly test the software in non-production environments before relying on it for live trading. Features may be incomplete, and bugs may exist. Use at your own risk.
8787
8888
> [!IMPORTANT]
8989
> This project is **not affiliated** with Interactive Brokers Group, Inc. All references to Interactive Brokers, including trademarks, logos, and brand names, belong to their respective owners. The use of these names is purely for informational purposes and does not imply endorsement by Interactive Brokers.

client.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6329,3 +6329,75 @@ func (c *EClient) reqCurrentTimeInMillisProtoBuf(currentTimeInMillisRequestProto
63296329

63306330
c.reqChan <- me.Bytes()
63316331
}
6332+
6333+
// CancelContractData cancels contract data request.
6334+
func (c *EClient) CancelContractData(reqID int64) {
6335+
c.cancelContractDataProtoBuf(createCancelContractDataProto(reqID))
6336+
}
6337+
6338+
func (c *EClient) cancelContractDataProtoBuf(cancelContractDataProto *protobuf.CancelContractData) {
6339+
reqID := NO_VALID_ID
6340+
if cancelContractDataProto.ReqId != nil {
6341+
reqID = int64(*cancelContractDataProto.ReqId)
6342+
}
6343+
6344+
if !c.IsConnected() {
6345+
c.wrapper.Error(reqID, currentTimeMillis(), NOT_CONNECTED.Code, NOT_CONNECTED.Msg, "")
6346+
return
6347+
}
6348+
6349+
if c.serverVersion < MIN_SERVER_VER_CANCEL_CONTRACT_DATA {
6350+
c.wrapper.Error(reqID, currentTimeMillis(), UPDATE_TWS.Code, UPDATE_TWS.Msg+" It does not support contract data cancels.", "")
6351+
return
6352+
}
6353+
6354+
me := NewMsgEncoder(1, c)
6355+
6356+
me.encodeMsgID(CANCEL_CONTRACT_DATA + PROTOBUF_MSG_ID)
6357+
6358+
msg, err := proto.Marshal(cancelContractDataProto)
6359+
if err != nil {
6360+
c.wrapper.Error(reqID, currentTimeMillis(), ERROR_ENCODING_PROTOBUF.Code, ERROR_ENCODING_PROTOBUF.Msg+err.Error(), "")
6361+
return
6362+
}
6363+
6364+
me.encodeProto(msg)
6365+
6366+
c.reqChan <- me.Bytes()
6367+
}
6368+
6369+
// CancelHistoricalTicks cancels historical ticks request.
6370+
func (c *EClient) CancelHistoricalTicks(reqID int64) {
6371+
c.cancelHistoricalTicksProtoBuf(createCancelHistoricalTicksProto(reqID))
6372+
}
6373+
6374+
func (c *EClient) cancelHistoricalTicksProtoBuf(cancelHistoricalTicksProto *protobuf.CancelHistoricalTicks) {
6375+
reqID := NO_VALID_ID
6376+
if cancelHistoricalTicksProto.ReqId != nil {
6377+
reqID = int64(*cancelHistoricalTicksProto.ReqId)
6378+
}
6379+
6380+
if !c.IsConnected() {
6381+
c.wrapper.Error(reqID, currentTimeMillis(), NOT_CONNECTED.Code, NOT_CONNECTED.Msg, "")
6382+
return
6383+
}
6384+
6385+
if c.serverVersion < MIN_SERVER_VER_CANCEL_CONTRACT_DATA {
6386+
c.wrapper.Error(reqID, currentTimeMillis(), UPDATE_TWS.Code, UPDATE_TWS.Msg+" It does not support historical ticks cancels.", "")
6387+
return
6388+
}
6389+
6390+
me := NewMsgEncoder(1, c)
6391+
6392+
me.encodeMsgID(CANCEL_HISTORICAL_TICKS + PROTOBUF_MSG_ID)
6393+
6394+
msg, err := proto.Marshal(cancelHistoricalTicksProto)
6395+
if err != nil {
6396+
c.wrapper.Error(reqID, currentTimeMillis(), ERROR_ENCODING_PROTOBUF.Code, ERROR_ENCODING_PROTOBUF.Msg+err.Error(), "")
6397+
return
6398+
}
6399+
6400+
me.encodeProto(msg)
6401+
6402+
c.reqChan <- me.Bytes()
6403+
}

client_utils.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,3 +2049,21 @@ func createUnsubscribeFromGroupEventsRequestProto(reqID int64) *protobuf.Unsubsc
20492049
func createMarketDepthExchangesRequestProto() *protobuf.MarketDepthExchangesRequest {
20502050
return &protobuf.MarketDepthExchangesRequest{}
20512051
}
2052+
2053+
func createCancelContractDataProto(reqID int64) *protobuf.CancelContractData {
2054+
req := &protobuf.CancelContractData{}
2055+
if isValidInt64Value(reqID) {
2056+
id := int32(reqID)
2057+
req.ReqId = &id
2058+
}
2059+
return req
2060+
}
2061+
2062+
func createCancelHistoricalTicksProto(reqID int64) *protobuf.CancelHistoricalTicks {
2063+
req := &protobuf.CancelHistoricalTicks{}
2064+
if isValidInt64Value(reqID) {
2065+
id := int32(reqID)
2066+
req.ReqId = &id
2067+
}
2068+
return req
2069+
}

message.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ const (
179179
CANCEL_WSH_EVENT_DATA OUT = 103
180180
REQ_USER_INFO OUT = 104
181181
REQ_CURRENT_TIME_IN_MILLIS OUT = 105
182+
CANCEL_CONTRACT_DATA OUT = 106
183+
CANCEL_HISTORICAL_TICKS OUT = 107
182184
)
183185

184186
// TWS New Bulletins constants

proto/CancelContractData.proto

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

proto/CancelHistoricalTicks.proto

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

protobuf/CancelContractData.pb.go

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

0 commit comments

Comments
 (0)