binance / binance-connector-dotnet

Lightweight connector for integration with Binance API
MIT License
207 stars 69 forks source link

Can not make a request #7

Closed iDomas closed 2 years ago

iDomas commented 2 years ago

Hello, can not get system status, getting this error

      An unhandled exception has occurred while executing the request.
      System.NullReferenceException: Object reference not set to an instance of an object.
         at Binance.Common.BinanceService.SendAsync[T](String requestUri, HttpMethod httpMethod, Object content)
         at Binance.Common.BinanceService.SendPublicAsync[T](String requestUri, HttpMethod httpMethod, Dictionary`2 query, Object content)
         at Binance.Spot.Wallet.SystemStatus()
         at binance_api_consumer.wallet.WalletWrapper.GetSystemStatus() in /Users/domas/ws/binance-api-consumer/wallet/WalletWrapper.cs:line 24
         at Program.<>c__DisplayClass0_0.<<<Main>$>b__2>d.MoveNext() in /Users/domas/ws/binance-api-consumer/Program.cs:line 16
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Http.RequestDelegateFactory.<ExecuteTaskOfString>g__ExecuteAwaited|59_0(Task`1 task, HttpContext httpContext)
         at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Here is code I Wrote:

{
    public class WalletWrapper
    {
        private Config _config;
        private Wallet wallet;

        public WalletWrapper(Config config)
        {
            _config = config;
            wallet = new Wallet(baseUrl: config.baseUrl, apiKey: config.apiKey, apiSecret: config.secretKey);
        }

        public async Task<string> GetSystemStatus()
        {
            Console.WriteLine(wallet);
            return await wallet.SystemStatus();
        } 
    }
}

and Porgram.cs:

using binance_api_consumer.config;
using binance_api_consumer.wallet;
using Binance.Spot;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

var config = new ConfigReader().config;

app.MapGet("/", () => "Welcome!");
app.MapGet("/config", () => config);

var walletWrapper = new WalletWrapper(config);

var func = async () => {
    string s = await walletWrapper.GetSystemStatus();
    Console.WriteLine(s);
    return s;
};

app.MapGet("/wallet", () => func());

app.Run();
tantialex commented 2 years ago

Unable to reproduce.

Can you provide more details regarding your dotnet environment? (Run dotnet --info)

iDomas commented 2 years ago
.NET SDK (reflecting any global.json):
 Version:   6.0.100
 Commit:    9e8b04bbff

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  12.0
 OS Platform: Darwin
 RID:         osx-arm64
 Base Path:   /usr/local/share/dotnet/sdk/6.0.100/

Host (useful for support):
  Version: 6.0.0
  Commit:  4822e3c3aa

.NET SDKs installed:
  6.0.100 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
tantialex commented 2 years ago

Still unable to reproduce.

Can you try to reproduce the issue in it's simplest form as below?

using Binance.Spot;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/wallet", async () => {
    Wallet wallet = new Wallet(baseUrl: "https://api.binance.com", apiKey: null, apiSecret: null);
    string s = await wallet.SystemStatus();
    return s;
});

app.Run();
iDomas commented 2 years ago

I tried and got response below: {"status":0,"msg":"normal"}

Thanks, I believe it was on my side then. But not sure what :/

EDIT: also I used testnet API, can be this a problem? So I tried on testnet API (https://testnet.binance.vision) and got an error

Screenshot 2022-01-17 at 20 04 06
tantialex commented 2 years ago

The SystemStatus endpoint is /sapi/v1/system/status, which is not supported by the SPOT Testnet, only /api/* endpoints are supported.

Will improve the exception thrown to provide more context regarding the response from the server.