Skip to content

Commit

Permalink
fix #17
Browse files Browse the repository at this point in the history
  • Loading branch information
hadrianl committed Sep 15, 2020
1 parent 100ee67 commit df7d4a4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 40 deletions.
57 changes: 29 additions & 28 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ func TestClient(t *testing.T) {
ic.ReqAllOpenOrders()
ic.ReqPositions()
// ic.CancelPositions()
ic.ReqAccountUpdatesMulti(ic.GetReqID(), "DU1382837", "", true)
// ic.ReqAccountUpdatesMulti(ic.GetReqID(), "DU1382837", "", true)
// ic.CancelAccountUpdatesMulti()
ic.ReqPositionsMulti(ic.GetReqID(), "DU1382837", "")
// ic.ReqPositionsMulti(ic.GetReqID(), "DU1382837", "")
// ic.CancelPositionsMulti()
tags := []string{"AccountType", "NetLiquidation", "TotalCashValue", "SettledCash",
"AccruedCash", "BuyingPower", "EquityWithLoanValue",
"PreviousEquityWithLoanValue", "GrossPositionValue", "ReqTEquity",
"ReqTMargin", "SMA", "InitMarginReq", "MaintMarginReq", "AvailableFunds",
"ExcessLiquidity", "Cushion", "FullInitMarginReq", "FullMaintMarginReq",
"FullAvailableFunds", "FullExcessLiquidity", "LookAheadNextChange",
"LookAheadInitMarginReq", "LookAheadMaintMarginReq",
"LookAheadAvailableFunds", "LookAheadExcessLiquidity",
"HighestSeverity", "DayTradesRemaining", "Leverage", "$LEDGER:ALL"}
ic.ReqAccountSummary(ic.GetReqID(), "All", strings.Join(tags, ","))
// tags := []string{"AccountType", "NetLiquidation", "TotalCashValue", "SettledCash",
// "AccruedCash", "BuyingPower", "EquityWithLoanValue",
// "PreviousEquityWithLoanValue", "GrossPositionValue", "ReqTEquity",
// "ReqTMargin", "SMA", "InitMarginReq", "MaintMarginReq", "AvailableFunds",
// "ExcessLiquidity", "Cushion", "FullInitMarginReq", "FullMaintMarginReq",
// "FullAvailableFunds", "FullExcessLiquidity", "LookAheadNextChange",
// "LookAheadInitMarginReq", "LookAheadMaintMarginReq",
// "LookAheadAvailableFunds", "LookAheadExcessLiquidity",
// "HighestSeverity", "DayTradesRemaining", "Leverage", "$LEDGER:ALL"}
// ic.ReqAccountSummary(ic.GetReqID(), "All", strings.Join(tags, ","))
// ic.CancelAccountSummary()

// ########################## request market data #################################################
Expand Down Expand Up @@ -89,9 +89,9 @@ func TestClient(t *testing.T) {
// ic.ReqHistoricalData(ic.GetReqID(), hsiSpread, "", "4800 S", "1 min", "TRADES", false, 1, false, nil)

// ######################### request contract ############################################################
hsi := Contract{Symbol: "HSI", SecurityType: "FUT", Exchange: "HKFE"}
ic.ReqContractDetails(ic.GetReqID(), &hsi)
ic.ReqMatchingSymbols(ic.GetReqID(), "IB")
// hsi := Contract{Symbol: "HSI", SecurityType: "FUT", Exchange: "HKFE"}
// ic.ReqContractDetails(ic.GetReqID(), &hsi)
// ic.ReqMatchingSymbols(ic.GetReqID(), "IB")

// ######################### market scanner #############################################################
// ic.ReqScannerParameters()
Expand All @@ -114,20 +114,21 @@ func TestClient(t *testing.T) {

// ############################ others #########################################################################

ic.ReqFamilyCodes()
// ic.ReqFamilyCodes()
// ic.ReqScannerParameters()
ic.ReqManagedAccts()
ic.ReqSoftDollarTiers(ic.GetReqID())
ic.ReqNewsProviders()
ic.ReqMarketDataType(1)
ic.ReqPnLSingle(ic.GetReqID(), "DU1382837", "", 351872027)
ic.ReqNewsBulletins(true)
ic.ReqSmartComponents(ic.GetReqID(), "a6")
ic.ReqMktDepthExchanges()
ic.ReqMatchingSymbols(ic.GetReqID(), "HSI")
ic.ReqSecDefOptParams(ic.GetReqID(), "HSI", "", "IND", 1328298)
ic.ReqGlobalCancel()
ic.ReqIDs()
// ic.ReqManagedAccts()
// ic.ReqSoftDollarTiers(ic.GetReqID())
// ic.ReqNewsProviders()
// ic.ReqMarketDataType(1)
// ic.ReqPnLSingle(ic.GetReqID(), "DU1382837", "", 351872027)
// ic.ReqNewsBulletins(true)
// ic.ReqSmartComponents(ic.GetReqID(), "a6")
// ic.ReqMktDepthExchanges()
// ic.ReqMatchingSymbols(ic.GetReqID(), "HSI")
// ic.ReqSecDefOptParams(ic.GetReqID(), "HSI", "", "IND", 1328298)
// ic.ReqGlobalCancel()
// ic.ReqIDs()
ic.ReqCompletedOrders(false)
// lmtOrder := NewLimitOrder("BUY", 26640, 1)
// mktOrder := NewMarketOrder("BUY", 1)
// ic.PlaceOrder(ibwrapper.GetNextOrderID(), &hsi1909, lmtOrder)
Expand Down
17 changes: 5 additions & 12 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1898,7 +1898,6 @@ func (d *ibDecoder) processCompletedOrderMsg(msgBuf *MsgBuffer) {
o.Origin = msgBuf.readInt()

o.OrderRef = msgBuf.readString()
o.ClientID = msgBuf.readInt()
o.PermID = msgBuf.readInt()

o.OutsideRTH = msgBuf.readBool()
Expand Down Expand Up @@ -1955,13 +1954,9 @@ func (d *ibDecoder) processCompletedOrderMsg(msgBuf *MsgBuffer) {

if version >= 27 && o.DeltaNeutralOrderType != "" {
o.DeltaNeutralContractID = msgBuf.readInt()
o.DeltaNeutralSettlingFirm = msgBuf.readString()
o.DeltaNeutralClearingAccount = msgBuf.readString()
o.DeltaNeutralClearingIntent = msgBuf.readString()
}

if version >= 31 && o.DeltaNeutralOrderType != "" {
o.DeltaNeutralOpenClose = msgBuf.readString()
o.DeltaNeutralShortSale = msgBuf.readBool()
o.DeltaNeutralShortSaleSlot = msgBuf.readInt()
o.DeltaNeutralDesignatedLocation = msgBuf.readString()
Expand All @@ -1972,14 +1967,12 @@ func (d *ibDecoder) processCompletedOrderMsg(msgBuf *MsgBuffer) {

//TrailParams
o.TrailStopPrice = msgBuf.readFloatCheckUnset()

if version >= 30 {
o.TrailingPercent = msgBuf.readFloatCheckUnset() //show_unset
}

//ComboLegs
c.ComboLegsDescription = msgBuf.readString()

if version >= 29 {
combolegN := msgBuf.readInt()
c.ComboLegs = make([]ComboLeg, 0, combolegN)
Expand Down Expand Up @@ -2047,18 +2040,14 @@ func (d *ibDecoder) processCompletedOrderMsg(msgBuf *MsgBuffer) {
}
}

// if version >= 25 {
// o.OptOutSmartRouting = decodeBool(f[68])
// f = f[1:]
// }

o.ClearingAccount = msgBuf.readString()
o.ClearingIntent = msgBuf.readString()

if version >= 22 {
o.NotHeld = msgBuf.readBool()
}

// DeltaNeutral
if version >= 20 {
deltaNeutralContractPresent := msgBuf.readBool()
if deltaNeutralContractPresent {
Expand Down Expand Up @@ -2089,12 +2078,14 @@ func (d *ibDecoder) processCompletedOrderMsg(msgBuf *MsgBuffer) {

orderState.Status = msgBuf.readString()

// VolRandomizeFlags
if version >= 34 {
o.RandomizeSize = msgBuf.readBool()
o.RandomizePrice = msgBuf.readBool()
}

if d.version >= mMIN_SERVER_VER_PEGGED_TO_BENCHMARK {
// PegToBenchParams
if o.OrderType == "PEG BENCH" {
o.ReferenceContractID = msgBuf.readInt()
o.IsPeggedChangeAmountDecrease = msgBuf.readBool()
Expand All @@ -2103,6 +2094,7 @@ func (d *ibDecoder) processCompletedOrderMsg(msgBuf *MsgBuffer) {
o.ReferenceExchangeID = msgBuf.readString()
}

// Conditions
if n := msgBuf.readInt(); n > 0 {
o.Conditions = make([]OrderConditioner, 0, n)
for ; n > 0; n-- {
Expand All @@ -2117,6 +2109,7 @@ func (d *ibDecoder) processCompletedOrderMsg(msgBuf *MsgBuffer) {
}
}

// StopPriceAndLmtPriceOffset
o.TrailStopPrice = msgBuf.readFloat()
o.LimitPriceOffset = msgBuf.readFloat()

Expand Down

0 comments on commit df7d4a4

Please sign in to comment.