-
Notifications
You must be signed in to change notification settings - Fork 24
/
OrderClient.cs
79 lines (72 loc) · 2.74 KB
/
OrderClient.cs
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
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net.Http;
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace Boukenken.Gdax
{
public interface IOrderClient
{
Task<ApiResponse<IEnumerable<Order>>> GetOpenOrdersAsync();
Task<ApiResponse<IEnumerable<Guid>>> CancelOpenOrdersAsync(string productId = null);
Task<ApiResponse<Order>> PlaceOrderAsync(string side, string productId, decimal size, decimal price, string type, string cancelAfter = null, string timeInForce = null);
Task<ApiResponse<Order>> PlaceOrderAsync(string side, string productId, decimal size, decimal price, string type, bool postOnly, string cancelAfter = null, string timeInForce = null);
}
public class OrderClient : GdaxClient
{
public OrderClient(string baseUrl, RequestAuthenticator authenticator)
: base(baseUrl, authenticator)
{
}
public async Task<ApiResponse<Order>> PlaceOrderAsync(string side, string productId, decimal size, decimal price, string type, bool postOnly, string cancelAfter = null, string timeInForce = null)
{
return await this.GetResponseAsync<Order>(
new ApiRequest(HttpMethod.Post, "/orders", Serialize(new
{
size = size,
side = side,
type = type,
price = price,
product_id = productId,
post_only = postOnly,
cancel_after = cancelAfter,
time_in_force = timeInForce
}))
);
}
public async Task<ApiResponse<Order>> PlaceOrderAsync(string side, string productId, decimal size, decimal price, string type, string cancelAfter = null, string timeInForce = null)
{
return await this.GetResponseAsync<Order>(
new ApiRequest(HttpMethod.Post, "/orders", Serialize(new {
size = size,
side = side,
type = type,
price = price,
product_id = productId,
post_only = false,
cancel_after = cancelAfter,
time_in_force = timeInForce
}))
);
}
public async Task<ApiResponse<IEnumerable<Order>>> GetOpenOrdersAsync()
{
return await this.GetResponseAsync<IEnumerable<Order>>(
new ApiRequest(HttpMethod.Get, "/orders?status=all")
);
}
public async Task<ApiResponse<Order>> GetOpenOrdersAsync(string Id)
{
return await this.GetResponseAsync<Order>(
new ApiRequest(HttpMethod.Get, "/orders/" + Id)
);
}
public async Task<ApiResponse<IEnumerable<Guid>>> CancelOpenOrdersAsync(string productId = null)
{
return await this.GetResponseAsync<IEnumerable<Guid>>(
new ApiRequest(HttpMethod.Delete, "/orders" + (productId == null ? "" : $"?product_id={productId}"))
);
}
}
}