# Can you place an API trade against replay?

**URL:** <https://community.tradovate.com/t/can-you-place-an-api-trade-against-replay/2682>\
**Category:** API Developers\
**Created:** [July 9, 2021, 8:27pm UTC](https://community.tradovate.com/t/can-you-place-an-api-trade-against-replay/2682 "2021-07-09T20:27:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![wogann](https://avatars.discourse-cdn.com/v4/letter/w/7ea924/32.png) [@wogann](https://community.tradovate.com/u/wogann)\
**Post date:** [July 9, 2021, 8:27pm UTC](https://community.tradovate.com/t/can-you-place-an-api-trade-against-replay/2682/1 "2021-07-09T20:27:34Z")

</div>

Quick question, is there a rest endpoint for replay? eg. to place orders

I have successfully gotten an access token and placed an order against Demo and Live however I cannot receive an access token from the following replayUrl.

[https://demo.tradovateapi.com/v1](https://demo.tradovateapi.com/v1)  
[https://live.tradovateapi.com/v1](https://live.tradovateapi.com/v1)  
[https://replay.tradovateapi.com/v1](https://replay.tradovateapi.com/v1)

---

<div class="post-metadata">

**Author:** ![Alexander](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/alexander/32/988_2.png) [@Alexander](https://community.tradovate.com/u/Alexander)\
**Post date:** [October 1, 2021, 12:50pm UTC](https://community.tradovate.com/t/can-you-place-an-api-trade-against-replay/2682/2 "2021-10-01T12:50:32Z")

</div>

Hello @wogann,

You need to use a WebSocket to start a replay session. For more info on using WebSockets to run Replay sessions, check out [this section](https://api.tradovate.com/#section/Request-Examples/Market-Replay) of the docs.

---

<div class="post-metadata">

**Author:** ![wogann](https://avatars.discourse-cdn.com/v4/letter/w/7ea924/32.png) [@wogann](https://community.tradovate.com/u/wogann)\
**Post date:** [October 5, 2021, 11:07pm UTC](https://community.tradovate.com/t/can-you-place-an-api-trade-against-replay/2682/3 "2021-10-05T23:07:40Z")

</div>

Yes I meant to place a trade against replay? Can I send a socket client request like this in order to place an order?

WebSocket.Send(“order/placeorder\n50\n\n{“AccountSpec”: “RPLxxxxxx-x”,“AccountId”: “”,“ClOrdId”: “”,“Action”: “Buy”,“Symbol”: “MNQZ1”,“OrderQty”: 1,“OrderType”: “Market”,“Price”: “”,“StopPrice”: “”,“MaxShow”: “”,“PegDifference”: “”,“TimeInForce”: “Day”,“ExpireTime”: “”,“Text”: “Sample”,“ActivationTime”: “”,“IsAutomated”: “True”}”);

---

<div class="post-metadata">

**Author:** ![Alexander](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/alexander/32/988_2.png) [@Alexander](https://community.tradovate.com/u/Alexander)\
**Post date:** [October 6, 2021, 1:14pm UTC](https://community.tradovate.com/t/can-you-place-an-api-trade-against-replay/2682/4 "2021-10-06T13:14:47Z")

</div>

That’s pretty much exactly how you’d do it.

The Market Replay socket is unique in the sense that it occupies the same functional domains as both the real time socket (wss://live.tradovateapi.com/v1/websocket) and the market data socket (wss://md.tradovateapi.com/v1/websocket). So whether you want market data or to make a trade against replay, you’ll use the same Market Replay socket’s `send` method.

---

<div class="post-metadata">

**Author:** ![wogann](https://avatars.discourse-cdn.com/v4/letter/w/7ea924/32.png) [@wogann](https://community.tradovate.com/u/wogann)\
**Post date:** [September 25, 2022, 1:17am UTC](https://community.tradovate.com/t/can-you-place-an-api-trade-against-replay/2682/5 "2022-09-25T01:17:33Z")

</div>

Hi @Alexander I’m finally circling back on this one. I have not had success so far. I am not sure if I am missing a required field or I am targeting the right replay session since the -x on the end is variable each replay session.

When sending a change to the replay speed it is working and I see the change happen in the UI, so I know I have an active websocket connection to replay and am able to push a correctly formatted message. I believe my issue with /placeorder is the json itself. No issues with the following.

```auto
replay/changespeed
49

{ "speed":100}

```

This however is not working

```auto
order/placeorder
5

{"accountSpec": "DEMO123456","accountId": "RPL123456-62","action": "Buy","symbol":"NQU2","orderQty": 1,"orderType": "Market","isAutomated": true }

```

or

```auto
order/placeorder
5

{"AccountSpec": "RPL123456-62","AccountId": "","ClOrdId": "","Action": "Buy","Symbol": "NQU2","OrderQty": 1,"OrderType": "Market","Price": "","StopPrice": "","MaxShow": "","PegDifference": "","TimeInForce": "Day","ExpireTime": "","Text": "Sample","ActivationTime": ""}

```

or

```auto
order/placeorder
5

{"AccountSpec": "DEMO123456","AccountId": "","ClOrdId": "","Action": "Buy","Symbol": "NQU2","OrderQty": 1,"OrderType": "Market","Price": "","StopPrice": "","MaxShow": "","PegDifference": "","TimeInForce": "Day","ExpireTime": "","Text": "Sample","ActivationTime": ""}

```

I feel like I’m close on this but no luck so far, could you please advise?

Update: I found the response error. I definitely need help with the correct json to send in here.  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/tradingforum/original/2X/c/ca2cb9b529d71d93eb60079ae0e28fd983f4bd4b.png)

Next update: The first issue here is the AccountSpec is your username, and AccountId is the AccountId without DEMO or RPL prefixed to the integer. Maybe the doc can be more clear here?

```auto
order/placeorder
5

{"accountSpec": "userId","accountId": 123456,"action": "Buy","symbol":"NQU2","orderQty": 1,"orderType": "Market","isAutomated": true }

```

I am now stuck on a ‘Access is denied’, however I have confirmed the token has the maximum permissions possible and full access to the orders endpoint…Will continue.

 ![Screenshot 2022-09-24 230354](https://us1.discourse-cdn.com/flex015/uploads/tradingforum/original/2X/6/682711ce9fd005af8e9825538a451976f292789e.png)

---

<div class="post-metadata">

**Author:** ![AaronL](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@AaronL](https://community.tradovate.com/u/AaronL)\
**Post date:** [August 21, 2023, 4:45am UTC](https://community.tradovate.com/t/can-you-place-an-api-trade-against-replay/2682/6 "2023-08-21T04:45:54Z")

</div>

Were you ever able to figure this out? I’m having the same issue. I believe it’s because the accountId is incorrect. How do we get the accountId for a replay session?

The way I get it for a normal session is the API’s /account/list endpoint, but using that for a replay session just returns my DEMO account ID.

---

<div class="post-metadata">

**Author:** ![Frik](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/frik/32/2627_2.png) [@Frik](https://community.tradovate.com/u/Frik)\
**Post date:** [September 6, 2024, 7:59pm UTC](https://community.tradovate.com/t/can-you-place-an-api-trade-against-replay/2682/7 "2024-09-06T19:59:27Z")

</div>

Your accountId is wrong… it should be a number.

---

<div class="post-metadata">

**Author:** ![Frik](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/frik/32/2627_2.png) [@Frik](https://community.tradovate.com/u/Frik)\
**Post date:** [September 6, 2024, 8:00pm UTC](https://community.tradovate.com/t/can-you-place-an-api-trade-against-replay/2682/8 "2024-09-06T20:00:24Z")

</div>

as soon as you do an initClock, it will create a brand new account.

userSync events will tell what that account number is at that time when it is created
