Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#BINANCEDOTNET C# STREAM USER DATA ConnectToUserDataWebSocket need help ! #61

Closed
Mlouden opened this issue Mar 3, 2018 · 6 comments
Closed

Comments

@Mlouden
Copy link

Mlouden commented Mar 3, 2018

Anyone knows how to stream user data with BinanceDotNet package ? I've tried everything I looked up for example but no one works. I'm desperate -.- !

It's C# Console application :

using BinanceExchange.API.Client;
using BinanceExchange.API.Models.WebSocket;
using BinanceExchange.API.Websockets;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace CsharpBi
{
    class Program
    {
        static void Main(string[] args)
        {
            var client = new BinanceClient(new ClientConfiguration()
            {
                ApiKey = "xxxxxx",
                SecretKey = "xxxxxxx",
            });
           
            using (var binanceWebSocketClient = new DisposableBinanceWebSocketClient(client))
            {
                binanceWebSocketClient.ConnectToUserDataWebSocket(new UserDataWebSocketMessages);

            }

        }
    }
}

I am stuck at ConnectToUserDataWebSocket(new UserDataWebSocketMessages), I didnt find examples about this method and how to use it ! Anyone can help me plz ?!

@Mlouden Mlouden changed the title ConnectToUserDataWebSocket need help ! STREAM USER DATA ConnectToUserDataWebSocket need help ! Mar 3, 2018
@Mlouden Mlouden changed the title STREAM USER DATA ConnectToUserDataWebSocket need help ! #BINANCEDOTNET C# STREAM USER DATA ConnectToUserDataWebSocket need help ! Mar 3, 2018
@romjab
Copy link

romjab commented Mar 3, 2018

Try this sample code:

            UserDataWebSocketMessages userDataWebSocketMessages = new UserDataWebSocketMessages
            {
                OrderUpdateMessageHandler = new BinanceWebSocketMessageHandler<BinanceTradeOrderData>(x =>
                {
                    Console.WriteLine(x.Balances.Find(y => y.Asset == "BTC").Free);
                }),
                TradeUpdateMessageHandler = new BinanceWebSocketMessageHandler<BinanceTradeOrderData>(x =>
                {
                    Console.WriteLine(x.TimeStamp);
                }),
                AccountUpdateMessageHandler = new BinanceWebSocketMessageHandler<BinanceAccountUpdateData>(x =>
                {
                    Console.WriteLine(x.TimeStamp);
                })
            };

            using (var binanceWebSocketClient = new DisposableBinanceWebSocketClient(client))
            {
                binanceWebSocketClient.ConnectToUserDataWebSocket(userDataWebSocketMessages);
                await Task.Delay(-1);
            }

@Mlouden
Copy link
Author

Mlouden commented Mar 3, 2018

@romjab thanks for your quick reply;
unfortunately I've tired with your sample code and the result still the same for me. When I run the program, it shows me an empty window. This is my whole program.cs :

using BinanceExchange.API.Client;
using BinanceExchange.API.Models.WebSocket;
using BinanceExchange.API.Websockets;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace CsharpBi
{
    class Program
    {
        static void Main(string[] args)
        {
            MainAsync(args).Wait();
        }

        static async Task MainAsync(string[] args)
        {
            var client = new BinanceClient(new ClientConfiguration()
            {
                ApiKey = "xxxx",
                SecretKey = "xxxxxx",
            });
            UserDataWebSocketMessages userDataWebSocketMessages = new UserDataWebSocketMessages()
            {                
                AccountUpdateMessageHandler = new BinanceWebSocketMessageHandler<BinanceAccountUpdateData>(x =>
                {
                    Console.WriteLine(x.Balances.Find(y => y.Asset == "XRP").Free);
                })
            };
            using (var binanceWebSocketClient = new DisposableBinanceWebSocketClient(client))
            {
                await binanceWebSocketClient.ConnectToUserDataWebSocket(userDataWebSocketMessages);
                await Task.Delay(-1);
            }
        }      
    }
}

Any suggestion ?

@romjab
Copy link

romjab commented Mar 4, 2018

The code looks like it should work.

Have you tried creating an order ? the websocket only broadcasts when an order is created/executed/cancelled.

Also make sure you have the latest version of the wrapper (4.2.4 as of today), since there we're multiple fixes made on the userdatawebsocket on the latest update

@romjab
Copy link

romjab commented Mar 4, 2018

also try to add the other OrderUpdateMessageHandler and TradeUpdateMessageHandler , even if you're not gonna use it. I believe you need all 3 handlers to not be null, but I could be wrong.

                OrderUpdateMessageHandler = new BinanceWebSocketMessageHandler<BinanceExchange.API.Models.WebSocket.BinanceTradeOrderData>(x =>
                {
                }),
                TradeUpdateMessageHandler = new BinanceWebSocketMessageHandler<BinanceExchange.API.Models.WebSocket.BinanceTradeOrderData>(x =>
                {
                })

@Mlouden
Copy link
Author

Mlouden commented Mar 5, 2018

@romjab thanks for your help I apreciate ! It could be great if there is a way to broadcast live user balances on websocket without creating/excuting/canceling orders.
I'll keep the topic opened in case I find something. Thanks again !

@mytran1998
Copy link

mytran1998 commented Aug 27, 2022

I also had the same problem, you solved issue? Help me :|
Log:
WebSocket Opened:wss://stream.binance.com:9443/ws/*****************************

But it cannot update data user

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

No branches or pull requests

4 participants