pilwon / node-ib

Interactive Brokers TWS API client library for Node.js
381 stars 133 forks source link

Incoming.prototype._POSITION_MULTI missing one field to be dequeued #144

Open AdityaSantoso opened 4 years ago

AdityaSantoso commented 4 years ago

When using reqPositionMulti, the resulting positionMulti event always incur an error like such

Unknown incoming first token: NaN

Upon closer debugging, it seems like Incoming.prototype._POSITION_MULTI should have one extra this.dequeue() to avoid having a field unconsumed. This causes the Incoming.prototype.process to always throw Unknown incoming first token

To repro: fire a reqPositionsMulti with modelCode null.

AdityaSantoso commented 4 years ago

Comparing this with the C# equivalent, it seems like the last field should have belonged to the modelCode

private void PositionMultiEvent()
        {
            int msgVersion = ReadInt();
            int requestId = ReadInt();
            string account = ReadString();
            Contract contract = new Contract();
            contract.ConId = ReadInt();
            contract.Symbol = ReadString();
            contract.SecType = ReadString();
            contract.LastTradeDateOrContractMonth = ReadString();
            contract.Strike = ReadDouble();
            contract.Right = ReadString();
            contract.Multiplier = ReadString();
            contract.Exchange = ReadString();
            contract.Currency = ReadString();
            contract.LocalSymbol = ReadString();
            contract.TradingClass = ReadString();
            var pos = ReadDouble();
            double avgCost = ReadDouble();
            string modelCode = ReadString(); // <--- there is no equivalent to this in the javascript version
            eWrapper.positionMulti(requestId, account, modelCode, contract, pos, avgCost);
        }