Skip to content

Conversation

@BlackUppsss
Copy link

i try the event with this code before and the trade event won't work but aggTrade is working. but in the postman is working with this endpoint "wss://stream.binance.com/ws/btcusdt@trade"

fn main() {
    let keep_running = AtomicBool::new(true);
    
    // Change the stream to test different events
    let stream = "btcusdt@aggTrade";
    // let stream = "btcusdt@trade";
    
    let mut web_socket = WebSockets::new(|event: WebsocketEvent| {
        match &event {
            WebsocketEvent::Trade(trade_event) => {
                println!("TRADE - Symbol: {}, Price: {}, Qty: {}", 
                    trade_event.symbol, 
                    trade_event.price, 
                    trade_event.qty
                );
            },
            WebsocketEvent::AggrTrades(agg_event) => {
                println!("AGGR - Symbol: {}, Price: {}, Qty: {}", 
                    agg_event.symbol, 
                    agg_event.price, 
                    agg_event.qty,
                );
            },
            _ => {
                println!("Other event: {:?}", event);
            }
        }

        Ok(())
    });

    println!("Connecting to Binance WebSocket...");
    web_socket.connect(&stream).unwrap();
    println!("Connected! Waiting for events...");
    
    if let Err(e) = web_socket.event_loop(&keep_running) {
        match e {
            err => {
                println!("Error: {:?}", err);
            }
        }
    }
}

https://github.com/binance/binance-spot-api-docs/blob/master/web-socket-streams.md#trade-streams

so i change the struct to this format depend on binance docs, maybe this work. (btw i don't event tested it after i change the struct)

{
"e": "trade",
"E": 1672515782136,
"s": "BNBBTC",
"t": 12345,
"p": "0.001",
"q": "100",
"T": 1672515782136,
"m": true,
"M": true
}

@carlosmiei
Copy link
Collaborator

@BlackUppsss Thanks for your contribution, can you please test the edit?

@BlackUppsss
Copy link
Author

Connecting to Binance WebSocket...
Connected! Waiting for events...
TRADE - Symbol: BTCUSDT, Price: 115063.34000000, Qty: 0.00076000
TRADE - Symbol: BTCUSDT, Price: 115063.33000000, Qty: 0.00011000
TRADE - Symbol: BTCUSDT, Price: 115063.34000000, Qty: 0.00191000
TRADE - Symbol: BTCUSDT, Price: 115063.33000000, Qty: 0.00005000
TRADE - Symbol: BTCUSDT, Price: 115063.34000000, Qty: 0.13277000
TRADE - Symbol: BTCUSDT, Price: 115063.33000000, Qty: 0.00007000
TRADE - Symbol: BTCUSDT, Price: 115063.33000000, Qty: 0.00129000
TRADE - Symbol: BTCUSDT, Price: 115063.33000000, Qty: 0.00005000

yea it's work

@carlosmiei
Copy link
Collaborator

@BlackUppsss can you fix the linting plz?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants