Skip to content

Commit

Permalink
[Feature] Products service (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
dougdellolio authored Dec 5, 2017
1 parent 621ac68 commit 63d88b7
Show file tree
Hide file tree
Showing 32 changed files with 411 additions and 19 deletions.
5 changes: 5 additions & 0 deletions GDAXClient.Specs/GDAXClient.Specs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
<Compile Include="JsonFixtures\Orders\CancelOrderResponseFixture.cs" />
<Compile Include="JsonFixtures\Orders\OrderResponseFixture.cs" />
<Compile Include="JsonFixtures\Payments\PaymentMethodsResponseFixture.cs" />
<Compile Include="JsonFixtures\Products\ProductsOrderBookResponseFixture.cs" />
<Compile Include="JsonFixtures\Products\ProductsResponseFixture.cs" />
<Compile Include="JsonFixtures\Products\ProductStatsFixture.cs" />
<Compile Include="JsonFixtures\Products\ProductTickerFixture.cs" />
<Compile Include="JsonFixtures\Withdrawals\CoinbaseWithdrawalResponseFixture.cs" />
<Compile Include="JsonFixtures\Withdrawals\CryptoWithdrawalResponseFixture.cs" />
<Compile Include="JsonFixtures\Withdrawals\WithdrawalsResponseFixture.cs" />
Expand All @@ -94,6 +98,7 @@
<Compile Include="Services\HttpRequest\HttpRequestMessageServiceSpecs.cs" />
<Compile Include="Services\Orders\OrdersServiceSpecs.cs" />
<Compile Include="Services\Payments\PaymentsServiceSpecs.cs" />
<Compile Include="Services\Products\ProductsServiceSpecs.cs" />
<Compile Include="Services\Withdrawals\WithdrawalsServiceSpecs.cs" />
<Compile Include="Utilities\Extensions\DateExtensionsSpecs.cs" />
<Compile Include="Utilities\Extensions\ProductTypeExtensionsSpecs.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace GDAXClient.Specs.JsonFixtures.Deposits
{
class CoinbaseDepositResponseFixture
public static class CoinbaseDepositResponseFixture
{
public static string Create()
{
Expand Down
19 changes: 19 additions & 0 deletions GDAXClient.Specs/JsonFixtures/Products/ProductStatsFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace GDAXClient.Specs.JsonFixtures.Products
{
public static class ProductStatsFixture
{
public static string Create()
{

var json = @"
{
'open': '34.19000000',
'high': '95.70000000',
'low': '7.06000000',
'volume': '2.41000000'
}";

return json;
}
}
}
21 changes: 21 additions & 0 deletions GDAXClient.Specs/JsonFixtures/Products/ProductTickerFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace GDAXClient.Specs.JsonFixtures.Products
{
public static class ProductTickerFixture
{
public static string Create()
{
var json = @"
{
'trade_id': 4729088,
'price': '333.99',
'size': '0.193',
'bid': '333.98',
'ask': '333.99',
'volume': '5957.11914015',
'time': '2016-12-08T24:00:00Z'
}";

return json;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace GDAXClient.Specs.JsonFixtures.Products
{
public static class ProductsOrderBookResponseFixture
{
public static string Create()
{
var json = @"
{
'sequence': '3',
'bids': [
[200, 100, 3],
],
'ask': [
[200, 100, 3],
]
}";

return json;
}
}
}
22 changes: 22 additions & 0 deletions GDAXClient.Specs/JsonFixtures/Products/ProductsResponseFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace GDAXClient.Specs.JsonFixtures.Products
{
public static class ProductsResponseFixture
{
public static string Create()
{
var json = @"
[
{
'id': 'BTC-USD',
'base_currency': 'BTC',
'quote_currency': 'USD',
'base_min_size': '0.01',
'base_max_size': '10000.00',
'quote_increment': '0.01'
}
]";

return json;
}
}
}
150 changes: 150 additions & 0 deletions GDAXClient.Specs/Services/Products/ProductsServiceSpecs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
using GDAXClient.Authentication;
using GDAXClient.HttpClient;
using GDAXClient.Products;
using GDAXClient.Services.HttpRequest;
using GDAXClient.Services.Orders;
using GDAXClient.Services.Products;
using GDAXClient.Services.Products.Models;
using GDAXClient.Services.Products.Models.Responses;
using GDAXClient.Specs.JsonFixtures.Products;
using Machine.Fakes;
using Machine.Specifications;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

namespace GDAXClient.Specs.Services.Payments
{
[Subject("ProductsService")]
public class ProductsServiceSpecs : WithSubject<ProductsService>
{
static Authenticator authenticator;

static IEnumerable<Product> products_result;

static ProductsOrderBookResponse product_order_books_response;

static ProductTicker product_ticker_result;

static ProductStats product_stats_result;

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

class when_getting_all_products
{
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(ProductsResponseFixture.Create()));
};

Because of = () =>
products_result = Subject.GetAllProductsAsync().Result;

It should_have_correct_products_response_count = () =>
products_result.Count().ShouldEqual(1);

It should_have_correct_products = () =>
{
products_result.First().Id.ShouldEqual("BTC-USD");
products_result.First().Base_currency.ShouldEqual("BTC");
products_result.First().Quote_currency.ShouldEqual("USD");
products_result.First().Base_min_size.ShouldEqual("0.01");
products_result.First().Base_max_size.ShouldEqual("10000.00");
products_result.First().Quote_increment.ShouldEqual("0.01");
};
}

class when_getting_a_product_order_book
{
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(ProductsOrderBookResponseFixture.Create()));
};

Because of = () =>
product_order_books_response = Subject.GetProductOrderBookAsync(ProductType.BtcUsd).Result;

It should_have_correct_product_order_book_response = () =>
{
product_order_books_response.Sequence.ShouldEqual(3M);
product_order_books_response.Bids.SelectMany(p => p).ShouldContain(200);
product_order_books_response.Bids.SelectMany(p => p).ShouldContain(100);
product_order_books_response.Bids.SelectMany(p => p).ShouldContain(3);
product_order_books_response.Ask.SelectMany(p => p).ShouldContain(200);
product_order_books_response.Ask.SelectMany(p => p).ShouldContain(100);
product_order_books_response.Ask.SelectMany(p => p).ShouldContain(3);
};
}

class when_getting_a_product_ticker
{
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(ProductTickerFixture.Create()));
};

Because of = () =>
product_ticker_result = Subject.GetProductTickerAsync(ProductType.BtcUsd).Result;

It should_have_correct_product_ticker = () =>
{
product_ticker_result.Trade_id.ShouldEqual(4729088);
product_ticker_result.Price.ShouldEqual(333.99M);
product_ticker_result.Size.ShouldEqual(0.193M);
product_ticker_result.Bid.ShouldEqual(333.98M);
product_ticker_result.Ask.ShouldEqual(333.99M);
product_ticker_result.Volume.ShouldEqual(5957.11914015M);
product_ticker_result.Time.ShouldEqual(new System.DateTime(2016, 12, 9));
};
}

class when_getting_product_stats
{
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(ProductStatsFixture.Create()));
};

Because of = () =>
product_stats_result = Subject.GetProductStatsAsync(ProductType.BtcUsd).Result;

It should_have_correct_product_stats = () =>
{
product_stats_result.Open.ShouldEqual(34.19000000M);
product_stats_result.High.ShouldEqual(95.70000000M);
product_stats_result.Low.ShouldEqual(7.06000000M);
product_stats_result.Volume.ShouldEqual(2.41000000M);
};
}
}
}
4 changes: 4 additions & 0 deletions GDAXClient/GDAXClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GDAXClient.Authentication;
using GDAXClient.Products;
using GDAXClient.Services.Accounts;
using GDAXClient.Services.CoinbaseAccounts;
using GDAXClient.Services.Deposits;
Expand Down Expand Up @@ -27,6 +28,7 @@ public GDAXClient(Authenticator authenticator, bool sandBox = false)
PaymentsService = new PaymentsService(httpClient, httpRequestMessageService, authenticator);
WithdrawalsService = new WithdrawalsService(httpClient, httpRequestMessageService, authenticator);
DepositsService = new DepositsService(httpClient, httpRequestMessageService, authenticator);
ProductsService = new ProductsService(httpClient, httpRequestMessageService, authenticator);
}

