Skip to content

Commit

Permalink
[Bug] Fix GTT order parameters (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
dougdellolio authored Jan 30, 2018
1 parent c3dbf34 commit 1dac933
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 37 deletions.
2 changes: 1 addition & 1 deletion GDAXClient.Specs/Services/Orders/OrdersServiceSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class when_placing_a_limit_order
};

Because of = () =>
order_response_result = Subject.PlaceLimitOrderAsync(OrderSide.Buy, ProductType.BtcUsd, .01M, 0.1M, DateTime.Today.Date.ToUniversalTime()).Result;
order_response_result = Subject.PlaceLimitOrderAsync(OrderSide.Buy, ProductType.BtcUsd, .01M, 0.1M, GoodTillTime.Min).Result;

It should_have_correct_account_information = () =>
{
Expand Down
2 changes: 1 addition & 1 deletion GDAXClient/GDAXClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public GDAXClient(

AccountsService = new AccountsService(httpClient, httpRequestMessageService, authenticator);
CoinbaseAccountsService = new CoinbaseAccountsService(httpClient, httpRequestMessageService, authenticator);
OrdersService = new OrdersService(httpClient, httpRequestMessageService, authenticator, queryBuilder);
OrdersService = new OrdersService(httpClient, httpRequestMessageService, authenticator);
PaymentsService = new PaymentsService(httpClient, httpRequestMessageService, authenticator);
WithdrawalsService = new WithdrawalsService(httpClient, httpRequestMessageService, authenticator);
DepositsService = new DepositsService(httpClient, httpRequestMessageService, authenticator);
Expand Down
1 change: 1 addition & 0 deletions GDAXClient/GDAXClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<Compile Include="GDAXClient.cs" />
<Compile Include="HttpClient\HttpClient.cs" />
<Compile Include="HttpClient\IHttpClient.cs" />
<Compile Include="Services\Orders\Models\GoodTillTime.cs" />
<Compile Include="Services\Orders\TimeInForce.cs" />
<Compile Include="Services\Accounts\Models\AccountHistory.cs" />
<Compile Include="Services\Accounts\Models\AccountHold.cs" />
Expand Down
2 changes: 1 addition & 1 deletion GDAXClient/Services/Fundings/FundingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task<IList<IList<Funding>>> GetAllFundingsAsync(int limit = 100, Fu
{
var queryString = queryBuilder.BuildQuery(
new KeyValuePair<string, string>("limit", limit.ToString()),
new KeyValuePair<string, string>("status", status?.ToString()));
new KeyValuePair<string, string>("status", status?.ToString().ToLower()));

var httpResponseMessage = await SendHttpRequestMessagePagedAsync<Funding>(HttpMethod.Get, authenticator, "/funding" + queryString);

Expand Down
9 changes: 9 additions & 0 deletions GDAXClient/Services/Orders/Models/GoodTillTime.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GDAXClient.Services.Orders.Models
{
public enum GoodTillTime
{
Min,
Hour,
Day
}
}
4 changes: 4 additions & 0 deletions GDAXClient/Services/Orders/Models/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ public class Order
public string type { get; set; }

public string product_id { get; set; }

public string time_in_force { get; set; }

public string cancel_after { get; set; }
}
}
54 changes: 21 additions & 33 deletions GDAXClient/Services/Orders/OrdersService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using GDAXClient.Services.Orders.Models;
using GDAXClient.Services.Orders.Models.Responses;
using GDAXClient.Shared;
using GDAXClient.Utilities;
using GDAXClient.Utilities.Extensions;
using Newtonsoft.Json;

Expand All @@ -21,24 +20,20 @@ public class OrdersService : AbstractService

private readonly IAuthenticator authenticator;

private readonly IQueryBuilder queryBuilder;

public OrdersService(
IHttpClient httpClient,
IHttpRequestMessageService httpRequestMessageService,
IAuthenticator authenticator,
IQueryBuilder queryBuilder)
IAuthenticator authenticator)
: base(httpClient, httpRequestMessageService)

{
this.httpClient = httpClient;
this.authenticator = authenticator;
this.queryBuilder = queryBuilder;
}

