-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSportXAPI.cs
More file actions
55 lines (51 loc) · 1.7 KB
/
SportXAPI.cs
File metadata and controls
55 lines (51 loc) · 1.7 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
using Newtonsoft.Json;
using System.Text;
namespace NethereumSample
{
class SportXAPI
{
static readonly HttpClient client = new HttpClient();
public string url;
public async Task<string> PostNewOrder(SignedOrder order)
{
var obj = new {orders = new SignedOrder[] {order}};
var serialized = JsonConvert.SerializeObject(obj);
Console.WriteLine(serialized);
var httpContent = new StringContent(serialized, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(
url + "/orders/new",
httpContent
);
if (response.Content != null)
{
return await response.Content.ReadAsStringAsync();
}
else
{
throw new Exception("Content is null");
}
}
public async Task<string> CancelOrder(
string[] orderHashes,
string message,
string signature
)
{
var obj = new { orders = orderHashes, message, cancelSignature = signature };
var serialized = JsonConvert.SerializeObject(obj);
var httpContent = new StringContent(serialized, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(
url + "/orders/cancel",
httpContent
);
if (response.Content != null)
{
return await response.Content.ReadAsStringAsync();
}
else
{
throw new Exception("Content is null");
}
}
}
}