# Feed 'P' - Positions

Please find the position elements description in the  [Positions feed documentation](/api-reference/websocket-api/feed-k-positions.md).

The P feed is considered obsolete, and one is highly encouraged to use dedicated (S, K, O) feeds instead.

\
**Requests**

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

```json
{"event": "bind", "feed": "P"}
```

{% endtab %}

{% tab title="Unsubscribe" %}

```json
{"event": "unbind", "feed": "P"}
```

{% endtab %}
{% endtabs %}

**Feed handling**

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

```json
position = [
  0: currencyName (string)
  1: value (Efx::Size)
  2: counterpartyId (Efx::ClientId)
  3: maxReachablePosition (Efx::Size)
  4: minReachablePosition (Efx::Size)
]

order = [
  0: instrumentName (string)
  1: orderType (unsigned int16)
  2: orderSide (Efx::Side)
  3: orderCancelReason (Efx::CancelReason)
  4: orderId (Efx::OrderId)
  5: clientOrderId (Efx::ClientOrderId)
  6: orderPrice (Efx::Price)
  7: initialSize (Efx::Size)
  8: sizeLeft (Efx::Size)
  9: createdAt (Efx::Timestamp)
  10: bySizeOrByVolume (unsigned int16)
]

deal = [
  0: instrumentName (string)
  1: orderType (unsigned int16)
  2: orderSide (Efx::Side)
  3: orderCancelReason (Efx::CancelReason)
  4: orderId (Efx::OrderId)
  5: clientOrderId (Efx::ClientOrderId)
  6: orderPrice (Efx::Price)
  7: initialSize (Efx::Size)
  8: sizeOrVolumeLeft (Efx::Size)
  9: createdAt (Efx::Timestamp)
  10: dealMoment (Efx::Timestamp)
  11: dealId (Efx::DealId)
  12: dealAggressorSide (Efx::Side)
  13: dealPrice (Efx::Price)
  14: dealSize (Efx::Size)
  15: dealVolume (Efx::Size)
  16: dealDelta (Efx::Size)
  17: counterpartyId (Efx::ClientId)
  18: isOrderByVolume (unsigned int16)
  19: takerOrderOwnerId (Efx::ClientId)
  20: linkedTo (Efx::DealId)
  21: dealType (DealType)
  22: makerOrderOwnerId (Efx::ClientId)
  23: liquiditySource (Efx::LiquiditySource)
]

settlementOrder = [
  0: settlementOrderId (Efx::OrderId)
  1: currency1 (string)
  2: currency2 (string)
  3: size1 (Efx::Size)
  4: size2 (Efx::Size)
  5: createdAt (Efx::Timestamp)
  6: counterpartyId (Efx::ClientId)
  7: network1 (string)
  8: network2 (string)
]

settlementDeal = [
  0: settlementOrderId (Efx::OrderId)
  1: currency1 (string)
  2: currency2 (string)
  3: size1 (Efx::Size)
  4: size2 (Efx::Size)
  5: createdAt (Efx::Timestamp)
  6: counterpartyId (Efx::ClientId)
  7: network1 (string)
  8: network2 (string)
  9: settlementMoment (Efx::Timestamp)
  10: settlementId (Efx::DealId)
]
```

For detailed positions description

{% content-ref url="/pages/5ensabH5Bq5yg86N0vtS" %}
[positions](/api-reference/rest-api/deals-and-positions/positions.md)
{% endcontent-ref %}
{% endtab %}

{% tab title="Possible updates" %}

```json
// snapshot
['P', 0, 'S', [
  nextDealOrSettlementOrTransactionId (Efx::DealId),
  array of position,
  array of order,
  array of settlementOrder
]]

// order added
['O', 0, '+', order]

// order executed
['O', 0, 'D', deal]

// order removed
['O', 0, '-', order]

// settlement order added
['S', 0, '+', settlementOrder]

// settlement order modifed
['S', 0, 'M', settlementOrder]

// settlement order executed
['S', 0, 'D', settlementDeal]

// settlement order removed
['S', 0, '-', settlementOrder]

// failed to subscribe
['P', 0, 'Z', 2]

// unsubscribed
['P', 0, 'U', 0]
```

{% endtab %}

{% tab title="Feed update example" %}

