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.03k stars 425 forks source link

Error: Modify Isolated Position Margin #346

Closed dante1989 closed 4 years ago

dante1989 commented 4 years ago

i use ModifyPositionMarginAsync. But it did not work. I using isolated mode Dim clientFutureBinance = New BinanceFuturesClient 'API Binance Future clientFutureBinance.SetApiCredentials(API_Binance2, Secret_Binance2) Dim Symbol As String = "BTCUSDT"

    Await clientFutureBinance.ModifyPositionMarginAsync(Symbol, 100, FuturesMarginChangeDirectionType.Add)

Nothing happened for both One-way Mode and Hedge Mode

I do not see position side in your parameters like this: https://binance-docs.github.io/apidocs/futures/en/#modify-isolated-position-margin-trade

Please help me, thank you so much

JKorf commented 4 years ago

Can you check what the result is? There probably is an error in the result.Error property.

dante1989 commented 4 years ago

Can you check what the result is? There probably is an error in the result.Error property.

I have checked the results, nothing happened, No crash when running, No Margrin added. I guest that you forget parameter position side in you function

JKorf commented 4 years ago

Hi, this should be fixed in the latest version.

dante1989 commented 4 years ago

Dim clientFutureBinance = New BinanceFuturesClient 'API Binance Future clientFutureBinance.SetApiCredentials(API_Binance2, Secret_Binance2)

Dim Symbol As String = "BTCUSDT"

    Dim Test As WebCallResult(Of BinanceFuturesPositionMarginResult) = Await clientFutureBinance.ModifyPositionMarginAsync(Symbol, 50, FuturesMarginChangeDirectionType.Add, positionSide:=PositionSide.Short)

    Try
        MsgBox(Test.Error.Message)
        MsgBox(Test.Success)
    Catch ex As Exception

    End Try

The Message is: "Server Error" And Test.Success is "FALSE"

I have one Position Short with Isolated and Hedge Mode

Please check it again

JKorf commented 4 years ago

Can you try again with the latest version? There might have been a culture issue.

dante1989 commented 4 years ago

I have tried again, but i got the same error, no changes i use windows 10 english language

JKorf commented 4 years ago

What is the output when you do MsgBox(Test.Error.ToString()) in your sample code?

dante1989 commented 4 years ago

The output is: "Server Error" Test.Success is "FALSE"

I have one Position Short with Isolated and Hedge Mode

JKorf commented 4 years ago

Can you paste the relevant debug logging? Set log verbosity to Debug in the options when creating a client and check the output.

var client = new BinanceClient(new BinanceClientOptions{
    LogVerbosity = LogVerbosity.Debug
});
dante1989 commented 4 years ago

Can you paste the relevant debug logging? Set log verbosity to Debug in the options when creating a client and check the output.

var client = new BinanceClient(new BinanceClientOptions{
    LogVerbosity = LogVerbosity.Debug
});

i do not understand what that code mean and how to get output when i use that code

JKorf commented 4 years ago

I realize you're using vb.net where as that code is C#, but apart from some syntax changes it should be roughly the same in both languages. Where you create your client (clientFutureBinance in your case) you'll need to set the LogVerbosity property in the options. Somewhere in you're code you construct the client; something like this in your case probably:

Dim clientFutureBinance As New BinanceFuturesClient()

You'll need to change that to something like this:

Dim options As New BinanceFuturesClientOptions()
options.LogVerbosity = LogVerbosity.Debug;
Dim clientFutureBinance As New BinanceFuturesClient(options)

I was assuming you're running your application from visual studio? In that case the logging should appear in the output window in Visual Studio when you select 'Show output from: Debug':

image

dante1989 commented 4 years ago

Tôi nhận ra rằng bạn đang sử dụng vb.net trong đó mã đó là C #, nhưng ngoài một số thay đổi về cú pháp, nó phải gần như giống nhau ở cả hai ngôn ngữ. Khi bạn tạo khách hàng của mình ( clientFutureBinancetrong trường hợp của bạn), bạn sẽ cần đặt thuộc tính LogVerbosity trong các tùy chọn. Ở đâu đó trong mã của bạn, bạn xây dựng ứng dụng khách; một cái gì đó như thế này trong trường hợp của bạn có thể:

Dim clientFutureBinance As New BinanceFuturesClient()

Bạn sẽ cần phải thay đổi điều đó thành một cái gì đó như sau:

Dim options As New BinanceFuturesClientOptions()
options.LogVerbosity = LogVerbosity.Debug;
Dim clientFutureBinance As New BinanceFuturesClient(options)

Tôi giả sử bạn đang chạy ứng dụng của mình từ studio trực quan? Trong trường hợp đó, ghi nhật ký sẽ xuất hiện trong cửa sổ đầu ra trong Visual Studio khi bạn chọn 'Hiển thị đầu ra từ: Gỡ lỗi':

hình ảnh

