Fetch data from !ticker@arr

Hello,

I am very unexperienced with this.
But I cant find a way to fetch the data from !ticker@arr
could you by any way help me?

I try different ways such as

def on_message(ws, message):

try:
    json_message = json.loads(message)
    cs = json_message
    print(cs["e"])

Code:

import json

import websocket

import time

def on_message(ws, message):

    try:

        json_message = json.loads(message)
        print(json_message)
          
    except:
        print("Please wait..")
        time.sleep(1)    

def on_error(ws, error):

    print(error)

def on_close(ws, close_status_code, close_msg):

    print("connection closed")

def on_open(ws):

    print("Opened connection")

socket = "wss://fstream.binance.com/ws/!ticker@arr"
ws = websocket.WebSocketApp(socket, on_message=on_message, on_close=on_close)
ws.run_forever()

output:
[{β€˜e’: β€˜24hrTicker’, β€˜E’: 1653386244134, β€˜s’: β€˜BTCUSDT’, β€˜p’: β€˜-1188.00’, β€˜P’: β€˜-3.901’, β€˜w’: β€˜29737.47’, β€˜c’: β€˜29268.10’, β€˜Q’: β€˜0.001’, β€˜o’: β€˜30456.10’, β€˜h’: β€˜30624.90’, β€˜l’: β€˜28840.70’, β€˜v’: β€˜448814.969’, β€˜q’: β€˜13346619946.10’, β€˜O’: 1653299820000, β€˜C’: 1653386244131, β€˜F’: 2279373613, β€˜L’: 2283415610, β€˜n’: 4041918}, {β€˜e’: β€˜24hrTicker’, β€˜E’: 1653386244109, β€˜s’: β€˜AUDIOUSDT’, β€˜p’: β€˜-0.0375’, β€˜P’: β€˜-7.742’, β€˜w’: β€˜0.4690’, β€˜c’: β€˜0.4469’, β€˜Q’: β€˜12’, β€˜o’: β€˜0.4844’, β€˜h’: β€˜0.5071’, β€˜l’: β€˜0.4347’, β€˜v’: β€˜100606416’, β€˜q’: β€˜47184918.0000’, β€˜O’: 1653299820000, β€˜C’: 1653386244090, β€˜F’: 75877444, β€˜L’: 76060568, β€˜n’: 183125},…

I don’t see any error here, you have received ticker info from multi symbols.

Hello Dino,

I dont know if what I say makes sense, but what i want is not to have an output like that.
What I wish to have is something like :

BTCUSDT: lastPrice: 20000
ETHUSDT: lastPrice 5000
…

Is this possible?
I cant manage to find how to do that

And I am finding this limitation on having to use the futures api for ticker_size too which seems to be giving the output exactly in this way.

Thanks

that can be easily done in your side. Ge the data from streams, and pick the value you need, discard those you don’t.

1 Like