```javascript
applyToSnapshot(prevSnapshot, feed, action, data) {
    switch (feed) {
        case 'P': {
            switch (action) {
                case 'S' : {
                    return [data[0], [...data[1]], [...data[2]], [...data[3]]]
                }
            }
            break
        }
        case 'O': {
            switch (action) {
                case '+' : {
                    prevSnapshot[2].push(data)
                    break
                }
                case 'D' : {
                    // 1) update next dealOrSettlementId

                    prevSnapshot[0] = data[11] + 1

                    // 2) apply to positions

                    let [assetCurrency, balanceCurrency] = data[0].split('-')

                    for (var i in prevSnapshot[1]) {
                        if (prevSnapshot[1][i][0] == assetCurrency &&
                            prevSnapshot[1][i][2] == data[17]) {

                            if (data[2]) {
                                prevSnapshot[1][i][1] -= data[14]
                            } else {
                                prevSnapshot[1][i][1] += data[14]
                            }
                            if (0 == prevSnapshot[1][i][1]) {
                                prevSnapshot[1].splice(i, 1)
                            }
                            assetCurrency = null
                            break
                        }
                    }

                    for (var i in prevSnapshot[1]) {
                        if (prevSnapshot[1][i][0] == balanceCurrency &&
                            prevSnapshot[1][i][2] == data[17]) {

                            if (data[2]) {
                                prevSnapshot[1][i][1] += data[15] - data[16]
                            } else {
                                prevSnapshot[1][i][1] -= data[15] + data[16]
                            }
                            if (0 == prevSnapshot[1][i][1]) {
                                prevSnapshot[1].splice(i, 1)
                            }
                            balanceCurrency = null
                            break
                        }
                    }
                    if (assetCurrency) {
                        if (data[14]) {
                            if (data[2]) {
                                prevSnapshot[1].push([assetCurrency, -data[14], data[17]])
                            } else {
                                prevSnapshot[1].push([assetCurrency, data[14], data[17]])
                            }
                        }
                    }
                    if (balanceCurrency) {
                        if (data[2]) {
                            if (data[15] - data[16]) {
                                prevSnapshot[1].push([balanceCurrency, data[15] - data[16], data[17]])
                            }
                        } else {
                            if (- data[15] - data[16]) {
                                prevSnapshot[1].push([balanceCurrency, - data[15] - data[16], data[17]])
                            }
                        }
                    }

                    // 3) update or remove item

                    if (data[8]) {
                        for (var i in prevSnapshot[2]) {
                            if (prevSnapshot[2][i][4] == data[4]) {
                                for (var field = 0; field < 10; ++field) {
                                    prevSnapshot[2][i][field] = data[field]
                                }
                                break
                            }
                        }
                    } else {
                        for (var i in prevSnapshot[2]) {
                            if (prevSnapshot[2][i][4] == data[4]) {
                                prevSnapshot[2].splice(i, 1)
                                break
                            }
                        }

                    }
                    break
                }
                case '-' : {
                    for (var i in prevSnapshot[2]) {
                        if (prevSnapshot[2][i][4] == data[4]) {
                            prevSnapshot[2].splice(i, 1)
                            break
                        }
                    }
                    break
                }
            }
            break
        }
        case 'S': {
            switch (action) {
                case '+' : {
                    prevSnapshot[3].push(data)
                    break
                }
                case 'M' : {
                    for (var i in prevSnapshot[3]) {
                        if (prevSnapshot[3][i][0] == data[0]) {
                            prevSnapshot[3][i] = data
                            break
                        }
                    }
                    break
                }
                case 'D' : {
                    // 1) update next dealOrSettlementId

                    prevSnapshot[0] = data[8] + 1

                    // 2) apply to positions

                    let currency1 = data[1]
                    let size1 = data[3]
                    for (var i in prevSnapshot[1]) {
                        if (prevSnapshot[1][i][0] == currency1 &&
                            prevSnapshot[1][i][2] == data[6]) {

                            prevSnapshot[1][i][1] += size1
                            if (0 == prevSnapshot[1][i][1]) {
                                prevSnapshot[1].splice(i, 1)
                            }
                            currency1 = null
                            break
                        }
                    }
                    let currency2 = data[2]
                    let size2 = data[4]
                    if (currency2 == '') {
                        currency2 = null
                    }
                    if (currency2) {
                        for (var i in prevSnapshot[1]) {
                            if (prevSnapshot[1][i][0] == currency2 &&
                                prevSnapshot[1][i][2] == data[6]) {

                                prevSnapshot[1][i][1] += size2
                                if (0 == prevSnapshot[1][i][1]) {
                                    prevSnapshot[1].splice(i, 1)
                                }
                                currency2 = null
                                break
                            }
                        }
                    }

                    if (currency1) {
                        prevSnapshot[1].push([currency1, size1, data[6]])
                    }
                    if (currency2) {
                        prevSnapshot[1].push([currency2, size2, data[6]])
                    }

                    // 3) remove item

                    for (var i in prevSnapshot[3]) {
                        if (prevSnapshot[3][i][0] == data[0]) {
                            prevSnapshot[3].splice(i, 1)
                            break
                        }
                    }
                    break
                }
                case '-' : {
                    for (var i in prevSnapshot[3]) {
                        if (prevSnapshot[3][i][0] == data[0]) {
                            prevSnapshot[3].splice(i, 1)
                            break
                        }
                    }
                    break
                }
            }
            break
        }
    }
    return prevSnapshot
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://faq.finerymarkets.com/api-reference/websocket-api/feed-p-positions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