here it is:

2020/08/13 16:02:53:136 | Debug | Client configuration: LogVerbosity: Debug, Writers: 1, Credentials: -, BaseAddress: https://fapi.binance.com, Proxy: -, RateLimiters: 0, RateLimitBehaviour: Wait, RequestTimeout: 00:00:30 2020/08/13 16:02:53:161 | Debug | Setting api credentials 2020/08/13 16:02:53:194 | Debug | Creating request for https://fapi.binance.com/fapi/v1/time 'Bot Trade.exe' (CLR v4.0.30319: Bot Trade.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 2020/08/13 16:02:53:487 | Debug | Sending GET request to https://fapi.binance.com/fapi/v1/time 2020/08/13 16:02:53:756 | Debug | Data received: {"serverTime":1597309374723} 2020/08/13 16:02:53:762 | Debug | Creating request for https://fapi.binance.com/fapi/v1/time 2020/08/13 16:02:53:763 | Debug | Sending GET request to https://fapi.binance.com/fapi/v1/time 2020/08/13 16:02:53:843 | Debug | Data received: {"serverTime":1597309374828} 2020/08/13 16:02:53:844 | Info | Time offset set to 1065.6788ms 2020/08/13 16:02:53:881 | Debug | Creating request for https://fapi.binance.com/fapi/v1/positionMargin 2020/08/13 16:02:53:883 | Debug | Sending GET signed request to https://fapi.binance.com/fapi/v1/positionMargin?symbol=BTCUSDT&amount=50&type=1&timestamp=1597309374943&positionSide=LONG&recvWindow=5000&signature=164DD9B482492E2EFA93657612B01F4DAC652930A0BCF1A0AC16C89FE38840B5 2020/08/13 16:02:53:985 | Debug | Error received: 2020/08/13 16:02:53:987 | Error | Empty data object received The thread 0x125c has exited with code 0 (0x0). Capture 2 Capture 1

JKorf commented 4 years ago

I see, it sends a GET request while it should be a POST. I've pushed a new version (6.0.0-beta.2) to fix this. To use the new beta version you might need to do some refactoring though since I've restructured the clients a bit. To access the futures API use the Futures property in the BinanceClient:

Dim clientFutureBinance As New BinanceClient(options)
Dim Test As WebCallResult(Of BinanceFuturesPositionMarginResult) = Await client.Futures.ModifyPositionMarginAsync(/*params*/)
dante1989 commented 4 years ago

To access the futures API use the Futures property in the BinanceClient:

Thank you, i will test it later

dante1989 commented 3 years ago

Hello, for isolated mode, after fixing, the Future USDT is working for ModifyPositionMarginAsync very well. But Coin Future is not working for ModifyPositionMarginAsync clientBinance.FuturesUsdt.ModifyPositionMarginAsync: Work well clientBinance.FuturesCoin.ModifyPositionMarginAsync: Not Work and got error Please check error with FuturesCoin. I think it sends a GET request while it should be a POST Here it is error:

2021/01/05 22:01:36:674 | Binance | Debug | Client configuration: LogVerbosity: Debug, Writers: 1, Credentials: -, BaseAddress: https://api.binance.com/, Proxy: -, RateLimiters: 0, RateLimitBehaviour: Wait, RequestTimeout: 00:00:30 2021/01/05 22:01:36:685 | Binance | Debug | Setting api credentials 2021/01/05 22:01:36:695 | Binance | Debug | [1] Creating request for https://api.binance.com/api/v3/time 'Bot Trade.exe' (CLR v4.0.30319: Bot Trade.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 2021/01/05 22:01:36:713 | Binance | Debug | [1] Sending GET request to https://api.binance.com/api/v3/time 2021/01/05 22:01:36:996 | Binance | Debug | [1] Response received in 272ms: {"serverTime":1609858898491} 2021/01/05 22:01:37:021 | Binance | Debug | [2] Creating request for https://api.binance.com/api/v3/time 2021/01/05 22:01:37:023 | Binance | Debug | [2] Sending GET request to https://api.binance.com/api/v3/time 2021/01/05 22:01:37:106 | Binance | Debug | [2] Response received in 81ms: {"serverTime":1609858898669} 2021/01/05 22:01:37:107 | Binance | Info | Time offset set to 1647.7371ms 2021/01/05 22:01:37:144 | Binance | Debug | [3] Creating request for https://dapi.binance.com/dapi/v1/positionMargin Exception thrown: 'System.NullReferenceException' in mscorlib.dll Object reference not set to an instance of an object.

JKorf commented 3 years ago

The call is the same for USDT and Coin futures, just with slightly changed endpoints. If the USDT futures is correct, the Coin futures should also be correct (or at least send the same HTTP method). Your logging doesn't show that the request was actually sent to the server. I would expect a Sending POST request to xxx message, but there are only those for the timestamp.

Are you sure the issue isn't somewhere in you code?