Feed 'P' - Positions
Positions, Orders and Settlement Orders feed
Requests
{"event": "bind", "feed": "P"}
{"event": "unbind", "feed": "P"}
Feed handling
position = [
0: currencyName (string)
1: value (Efx::Size)
2: counterpartyId (Efx::ClientId)
]
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: counterpartySubaccountId (Efx::ClientId)
20: linkedTo (Efx::DealId)
21: dealType (DealType)
]
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
positions// 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]
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
}
Last updated