Feed 'B' - Global order books
Global book feed, returns only first 25 book levels
Requests
{"event": "bind", "feed": "B", "feedId": "BTC-EUR"}
Useinstrument name
as "feedId"
value to subscribe on instrument book
{"event": "unbind", "feed": "B", "feedId": "BTC-USD"}
Feed handling
bookLevel = [
0: price (Efx::Price)
1: size (Efx::Size)
]
bookUpdate = [
0: action ('+', 'M', '-' or '~')
1: price (Efx::Price)
2: size (Efx::Size)
]
"+" action: book level added
"M" action: book level size modified
"-" action: book level removed
"~" action: top of book removed till specified price,
price and size of a new top level are returned
(both zeros if book side became empty)
For detailed book description
book// snapshot
['B', feed_id, 'S', [
array of bid bookLevel,
array of ask boolLevel
]]
// book levels modified
['B', feed_id, 'M', [
array of bid bookUpdate,
array of ask bookUpdate,
]]
// book levels added
['B', feed_id, 'M', [[['+', 300000000000, 10000000]], []]]
// book level size modified
['B', feed_id, 'M', [[['M', 300000000000, 10000000]], []]]
// book levels removed
['B', feed_id, 'M', [[['-', 300000000000, 10000000]], []]]
// till specified price, price and size of a new top level are returned
// (both zeros if book side became empty)
['B', feed_id, 'M', [[['~', 300000000000, 10000000]], []]]
// failed to subscribe
['B', feed_id, 'Z', 2]
// unsubscribed
['B', feed_id, 'U', 0]
applyToSnapshot(prevSnapshot, feed, action, data) {
switch (feed) {
case 'B': {
switch (action) {
case 'S' : {
return [[...data[0]], [...data[1]]]
}
case 'M' : {
data[0].forEach(item => {
var side = prevSnapshot[0]
switch (item[0]) {
case '+': {
var found = false
for (var i in side) {
if (side[i][0] < item[1]) {
side.splice(i, 0, [item[1], item[2]])
found = true
break
}
}
if (!found) {
side.push([item[1], item[2]])
}
break
}
case 'M': {
for (var i in side) {
if (side[i][0] == item[1]) {
side[i][1] = item[2]
break
}
}
break
}
case '-': {
for (var i in side) {
if (side[i][0] == item[1]) {
side.splice(i, 1)
break
}
}
break
}
case '~': {
if (item[1]) {
for (var i in side) {
if (side[i][0] == item[1]) {
side[i][1] = item[2]
if (i > 0) {
side.splice(0, i)
}
break
}
}
} else {
side.length = 0
}
break
}
}
})
data[1].forEach(item => {
var side = prevSnapshot[1]
switch (item[0]) {
case '+': {
var found = false
for (var i in side) {
if (side[i][0] > item[1]) {
side.splice(i, 0, [item[1], item[2]])
found = true
break
}
}
if (!found) {
side.push([item[1], item[2]])
}
break
}
case 'M': {
for (var i in side) {
if (side[i][0] == item[1]) {
side[i][1] = item[2]
break
}
}
break
}
case '-': {
for (var i in side) {
if (side[i][0] == item[1]) {
side.splice(i, 1)
break
}
}
break
}
case '~': {
if (item[1]) {
for (var i in side) {
if (side[i][0] == item[1]) {
side[i][1] = item[2]
if (i > 0) {
side.splice(0, i)
}
break
}
}
} else {
side.length = 0
}
break
}
}
})
break
}
}
break
}
}
return prevSnapshot
}
Last updated