JKorf / Binance.Net

A C# .netstandard client library for the Binance REST and Websocket Spot and Futures API focusing on clear usage and models
https://jkorf.github.io/Binance.Net/
MIT License
1.02k stars 420 forks source link

UsdFuturesApi.SubscribeToUserDataUpdatesAsync #1382

Open wnazato opened 3 weeks ago

wnazato commented 3 weeks ago

Hello Everyone, can you check if i'm missing something on subscribe user data, i can see the subscrition live, but do not get any event: ` var startOkay = await _binanceSocketClient.SpotApi.Account.StartUserStreamAsync(); var key = startOkay.Data.Result; var OrderSubscriptionResult = await _binanceSocketClient.UsdFuturesApi.SubscribeToUserDataUpdatesAsync(key, onLeverageUpdate: (data) => { Console.WriteLine("onLeverageUpdate"); }, onMarginUpdate: (data) => { Console.WriteLine(data.OriginalData); }, onAccountUpdate: (data) => { Console.WriteLine(data.OriginalData); }, onOrderUpdate: (data) => { Console.WriteLine(data.OriginalData); }, onListenKeyExpired: (data) => { Console.WriteLine(data.OriginalData); }, onStrategyUpdate: (data) => { Console.WriteLine(data.OriginalData); }, onGridUpdate: (data) => { Console.WriteLine(data.OriginalData); }, onConditionalOrderTriggerRejectUpdate: (data) => { Console.WriteLine(data.OriginalData); } );

//My DI builder.Services.AddBinance(restOptions => { restOptions.Environment = BinanceEnvironment.Testnet; restOptions.ApiCredentials = new ApiCredentials("MyKey", "MySecret"); },

socketOptions => { socketOptions.Environment = BinanceEnvironment.Testnet; socketOptions.ApiCredentials = new ApiCredentials("MyKey", "MySecret"); });`

JKorf commented 3 weeks ago

Hi, I don't immediately see anything wrong. You should probably check startOkay.Success / startOkay.Error. And you're connecting to the test net, which is a different environment than the live/production environment. So it will only push events when something changes on the test net

wnazato commented 3 weeks ago

i tried to push the BinanceEnvironment.Live too, but didn't triggered maybe the key provided by var startOkay = await _binanceSocketClient.SpotApi.Account.StartUserStreamAsync(); don't work for the UsdFuturesApi, and i couldn't find the StartUserStream for this namespasce.

SamMikkalson commented 1 week ago

I had to grab the key from the BinanceRestClient

var client2 = new BinanceRestClient(options => { options.ApiCredentials = new ApiCredentials(key, secret); }); var startOkay = client2.UsdFuturesApi.Account.StartUserStreamAsync().GetAwaiter().GetResult(); if (!startOkay.Success) { // messageBoxService.ShowMessage($"Error starting user stream: {startOkay.Error.Message}", "error", MessageBoxButton.OK, MessageBoxImage.Error); return; } string listenKey = startOkay.Data;

this worked for me.