Skip to content

Commit

Permalink
[Feature] Add more services (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
dougdellolio authored Dec 10, 2017
1 parent d840db7 commit 122356d
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 63 deletions.
3 changes: 3 additions & 0 deletions GDAXClient.Specs/GDAXClient.Specs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@
</ItemGroup>
<ItemGroup>
<Compile Include="JsonFixtures\Accounts\AccountByIdResponseFixture.cs" />
<Compile Include="JsonFixtures\Accounts\AccountHoldsResponseFixture.cs" />
<Compile Include="JsonFixtures\Accounts\AccountsHistoryResponseFixture.cs" />
<Compile Include="JsonFixtures\Accounts\AllAccountsResponseFixture.cs" />
<Compile Include="JsonFixtures\CoinbaseAccounts\AllCoinbaseResponseFixture.cs" />
<Compile Include="JsonFixtures\Currencies\CurrenciesResponseFixture.cs" />
<Compile Include="JsonFixtures\Deposits\CoinbaseDepositResponseFixture.cs" />
<Compile Include="JsonFixtures\Deposits\DepositsResponseFixture.cs" />
<Compile Include="JsonFixtures\HttpResponseMessage\HttpResponseMessageFixture.cs" />
Expand All @@ -96,6 +98,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\Accounts\AccountsServiceSpecs.cs" />
<Compile Include="Services\CoinbaseAccounts\CoinbaseAccountsServiceSpecs.cs" />
<Compile Include="Services\Currencies\CurrenciesServiceSpecs.cs" />
<Compile Include="Services\Deposits\DepositsServiceSpecs.cs" />
<Compile Include="Services\HttpRequest\HttpRequestMessageServiceSpecs.cs" />
<Compile Include="Services\Orders\OrdersServiceSpecs.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace GDAXClient.Specs.JsonFixtures.Accounts
{
public static class AccountHoldsResponseFixture
{
public static string Create()
{
var json = @"
[
{
""id"": ""82dcd140-c3c7-4507-8de4-2c529cd1a28f"",
""account_id"": ""e0b3f39a-183d-453e-b754-0c13e5bab0b3"",
""created_at"": ""2016-12-08T24:00:00Z"",
""updated_at"": ""2016-12-08T24:00:00Z"",
""amount"": ""4.23"",
""type"": ""order"",
""ref"": ""0a205de4-dd35-4370-a285-fe8fc375a273"",
}
]";

return json;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace GDAXClient.Specs.JsonFixtures.Currencies
{
public static class CurrenciesResponseFixture
{
public static string Create()
{
var json = @"
[{
""id"": ""BTC"",
""name"": ""Bitcoin"",
""min_size"": ""0.00000001""
}, {
""id"": ""USD"",
""name"": ""United States Dollar"",
""min_size"": ""0.01000000""
}]";

return json;
}
}
}
31 changes: 31 additions & 0 deletions GDAXClient.Specs/Services/Accounts/AccountsServiceSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,36 @@ class when_getting_account_history
result.First().First().Details.Product_id.ShouldEqual("BTC-USD");
};
}

class when_getting_account_holds
{
static IList<IList<AccountHold>> result;

Establish context = () =>
{
The<IHttpRequestMessageService>().WhenToldTo(p => p.CreateHttpRequestMessage(Param.IsAny<HttpMethod>(), Param.IsAny<Authenticator>(), Param.IsAny<string>(), Param.IsAny<string>()))
.Return(new HttpRequestMessage());

The<IHttpClient>().WhenToldTo(p => p.SendASync(Param.IsAny<HttpRequestMessage>()))
.Return(Task.FromResult(HttpResponseMessageFixture.CreateWithEmptyValue()));

The<IHttpClient>().WhenToldTo(p => p.ReadAsStringAsync(Param.IsAny<HttpResponseMessage>()))
.Return(Task.FromResult(AccountHoldsResponseFixture.Create()));
};

Because of = () =>
result = Subject.GetAccountHoldsAsync("a1b2c3d4", 1).Result;

It should_have_correct_account_information = () =>
{
result.First().First().Id.ShouldEqual("82dcd140-c3c7-4507-8de4-2c529cd1a28f");
result.First().First().Account_id.ShouldEqual("e0b3f39a-183d-453e-b754-0c13e5bab0b3");
result.First().First().Created_at.ShouldEqual(new DateTime(2016, 12, 9));
result.First().First().Updated_at.ShouldEqual(new DateTime(2016, 12, 9));
result.First().First().Amount.ShouldEqual(4.23M);
result.First().First().Type.ShouldEqual("order");
result.First().First().@Ref.ShouldEqual("0a205de4-dd35-4370-a285-fe8fc375a273");
};
}
}
}
57 changes: 57 additions & 0 deletions GDAXClient.Specs/Services/Currencies/CurrenciesServiceSpecs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Net.Http;
using System.Threading.Tasks;
using GDAXClient.Authentication;
using GDAXClient.HttpClient;
using GDAXClient.Services.HttpRequest;
using Machine.Fakes;
using Machine.Specifications;
using GDAXClient.Services.Currencies;
using System.Collections.Generic;
using GDAXClient.Specs.JsonFixtures.Currencies;
using System.Linq;
using GDAXClient.Services.Currencies.Models;

