# Curl example for /v2/orders

**URL:** <https://forum.alpaca.markets/t/curl-example-for-v2-orders/7583>\
**Category:** Alpaca Trading\
**Created:** [November 29, 2021, 10:15pm UTC](https://forum.alpaca.markets/t/curl-example-for-v2-orders/7583 "2021-11-29T22:15:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bubuia](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@bubuia](https://forum.alpaca.markets/u/bubuia)\
**Post date:** [November 29, 2021, 10:15pm UTC](https://forum.alpaca.markets/t/curl-example-for-v2-orders/7583/1 "2021-11-29T22:15:33Z")

</div>

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.

curl -X POST -H “APCA-API-KEY-ID: %APCA\_API\_KEY\_ID%” -H “APCA-API-SECRET-KEY: %APCA\_API\_SECRET\_KEY%” [https://paper-api.alpaca.markets/v2/orders?parameters](https://paper-api.alpaca.markets/v2/orders?parameters) -o test.out

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!

---

<div class="post-metadata">

**Author:** ![Francisco\_Morales](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/francisco_morales/32/1103_2.png) [@Francisco\_Morales](https://forum.alpaca.markets/u/Francisco_Morales)\
**Post date:** [December 1, 2021, 2:24pm UTC](https://forum.alpaca.markets/t/curl-example-for-v2-orders/7583/2 "2021-12-01T14:24:54Z")

</div>

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”}}’ “[https://paper-api.alpaca.markets/v2/orders](https://paper-api.alpaca.markets/v2/orders)”

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” }}’ “[https://paper-api.alpaca.markets/v2/orders](https://paper-api.alpaca.markets/v2/orders)”

---

<div class="post-metadata">

**Author:** ![bubuia](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@bubuia](https://forum.alpaca.markets/u/bubuia)\
**Post date:** [December 1, 2021, 7:36pm UTC](https://forum.alpaca.markets/t/curl-example-for-v2-orders/7583/3 "2021-12-01T19:36:46Z")

</div>

Many thanks Mr Morales!

---

<div class="post-metadata">

**Author:** ![bubuia](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@bubuia](https://forum.alpaca.markets/u/bubuia)\
**Post date:** [December 1, 2021, 9:28pm UTC](https://forum.alpaca.markets/t/curl-example-for-v2-orders/7583/4 "2021-12-01T21:28:22Z")

</div>

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](https://github.com/alpacahq/Alpaca-API/issues/89) 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.

---

<div class="post-metadata">

**Author:** ![bubuia](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@bubuia](https://forum.alpaca.markets/u/bubuia)\
**Post date:** [September 13, 2022, 2:49pm UTC](https://forum.alpaca.markets/t/curl-example-for-v2-orders/7583/5 "2022-09-13T14:49:23Z")

</div>

Finally found time to read the documentation at [curl for Windows](https://curl.se/windows/) The problem seems to be that Windows **always** requires double quotes as the outer quotes at the command line. To use inner double quotes you have to escape them.

For example:

curl -H “Content-Type: application/json” -H “APCA-API-KEY-ID: zzzz” -H “APCA-API-SECRET-KEY: zzzz” -d ‘{“symbol”:“AAPL”,“qty”:“1”,“side”:“buy”,“type”:“market”,“time\_in\_force”:“gtc”}’ “[https://paper-api.alpaca.markets/v2/orders](https://paper-api.alpaca.markets/v2/orders)”

becomes (note that POST is redundant when using -d)

curl -H “Content-Type: application/json” -H “APCA-API-KEY-ID: zzzz” -H “APCA-API-SECRET-KEY: zzzz” -d “{"symbol":"AAPL","qty":"1","side":"buy","type":"market","time\_in\_force":"gtc"}” “[https://paper-api.alpaca.markets/v2/orders](https://paper-api.alpaca.markets/v2/orders)”

and returns the order confirmation:

{“id”:“a1fc03cb-bfe5-4b49-a5b3-002b73363215”,“client\_order\_id”:“0e0bc9d6-bcee-4eb1-ad87-68ea782754ee”,“created\_at”:“2022-09-13T14:35:14.314459208Z”,“updated\_at”:“2022-09-13T14:35:14.314517458Z”,“submitted\_at”:“2022-09-13T14:35:14.313371839Z”,“filled\_at”:null,“expired\_at”:null,“canceled\_at”:null,“failed\_at”:null,“replaced\_at”:null,“replaced\_by”:null,“replaces”:null,“asset\_id”:“b0b6dd9d-8b9b-48a9-ba46-b9d54906e415”,“symbol”:“AAPL”,“asset\_class”:“us\_equity”,“notional”:null,“qty”:“1”,“filled\_qty”:“0”,“filled\_avg\_price”:null,“order\_class”:“”,“order\_type”:“market”,“type”:“market”,“side”:“buy”,“time\_in\_force”:“gtc”,“limit\_price”:null,“stop\_price”:null,“status”:“pending\_new”,“extended\_hours”:false,“legs”:null,“trail\_percent”:null,“trail\_price”:null,“hwm”:null,“subtag”:null,“source”:null}

This is a Windows idiosyncrasy and has nothing to do with curl per se. If you install a different version of curl not from MSFT, my best guess is that escaping doublequotes will still be required.

D:\>curl -V  
curl 7.83.1 (Windows) libcurl/7.83.1 Schannel  
Release-Date: 2022-05-13  
Protocols: dict file ftp ftps http https imap imaps pop3 pop3s smtp smtps telnet tftp  
Features: AsynchDNS HSTS IPv6 Kerberos Largefile NTLM SPNEGO SSL SSPI UnixSockets

---

<div class="post-metadata">

**Author:** ![bubuia](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@bubuia](https://forum.alpaca.markets/u/bubuia)\
**Post date:** [September 13, 2022, 2:50pm UTC](https://forum.alpaca.markets/t/curl-example-for-v2-orders/7583/6 "2022-09-13T14:50:31Z")

</div>

and the escape character \ was stripped out of the reply.

---

<div class="post-metadata">

**Author:** ![bubuia](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@bubuia](https://forum.alpaca.markets/u/bubuia)\
**Post date:** [September 13, 2022, 2:54pm UTC](https://forum.alpaca.markets/t/curl-example-for-v2-orders/7583/7 "2022-09-13T14:54:35Z")

</div>

The escape char \ is replaced by / in this example to preserve place, but the actual code should use .

For example:  
curl -H “Content-Type: application/json” -H “APCA-API-KEY-ID: zzzz” -H “APCA-API-SECRET-KEY: zzzz” -d ‘{“symbol”:“AAPL”,“qty”:“1”,“side”:“buy”,“type”:“market”,“time\_in\_force”:“gtc”}’ “[https://paper-api.alpaca.markets/v2/orders”](https://paper-api.alpaca.markets/v2/orders%E2%80%9D)

becomes (note that POST is redundant when using -d)

curl -H “Content-Type: application/json” -H “APCA-API-KEY-ID: zzzz” -H “APCA-API-SECRET-KEY: zzzz” -d “{/“symbol/”:/“AAPL/”,/“qty/”:/“1/”,/“side/”:/“buy/”,/“type/”:/“market/”,/“time\_in\_force/”:/“gtc/”}” “[https://paper-api.alpaca.markets/v2/orders](https://paper-api.alpaca.markets/v2/orders)”
