Skip to content

Commit a79f00e

Browse files
committed
[Feature] Add GetSingleProductAsync to ProductsService
1 parent 51ca053 commit a79f00e

File tree

6 files changed

+73
-0
lines changed

6 files changed

+73
-0
lines changed

CoinbasePro.Specs/JsonFixtures/Services/Products/ProductsResponseFixture.cs

+25
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,31 @@ public static string Create()
2828
return json;
2929
}
3030

31+
public static string CreateSingle()
32+
{
33+
var json = @"
34+
{
35+
'id': 'BTC-USD',
36+
'display_name': 'BTC/USD',
37+
'base_currency': 'BTC',
38+
'quote_currency': 'USD',
39+
'base_increment': '0.00000001',
40+
'quote_increment': '0.01000000',
41+
'base_min_size': '0.00100000',
42+
'base_max_size': '280.00000000',
43+
'min_market_funds': '5',
44+
'max_market_funds': '1000000',
45+
'status': 'online',
46+
'status_message': '',
47+
'cancel_only': false,
48+
'limit_only': false,
49+
'post_only': false,
50+
'trading_disabled': false
51+
}";
52+
53+
return json;
54+
}
55+
3156
public static string CreateWithUnknownProductType()
3257
{
3358
var json = @"

CoinbasePro.Specs/Services/Products/ProductsServiceSpecs.cs

+38
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public class ProductsServiceSpecs : WithSubject<ProductsService>
2121
{
2222
static IEnumerable<Product> products_result;
2323

24+
static Product product_result;
25+
2426
static ProductsOrderBookResponse product_order_books_response;
2527

2628
static IList<Candle> product_history_response;
@@ -95,6 +97,42 @@ class with_unknown_products
9597
}
9698
}
9799

100+
class when_getting_a_single_product
101+
{
102+
class with_known_products
103+
{
104+
Establish context = () =>
105+
The<IHttpClient>().WhenToldTo(p => p.ReadAsStringAsync(Param.IsAny<HttpResponseMessage>()))
106+
.Return(Task.FromResult(ProductsResponseFixture.CreateSingle()));
107+
108+
Because of = () =>
109+
product_result = Subject.GetSingleProductAsync(ProductType.BtcUsd).Result;
110+
111+
It should_have_a_product_response = () =>
112+
product_result.ShouldNotBeNull();
113+
114+
It should_have_correct_product = () =>
115+
{
116+
product_result.Id.ShouldEqual(ProductType.BtcUsd);
117+
product_result.DisplayName.ShouldEqual("BTC/USD");
118+
product_result.BaseCurrency.ShouldEqual(Currency.BTC);
119+
product_result.QuoteCurrency.ShouldEqual(Currency.USD);
120+
product_result.BaseMinSize.ShouldEqual(0.00100000M);
121+
product_result.BaseMaxSize.ShouldEqual(280.00000000M);
122+
product_result.QuoteIncrement.ShouldEqual(0.01M);
123+
product_result.MinMarketFunds.ShouldEqual(5M);
124+
product_result.MaxMarketFunds.ShouldEqual(1000000M);
125+
product_result.BaseIncrement.ShouldEqual(0.00000001M);
126+
product_result.PostOnly.ShouldEqual(false);
127+
product_result.LimitOnly.ShouldEqual(false);
128+
product_result.CancelOnly.ShouldEqual(false);
129+
product_result.TradingDisabled.ShouldEqual(false);
130+
product_result.Status.ShouldEqual("online");
131+
product_result.StatusMessage.ShouldBeEmpty();
132+
};
133+
}
134+
}
135+
98136
class when_getting_a_product_order_book_for_level_one
99137
{
100138
Establish context = () =>

CoinbasePro/Services/Products/IProductsService.cs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public interface IProductsService
1212
{
1313
Task<IEnumerable<Product>> GetAllProductsAsync();
1414

15+
Task<Product> GetSingleProductAsync(ProductType productId);
16+
1517
Task<ProductsOrderBookResponse> GetProductOrderBookAsync(
1618
ProductType productId,
1719
ProductLevel productLevel = ProductLevel.One);

CoinbasePro/Services/Products/Models/Product.cs

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class Product
1515
[JsonConverter(typeof(StringEnumWithDefaultConverter))]
1616
public Currency QuoteCurrency { get; set; }
1717

18+
public string DisplayName { get; set; }
19+
1820
public decimal BaseMinSize { get; set; }
1921

2022
public decimal BaseMaxSize { get; set; }

CoinbasePro/Services/Products/ProductsService.cs

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public async Task<ProductsOrderBookResponse> GetProductOrderBookAsync(
4343
return productOrderBookResponse;
4444
}
4545

46+
public async Task<Product> GetSingleProductAsync(ProductType productId)
47+
{
48+
return await SendServiceCall<Product>(HttpMethod.Get, $"/products/{productId.GetEnumMemberValue()}");
49+
}
50+
4651
public async Task<ProductTicker> GetProductTickerAsync(ProductType productId)
4752
{
4853
return await SendServiceCall<ProductTicker>(HttpMethod.Get, $"/products/{productId.GetEnumMemberValue()}/ticker").ConfigureAwait(false);

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ var allAccounts = await coinbaseProClient.AccountsService.GetAllAccountsAsync();
6868

6969
###### Products ######
7070
- GetAllProductsAsync() - get a list of available currency pairs for trading
71+
- GetSingleProductAsync(productType) - get market data for a specific currency pair
7172
- GetProductOrderBookAsync(productType, productLevel) - get a list of open orders for a product (specify level 1, 2, or 3)
7273
- GetProductTickerAsync(productType) - get information about the last trade (tick), best bid/ask and 24h volume
7374
- GetTradesAsync(productType, limit, numberOfPages) - get latest trades for a product (paged response)

0 commit comments

Comments
 (0)