Running boilerplate strategy: web socket passes null

Hello community,

I just started my API access subscription and am working through the AutoTrade tutorial series, but I can’t seem to get the templates to even run.

I suspect it has something to do with a wrong or missing parameter being fed into the web socket, but I can’t trace it back to what the issue is. I have updated the REPLAY_TIMES inputs in the index file to something more recent, thinking that perhaps the default date/times were out of range, but that isn’t it.

Here is what I am getting:

[AutoTrade]: You chose NQH2 for parameter contract.
[AutoTrade]: You chose Tick for parameter barType.
[AutoTrade]: You chose 10 for parameter barInterval.
[AutoTrade]: You chose UnderlyingUnits for parameter elementSizeUnit.
[AutoTrade]: You chose true for parameter histogram.
[AutoTrade]: You chose asMuchAsElements for parameter timeRangeType.
[AutoTrade]: You chose 10 for parameter timeRangeValue.
Is this information correct?

[1.] Yes
[2.] No

{
contract: {
id: 2419021,
name: ‘NQH2’,
contractMaturityId: 44664,
status: ‘DefinitionChecked’,
providerTickSize: 0.25
},
barType: ‘Tick’,
barInterval: 10,
elementSizeUnit: ‘UnderlyingUnits’,
histogram: true,
timeRangeType: ‘asMuchAsElements’,
timeRangeValue: 10,
dev_mode: true,
replay_periods: [
{
start: ‘2021-12-26T23:00:00.000Z’,
stop: ‘2021-12-26T23:01:00.000Z’
},
{
start: ‘2021-12-26T23:02:00.000Z’,
stop: ‘2021-12-26T23:03:00.000Z’
}
]
}
./example-api-trading-strategy/websocket/TradovateSocket.js:53
this.ws.addEventListener(‘message’, resSubscription)
^

TypeError: Cannot read properties of null (reading ‘addEventListener’)
at ReplaySocket.TradovateSocket.request (./example-api-trading-strategy/websocket/TradovateSocket.js:53:13)
at ReplaySocket.checkReplaySession (./example-api-trading-strategy/websocket/ReplaySocket.js:11:17)
at new Strategy (./example-api-trading-strategy/strategies/strategy/strategy.js:67:38)
at new PriceDisplayStrategyFP (./example-api-trading-strategy/strategies/priceDisplayFP/priceDisplayStrategyFP.js:6:1)
at configureRobot (./example-api-trading-strategy/utils/configureRobot.js:67:30)
at async main (./example-api-trading-strategy/index.js:96:22)
error Command failed with exit code 1.
info Visit yarn run | Yarn for documentation about this command.

If anyone has any thoughts as to what my issue could be, I would appreciate it!

Just to make sure, you’ve set your credentials - username, password, cid & api secret - correctly? And you also have run the preliminary yarn install in the containing directory?

Hi Alexander, yes, that is correct. It does confirm that I have acquired an access token and run me through the parameter queries. Here is the sequence it goes through after I call yarn start:

[AutoTrade]: Device <> detected.
{
accessToken: ‘
’,
mdAccessToken: ‘,
expirationTime: ‘2021-12-27T17:45:56.875Z’,
userStatus: ‘Active’,
userId: ,
name: ‘
,
hasLive: true,
outdatedTaC: false,
hasFunded: true,
hasMarketData: true,
outdatedLiquidationPolicy: false
}
[AutoTrade]: Successfully acquired Access Token.

{
id: ,
name: 'DEMO
’,
userId: ******,
accountType: ‘Customer’,
active: true,
clearingHouseId: 2,
riskCategoryId: 2,
autoLiqProfileId: 1,
marginAccountType: ‘Speculator’,
legalStatus: ‘Individual’,
archived: false,
timestamp: ‘2021-06-18T16:39:26Z’
}

[AutoTrade]: Welcome, ***********.

Press enter to continue…

[AutoTrade]: I found these possible contracts

[1.] NQH2
[2.] NQM2
[3.] NQU2
[4.] NQZ2
[5.] NQH3
[6.] NQZ1
[7.] Try another query…

{
id: 2419021,
name: ‘NQH2’,
contractMaturityId: 44664,
status: ‘DefinitionChecked’,
providerTickSize: 0.25
}

Press enter to continue…

I suspect that it has to do with the way that replay is handled. I’ve made a few changes. Please update your code (github desktop works nicely for this purpose) and try to run it again. That fixed the issue for me, but let me know if you still have a problem!

