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

Can't access Coin-M Futures API at all #618

Closed jinglenose closed 3 years ago

jinglenose commented 3 years ago

Hi,

I just started using this API by calling it from VB.Net and I've had no problems with spot and USDT futures calls so far. However the same calls don't work for Coin-M futures. I just get a generic error and no data with the code below...

Private Sub MyProc

    Dim oOptions As New BinanceClientOptions("https://api.binance.com", "https://fapi.binance.com", "https://dapi.binance.com")
    oOptions.LogVerbosity = LogVerbosity.Debug
    Dim oClient As New Binance.Net.BinanceClient(oOptions)
    oClient.SetApiCredentials("API", "Secret") 'Set appropriately
    Dim oSpot As CryptoExchange.Net.Objects.WebCallResult(Of MarketData.BinanceBookPrice)
    oSpot = oClient.Spot.Market.GetBookPrice("BTCUSDT")
    ShowProgress(CStr(oSpot.Data.BestAskPrice))

    Dim oFutures As CryptoExchange.Net.Objects.WebCallResult(Of MarketData.BinancePrice)
    oFutures = oClient.FuturesUsdt.Market.GetPrice("BTCUSDT")

    ''This failes with Error (in double quotes)...
    ''"An error occurred while sending the request.
    ''The request was aborted: Could Not create SSL/TLS secure channel."
    ''It also fails when I use the symbol "BTCUSD_PERP" Or "BTCUSD_210326"
    Dim oCoin As CryptoExchange.Net.Objects.WebCallResult(Of MarketData.BinancePrice)
    oCoin = oClient.FuturesCoin.Market.GetPrice("BTCUSD")

End Sub

I have set LogVerbosity to Debug but I don't know where it's logging the errors. Just to be clear the error I am getting is as follows "An error occurred while sending the request. The request was aborted: Could Not create SSL/TLS secure channel."

I get the same errors in the Example code in c# in the Main routine of the commend line program.

I can however call the API directly from a browser as follows:

https://dapi.binance.com/dapi/v1/ticker/price?symbol=BTCUSD_PERP

Gives me the price of the BTCUSD perpetual contract without any errors.

Any ideas what I can do to fix this code?

JKorf commented 3 years ago

Try this: https://stackoverflow.com/a/2904963

jinglenose commented 3 years ago

Hi JKorf,

It works now, thanks. I just added the following lines.

Imports System.Net 'At the top of the code ServicePointManager.Expect100Continue = True ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

Is this something that can be added to the Coin-M futures code so you don't have to dig it out?

Nigel