# Api websocket and marketdata websocket

**URL:** <https://community.tradovate.com/t/api-websocket-and-marketdata-websocket/4037>\
**Category:** Community Support\
**Created:** [February 21, 2022, 8:40am UTC](https://community.tradovate.com/t/api-websocket-and-marketdata-websocket/4037 "2022-02-21T08:40:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![beebee](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/beebee/32/1776_2.png) [@beebee](https://community.tradovate.com/u/beebee)\
**Post date:** [February 21, 2022, 8:40am UTC](https://community.tradovate.com/t/api-websocket-and-marketdata-websocket/4037/1 "2022-02-21T08:40:16Z")

</div>

Hello

I am creating two websocket connections in different threads. I create a marketdata websocket connecting to  
`wss://md-demo.tradovateapi.com/v1/websocket`

I can subscribe to a particular future and get the market data.

I create another websocket to  
`wss.demo.tradovateapi.com/v1/websocket`  
The websocket comes up successfully but when I create a sample place order request like this  
order/placeorder

```auto
0

{"accountSpec":"xxx","accountId":xxx,"action":"Buy","timeInForce":"Day","symbol":"MESH2","orderQty":1,"orderType":"Market","isAutomated":true}

```

accountSpec is username returned from authentication  
accountId is the integer account id

I get this response  
`{'s': 200, 'i': 0, 'd': {'failureReason': 'UnknownReason', 'failureText': 'Access is denied'}}`

I am not sure why I am getting access denied. I noticed that there are two access tokens when I authenticate. There’s an accessToken and a mdAccessToken.

Why am I getting an access deniedd when trying to send buy/sell orders? I do not get any errors when sending orders to the marketdata websocket.

Also, does the sequence number need to be unique across the entire session or unique for each of the websocket connections?

---

<div class="post-metadata">

**Author:** ![beebee](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/beebee/32/1776_2.png) [@beebee](https://community.tradovate.com/u/beebee)\
**Post date:** [February 21, 2022, 1:57pm UTC](https://community.tradovate.com/t/api-websocket-and-marketdata-websocket/4037/2 "2022-02-21T13:57:27Z")

</div>

> [@beebee](#):
>
> ‘failureReason’: ‘UnknownReason’

Solving my own issue based on the response here: [Can trade in demo account, having trouble with live account - #10 by Alexander](https://community.tradovate.com/t/can-trade-in-demo-account-having-trouble-with-live-account/2663/10)

You need to call the account list endpoint, get the demo account userspec and userid, use that with when routing the orders and everything should work as expected.

---

<div class="post-metadata">

**Author:** ![Kart](https://avatars.discourse-cdn.com/v4/letter/k/87869e/32.png) [@Kart](https://community.tradovate.com/u/Kart)\
**Post date:** [April 29, 2022, 2:52am UTC](https://community.tradovate.com/t/api-websocket-and-marketdata-websocket/4037/3 "2022-04-29T02:52:34Z")

</div>

hi, which attribute from account list endpoint passing to ‘accountSpec’ in placeorder endpoint.

Appreciate your help!

---

<div class="post-metadata">

**Author:** ![beebee](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/beebee/32/1776_2.png) [@beebee](https://community.tradovate.com/u/beebee)\
**Post date:** [April 29, 2022, 12:48pm UTC](https://community.tradovate.com/t/api-websocket-and-marketdata-websocket/4037/4 "2022-04-29T12:48:21Z")

</div>

when u get the access token response

accountSpec is name from access token response  
accountId is userId from access token response

---

<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:** [April 29, 2022, 1:04pm UTC](https://community.tradovate.com/t/api-websocket-and-marketdata-websocket/4037/5 "2022-04-29T13:04:39Z")

</div>

`accountSpec` is the `name` field from the `accessTokenRequest` ([docs](https://api.tradovate.com/#operation/accessTokenRequest)) response, correct. But the `accountId` you need to get from the `/account/list` operation ([docs](https://api.tradovate.com/#operation/accountList)). Then you can choose one of your accounts. Typical users have a single account but it isn’t unheard of to have multiples. The `userId` field is used for things like starting a subscription to real-time data for your user.

---

<div class="post-metadata">

**Author:** ![beebee](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/beebee/32/1776_2.png) [@beebee](https://community.tradovate.com/u/beebee)\
**Post date:** [April 29, 2022, 1:18pm UTC](https://community.tradovate.com/t/api-websocket-and-marketdata-websocket/4037/6 "2022-04-29T13:18:20Z")

</div>

Thanks for the clarification.

There are the get account list and get user lists will provide more complete information.
