fail to compile generated code from spot api in csharp

Hello,
I am trying to make a csharp client to the binance spot API using Visual Studio Community 2022. I use binance-api-swagger/spot_api.yaml at master · binance/binance-api-swagger · GitHub as the source of my OpenAPI adding in VS. I do get the auto=generated code but it doesn’t compile for several reasons :

  • 24hrAsync method is not correct in csharp (cannot start with a number)
  • 2 properties called “M” (in uppercase)
  • some references are missing
  • public System.Collections.Generic.ICollection<System.Collections.Generic.ICollection> Bids { get; set; } = new System.Collections.ObjectModel.Collection<System.Collections.ObjectModel.Collection>(); : cannot implicitly convert
    How come binance provides a yaml that is not well supported by Visual Studio (code Generated using NSwag toolchain v13.8.2.0 (NJsonSchema v10.2.1.0 (Newtonsoft.Json v11.0.0.0)) (http://NSwag.org)) ?And how to correct my last convertion issue please ?
    Thanks for your help

How come binance provides a yaml that is not well supported by Visual Studio (code Generated using NSwag toolchain v13.8.2.0 (NJsonSchema v10.2.1.0 (Newtonsoft.Json v11.0.0.0))

The swagger specification is not maintained with the intention of being used with Swagger Code Generators such as NSwag. Most of the points mentioned are due to a lack of “adaptability” of NSwag rather than a fault in the specification.

  • 24hrAsync method is not correct in csharp (cannot start with a number)

Open API accepts names beginning with numerical characters, however, CSharp does not allow method names beginning with numerical characters.

  • 2 properties called “M” (in uppercase)

Open API’s json linter is case sensitive, which allows a JSON object to contain both “m” and “M” properties, while CSharp’s Newstonsoft is case insensitive.

public System.Collections.Generic.ICollection<System.Collections.Generic.ICollection> Bids { get; set; } = new System.Collections.ObjectModel.Collection<System.Collections.ObjectModel.Collection>(); : cannot implicitly convert

The error is too vague to identify a definitive cause. Implicit conversion errors are raised when the compiler is not able to determine the type conversion between the two entities.

Thank you for your answer.
Do you know some efficient alternatives to NSwag though to generate correct csharp client please ?

Unfortunately we have not tested any code generators for CSharp, however we do have an official CSharp connector.

1 Like

OK thank you I saw it indeed. So you confirm it allows to access 100% of your API functionalities ? I was not sure about that “official” aspect, that’s why I wanted to start from the API.
How does it work when you add new functionalities or withdraw some (I regularly receive those notification on my Binance app), you simultaneously update the connectors ?
Is this csharp connector part of Nuget in order to update it easily ?

OK thank you I saw it indeed. So you confirm it allows to access 100% of your API functionalities ?

The connector only supports the SPOT exchange. No USD-M or Coin-M Futures exchange endpoints.

How does it work when you add new functionalities or withdraw some (I regularly receive those notification on my Binance app), you simultaneously update the connectors ?

Connectors are maintained and up-to-date with the latest API changes.

Is this csharp connector part of Nuget in order to update it easily ?

Yes, NuGet Gallery | Binance.Spot 1.5.0.

1 Like