public AccountsService AccountsService { get; }
Expand All @@ -40,5 +42,7 @@ public GDAXClient(Authenticator authenticator, bool sandBox = false)
public WithdrawalsService WithdrawalsService { get; }

public DepositsService DepositsService { get; }

public ProductsService ProductsService { get; }
}
}
40 changes: 23 additions & 17 deletions GDAXClient/GDAXClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,39 @@
<Compile Include="GDAXClient.cs" />
<Compile Include="HttpClient\HttpClient.cs" />
<Compile Include="HttpClient\IHttpClient.cs" />
<Compile Include="Services\Products\Models\Product.cs" />
<Compile Include="Services\Products\Models\ProductStats.cs" />
<Compile Include="Services\Products\Models\ProductTicker.cs" />
<Compile Include="Services\Products\Models\Responses\ProductsOrderBookResponse.cs" />
<Compile Include="Services\Products\ProductsService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\AbstractService.cs" />
<Compile Include="Services\Accounts\Account.cs" />
<Compile Include="Services\Accounts\Models\Account.cs" />
<Compile Include="Services\Accounts\AccountsService.cs" />
<Compile Include="Authentication\IAuthenticator.cs" />
<Compile Include="Services\CoinbaseAccounts\CoinbaseAccount.cs" />
<Compile Include="Services\CoinbaseAccounts\Models\CoinbaseAccount.cs" />
<Compile Include="Services\CoinbaseAccounts\CoinbaseAccountsService.cs" />
<Compile Include="Services\Currency.cs" />
<Compile Include="Services\Deposits\Deposit.cs" />
<Compile Include="Services\Deposits\DepositResponse.cs" />
<Compile Include="Shared\Currency.cs" />
<Compile Include="Services\Deposits\Models\Deposit.cs" />
<Compile Include="Services\Deposits\Models\Responses\DepositResponse.cs" />
<Compile Include="Services\Deposits\DepositsService.cs" />
<Compile Include="Services\HttpRequest\HttpRequestMessageService.cs" />
<Compile Include="Services\HttpRequest\IHttpRequestMessageService.cs" />
<Compile Include="Services\Orders\CancelOrderResponse.cs" />
<Compile Include="Services\Orders\Order.cs" />
<Compile Include="Services\Orders\OrderResponse.cs" />
<Compile Include="Services\Orders\OrderSide.cs" />
<Compile Include="Services\Orders\Models\Responses\CancelOrderResponse.cs" />
<Compile Include="Services\Orders\Models\Order.cs" />
<Compile Include="Services\Orders\Models\Responses\OrderResponse.cs" />
<Compile Include="Services\Orders\Models\OrderSide.cs" />
<Compile Include="Services\Orders\OrdersService.cs" />
<Compile Include="Services\Orders\OrderType.cs" />
<Compile Include="Services\Orders\ProductType.cs" />
<Compile Include="Services\Payments\PaymentMethod.cs" />
<Compile Include="Shared\ProductType.cs" />
<Compile Include="Services\Payments\Models\PaymentMethod.cs" />
<Compile Include="Services\Payments\PaymentsService.cs" />
<Compile Include="Services\Withdrawals\Coinbase.cs" />
<Compile Include="Services\Withdrawals\CoinbaseResponse.cs" />
<Compile Include="Services\Withdrawals\Crypto.cs" />
<Compile Include="Services\Withdrawals\CryptoResponse.cs" />
<Compile Include="Services\Withdrawals\Withdrawal.cs" />
<Compile Include="Services\Withdrawals\WithdrawalResponse.cs" />
<Compile Include="Services\Withdrawals\Models\Coinbase.cs" />
<Compile Include="Services\Withdrawals\Models\Responses\CoinbaseResponse.cs" />
<Compile Include="Services\Withdrawals\Models\Crypto.cs" />
<Compile Include="Services\Withdrawals\Models\Responses\CryptoResponse.cs" />
<Compile Include="Services\Withdrawals\Models\Withdrawal.cs" />
<Compile Include="Services\Withdrawals\Models\Responses\WithdrawalResponse.cs" />
<Compile Include="Services\Withdrawals\WithdrawalsService.cs" />
<Compile Include="Utilities\Clock.cs" />
<Compile Include="Utilities\Extensions\DateExtensions.cs" />
Expand All @@ -95,5 +100,6 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions GDAXClient/Services/Products/Models/Product.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace GDAXClient.Services.Products
{
public class Product
{
public string Id { get; set; }

public string Base_currency { get; set; }

public string Quote_currency { get; set; }

public string Base_min_size { get; set; }

public string Base_max_size { get; set; }

public string Quote_increment { get; set; }
}
}
13 changes: 13 additions & 0 deletions GDAXClient/Services/Products/Models/ProductStats.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace GDAXClient.Services.Products.Models
{
public class ProductStats
{
public decimal Open { get; set; }

public decimal High { get; set; }

public decimal Low { get; set; }

public decimal Volume { get; set; }
}
}
Loading

0 comments on commit 63d88b7

Please sign in to comment.