-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathApiClientAbstract.cs
More file actions
84 lines (73 loc) · 2.73 KB
/
ApiClientAbstract.cs
File metadata and controls
84 lines (73 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Net.Http;
using WebSocketSharp;
namespace Binance.API.Csharp.Client.Domain.Abstract
{
public abstract class ApiClientAbstract
{
/// <summary>
/// Secret used to authenticate within the API.
/// </summary>
public readonly string _apiUrl = "";
/// <summary>
/// Key used to authenticate within the API.
/// </summary>
public readonly string _apiKey = "";
/// <summary>
/// API secret used to signed API calls.
/// </summary>
public readonly string _apiSecret = "";
/// <summary>
/// HttpClient to be used to call the API.
/// </summary>
public readonly HttpClient _httpClient;
/// <summary>
/// URL of the WebSocket Endpoint
/// </summary>
public readonly string _webSocketEndpoint = "";
/// <summary>
/// Used to store all the opened web sockets.
/// </summary>
public List<WebSocket> _openSockets;
/// <summary>
/// Delegate for the messages returned by the websockets.
/// </summary>
/// <typeparam name="T">Type used to parsed the response message.</typeparam>
/// <param name="messageData">Websocket response data.</param>
public delegate void MessageHandler<T>(T messageData);
/// <summary>
/// Defines the constructor of the Api Client.
/// </summary>
/// <param name="apiKey">Key used to authenticate within the API.</param>
/// <param name="apiSecret">API secret used to signed API calls.</param>
/// <param name="apiUrl">API based url.</param>
public ApiClientAbstract(string apiKey, string apiSecret, string apiUrl = @"https://us.binance.com", string webSocketEndpoint = @"wss://stream.binance.com:9443/ws/", bool addDefaultHeaders = true)
{
_apiUrl = apiUrl;
_apiKey = apiKey;
_apiSecret = apiSecret;
_webSocketEndpoint = webSocketEndpoint;
_openSockets = new List<WebSocket>();
_httpClient = new HttpClient
{
BaseAddress = new Uri(_apiUrl)
};
if (addDefaultHeaders)
{
ConfigureHttpClient();
}
}
/// <summary>
/// Configures the HTTPClient.
/// </summary>
private void ConfigureHttpClient()
{
_httpClient.DefaultRequestHeaders
.Add("X-MBX-APIKEY", _apiKey);
_httpClient.DefaultRequestHeaders
.Accept
.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
}
}
}