Here’s how to use websocketsharp with Binanceapi to subjugate the connection, you have no orders for the field:
Binning Api Binance Api: Handmade with Websocketsharp
Insurance
————-
It is important to establish a stubborn tension for indignation of the cornerstone. The topic does not change, the voltage can be passed through different maintenance, such as the server or network problems. To come up with this, we are spreading, how to use Websocketsharp to send the Binance link, you don’t get your orders.
Suppliers
- You installed Binanceapi Bin using the ‘BinanCleClient class.
- You are familiar with Binanceapi Websocket Protocket and Binanceapi (Ws.binance.com).
Link settings
Before that, take out the decree, let’s make a simple reward to raise how to establish a permanent relationship:
csharp
Use of the system;
Use of System.net.http;
Ustem.threading.tasks;
Public Class BinanceClient
{
Private Readonly httpClient _httpClient = new httpClient ();
Private Readonly Websocket _Ws = New Websocket ("Ws.binance.com:9001");
Public asynchronized task Startconnectionasync ()
{
Wait _ws.Connectasync (). Wait ();
}
Public asynchronized task densonectasync ()
{
Wish _ws.disconnectasync (). wait ();
}
}
Class
{
Statistical Void Main (String [] args)
{
var client = new binanceClient ();
// Install a link to a StartConnectionasyNc publication
Wait client.Startconnectionasync ();
// Modeling some calling API to check one
for (int i = 0; I <10; I ++)
{
Var Result = Waw Client.getorderdync (i);
Console.Writeline (result);
// dry 1 second, pre -verified
Wait for the tasks. Delay (1000);
}
// returned the WebSocket relationship to close the link after one
Wait client.Disconnectasync ();
}
}
Using WebSocketSharp
Now that we have a constant connection, let’s turn our call Binanceapi using Websocketsarp:
csharp
Use of the system;
Use of System.net.http;
Ustem.threading.tasks;
Account Class orders
{
Private Readonly httpClient _httpClient = new httpClient ();
Public Asynchronization Task
{
Var OrderRequest = new order {id = id};
Var Reply = Wait
If (Respose.Sissuccessstatuscode)
{
Return Ueat Response.Content.Readfromjsonasync
}
still
{
Console.Writeline ($ "lining: {response.statuscode}");
Returned Nell;
}
}
}
As this result, we use websocketsarp to establish a constant connection and modeling of API calls for arrangements. The Getperordersync
method attracts the disabled to the end point of Binanceapi with details about JSON -shaped orders.
Summary of the Rescue Line
To judge the lining, you don’t get orders for the field, we need:
- Install the permanent connection using
Startconnectionasync
.
- Model the API call to verify connectivity.
- Different 1 second, pre -check and take the need to connect.
Here is a conjugated fragment of the code that includes this Shagie:
`csharp
Use of the system;
Use of System.net.http;
Ustem.threading.tasks;
Account Class orders
{
Private Readonly httpClient _httpClient = new httpClient ();
Private static Readonly Websocket _Ws = New Websocket (“Ws.binance.