Ad

Python Websocket Not Getting All Data

I am writing a Python bot to collect Bitfinex open book orders through WebSocket, but instead of getting all the data at one time I am getting it one by one. Below is my code:

import json

from websocket import create_connection
ws = create_connection("wss://api.bitfinex.com/ws/1")
#ws.connect("wss://api2.bitfinex.com:3000/ws")
ws.send(json.dumps({
"event": "subscribe",
"channel": "book",
"symbol": "tBTCUSD",
"prec": "P1",
"freq": "F1",
"len": "25"
 }))


while True:
result = ws.recv()
result = json.loads(result)
print (result)
ws.close()

First I am getting this data:

{'event': 'info', 'version': 1.1, 'platform': {'status': 1}}
{'event': 'subscribed', 'channel': 'book', 'chanId': 9479, 'prec': 'P1', 'freq': 'F1', 'len': '25', 'pair': 'BTCUSD'}
[9479, [[9242, 3, 2.48234792], [9241, 4, 2.14994206], [9240, 7, 18.84], [9239, 4, 0.18569934], [9236, 4, 2.40599999], [9235, 2, 0.84793866], [9234, 3, 0.7], [9232, 1, 0.1], [9230, 5, 17.46637416], [9229, 1, 0.5], [9228, 2, 0.50405148], [9227, 1, 0.05410933], [9226, 3, 6.833112], [9225, 1, 1.2], [9224, 5, 2.44538683], [9222, 6, 8.21999999], [9221, 3, 1.12], [9220, 3, 2.022], [9219, 1, 7.04], [9218, 2, 0.40431586], [9217, 4, 5.68698009], [9216, 4, 2.86999999], [9215, 1, 0.09335208], [9214, 1, 6.1], [9213, 2, 2.02], [9246, 2, -0.042], [9247, 1, -1.079], [9249, 2, -1.20650001], [9250, 8, -42.96401676], [9251, 4, -8.99723363], [9253, 3, -0.02800001], [9254, 2, -0.48926159]

Then getting it one by one, like that:

[9479, 9245, 2, 2.01234792]

How I can get the full order book at once through websocket not API, like listed below:

[9479, [[9242, 3, 2.48234792], [9241, 4, 2.14994206], [9240, 7, 18.84], [9239, 4, 0.18569934], [9236, 4, 2.40599999], [9235, 2, 0.84793866], [9234, 3, 0.7], [9232, 1, 0.1], [9230, 5, 17.46637416], [9229, 1, 0.5], [9228, 2, 0.50405148], [9227, 1, 0.05410933], [9226, 3, 6.833112], [9225, 1, 1.2], [9224, 5, 2.44538683], [9222, 6, 8.21999999], [9221, 3, 1.12], [9220, 3, 2.022], [9219, 1, 7.04], [9218, 2, 0.40431586], [9217, 4, 5.68698009], [9216, 4, 2.86999999], [9215, 1, 0.09335208], [9214, 1, 6.1], [9213, 2, 2.02], [9246, 2, -0.042], [9247, 1, -1.079], [9249, 2, -1.20650001], [9250, 8, -42.96401676], [9251, 4, -8.99723363], [9253, 3, -0.02800001], [9254, 2, -0.48926159], [9255, 2, -2.5], [9256, 4, -10.30405436], [9258, 2, -6.75], [9259, 2, -0.04], [9260, 1, -0.6], [9262, 1, -0.25], [9263, 3, -7.8391], [9264, 1, -1.6], [9265, 2, -0.1606286], [9266, 2, -6.93685322], [9267, 6, -1.87947602], [9268, 4, -17.67527073], [9270, 6, -8.65613095], [9271, 2, -1.75519738], [9272, 6, -2.09804066], [9273, 1, -0.5], [9275, 3, -11.95653655], [9276, 1, -0.75519738]]]
Ad

Answer

from the official web site

The pair list is continuously growing, to get the an up to date list you can query the symbols this endpoint: https://api.bitfinex.com/v1/symbols

so you can append and updated the target="_blank" rel="nofollow noreferrer" href="https://api.bitfinex.com/v1/symbols" rel="nofollow noreferrer">https://api.bitfinex.com/v1/symbols

so you can append and updated the list with each new data received or use the above api...

Ad
source: stackoverflow.com
Ad