> For the complete documentation index, see [llms.txt](https://www.notbank.com/learn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.notbank.com/learn/api-reference/websocket-api/websocket-subscription.md).

# Websocket subscription

### SubscribeLevel1

**Permissions:** Public\
**Call Type:** Synchronous

Gets the latest Level 1 Ticker information and then subscribes the user to ongoing Level 1 market data event updates for one specific instrument.

The **SubscribeLevel1** API method responds with the Level 1 response shown below. The OMS then periodically sends in the same format as this response *Leve1UpdateEvent* information when best-bid/best-offer issue, until you send the **UnsubscribeLevel1** call.

#### Request

{% tabs %}
{% tab title="Node" %}

```javascript
import Notbank from 'notbank'
// websocket connection code ...

await client.getSubscriptionService().subscribeLevel1({
  InstrumentId: 2
});

// parameters
{
  InstrumentId?: number;
  Symbol?: string;
}
```

{% endtab %}

{% tab title="Java" %}

```java
import exchange.notbank.subscription.paramBuilders.SubscribeLevel1ParamBuilder;

var response = client.getSubscriptionService().subscribeLevel1(
    new SubscribeLevel1ParamBuilder(2),
        level1 -> snapshotConsumer(level1),
        level1 -> updateConsumer(level1)).get();
```

{% endtab %}

{% tab title="Python" %}

```python
from notbank_python_sdk.requests_models import SubscribeLevel1Request

client.subscribe_level_1(
    SubscribeLevel1Request(2),
    lambda level1: snapshot_handler(level1),
    lambda level1: update_handler(level1))
```

{% endtab %}

{% tab title="Json" %}

```json
{
  "m": 0,
  "i": 0,
  "n": "SubscribeLevel1",
  "o": "{
    \"OMSId\": 1,
    \"InstrumentId\": 2
  }"
}
```

{% endtab %}
{% endtabs %}

> SubscribeLevel1 is not available in http. Subscription APIs are only supported in websockets.

| Key          | Value                                                                                                                   |
| ------------ | ----------------------------------------------------------------------------------------------------------------------- |
| OMSId        | **integer**. The ID of the OMS. **required**.                                                                           |
| InstrumentId | **integer**. The ID of the instrument you’re tracking. **optional**.                                                    |
| Symbol       | **string**. Can be used instead of the InstrumentId. The symbol of the instrument you are subscribing to. **optional**. |

#### Response

The **SubscribeLevel1** response and *Level1UpdateEvent* both provide the same information.

```json
{
  "m": 1,
  "i": 0,
  "n": "SubscribeLevel1",
  "o": "{
    \"OMSId\": 1,
    \"InstrumentId\": 1,
    \"BestBid\": 6423.57,
    \"BestOffer\": 6436.53,
    \"LastTradedPx\": 6423.57,
    \"LastTradedQty\": 0.96183964,
    \"LastTradeTime\": 1534862990343,
    \"SessionOpen\": 6249.64,
    \"SessionHigh\": 11111,
    \"SessionLow\": 4433,
    \"SessionClose\": 6249.64,
    \"Volume\": 0.96183964,
    \"CurrentDayVolume\": 3516.31668185,
    \"CurrentDayNumTrades\": 8529,
    \"CurrentDayPxChange\": 173.93,
    \"CurrentNotional\": 0.0,
    \"Rolling24HrNotional\": 0.0,
    \"Rolling24HrVolume\": 4319.63870783,
    \"Rolling24NumTrades\": 10585,
    \"Rolling24HrPxChange\": -0.4165607307408487,
    \"TimeStamp\": \"1534862990358\"
  }"
}
```

> SubscribeLevel1 is not available in http. Subscription APIs are only supported in websockets.

| Key                  | Value                                                                                                                                                                             |
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| OMSId                | **integer**. The ID of the OMS.                                                                                                                                                   |
| InstrumentId         | **integer**. The ID of the instrument being tracked.                                                                                                                              |
| BestBid              | **decimal**. The current best bid for the instrument.                                                                                                                             |
| BestOffer            | **decimal**. The current best offer for the instrument.                                                                                                                           |
| LastTradedPx         | **decimal**. The last-traded price for the instrument.                                                                                                                            |
| LastTradedQty        | **decimal**. The last-traded quantity for the instrument.                                                                                                                         |
| LastTradeTime        | **long integer**. The time of the last trade, in POSIX format.                                                                                                                    |
| SessionOpen          | **decimal**. Opening price. In markets with openings and closings, this is the opening price for the current session; in 24-hour markets, it is the price as of UTC Midnight.     |
| SessionHigh          | **decimal**. Highest price during the trading day, either during a session with opening and closing prices or UTC midnight to UTC midnight.                                       |
| SessionLow           | **decimal**. Lowest price during the trading day, either during a session with opening and closing prices or UTC midnight to UTC midnight.                                        |
| SessionClose         | **decimal**. The closing price. In markets with openings and closings, this is the closing price for the current session; in 24-hour markets, it is the price as of UTC Midnight. |
| Volume               | **decimal**. The last-traded quantity for the instrument, same value as LastTradedQty                                                                                             |
| CurrentDayVolume     | **decimal**. The unit volume of the instrument traded either during a session with openings and closings or in 24-hour markets, the period from UTC Midnight to UTC Midnight.     |
| CurrentDayNumTrades  | **integer**. The number of trades during the current day, either during a session with openings and closings or in 24-hour markets, the period from UTC Midnight to UTC Midnight. |
| CurrentDayPxChange   | **decimal**. Current day price change, either during a trading session or UTC Midnight to UTC midnight.                                                                           |
| CurrentNotional      | **decimal**. Current day quote volume - resets at UTC Midnight.                                                                                                                   |
| Rolling24HrNotional  | **decimal**. Rolling 24 hours quote volume.                                                                                                                                       |
| Rolling24HrVolume    | **decimal**. Unit volume of the instrument during the past 24 hours, regardless of time zone. Recalculates continuously.                                                          |
| Rolling24HrNumTrades | **decimal**. Number of trades during the past 24 hours, regardless of time zone. Recalculates continuously.                                                                       |
| Rolling24HrPxChange  | **decimal**. Price change during the past 24 hours, regardless of time zone. Recalculates continuously.                                                                           |
| TimeStamp            | **string**. The time this information was provided, in POSIX format, it is stringified.                                                                                           |

### UnsubscribeLevel1

**Permissions:** Public\
**Call Type:** Synchronous

Unsubscribes the user from a Level 1 Market Data Feed subscription.

#### Request

{% tabs %}
{% tab title="Node" %}

```javascript
import Notbank from 'notbank'
// websocket connection code ...

await client.getSubscriptionService().unsubscribeLevel1({
  InstrumentId: 2
});

// parameters
{
  InstrumentId?: number;
  Symbol?: string;
}
```

{% endtab %}

{% tab title="Java" %}

```java
import exchange.notbank.subscription.paramBuilders.UnsubscribeLevel1ParamBuilder;

client.getSubscriptionService().unsubscribeLevel1(new UnsubscribeLevel1ParamBuilder(2));
```

{% endtab %}

{% tab title="Python" %}

```python
from notbank_python_sdk.requests_models import UnsubscribeLevel1Request

client.unsubscribe_level_1(UnsubscribeLevel1Request(2))
```

{% endtab %}

{% tab title="Json" %}

```json
{
  "m": 0,
  "i": 0,
  "n": "SubscribeLevel1",
  "o": "{
    \"OMSId\": 1,
    \"InstrumentId\": 2,
  }"
}
```

{% endtab %}
{% endtabs %}

> UnSubscribeLevel1 is not available in http. Subscription APIs are only supported in websockets.

| Key          | Value                                                                                                                                     |
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------- |
| OMSId        | **integer**. The ID of the OMS. **required**.                                                                                             |
| InstrumentId | **integer**. The ID of the instrument you’re unsubscribing level1 updates from. **optional**.                                             |
| Symbol       | **string**. Can be used instead of the InstrumentId. The symbol of the instrument you’re unsubscribing level1 updates from. **optional**. |

#### Response

```json
{
  "m": 1,
  "i": 0,
  "n": "SubscribeLevel1",
  "o": "{
    \"result\": true,
    \"errormsg\": null,
    \"errorcode\": 0,
    \"detail\": null
  }"
}
```

> UnSubscribeLevel1 is not available in http. Subscription APIs are only supported in websockets.

| Key       | Value                                                                                                                                                                                                                                                                                                                                                                                   |
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| result    | **boolean**. A successful receipt of the unsubscribe request returns *true*; and unsuccessful receipt (an error condition) returns *false*.                                                                                                                                                                                                                                             |
| errormsg  | <p><strong>string</strong>. A successful receipt of the unsubscribe request returns <em>null</em>; the <em>errormsg</em> parameter for an unsuccessful request returns one of the following messages:<br>Not Authorized (errorcode 20)<br>Invalid Request (errorcode 100)<br>Operation Failed (errorcode 101)<br>Server Error (errorcode 102)<br>Resource Not Found (errorcode 104)</p> |
| errorcode | **integer**. A successful receipt of the unsubscribe request returns 0. An unsuccessful receipt returns one of the *errorcodes* shown in the *errormsg* list.                                                                                                                                                                                                                           |
| detail    | **string**. Message text that the system may send. Usually *null*.                                                                                                                                                                                                                                                                                                                      |

### SubscribeLevel2

**Permissions:** Public\
**Call Type:** Synchronous

Gets the latest Level 2 Ticker information and then subscribes the user to Level 2 market data event updates for one specific instrument. Level 2 allows the user to specify the level of market depth information on either side of the bid and ask. The **SubscribeLevel2** call responds with the Level 2 response shown below. The OMS then periodically sends *Level2UpdateEvent* information in the same format as this response until you send the **UnsubscribeLevel2** call.

**Note:** *Depth* in this API method is "depth of market," the number of buyers and sellers at greater or lesser prices in the order book for the instrument.

#### Request

{% tabs %}
{% tab title="Node" %}

```javascript
import Notbank from 'notbank'
// websocket connection code ...

await client.getSubscriptionService().subscribeLevel2({
  InstrumentId: 2,
  Depth: 10
});

// parameters
{
  InstrumentId?: number;
  Symbol?: string;
  Depth: number;
}
```

{% endtab %}

{% tab title="Java" %}

```java
import exchange.notbank.subscription.paramBuilders.SubscribeLevel2ParamBuilder;

var response = client.getSubscriptionService().subscribeLevel2(
        new SubscribeLevel2ParamBuilder(2, 10),
        level2 -> snapshotConsumer(level2),
        level2 -> updateConsumer(level2)).get();
```

{% endtab %}

{% tab title="Python" %}

```python
from notbank_python_sdk.requests_models import SubscribeLevel2Request

response = client.subscribe_level_2(
    SubscribeLevel2Request(10, 2),
    lambda level2: handle_snapshot(level2),
    lambda level2: handle_update(level2))
```

{% endtab %}

{% tab title="Json" %}

```json
{
  "m": 0,
  "i": 0,
  "n": "SubscribeLevel2",
  "o": "{
    \"OMSId\": 1,
    \"InstrumentId\": 2,
    \"Depth\": 2
  }"
}
```

{% endtab %}
{% endtabs %}

> SubscribeLevel2 is not available in http. Subscription APIs are only supported in websockets.

| Key          | Value                                                                                                                           |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------- |
| OMSId        | **integer**. The ID of the OMS. **required**.                                                                                   |
| InstrumentId | **integer**. The ID of the instrument you’re tracking. **optional**.                                                            |
| Symbol       | **string**. Can be used instead of the InstrumentId. The symbol of the instrument you are subscribing to. **optional**.         |
| Depth        | **integer**. The depth of the order book. The example request returns 10 price levels on each side of the market. **required**. |

#### Response

```json
{
  "m": 1,
  "i": 0,
  "n": "SubscribeLevel2",
  "o": "[
    [
      0, // MDUpdateId
      1, // Number of Accounts
      123, // ActionDateTime in Posix format X 1000
      0, // ActionType 0 (New), 1 (Update), 2(Delete)
      0.0, // LastTradePrice
      0, // Number of Orders
      0.0, //Price
      0, // ProductPairCode
      0.0, // Quantity
      0, // Side
    ]
  ]"
}
```

> SubscribeLevel2 is not available in http. Subscription APIs are only supported in websockets.

The response is an array of elements for one specific instrument, the number of elements correspons to the depth specified in the Request. It is sent as an uncommented, comma-delimited list of numbers. The example is commented.

| Key                | Value                                                                                                                                                                                                          |
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| MDUpdateID         | **long integer**. Market Data Update ID. This sequential ID identifies the order in which the update was created.                                                                                              |
| Number of Accounts | **integer**. Number of accounts                                                                                                                                                                                |
| ActionDateTime     | **long integer**. *ActionDateTime* identifies the time and date that the snapshot was taken or the event occurred, in POSIX format X 1000 (milliseconds since 1 January 1970).                                 |
| ActionType         | <p><strong>integer</strong>. L2 information provides price data. This value shows whether this data is one of:<br>- <strong>0</strong> new<br>- <strong>1</strong> update<br>- <strong>2</strong> deletion</p> |
| LastTradePrice     | **decimal**. The price at which the instrument was last traded.                                                                                                                                                |
| Number of Orders   | **decimal**. Number of orders.                                                                                                                                                                                 |
| Price              | **decimal**. Bid or Ask price for the Quantity (see *Quantity* below).                                                                                                                                         |
| ProductPairCode    | **integer**. *ProductPairCode* is the same value and used for the same purpose as *InstrumentID*. The two are completely equivalent. *InstrumentId* 47 = *ProductPairCode* 47.                                 |
| Quantity           | **decimal**. Quantity available at a given Bid or Ask price (see *Price* above).                                                                                                                               |
| Side               | <p><strong>integer</strong>. One of:<br>- <strong>0</strong> Buy<br>- <strong>1</strong> Sell<br>- <strong>2</strong> Short (reserved for future use)<br>- <strong>3</strong> Unknown (an error condition)</p> |

### UnsubscribeLevel2

**Permissions:** Public\
**Call Type:** Synchronous

Unsubscribes the user from a Level 2 Market Data Feed subscription.

#### Request

{% tabs %}
{% tab title="Node" %}

```javascript
import Notbank from 'notbank'
// websocket connection code ...
await client.getSubscriptionService().unsubscribeLevel2({
  Symbol: "BTCUSD"
});

// parameters
{
  InstrumentId?: number;
  Symbol?: string;
}
```

{% endtab %}

{% tab title="Java" %}

```java
import exchange.notbank.subscription.paramBuilders.UnsubscribeLevel2ParamBuilder;

client.getSubscriptionService().unsubscribeLevel2(new UnsubscribeLevel2ParamBuilder(2));
```

{% endtab %}

{% tab title="Python" %}

```python
from notbank_python_sdk.requests_models import UnsubscribeLevel2Request

client.unsubscribe_level_2(
            UnsubscribeLevel2Request(2))
```

{% endtab %}

{% tab title="Json" %}

```json
{
  "m": 0,
  "i": 0,
  "n": "UnsubscribeLevel2",
  "o": "{
    \"OMSId\": 1,
    \"InstrumentId\": 2,
  }"
}
```

{% endtab %}
{% endtabs %}

> UnSubscribeLevel2 is not available in http. Subscription APIs are only supported in websockets.

| Key          | Value                                                                                                                                   |
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
| OMSId        | **integer**. The ID of the OMS. **required**.                                                                                           |
| InstrumentId | **integer**. The ID of the instrument being tracked by the Level 2 market data feed. **optional**.                                      |
| Symbol       | **string**. Can be used instead of the InstrumentId. The symbol of the instrument you are unsubscribing level2 data from. **optional**. |

#### Response

```json
{
  "m": 1,
  "i": 0,
  "n": "UnsubscribeLevel2",
  "o": "{
    \"result\": true,
    \"errormsg\": null,
    \"errorcode\": 0,
    \"detail\": null
  }"
}
```

> UnSubscribeLevel2 is not available in http. Subscription APIs are only supported in websockets.

| Key       | Value                                                                                                                                                                                                                                                                                                                                                                                   |
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| result    | **boolean**. A successful receipt of the unsubscribe request returns *true*; and unsuccessful receipt (an error condition) returns *false*.                                                                                                                                                                                                                                             |
| errormsg  | <p><strong>string</strong>. A successful receipt of the unsubscribe request returns <em>null</em>; the <em>errormsg</em> parameter for an unsuccessful request returns one of the following messages:<br>Not Authorized (errorcode 20)<br>Invalid Request (errorcode 100)<br>Operation Failed (errorcode 101)<br>Server Error (errorcode 102)<br>Resource Not Found (errorcode 104)</p> |
| errorcode | **integer**. A successful receipt of the unsubscribe request returns 0. An unsuccessful receipt returns one of the *errorcodes* shown in the *errormsg* list.                                                                                                                                                                                                                           |
| detail    | **string**. Message text that the system may send. Usually *null*.                                                                                                                                                                                                                                                                                                                      |

### SubscribeTrades

**Permissions:** Public\
**Call Type:** Synchronous

Subscribes an authenticated user to the Trades Market Data Feed for a specific instrument.

#### Request

{% tabs %}
{% tab title="Node" %}

```javascript
import Notbank from 'notbank'
// websocket connection code ...

await client.getSubscriptionService().subscribeTrades(
  request: {
    InstrumentId: 2,
    IncludeLastCount: 3
  },
  subcriptionHandler: (trade: TradeSummary) => void
);

// parameters
{
  InstrumentId: number;
  IncludeLastCount: number;
}

// response
TradeSummary: {
  TradeId: number;
  InstrumentId: number;
  Quantity: number;
  Price: number;
  Order1: number;
  Order2: number;
  Tradetime: number;
  Direction: number;
  TakerSide: number;
  BlockTrade: boolean;
  OrderClientId: number;
}
```

{% endtab %}

{% tab title="Java" %}

```java
import exchange.notbank.subscription.paramBuilders.SubscribeTradesParamBuilder;

var response = client.getSubscriptionService().subscribeTrades(
        new SubscribeTradesParamBuilder(2, 3),
        trades -> snapshotConsumer(trades),
        trades -> updateConsumer(trades)).get();
```

{% endtab %}

{% tab title="Python" %}

```python
from notbank_python_sdk.requests_models import SubscribeTradesRequest

client.subscribe_trades(
    SubscribeTradesRequest(2, 3),
    lambda trades: handle_snapshot(trades),
    lambda trades: handle_update(trades))
```

{% endtab %}

{% tab title="Json" %}

```json
{
  "m": 0,
  "i": 0,
  "n": "SubscribeTrades",
  "o": "{
    \"OMSId\": 1,
    \"InstrumentId\": 2,
    \"IncludeLastCount\": 3
  }"
}
```

{% endtab %}
{% endtabs %}

> SubscribeTrades is not available in http. Subscription APIs are only supported in websockets.

| Key              | Value                                                                                                     |
| ---------------- | --------------------------------------------------------------------------------------------------------- |
| OMSId            | **integer**. The ID of the OMS on which the instrument is traded. **required**.                           |
| InstrumentId     | **integer**. The ID of the instrument whose trades will be reported. **required**.                        |
| IncludeLastCount | **integer**. Specifies the number of previous trades to retrieve in the immediate snapshot. **required**. |

#### Response

> Numerical keys reduce package transmission load. See Response table for an explanation.

```json
{
  "m": 1,
  "i": 0,
  "n": "SubscribeTrades",
  "o": "[
    {
      0: 1713390,
      1: 1,
      2: 0.25643269,
      3: 6419.77,
      4: 203100209,
      5: 203101083,
      6: 1534863265752,
      7: 2,
      8: 1,
      9: 0,
      10: 0,
    },
  ]"
}
```

> SubscribeTrades is not available in http. Subscription APIs are only supported in websockets.

The response returns an array of trades. The keys of each trade are numbers to reduce payload traffic.

| Key                                   | Value                                                                                                                                                                                                                                                                                                                 |
| ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 0 (TradeId)                           | **integer**. The ID of this trade.                                                                                                                                                                                                                                                                                    |
| 1 (InstrumentId)                      | **integer**. The ID of the instrument.                                                                                                                                                                                                                                                                                |
| 2 (Quantity)                          | **decimal**. The quantity of the instrument traded.                                                                                                                                                                                                                                                                   |
| 3 (Price)                             | **decimal**. The price at which the instrument was traded.                                                                                                                                                                                                                                                            |
| 4 (Order1)                            | **integer**. The ID of the first order that resulted in the trade, either Buy or Sell.                                                                                                                                                                                                                                |
| 5 (Order2)                            | **integer**. The ID of the second order that resulted in the trade, either Buy or Sell.                                                                                                                                                                                                                               |
| 6 (Tradetime)                         | **long integer**. UTC trade time in Total Milliseconds. POSIX format.                                                                                                                                                                                                                                                 |
| 7 (Direction)                         | <p><strong>integer</strong>. Effect of the trade on the instrument’s market price. One of:<br>- 0 NoChange<br>- 1 UpTick<br>- 2 DownTick</p>                                                                                                                                                                          |
| 8 (TakerSide)                         | <p><strong>integer</strong>. The side of the trade that took liquidity. One of:<br>- 0 Buy<br>- 1 Sell<br>The maker side of the trade provides liquidity by placing the order on the book (this can be a buy or a sell order). The other, taker, side takes the liquidity. It, too, can be buy-side or sell-side.</p> |
| 9 (BlockTrade)                        | **boolean**. If this was a privately negotiated trade that was reported to the OMS. A private trade returns *true*; otherwise *false*. Default is *false*.                                                                                                                                                            |
| 10 (order1ClientId or order2ClientId) | **integer**. The client-supplied order ID for the trade. Internal logic determines whether the program reports the *order1ClientId* or the *order2ClientId*.                                                                                                                                                          |

### UnsubscribeTrades

**Permissions:** Public\
**Call Type:** Synchronous

Unsubscribes the user from a Trades Market Data Feed

#### Request

{% tabs %}
{% tab title="Node" %}

```javascript
import Notbank from 'notbank'
// websocket connection code ...

await client.getSubscriptionService().unsubscribeTrades({
  InstrumentId: 2
});
// parameters
{
  InstrumentId: number;
}
```

{% endtab %}

{% tab title="Java" %}

```java
import exchange.notbank.subscription.paramBuilders.UnsubscribeTradesParamBuilder;

client.getSubscriptionService().unsubscribeTrades(new UnsubscribeTradesParamBuilder(2));
```

{% endtab %}

{% tab title="Python" %}

```python
from notbank_python_sdk.requests_models import UnsubscribeTradesRequest

client.unsubscribe_trades(UnsubscribeTradesRequest(154))
```

{% endtab %}

{% tab title="Json" %}

```json
{
  "m": 0,
  "i": 0,
  "n": "UnsubscribeTrades",
  "o": "{
    \"OMSId\": 1,
    \"InstrumentId\": 2,
  }"
}
```

{% endtab %}
{% endtabs %}

> UnsubscribeTrades is not available in http. Subscription APIs are only supported in websockets.

| Key          | Value                                                                                                       |
| ------------ | ----------------------------------------------------------------------------------------------------------- |
| OMSId        | **integer**. The ID of the OMS on which the user has subscribed to a trades market data feed. **required**. |
| InstrumentId | **integer**. The ID of the instrument being tracked by the trades market data feed. **required**.           |

#### Response

```json
{
  "m": 1,
  "i": 0,
  "n": "UnsubscribeTrades",
  "o": "{
    \"result\": true,
    \"errormsg\": null,
    \"errorcode\": 0,
    \"detail\": null
  }"
}
```

> UnsubscribeTrades is not available in http. Subscription APIs are only supported in websockets.

| Key       | Value                                                                                                                                                                                                                                                                                                                                                                                   |
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| result    | **boolean**. A successful receipt of the unsubscribe request returns *true*; and unsuccessful receipt (an error condition) returns *false*.                                                                                                                                                                                                                                             |
| errormsg  | <p><strong>string</strong>. A successful receipt of the unsubscribe request returns <em>null</em>; the <em>errormsg</em> parameter for an unsuccessful request returns one of the following messages:<br>Not Authorized (errorcode 20)<br>Invalid Request (errorcode 100)<br>Operation Failed (errorcode 101)<br>Server Error (errorcode 102)<br>Resource Not Found (errorcode 104)</p> |
| errorcode | **integer**. A successful receipt of the unsubscribe request returns 0. An unsuccessful receipt returns one of the *errorcodes* shown in the *errormsg* list.                                                                                                                                                                                                                           |
| detail    | **string**. Message text that the system may send. Usually *null*.                                                                                                                                                                                                                                                                                                                      |

### SubscribeTicker

**Permissions:** Public\
**Call Type:** Synchronous

Subscribes User to Ticker Market Data Feed of a specific instrument. Interval is number of seconds for each bar. IncludeLastCount field specifies the number of previous bars to retrieve as a snapshot.

#### Request

{% tabs %}
{% tab title="Node" %}

```javascript
import Notbank from 'notbank'
// websocket connection code ...

await client.getSubscriptionService().subscribeTicker(
  request: {
    InstrumentId: 2,
    Interval: 60,
    IncludeLastCount: 5
  }, 
  // Callbacks
  snapshotHandler:  (tickers: TickerFeed[]) => void,
  updateHandler:  (tickers: TickerFeed[]) => void
);

// request parameters
{
  InstrumentId: number;
  Interval: number;
  IncludeLastCount: number;
}

// response
type TickerFeed = [
  EndDateTime: number,
  High: number,
  Low: number,
  Open: number,
  Close: number,
  Volume: number,
  Bid: number,
  Ask: number,
  InstrumentId: number,
  BeginDateTime: number
];
```

{% endtab %}

{% tab title="Java" %}

```java
import exchange.notbank.subscription.paramBuilders.SubscribeTickerParamBuilder;

var response = client.getSubscriptionService().subscribeTicker(
    new SubscribeTickerParamBuilder(2, 60, 5),
    ticker -> snapshotHandler(ticker),
    ticker -> updateHandler(ticker)).get();
```

{% endtab %}

{% tab title="Python" %}

```python
from notbank_python_sdk.requests_models import SubscribeTickerRequest

client.subscribe_ticker(
    SubscribeTickerRequest(2, 60, 5),
    lambda ticker: snapshot_handler(ticker),
    lambda ticker: update_handler(ticker))
```

{% endtab %}

{% tab title="Json" %}

```json
{
  "m": 0,
  "i": 0,
  "n": "SubscribeTicker",
  "o": "{
    \"OMSId\": 1,
    \"InstrumentId\": 2,
    \"IncludeLastCount\": 5
  }"
}
```

{% endtab %}
{% endtabs %}

> SubscribeTicker is not available in http. Subscription APIs are only supported in websockets.

| Key              | Value                                                                                                                                                                   |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| OMSId            | **integer**. The ID of the OMS. **required**.                                                                                                                           |
| InstrumentId     | **integer**. The ID of the instrument whose ticker data you want to track. **required**.                                                                                |
| Interval         | **integer**. The number of seconds for each bar. One of: 60, 300, 900, 1800, 3600, 7200, 14400, 21600, 43200, 86400, 604800, 2419200, 9676800, 125798400. **required**. |
| IncludeLastCount | **integer**. The number of previous bars to retrieve as a snapshot. **required**.                                                                                       |

#### Response

```json
{
  "m": 1,
  "i": 0,
  "n": "SubscribeTicker",
  "o": "[
    [
      1692926460000, //EndDateTime
      28432.44, //High
      28432.44, //Low
      28432.44, //Open
      28432.44, //Close
      0, //Volume
      0, //Best Bid
      0, //Best Ask
      1, //InstrumentId
      1692926400000, //BeginDateTime
    ],
  ]"
}
```

> SubscribeTicker is not available in http. Subscription APIs are only supported in websockets.

The response returns an array of objects , each object an unlabeled, comma-delimited array of numbers. The Open price and Close price are those at the beginning of the tick — the Interval time subscribed to in the request. For 24-hour exchanges, the trading day runs from UTC midnight to UTC midnight; highs, lows, opens, closes, and volumes consider that midnight-to-midnight period to be the trading day.

| Key           | Value                                                                                     |
| ------------- | ----------------------------------------------------------------------------------------- |
| EndDateTime   | **long integer**. The end/closing date and time of the ticker, in UTC and POSIX format.   |
| High          | **decimal**. The Highest Trade Price for the Time-Period (0 if no trades).                |
| Low           | **decimal**. The Lowest Trade Price for the Time-Period (0 if no trades).                 |
| Open          | **decimal**. The Opening Trade Price for the Time-Period (0 if no trades).                |
| Close         | **decimal**. The Last Trade Price for the Time-Period (0 if no trades).                   |
| Volume        | **decimal**. The Total Trade Volume since the last Tick.                                  |
| Bid           | **decimal**. The best bid price at the time of the Tick.                                  |
| Ask           | **decimal**. The best ask price at the time of the Tick.                                  |
| InstrumentId  | **integer**. The ID of the instrument.                                                    |
| BeginDateTime | **long integer**. The start/opening date and time of the ticker, in UTC and POSIX format. |

### UnsubscribeTicker

**Permissions:** Public\
**Call Type:** Synchronous

Unsubscribes the user from a Ticker Market Data Feed.

#### Request

{% tabs %}
{% tab title="Node" %}

```javascript
import Notbank from 'notbank'
// websocket connection code ...

await client.getSubscriptionService().unsubscribeTicker(
  InstrumentId: 2
);

// request parameters
{
  InstrumentId: number;
}
```

{% endtab %}

{% tab title="Java" %}

```java
import exchange.notbank.subscription.paramBuilders.UnsubscribeTickerParamBuilder;

var response = client.getSubscriptionService()
        .unsubscribeTicker(new UnsubscribeTickerParamBuilder(2)).get();
```

{% endtab %}

{% tab title="Python" %}

```python
from notbank_python_sdk.requests_models import UnsubscribeTickerRequest

client.unsubscribe_ticker(UnsubscribeTickerRequest(2))
```

{% endtab %}

{% tab title="Json" %}

```json
{
  "m": 0,
  "i": 0,
  "n": "UnsubscribeTicker",
  "o": "{
    \"OMSId\": 1,
    \"InstrumentId\": 2
  }"
}
```

{% endtab %}
{% endtabs %}

> UnsubscribeTicker is not available in http. Subscription APIs are only supported in websockets.

| Key          | Value                                                                                             |
| ------------ | ------------------------------------------------------------------------------------------------- |
| OMSId        | **integer**. The ID of the OMS. **required**.                                                     |
| InstrumentId | **integer**. The ID of the instrument being tracked by the ticker market data feed. **required**. |

#### Response

```json
{
  "m": 1,
  "i": 0,
  "n": "UnsubscribeTicker",
  "o": "{
    \"result\": true,
    \"errormsg\": null,
    \"errorcode\": 0,
    \"detail\": null
  }"
}
```

> UnsubscribeTicker is not available in http. Subscription APIs are only supported in websockets.

| Key       | Value                                                                                                                                                                                                                                                                                                                                                                                   |
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| result    | **boolean**. A successful receipt of the unsubscribe request returns *true*; and unsuccessful receipt (an error condition) returns *false*.                                                                                                                                                                                                                                             |
| errormsg  | <p><strong>string</strong>. A successful receipt of the unsubscribe request returns <em>null</em>; the <em>errormsg</em> parameter for an unsuccessful request returns one of the following messages:<br>Not Authorized (errorcode 20)<br>Invalid Request (errorcode 100)<br>Operation Failed (errorcode 101)<br>Server Error (errorcode 102)<br>Resource Not Found (errorcode 104)</p> |
| errorcode | **integer**. A successful receipt of the unsubscribe request returns 0. An unsuccessful receipt returns one of the *errorcodes* shown in the *errormsg* list.                                                                                                                                                                                                                           |
| detail    | **string**. Message text that the system may send. Usually *null*.                                                                                                                                                                                                                                                                                                                      |

### SubscribeAccountEvents

**Permissions:** NotbankTrading, NotbankReadOnly\
**Call Type:** Synchronous

Subscribe to account-level events, such as orders, trades, deposits and withdraws. Can be used to monitor account transactions real-time.

#### Request

{% tabs %}
{% tab title="Node" %}

```javascript
import Notbank from 'notbank'
// websocket connection code ...

await client.getSubscriptionService().subscribeAccountEvents(
  request: {
    AccountId: 1
  }, 
  subcriptionHandler: {
    withdrawTicketUpdateEventHandler?: (event: WithdrawTicket) => void;
    orderTradeEventHandler?: (event: OrderTrade) => void;
    orderStateEventHandler?: (event: Order) => void;
    depositTicketUpdateEventHandler?: (event: DepositTicket) => void;
    accountPositionEventHandler?: (event: AccountPosition) => void;
    accountInfoUpdateEventHandler?: (event: AccountInfo) => void;
    cancelOrderRejectEventHandler?: (event: CancelOrderRejectEvent) => void;
    depositEventHandler?: (event: DepositEvent) => void;
    transactionEventHandler?: (event: Transaction) => void;
  }
);

// request parameters
{
  AccountId: number;  // Required
}

// responses

WithdrawTicket {
  AssetManagerId: number;
  AccountProviderId: number;
  AccountId: number;
  AccountName: string;
  AssetId: number;
  AssetName: string;
  Amount: number;
  NotionalValue: number;
  NotionalProductId: number;
  TemplateForm: string;
  TemplateFormType?: string;
  OMSId: number;
  RequestCode: string;
  RequestIP?: string;
  RequestUserId: number;
  RequestUserName: string;
  OperatorId: number;
  Status: string;
  FeeAmt: number;
  UpdatedByUser: number;
  UpdatedByUserName?: string;
  TicketNumber: number;
  WithdrawTransactionDetails: string;
  RejectReason?: string;
  CreatedTimestamp: string;
  LastUpdateTimestamp: string;
  CreatedTimestampTick: number;
  LastUpdateTimestampTick: number;
  Comments: any[];
  Attachments: any[];
  AuditLog: any[];
}

OrderTrade {
  OMSId: number;
  ExecutionId: number;
  TradeId: number;
  OrderId: number;
  AccountId: number;
  AccountName: string;
  SubAccountId: number;
  ClientOrderId: number;
  InstrumentId: number;
  Side: TradeSide;
  OrderType: OrderTypeInt;
  Quantity: number;
  RemainingQuantity: number;
  Price: number;
  Value: number;
  CounterParty: string;
  OrderTradeRevision: number;
  Direction: TradeDirection;
  IsBlockTrade: boolean;
  Fee: number;
  FeeProductId: number;
  OrderOriginator: number;
  UserName: string;
  TradeTimeMS: number;
  MakerTaker: MakerTaker;
  InsideBid: number;
  InsideBidSize: number;
  InsideAsk: number;
  InsideAskSize: number;
  NotionalProductId: number;
  NotionalRate: number;
  NotionalValue: number;
  TradeTime: number;
  AdapterTradeId: number;
  IsQuote: boolean;
  CounterPartyClientUserId: number;
  NotionalHoldAmount: number;
  TradeFlag: string;
}

Order {
  OMSId: number;
  Side: OrderSide;
  OrderId: number;
  Price: number;
  Quantity: number;
  DisplayQuantity: number;
  Instrument: number;
  Account: number;
  AccountName: string;
  OrderType: OrderTypeInt;
  ClientOrderId: number;
  OrderState: OrderState;
  ReceiveTime: number;
  ReceiveTimeTicks: number;
  LastUpdatedTime: number;
  LastUpdatedTimeTicks: number;
  OrigQuantity: number;
  QuantityExecuted: number;
  GrossValueExecuted: number;
  ExecutableValue: number;
  AvgPrice: number;
  CounterPartyId: number;
  ChangeReason: ChangeReason;
  OrigOrderId: number;
  OrigClOrdId: number;
  EnteredBy: number;
  UserName: string;
  IsQuote: false;
  InsideAsk: number;
  InsideAskSize: number;
  InsideBid: number;
  InsideBidSize: number;
  LastTradePrice: number;
  RejectReason?: any;
  IsLockedIn: false;
  CancelReason?: any;
  OrderFlag: string;
  UseMargin: false;
  StopPrice: number;
  PegPriceType: string;
  PegOffset: number;
  PegLimitOffset: number;
  IpAddress?: any;
  IPv6a: number;
  IPv6b: number;
  ClientOrderIdUuid?: any;
}

DepositTicket {
  AssetManagerId: number;
  AccountProviderId: number;
  AccountId: number;
  AssetId: number;
  AccountName: string;
  AssetName: string;
  Amount: number;
  NotionalValue: number;
  NotionalProductId: number;
  OMSId: number;
  RequestCode: string;
  ReferenceId: string;
  RequestIP: string;
  RequestUser: number;
  RequestUserName: string;
  OperatorId: number;
  Status: string;
  FeeAmt: number;
  UpdatedByUser: number;
  UpdatedByUserName: string;
  TicketNumber: number;
  DepositInfo: string;
  RejectReason?: string;
  CreatedTimestamp: string;
  LastUpdateTimeStamp: string;
  CreatedTimestampTick: string;
  LastUpdateTimeStampTick: string;
  Comments: any[];
  Attachments: any[];
}

AccountPosition {
  OMSId: number;
  AccountId: number;
  ProductSymbol: string;
  ProductId: number;
  Amount: number;
  Hold: number;
  PendingDeposits: number;
  PendingWithdraws: number;
  TotalDayDeposits: number;
  TotalMonthDeposits: number;
  TotalYearDeposits: number;
  TotalDayDepositNotional: number;
  TotalMonthDepositNotional: number;
  TotalYearDepositNotional: number;
  TotalDayWithdraws: number;
  TotalMonthWithdraws: number;
  TotalYearWithdraws: number;
  TotalDayWithdrawNotional: number;
  TotalMonthWithdrawNotional: number;
  TotalYearWithdrawNotional: number;
  NotionalProductId: number;
  NotionalProductSymbol: string;
  NotionalValue: number;
  NotionalHoldAmount: number;
  NotionalRate: number;
  TotalDayTransferNotional: number;
}

AccountInfo {
  OMSID: number;
  AccountId: number;
  AccountName: string;
  AccountHandle?: string;
  FirmId?: string;
  FirmName?: string;
  AccountType: AccountType;
  FeeGroupId: number;
  ParentID: number;
  RiskType: RiskType;
  VerificationLevel: number;
  VerificationLevelName?: string;
  CreditTier: number;
  FeeProductType: FeeProductType;
  FeeProduct: number;
  RefererId: number;
  LoyaltyProductId: number;
  LoyaltyEnabled: boolean;
  PriceTier: number;
  Frozen: boolean;
}

CancelOrderRejectEvent {
  OMSId: number;
  AccountId: number;
  OrderId: number;
  OrderRevision: number;
  OrderType: string;
  InstrumentId: number;
  Status: string;
  RejectReason: string;
}

DepositEvent {
  OMSId: number;
  AccountId: number;
  ProductId: number;
  Quantity: number;
  SubAccountId: number;
}

Transaction {
  TransactionId: number;
  OMSId: number;
  AccountId: number;
  CR: number;
  DR: number;
  Counterparty: number;
  TransactionType: string;
  ReferenceId: number;
  ReferenceType: string;
  ProductId: number;
  Balance: number;
  TimeStamp: number;
}
```

{% endtab %}

{% tab title="Java" %}

```java
import exchange.notbank.subscription.paramBuilders.SubscribeAccountEventsParamBuilder;

var response = client.getSubscriptionService().subscribeAccountEvents(
    new SubscribeAccountEventsParamBuilder(7)
        .withdrawTicketHandler(withdrawTicket -> System.out.print("withdraw ticket: " + withdrawTicket))
        .transactionHandler(transaction -> System.out.println("transaction: " + transaction))
        .tradeHandler(trade -> System.out.println("trade: " + trade))
        .orderHandler(order -> System.out.println("Order: " + order))
        .depositTicketHandler(depositTicket -> System.out.println("Deposit Ticket: " + depositTicket))
        .accountInfoHandler(accountInfo -> System.out.println("Account Info: " + accountInfo))
        .depositHandler(deposit -> System.out.println("Deposit: " + deposit))
        .cancelOrderReject(cancelOrderReject -> System.out.println("Cancel Order Reject: " + cancelOrderReject))
        .balanceHandler(balance -> System.out.println("Balance: " + balance))).get();
```

{% endtab %}

{% tab title="Python" %}

```python
from notbank_python_sdk.requests_models import SubscribeAccountEventsRequest

client.subscribe_account_events(
    SubscribeAccountEventsRequest(1),
    lambda ticket: print("withdraw ticket", ticket),
    lambda transaction: print("transaction", transaction),
    lambda trade: print("trade", trade),
    lambda order: print("order", order),
    lambda ticket: print("ticket", ticket),
    lambda account: print("account", account),
    lambda deposit: print("deposit_ ticket", deposit),
    lambda cancel_order_reject_event: print(
        "cancel order reject event", cancel_order_reject_event),
    lambda account_position: print(
        "account position", account_position)
)
```

{% endtab %}

{% tab title="Json" %}

```json
{
  "m": 0,
  "i": 0,
  "n": "SubscribeAccountEvents",
  "o": "{
    \"OMSId\": 1,
    \"AccountId\": 2
  }"
}
```

{% endtab %}
{% endtabs %}

> SubscribeAccountEvents is not available in http. Subscription APIs are only supported in websockets.

| Key       | Value                                                               |
| --------- | ------------------------------------------------------------------- |
| OMSId     | **integer**. The ID of the OMS. **required**.                       |
| AccountId | **integer**. The ID of the account to subscribe with. **required**. |

#### Response

```json
{
  "m": 1,
  "i": 0,
  "n": "SubscribeAccountEvents",
  "o": "{
    \"Subscribed\": true
  }"
}

//Example account event that can be received
{
  "m": 3,
  "i": 2,
  "n": "WithdrawTicketUpdateEvent",
  "o": '{"AssetManagerId":1,"AccountProviderId":0,"AccountId":7,"AccountName":"sample_user","AssetId":3,"AssetName":"TBTC","Amount":0.0010000000000000000000000000,"NotionalValue":0.0010000000000000000000000000,"NotionalProductId":1,"TemplateForm":"{\"Fullname\":\"Sample\"}","TemplateFormType":null,"OMSId":1,"RequestCode":"ef0ec64d-953b-477d-80b7-c3b0bf4cad64","RequestIP":null,"RequestUserId":1,"RequestUserName":"admin","OperatorId":1,"Status":"Pending2Fa","FeeAmt":0.0000000000000000000000000000,"UpdatedByUser":0,"UpdatedByUserName":null,"TicketNumber":292,"WithdrawTransactionDetails":"{\"TxId\":null,\"ExternalAddress\":null,\"Amount\":0,\"Confirmed\":false,\"LastUpdated\":\"0001-01-01T00:00:00.000Z\",\"TimeSubmitted\":\"0001-01-01T00:00:00.000Z\",\"AccountProviderName\":null,\"AccountProviderId\":0}","RejectReason":null,"CreatedTimestamp":"2023-03-23T12:48:31.067Z","LastUpdateTimestamp":"2023-03-23T12:48:31.067Z","CreatedTimestampTick":638151725110676052,"LastUpdateTimestampTick":638151725110676052,"Comments":[],"Attachments":[],"AuditLog":[]}'
}

{
  "m": 3,
  "i": 4,
  "n": "AccountPositionEvent",
  "o": '{"OMSId":1,"AccountId":7,"ProductSymbol":"TBTC","ProductId":3,"Amount":1.1381543994360000000000000000,"Hold":1.1256211000000000000000000000,"PendingDeposits":0,"PendingWithdraws":0,"TotalDayDeposits":0,"TotalMonthDeposits":0,"TotalYearDeposits":0,"TotalDayDepositNotional":0,"TotalMonthDepositNotional":0,"TotalYearDepositNotional":0,"TotalDayWithdraws":0,"TotalMonthWithdraws":0,"TotalYearWithdraws":0,"TotalDayWithdrawNotional":0,"TotalMonthWithdrawNotional":0,"TotalYearWithdrawNotional":0,"NotionalProductId":1,"NotionalProductSymbol":"USD","NotionalValue":1.1381543994360000000000000000,"NotionalHoldAmount":1.1256211000000000000000000000,"NotionalRate":1,"TotalDayTransferNotional":0}'
}
```

> SubscribeAccountEvents is not available in http. Subscription APIs are only supported in websockets.

Returns either Subscribed: true or false. If false, it means that you were not able to subscribe to events of the account. After successfully subscribing to account events, you will receive the events message for transactions that involves the account such as a withdraw transaction, the specific event name will be **WithdrawTicketUpdateEvent**

### UnSubscribeAccountEvents

**Permissions:** NotbankTrading\
**Call Type:** Synchronous

UnSubscribe from account-level events. After being unsubscribed, you will stop receiving real-time events about transactions that concerns the specific account you unsubscribed to.

#### Request

{% tabs %}
{% tab title="Node" %}

```javascript
import Notbank from 'notbank'
// websocket connection code ...

await client.getSubscriptionService().unsubscribeAccountEvents(
  AccountId: 1
);

// request parameters
{
  AccountId: number;
}
```

{% endtab %}

{% tab title="Java" %}

```java
import exchange.notbank.subscription.paramBuilders.UnsubscribeAccountEventsParamBuilder;

client.getSubscriptionService().unsubscribeAccountEvents(new UnsubscribeAccountEventsParamBuilder(1)).get();
```

{% endtab %}

{% tab title="Python" %}

```python
from notbank_python_sdk.requests_models.unsubscribe_account_events_request import UnsubscribeAccountEventsRequest

client.unsubscribe_account_events(UnsubscribeAccountEventsRequest(7))
```

{% endtab %}

{% tab title="Json" %}

```json
{
  "m": 0,
  "i": 0,
  "n": "UnSubscribeAccountEvents",
  "o": "{
    \"OMSId\": 1,
    \"AccountId\": 2
  }"
}
```

{% endtab %}
{% endtabs %}

> UnSubscribeAccountEvents is not available in http. Subscription APIs are only supported in websockets.

| Key       | Value                                                                                                                                  |
| --------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| OMSId     | **integer**. The ID of the OMS. **required**.                                                                                          |
| AccountId | **integer**. The ID of the account to subscribe with. This to make sure you will be unsubscribed to the correct account. **required**. |

#### Response

```json
{
  "m": 1,
  "i": 0,
  "n": "UnSubscribeAccountEvents",
  "o": "{
    \"UnSubscribed\": true
  }"
}
```

> UnSubscribeAccountEvents is not available in http. Subscription APIs are only supported in websockets.

### SubscribeOrderStateEvents

**Permissions:** NotbankTrading\
**Call Type:** Synchronous

Subscribe to order state events of a specific account's orders. Optional parameter to filter by instrument.

#### Request

{% tabs %}
{% tab title="Node" %}

```javascript
import Notbank from 'notbank'
// websocket connection code ...

await client.getSubscriptionService().subscribeOrderStateEvents(
  AccountId: 1
);

// request parameters
{
  AccountId: number;
  InstrumentId?: number;
}
```

{% endtab %}

{% tab title="Java" %}

```java
import exchange.notbank.subscription.paramBuilders.SubscribeOrderStateEventsParamBuilder;

client.getSubscriptionService().subscribeOrderStateEvents(
        new SubscribeOrderStateEventsParamBuilder(7).instrumentId(99),
        order -> System.out.println(order)).get();
```

{% endtab %}

{% tab title="Python" %}

```python
from notbank_python_sdk.requests_models import SubscribeOrderStateEventsRequest

client.subscribe_order_state_events(
  SubscribeOrderStateEventsRequest(7, instrument_id=99),
  lambda order: print(order)
)
```

{% endtab %}

{% tab title="Json" %}

```json
{
  "m": 0,
  "i": 0,
  "n": "SubscribeOrderStateEvents",
  "o": "{
    \"OMSId\": 1,
    \"AccountId\": 2
  }"
}
```

{% endtab %}
{% endtabs %}

> SubscribeOrderStateEvents is not available in http. Subscription APIs are only supported in websockets.

| Key          | Value                                                                                                                              |
| ------------ | ---------------------------------------------------------------------------------------------------------------------------------- |
| OMSId        | **integer**. The ID of the OMS. **required**.                                                                                      |
| AccountId    | **integer**. The ID of the account to subscribe with. **required**.                                                                |
| InstrumentId | **integer**. The ID of the instrument to subscribe orderstateevents with. This field serves as the filter parameter. **optional**. |

#### Response

```json
{
  "m": 1,
  "i": 0,
  "n": "SubscribeOrderStateEvents",
  "o": "{
    \"Subscribed\": true
  }"
}
```

> SubscribeOrderStateEvents is not available in http. Subscription APIs are only supported in websockets.

Returns either Subscribed: true or false. If false, it means that you were not able to subscribe to *order state events* of the account. After successfully subscribing to *order state events* of the account, you will receive the events message for any change of state of the account's order/s.

### UnSubscribeOrderStateEvents

**Permissions:** NotbankTrading\
**Call Type:** Synchronous

UnSubscribe from account-level events. After being unsubscribed, you will stop receiving real-time events about transactions that concerns the specific account you unsubscribed to.

#### Request

{% tabs %}
{% tab title="Node" %}

```javascript
import Notbank from 'notbank'
// websocket connection code ...

await client.getSubscriptionService().unsubscribeOrderStateEvents(
  AccountId: 1
);

// request parameters
{
  AccountId: number;
  InstrumentId?: number;
}
```

{% endtab %}

{% tab title="Java" %}

```java
import exchange.notbank.subscription.paramBuilders.UnsubscribeOrderStateEventsParamBuilder;

client.getSubscriptionService().unsubscribeOrderStateEvents(new UnsubscribeOrderStateEventsParamBuilder(7));
```

{% endtab %}

{% tab title="Python" %}

```python
from notbank_python_sdk.requests_models import UnsubscribeOrderStateEventsRequest

client.unsubscribe_order_state_events(UnsubscribeOrderStateEventsRequest(7))
```

{% endtab %}

{% tab title="Json" %}

```json
{
  "m": 0,
  "i": 0,
  "n": "UnSubscribeOrderStateEvents",
  "o": "{
    \"OMSId\": 1,
    \"AccountId\": 2
  }"
}
```

{% endtab %}
{% endtabs %}

> UnSubscribeOrderStateEvents is not available in http. Subscription APIs are only supported in websockets.

| Key          | Value                                                                                                                                     |
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------- |
| OMSId        | **integer**. The ID of the OMS. **required**.                                                                                             |
| AccountId    | **integer**. The ID of the account to subscribe with. This is to make sure you will be unsubscribed to the correct account. **required**. |
| InstrumentId | **integer**. The ID of the instrument to unsubscribe orderstateevents with. This field serves as the filter parameter. **optional**.      |

#### Response

```json
{
  "m": 1,
  "i": 0,
  "n": "UnSubscribeOrderStateEvents",
  "o": "{
    \"UnSubscribed\": true
  }"
}
```

> UnSubscribeOrderStateEvents is not available in http. Subscription APIs are only supported in websockets.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.notbank.com/learn/api-reference/websocket-api/websocket-subscription.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