public async Task<OrderResponse> PlaceMarketOrderAsync(
OrderSide side,
ProductType productPair,
OrderSide side,
ProductType productPair,
decimal size)
{
var newOrder = JsonConvert.SerializeObject(new Order
Expand All @@ -57,11 +52,11 @@ public async Task<OrderResponse> PlaceMarketOrderAsync(
}

public async Task<OrderResponse> PlaceLimitOrderAsync(
OrderSide side,
ProductType productPair,
decimal size,
decimal price,
TimeInForce timeInForce = TimeInForce.Gtc,
OrderSide side,
ProductType productPair,
decimal size,
decimal price,
TimeInForce timeInForce = TimeInForce.Gtc,
bool postOnly = true)
{
var newOrder = JsonConvert.SerializeObject(new Order
Expand All @@ -70,26 +65,23 @@ public async Task<OrderResponse> PlaceLimitOrderAsync(
product_id = productPair.ToDasherizedUpper(),
type = OrderType.Limit.ToString().ToLower(),
price = price,
size = size
size = size,
time_in_force = timeInForce.ToString().ToUpper()
});

var queryString = queryBuilder.BuildQuery(
new KeyValuePair<string, string>("time_in_force", timeInForce.ToString().ToUpperInvariant()),
new KeyValuePair<string, string>("post_only", postOnly.ToString().ToLower()));

var httpResponseMessage = await SendHttpRequestMessageAsync(HttpMethod.Post, authenticator, "/orders" + queryString, newOrder).ConfigureAwait(false);
var httpResponseMessage = await SendHttpRequestMessageAsync(HttpMethod.Post, authenticator, "/orders", newOrder).ConfigureAwait(false);
var contentBody = await httpClient.ReadAsStringAsync(httpResponseMessage).ConfigureAwait(false);
var orderResponse = JsonConvert.DeserializeObject<OrderResponse>(contentBody);

return orderResponse;
}

public async Task<OrderResponse> PlaceLimitOrderAsync(
OrderSide side,
ProductType productPair,
decimal size,
decimal price,
DateTime cancelAfter,
OrderSide side,
ProductType productPair,
decimal size,
decimal price,
GoodTillTime cancelAfter,
bool postOnly = true)
{
var newOrder = JsonConvert.SerializeObject(new Order
Expand All @@ -98,21 +90,17 @@ public async Task<OrderResponse> PlaceLimitOrderAsync(
product_id = productPair.ToDasherizedUpper(),
type = OrderType.Limit.ToString().ToLower(),
price = price,
size = size
size = size,
cancel_after = cancelAfter.ToString().ToLower()
});

var queryString = queryBuilder.BuildQuery(
new KeyValuePair<string, string>("time_in_force", "GTT"),
new KeyValuePair<string, string>("cancel_after", cancelAfter.Minute + "," + cancelAfter.Hour + "," + cancelAfter.Day),
new KeyValuePair<string, string>("post_only", postOnly.ToString().ToLower()));

var httpResponseMessage = await SendHttpRequestMessageAsync(HttpMethod.Post, authenticator, "/orders" + queryString, newOrder);
var contentBody = await httpClient.ReadAsStringAsync(httpResponseMessage).ConfigureAwait(false);
var httpResponseMessage = await SendHttpRequestMessageAsync(HttpMethod.Post, authenticator, "/orders", newOrder);
var contentBody = await httpClient.ReadAsStringAsync(httpResponseMessage).ConfigureAwait(false);
var orderResponse = JsonConvert.DeserializeObject<OrderResponse>(contentBody);

return orderResponse;
}

public async Task<CancelOrderResponse> CancelAllOrdersAsync()
{
var httpResponseMessage = await SendHttpRequestMessageAsync(HttpMethod.Delete, authenticator, "/orders");
Expand Down
2 changes: 1 addition & 1 deletion GDAXClient/Utilities/QueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public string BuildQuery(params KeyValuePair<string, string>[] queryParameters)
{
if(queryParameter.Value != string.Empty)
{
queryString.Append(queryParameter.Key.ToLower() + "=" + queryParameter.Value.ToLower() + "&");
queryString.Append(queryParameter.Key.ToLower() + "=" + queryParameter.Value + "&");
}
}

Expand Down

0 comments on commit 1dac933

Please sign in to comment.