Thank you, Alexander. This got CrossoverStrategy and RsiStrategy working for me, but while am still trying to follow along with your tutorials, I still can’t seem to get the other strategies working out of the box. Here are the errors and call stack logs I am getting for each:

YourCustomStrategy log:

got DOM event
./example-api-trading-strategy/utils/dispatcher.js:52
const effects = () => store.effects ||
^

TypeError: Cannot read properties of undefined (reading ‘effects’)
at Object.effects (./example-api-trading-strategy/utils/dispatcher.js:52:33)
at YourCustomStrategy.Strategy._runSideFx (./example-api-trading-strategy/strategies/strategy/strategy.js:50:29)
at callback (./example-api-trading-strategy/strategies/strategy/strategy.js:165:22)
at Array.forEach ()
at callback (./example-api-trading-strategy/websocket/MarketDataSocket.js:37:18)
at ./example-api-trading-strategy/websocket/TradovateSocket.js:48:17
at Array.forEach ()
at WebSocket.resSubscription (./example-api-trading-strategy/websocket/TradovateSocket.js:46:18)
at WebSocket.onMessage (./example-api-trading-strategy/node_modules/ws/lib/event-target.js:132:16)
at WebSocket.emit (node:events:402:35)
error Command failed with exit code 1.


PriceDisplayStrategy log (from tutorial):

./example-api-trading-strategy/utils/dispatcher.js:52
const effects = () => store.effects ||
^

TypeError: Cannot read properties of undefined (reading ‘effects’)
at Object.effects (./example-api-trading-strategy/utils/dispatcher.js:52:33)
at PriceDisplayStrategy.Strategy._runSideFx (./example-api-trading-strategy/strategies/strategy/strategy.js:50:29)
at callback (./example-api-trading-strategy/strategies/strategy/strategy.js:165:22)
at Array.forEach ()
at callback (./example-api-trading-strategy/websocket/MarketDataSocket.js:37:18)
at ./example-api-trading-strategy/websocket/TradovateSocket.js:48:17
at Array.forEach ()
at WebSocket.resSubscription (./example-api-trading-strategy/websocket/TradovateSocket.js:46:18)
at WebSocket.onMessage (./example-api-trading-strategy/node_modules/ws/lib/event-target.js:132:16)
at WebSocket.emit (node:events:402:35)
error Command failed with exit code 1.


Oddly, the functioning example of this, PriceDisplayStrategyFP, returns a different error when it calls the last().close method in drawPrice:

./example-api-trading-strategy/strategies/priceDisplayFP/drawPrice.js:13
price: buffer.last().close
^

TypeError: Cannot read properties of undefined (reading ‘close’)
at drawPriceEffect (./example-api-trading-strategy/strategies/priceDisplayFP/drawPrice.js:13:33)
at ./example-api-trading-strategy/utils/dispatcher.js:18:18
at Array.forEach ()
at ./example-api-trading-strategy/utils/dispatcher.js:17:9
at Object.dispatch (./example-api-trading-strategy/utils/dispatcher.js:66:22)
at ./example-api-trading-strategy/strategies/strategy/strategy.js:58:27
at Array.forEach ()
at PriceDisplayStrategyFP.Strategy._runSideFx (./example-api-trading-strategy/strategies/strategy/strategy.js:53:25)
at callback (./example-api-trading-strategy/strategies/strategy/strategy.js:190:22)
at Array.forEach ()
error Command failed with exit code 1.


Thank you for looking into this and debugging with me as I continue to familiarize myself with the API and the examples you created.

The post above was edited to remove the RsiStrategy error log. Below is my amendment to the post before editing it:

Sorry, you can ignore the RsiStrategy log I mentioned above. I didn’t realize that the reference in index was pointing to the folder that was not FP.

The YourCustomStrategy strategy is unimplemented - it’s left as a template for the user to play with. As for the PriceDisplay strategy, what are the parameters you’re using that throw the error? I’ve tried a few chart configs and I can’t reproduce that error. Let me know and I’ll give it a closer look.

Thanks for that info. Here is the entire log from PriceDisplayFP, which has the input parameters up top:

[AutoTrade]: You chose NQH2 for parameter contract.
[AutoTrade]: You chose Tick for parameter barType.
[AutoTrade]: You chose 10 for parameter barInterval.
[AutoTrade]: You chose UnderlyingUnits for parameter elementSizeUnit.
[AutoTrade]: You chose true for parameter histogram.
[AutoTrade]: You chose asMuchAsElements for parameter timeRangeType.
[AutoTrade]: You chose 10 for parameter timeRangeValue.
Is this information correct?

[1.] Yes
[2.] No

{
contract: {
id: 2419021,
name: ‘NQH2’,
contractMaturityId: 44664,
status: ‘DefinitionChecked’,
providerTickSize: 0.25
},
barType: ‘Tick’,
barInterval: 10,
elementSizeUnit: ‘UnderlyingUnits’,
histogram: true,
timeRangeType: ‘asMuchAsElements’,
timeRangeValue: 10,
dev_mode: false,
replay_periods: [
{
start: ‘2021-07-29T02:30:00.000Z’,
stop: ‘2021-07-29T02:31:00.000Z’
},
{
start: ‘2021-07-29T02:31:00.000Z’,
stop: ‘2021-07-29T02:32:00.000Z’
}
]
}
./example-api-trading-strategy/strategies/priceDisplayFP/drawPrice.js:13
price: buffer.last().close
^

TypeError: Cannot read properties of undefined (reading ‘close’)
at drawPriceEffect (./example-api-trading-strategy/strategies/priceDisplayFP/drawPrice.js:13:33)
at ./example-api-trading-strategy/utils/dispatcher.js:18:18
at Array.forEach ()
at ./example-api-trading-strategy/utils/dispatcher.js:17:9
at Object.dispatch (./example-api-trading-strategy/utils/dispatcher.js:66:22)
at ./example-api-trading-strategy/strategies/strategy/strategy.js:58:27
at Array.forEach ()
at PriceDisplayStrategyFP.Strategy._runSideFx (./example-api-trading-strategy/strategies/strategy/strategy.js:53:25)
at callback (./example-api-trading-strategy/strategies/strategy/strategy.js:190:22)
at Array.forEach ()
error Command failed with exit code 1.

There was an error in the TicksTransformer - should be fixed now if you update your code. Let me know if you have any more issues.

That fixed it. Thank you!

Okay, now as I keep test-running the other examples, I’m trying to force a situation where it actually trades. For the RsiStrategy, it seems like it is not updating the rsi field. I understand that if it is in Watch mode, everything else would be 0, but I would think that the RSI call would be returning an actual number that updates.

Here is what I am seeing:

[AutoTrade]
mode: “[LongShortMode] Watch”
contract: “NQH2”
netPos: 0
rsi: 0
p&l: “$0.00”
realizedPnL: “$0”
{
id: 322266,
s: ‘’,
td: 20211228,
bp: 66117,
bt: 1640704894377,
ts: 0.25,
tks: [
{ t: 0, p: 0, s: 1, b: -2, a: 0, bs: 3, as: 1, id: 5810513 },
{ t: 0, p: 1, s: 1, b: -2, a: 0, bs: 3, as: 1, id: 5810514 },
{ t: 0, p: 1, s: 1, b: -2, a: 0, bs: 3, as: 1, id: 5810515 },
{ t: 0, p: 1, s: 1, b: -2, a: 0, bs: 3, as: 1, id: 5810516 },
{ t: 0, p: 1, s: 1, b: -2, a: 0, bs: 3, as: 1, id: 5810517 }
]
}


And here are my input parameters:

[AutoTrade]: You chose NQH2 for parameter contract.
[AutoTrade]: You chose Tick for parameter barType.
[AutoTrade]: You chose 10 for parameter barInterval.
[AutoTrade]: You chose UnderlyingUnits for parameter elementSizeUnit.
[AutoTrade]: You chose false for parameter histogram.
[AutoTrade]: You chose asMuchAsElements for parameter timeRangeType.
[AutoTrade]: You chose 10 for parameter timeRangeValue.
[AutoTrade]: You chose 10 for parameter period.
[AutoTrade]: You chose 1 for parameter orderQuantity.

RSI wasn’t equipped to handle ticks, fixed now.

Okay, thanks for fixing that. I’m looking at the other fields now, and it seems like when it enters into trading mode, the netPos and p&l do not refresh. Input parameters are the same as before:

[AutoTrade]
mode: “[LongShortMode] Short”
contract: “NQH2”
netPos: 0
rsi: 44.44444444444444
p&l: “$0.00”
realizedPnL: “$0”