namespace GDAXClient.Specs.Services.Deposits
{
[Subject("CurrenciesService")]
public class CurrenciesServiceSpecs : WithSubject<CurrenciesService>
{
static Authenticator authenticator;

static IEnumerable<Currency> result;

Establish context = () =>
authenticator = new Authenticator("apiKey", new string('2', 100), "passPhrase");

class when_getting_all_currencies
{
Establish context = () =>
{
The<IHttpRequestMessageService>().WhenToldTo(p => p.CreateHttpRequestMessage(Param.IsAny<HttpMethod>(), Param.IsAny<Authenticator>(), Param.IsAny<string>(), Param.IsAny<string>()))
.Return(new HttpRequestMessage());

The<IHttpClient>().WhenToldTo(p => p.SendASync(Param.IsAny<HttpRequestMessage>()))
.Return(Task.FromResult(new HttpResponseMessage()));

The<IHttpClient>().WhenToldTo(p => p.ReadAsStringAsync(Param.IsAny<HttpResponseMessage>()))
.Return(Task.FromResult(CurrenciesResponseFixture.Create()));
};

Because of = () =>
result = Subject.GetAllCurrenciesAsync().Result;

It should_return_a_correct_number_of_currencies = () =>
result.Count().ShouldEqual(2);

It should_return_a_correct_response = () =>
{
result.First().Id.ShouldEqual("BTC");
result.First().Name.ShouldEqual("Bitcoin");
result.First().Min_size.ShouldEqual(0.00000001M);
result.Skip(1).First().Id.ShouldEqual("USD");
result.Skip(1).First().Name.ShouldEqual("United States Dollar");
result.Skip(1).First().Min_size.ShouldEqual(0.01000000M);
};
}
}
}
101 changes: 49 additions & 52 deletions GDAXClient.Specs/Services/Orders/OrdersServiceSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class OrdersServiceSpecs : WithSubject<OrdersService>
{
static OrderResponse order_response_result;

static IEnumerable<OrderResponse> order_many_response_result;
static IList<IList<OrderResponse>> order_many_response_result;

static CancelOrderResponse cancel_order_response_result;

Expand Down Expand Up @@ -196,41 +196,41 @@ class when_getting_all_orders
order_many_response_result = Subject.GetAllOrdersAsync().Result;

It should_have_correct_number_of_orders = () =>
order_many_response_result.Count().ShouldEqual(2);
order_many_response_result.First().Count().ShouldEqual(2);

It should_have_correct_orders = () =>
{
order_many_response_result.First().Id.ShouldEqual(new System.Guid("d0c5340b-6d6c-49d9-b567-48c4bfca13d2"));
order_many_response_result.First().Price.ShouldEqual(0.10000000M);
order_many_response_result.First().Size.ShouldEqual(0.01000000M);
order_many_response_result.First().Product_id.ShouldEqual("BTC-USD");
order_many_response_result.First().Side.ShouldEqual("buy");
order_many_response_result.First().Stp.ShouldEqual("dc");
order_many_response_result.First().Type.ShouldEqual("limit");
order_many_response_result.First().Time_in_force.ShouldEqual("GTC");
order_many_response_result.First().Post_only.ShouldBeFalse();
order_many_response_result.First().Created_at.ShouldEqual(new System.DateTime(2016, 12, 9));
order_many_response_result.First().Fill_fees.ShouldEqual(0.0000000000000000M);
order_many_response_result.First().Filled_size.ShouldEqual(0.00000000M);
order_many_response_result.First().Executed_value.ShouldEqual(0.0000000000000000M);
order_many_response_result.First().Status.ShouldEqual("pending");
order_many_response_result.First().Settled.ShouldBeFalse();

order_many_response_result.Skip(1).First().Id.ShouldEqual(new System.Guid("8b99b139-58f2-4ab2-8e7a-c11c846e3022"));
order_many_response_result.Skip(1).First().Price.ShouldEqual(0.10000000M);
order_many_response_result.Skip(1).First().Size.ShouldEqual(0.01000000M);
order_many_response_result.Skip(1).First().Product_id.ShouldEqual("ETH-USD");
order_many_response_result.Skip(1).First().Side.ShouldEqual("buy");
order_many_response_result.Skip(1).First().Stp.ShouldEqual("dc");
order_many_response_result.Skip(1).First().Type.ShouldEqual("limit");
order_many_response_result.Skip(1).First().Time_in_force.ShouldEqual("GTC");
order_many_response_result.Skip(1).First().Post_only.ShouldBeFalse();
order_many_response_result.Skip(1).First().Created_at.ShouldEqual(new System.DateTime(2016, 12, 9));
order_many_response_result.Skip(1).First().Fill_fees.ShouldEqual(0.0000000000000000M);
order_many_response_result.Skip(1).First().Filled_size.ShouldEqual(0.00000000M);
order_many_response_result.Skip(1).First().Executed_value.ShouldEqual(0.0000000000000000M);
order_many_response_result.Skip(1).First().Status.ShouldEqual("pending");
order_many_response_result.Skip(1).First().Settled.ShouldBeFalse();
order_many_response_result.First().First().Id.ShouldEqual(new Guid("d0c5340b-6d6c-49d9-b567-48c4bfca13d2"));
order_many_response_result.First().First().Price.ShouldEqual(0.10000000M);
order_many_response_result.First().First().Size.ShouldEqual(0.01000000M);
order_many_response_result.First().First().Product_id.ShouldEqual("BTC-USD");
order_many_response_result.First().First().Side.ShouldEqual("buy");
order_many_response_result.First().First().Stp.ShouldEqual("dc");
order_many_response_result.First().First().Type.ShouldEqual("limit");
order_many_response_result.First().First().Time_in_force.ShouldEqual("GTC");
order_many_response_result.First().First().Post_only.ShouldBeFalse();
order_many_response_result.First().First().Created_at.ShouldEqual(new DateTime(2016, 12, 9));
order_many_response_result.First().First().Fill_fees.ShouldEqual(0.0000000000000000M);
order_many_response_result.First().First().Filled_size.ShouldEqual(0.00000000M);
order_many_response_result.First().First().Executed_value.ShouldEqual(0.0000000000000000M);
order_many_response_result.First().First().Status.ShouldEqual("pending");
order_many_response_result.First().First().Settled.ShouldBeFalse();

order_many_response_result.First().Skip(1).First().Id.ShouldEqual(new Guid("8b99b139-58f2-4ab2-8e7a-c11c846e3022"));
order_many_response_result.First().Skip(1).First().Price.ShouldEqual(0.10000000M);
order_many_response_result.First().Skip(1).First().Size.ShouldEqual(0.01000000M);
order_many_response_result.First().Skip(1).First().Product_id.ShouldEqual("ETH-USD");
order_many_response_result.First().Skip(1).First().Side.ShouldEqual("buy");
order_many_response_result.First().Skip(1).First().Stp.ShouldEqual("dc");
order_many_response_result.First().Skip(1).First().Type.ShouldEqual("limit");
order_many_response_result.First().Skip(1).First().Time_in_force.ShouldEqual("GTC");
order_many_response_result.First().Skip(1).First().Post_only.ShouldBeFalse();
order_many_response_result.First().Skip(1).First().Created_at.ShouldEqual(new DateTime(2016, 12, 9));
order_many_response_result.First().Skip(1).First().Fill_fees.ShouldEqual(0.0000000000000000M);
order_many_response_result.First().Skip(1).First().Filled_size.ShouldEqual(0.00000000M);
order_many_response_result.First().Skip(1).First().Executed_value.ShouldEqual(0.0000000000000000M);
order_many_response_result.First().Skip(1).First().Status.ShouldEqual("pending");
order_many_response_result.First().Skip(1).First().Settled.ShouldBeFalse();
};
}

