Node-RED is a graphical programming language based on NodeJS. I love Node-RED, it puts so many useful tasks right at your fingertips using a beautiful web-based GUI. Surprisingly there wasn’t a node already existing for Alpaca so I wrapped the official SDK into the required format for Node-RED and it worked! easy as pie. This is a work in progress; I plan on including all features and applying the appropriate polish so stay tuned!
I checked out your node red and all looks great! I am however getting an error with your submit order node
{“code”:40010000,“message”:“request body format is invalid”}
I tried just now myself and it seems to work for me, if you’re using the msg.topic to select the function make sure it is “lastQuote”, case sensitive, no spaces. My demo flow looks like this:
Perhaps you don’t have the latest version of the node? Open “Manage Palette” and if an update to 2.2.1 is available then click update and restart nodered
{“code”:40010000,“message”:“request body format is invalid”}
Sorry I missed this, this one is most likely as it says, something in the request is misspelled or misconfigured. This is why in newer version of the node I have a template available to copy/paste from the node configuration pane. For example the template for submit order is this:
Everything for me is the same except I’m not getting the error. That is odd.
I think this function was introduced somewhat recently (ie, in v2), maybe your nodered is somehow importing a different version of @alpacahq/alpaca-trade-api. Have you installed that package globally perhaps? Version 2.3.0 is the latest tested version, you should be able to see it in your node-red home directory (if you’re unsure, look at userDir which is printed in the logs at start of nodered)
Take the bottom path and follow it all the way to alpaca-trade-api and look at the package.json in that folder. if it’s < 2.3.0 then that may be your issue.
ok, so I was able to reproduce your error when using alpaca-trade-api v2.10.0
So, the short-term fix is to force my package to require v2.3.0 which it was developed with. I’ve bumped my node version to 2.2.2 with this change.
Update through the palette manager (if it doesn’t give the option may need to restart nodered), then update to 2.2.2 and restart nodered.***
***Or, you can run this command from the user directory:
npm install node-red-contrib-alpaca@latest
and restart nodered
Sorry for all the noise, (leaving it up for education purposes), but I was able to reproduce and subsequently fix the error so I’m pretty confident this is the solution.