binance / binance-connector-dotnet

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

Hey, great connector. Please tell me what am I doing wrong #19

Closed Polotenec closed 2 years ago

Polotenec commented 2 years ago

Description

namespace Binance.Spot.MarketExamples { using System; using System.Net; using System.Net.Http; using System.Threading.Tasks; using Binance.Common; using Binance.Spot; using Binance.Spot.Models; using Microsoft.Extensions.Logging;

public class CheckServerTime_Example
{
    public static async Task Main(string[] args)
    {

        HttpClient httpClient = new HttpClient();

        string apiKey = "ZkV5TA6y***********";
        string apiSecret = "LHbVgVD****;

        var spotAccountTrade = new SpotAccountTrade(httpClient, apiKey, apiSecret);

        var result = await spotAccountTrade.TestNewOrder("BNBUSDT", Side.SELL, OrderType.MARKET); <--- Error

/System.ArgumentNullException: "String reference not set to an instance of a String. Arg_ParamName_Name"/

        Console.ReadLine();
    }
}

}

tantialex commented 2 years ago

The SpotAccountTrade constructor is invoked incorrectly. The signature of the constructor above is

public SpotAccountTrade(HttpClient httpClient, string baseUrl = DEFAULT_SPOT_BASE_URL, string apiKey = null, string apiSecret = null)

Therefore, the second and third parameters passed are assigned to baseUrl and apiKey arguments respectively. I suggest the following amendment to the code above

var spotAccountTrade = new SpotAccountTrade(httpClient, apiKey: apiKey, apiSecret: apiSecret);
Polotenec commented 2 years ago

It didn’t work with the test order, but now everything is fine with getting the account information. I took the code I wrote above from your example file. And nothing worked when defining SpotAccountTrade