Curl example for /v2/orders

Would someone please provide a working example of placing a new order using curl?
I have this so far, but the parameter form and formats I have used don’t work with various error messages.


Tried an array of params, a hash, and various strings. Can’t quite figure it out. Using Windows 10 Pro with its version of curl. Or a pointer to the API primitives rather than the API wrappers. Thanks!

curl -s --request POST -H “Content-Type: application/json” -H "APCA-API-KEY-ID: XXXXX " -H “APCA-API-SECRET-KEY: XXXXXX” -d ‘{“symbol”:“TQQQ”,“qty”:“1”,“side”:“buy”,“type”:“market”,“time_in_force”:“day”,“order_class”:“bracket”,“take_profit”: { “limit_price”: “120”},“stop_loss”:{“stop_price”:“105”}}’ “

This is a sample for a braket order

And this one is for an OCO order:

curl -s --request POST -H “Content-Type: application/json” -H “APCA-API-KEY-ID: XXXX” -H “APCA-API-SECRET-KEY: XXXXX” -d ‘{“symbol”:“TQQQ”,“qty”:“1”,“side”:“sell”,“type”:“limit”,“time_in_force”: “day”, “order_class”: “oco”, “take_profit”: {“limit_price”: “300”}, “stop_loss”: { “stop_price”: “100” }}’ “

Many thanks Mr Morales!

I spoke too soon. I put in my Sandbox keys and changed nothing else. On Debian 9, it runs without errors or output, but does nothing. Same on Windows 7 with 3rd party curl. No order was created. No complaints, no message. Checked via the API as well as the web dashboard.

On Windows 10 (using Windows version of curl) for each unaltered curl I still get
{“code”:40010000,“message”:“request body format is invalid”}

That’s the same error I have been getting all along.

Also looked at Request body format is invalid · Issue #89 · alpacahq/Alpaca-API · GitHub and tried the “working” command there on Win 10. Same result - {“code”:40010000,“message”:“request body format is invalid”}

I need to put this aside for now. Some little idiosyncracy with Windows 10 that I may never figure out.

Thanks again, Mr Morales.