Expand All @@ -251,26 +251,23 @@ class when_getting_order_by_id
Because of = () =>
order_response_result = Subject.GetOrderByIdAsync("d0c5340b-6d6c-49d9-b567-48c4bfca13d2").Result;

It should_have_correct_number_of_orders = () =>
order_many_response_result.Count().ShouldEqual(2);

It should_have_correct_orders = () =>
It should_have_correct_order = () =>
{
order_many_response_result.First().Id.ShouldEqual(new System.Guid("d0c5340b-6d6c-49d9-b567-48c4bfca13d2"));
order_many_response_result.First().Price.ShouldEqual(0.10000000M);
order_many_response_result.First().Size.ShouldEqual(0.01000000M);
order_many_response_result.First().Product_id.ShouldEqual("BTC-USD");
order_many_response_result.First().Side.ShouldEqual("buy");
order_many_response_result.First().Stp.ShouldEqual("dc");
order_many_response_result.First().Type.ShouldEqual("limit");
order_many_response_result.First().Time_in_force.ShouldEqual("GTC");
order_many_response_result.First().Post_only.ShouldBeFalse();
order_many_response_result.First().Created_at.ShouldEqual(new System.DateTime(2016, 12, 9));
order_many_response_result.First().Fill_fees.ShouldEqual(0.0000000000000000M);
order_many_response_result.First().Filled_size.ShouldEqual(0.00000000M);
order_many_response_result.First().Executed_value.ShouldEqual(0.0000000000000000M);
order_many_response_result.First().Status.ShouldEqual("pending");
order_many_response_result.First().Settled.ShouldBeFalse();
order_response_result.Id.ShouldEqual(new Guid("d0c5340b-6d6c-49d9-b567-48c4bfca13d2"));
order_response_result.Price.ShouldEqual(0.10000000M);
order_response_result.Size.ShouldEqual(0.01000000M);
order_response_result.Product_id.ShouldEqual("BTC-USD");
order_response_result.Side.ShouldEqual("buy");
order_response_result.Stp.ShouldEqual("dc");
order_response_result.Type.ShouldEqual("limit");
order_response_result.Time_in_force.ShouldEqual("GTC");
order_response_result.Post_only.ShouldBeFalse();
order_response_result.Created_at.ShouldEqual(new System.DateTime(2016, 12, 9));
order_response_result.Fill_fees.ShouldEqual(0.0000000000000000M);
order_response_result.Filled_size.ShouldEqual(0.00000000M);
order_response_result.Executed_value.ShouldEqual(0.0000000000000000M);
order_response_result.Status.ShouldEqual("pending");
order_response_result.Settled.ShouldBeFalse();
};
}
}
Expand Down
4 changes: 4 additions & 0 deletions GDAXClient/GDAXClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using GDAXClient.Products;
using GDAXClient.Services.Accounts;
using GDAXClient.Services.CoinbaseAccounts;
using GDAXClient.Services.Currencies;
using GDAXClient.Services.Deposits;
using GDAXClient.Services.Orders;
using GDAXClient.Services.Payments;
Expand Down Expand Up @@ -29,6 +30,7 @@ public GDAXClient(Authenticator authenticator, bool sandBox = false)
WithdrawalsService = new WithdrawalsService(httpClient, httpRequestMessageService, authenticator);
DepositsService = new DepositsService(httpClient, httpRequestMessageService, authenticator);
ProductsService = new ProductsService(httpClient, httpRequestMessageService, authenticator);
CurrenciesService = new CurrenciesService(httpClient, httpRequestMessageService, authenticator);
}

