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

Spot Socket API -> V2 -> using block problem #116

Closed
emin-karadag opened this issue Mar 18, 2023 · 1 comment
Closed

Spot Socket API -> V2 -> using block problem #116

emin-karadag opened this issue Mar 18, 2023 · 1 comment

Comments

@emin-karadag
Copy link

Hello,
I am using Bybit.Net v1.5.2.

I want to listen to the user's orders instantly over the socket by using "BybitSocketClient". But when I use the relevant code block in using(), I cannot listen to user actions. The socket is not working.

When I don't use the using() block, I can listen for sockets.

Working Code:

var socketClient = new BybitSocketClient(new BybitSocketClientOptions
{
    ApiCredentials = new ApiCredentials(_appSettings.ExchangeSettings.ApiKey, _appSettings.ExchangeSettings.SecretKey)
});
await socketClient.SpotStreamsV2.SubscribeToAccountUpdatesAsync(
 accountUpdate =>
 {
     if (accountUpdate is not null)
     {

     }
 }, orderUpdate =>
 {
     if (orderUpdate is not null)
     {

     }
 }, stopOrderUpdate =>
 {
     if (stopOrderUpdate is not null)
     {

     }
 }, tradeUpdate =>
 {
     if (tradeUpdate is not null)
     {

     }
 }, stoppingToken);
}

Notworking Code:

using (var socketClient = new BybitSocketClient(new BybitSocketClientOptions
{
    ApiCredentials = new ApiCredentials(_appSettings.ExchangeSettings.ApiKey, _appSettings.ExchangeSettings.SecretKey)
}))
{
    await socketClient.SpotStreamsV2.SubscribeToAccountUpdatesAsync(
     accountUpdate =>
     {
         if (accountUpdate is not null)
         {

         }
     }, orderUpdate =>
     {
         if (orderUpdate is not null)
         {

         }
     }, stopOrderUpdate =>
     {
         if (stopOrderUpdate is not null)
         {

         }
     }, tradeUpdate =>
     {
         if (tradeUpdate is not null)
         {

         }
     }, stoppingToken);
}
@JKorf
Copy link
Owner

JKorf commented Apr 14, 2023

This is expected, the using disposes the client and closes any connections it manages

@JKorf JKorf closed this as completed Apr 14, 2023
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

No branches or pull requests

2 participants