public AccountsService AccountsService { get; }
Expand All @@ -44,5 +46,7 @@ public GDAXClient(Authenticator authenticator, bool sandBox = false)
public DepositsService DepositsService { get; }

public ProductsService ProductsService { get; }

public CurrenciesService CurrenciesService { get; }
}
}
3 changes: 3 additions & 0 deletions GDAXClient/GDAXClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<Compile Include="HttpClient\HttpClient.cs" />
<Compile Include="HttpClient\IHttpClient.cs" />
<Compile Include="Services\Accounts\Models\AccountHistory.cs" />
<Compile Include="Services\Accounts\Models\AccountHold.cs" />
<Compile Include="Services\Currencies\CurrenciesService.cs" />
<Compile Include="Services\Currencies\Models\Currency.cs" />
<Compile Include="Services\Products\Models\Product.cs" />
<Compile Include="Services\Products\Models\ProductStats.cs" />
<Compile Include="Services\Products\Models\ProductTicker.cs" />
Expand Down
10 changes: 8 additions & 2 deletions GDAXClient/Services/Accounts/AccountsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ public async Task<Account> GetAccountByIdAsync(string id)
return account;
}

public async Task<IList<IList<AccountHistory>>> GetAccountHistoryAsync(string id, decimal limit)
public async Task<IList<IList<AccountHistory>>> GetAccountHistoryAsync(string id, int limit = 100)
{
var accountHistory = new List<IList<AccountHistory>>();
var httpResponseMessage = await SendHttpRequestMessagePagedAsync<AccountHistory>(HttpMethod.Get, authenticator, $"/accounts/{id}/ledger?limit={limit}");

return httpResponseMessage;
}

public async Task<IList<IList<AccountHold>>> GetAccountHoldsAsync(string id, int limit = 100)
{
var httpResponseMessage = await SendHttpRequestMessagePagedAsync<AccountHold>(HttpMethod.Get, authenticator, $"/accounts/{id}/holds?limit={limit}");

return httpResponseMessage;
}
}
}
21 changes: 21 additions & 0 deletions GDAXClient/Services/Accounts/Models/AccountHold.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace GDAXClient.Services.Accounts.Models
{
public class AccountHold
{
public string Id { get; set; }

public string Account_id { get; set; }

public DateTime Created_at { get; set; }

public DateTime Updated_at { get; set; }

public decimal Amount { get; set; }

public string Type { get; set; }

public string @Ref { get; set; }
}
}
Loading

0 comments on commit 122356d

Please sign in to comment.