Skip to content

Commit

Permalink
[Feature] Add unknown types to handle new Product Types and Currencies (
Browse files Browse the repository at this point in the history
  • Loading branch information
dougdellolio authored Oct 28, 2018
1 parent 1ac7732 commit 48bb4b3
Show file tree
Hide file tree
Showing 28 changed files with 358 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,23 @@ public static string Create()

return json;
}

public static string CreateWithUnknownCurrency()
{
var json = @"
[
{
""id"": ""e316cb9a-0808-4fd7-8914-97829c1925de"",
""currency"": ""RANDOM"",
""balance"": ""80.2301373066930000"",
""available"": ""79.2266348066930000"",
""hold"": ""1.0035025000000000"",
""margin_enabled"": ""true"",
""profile_id"": ""75da88c5-05bf-4f54-bc85-5c775bd68254""
}
]";

return json;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,17 @@ public static string CreateEthereumClassic()

return json;
}

public static string CreateUnknown()
{
var json = @"
[{
""id"": ""UNK"",
""name"": ""Unknown Currency"",
""min_size"": ""0.00000001""
}]";

return json;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,22 @@ public static string Create()

return json;
}

public static string CreateWithUnknownProductType()
{
var json = @"
[
{
'id': 'UNKNOWN-USD',
'base_currency': 'unknown',
'quote_currency': 'unknown',
'base_min_size': '0.01',
'base_max_size': '10000.00',
'quote_increment': '0.01'
}
]";

return json;
}
}
}
68 changes: 48 additions & 20 deletions CoinbasePro.Specs/Services/Accounts/AccountsServiceSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,55 @@ public class AccountsServiceSpecs : WithSubject<AccountsService>

class when_getting_all_accounts
{
static IEnumerable<Account> result;

Establish context = () =>
The<IHttpClient>().WhenToldTo(p => p.ReadAsStringAsync(Param.IsAny<HttpResponseMessage>()))
.Return(Task.FromResult(AllAccountsResponseFixture.Create()));

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

It should_have_correct_count = () =>
result.Count().ShouldEqual(1);

It should_have_correct_account_information = () =>
class with_known_currency
{
result.First().Id.ShouldEqual(new Guid("e316cb9a-0808-4fd7-8914-97829c1925de"));
result.First().Currency.ShouldEqual(Currency.USD);
result.First().Balance.ShouldEqual(80.2301373066930000M);
result.First().Available.ShouldEqual(79.2266348066930000M);
result.First().Hold.ShouldEqual(1.0035025000000000M);
result.First().ProfileId.ShouldEqual(new Guid("75da88c5-05bf-4f54-bc85-5c775bd68254"));
};
static IEnumerable<Account> result;

Establish context = () =>
The<IHttpClient>().WhenToldTo(p => p.ReadAsStringAsync(Param.IsAny<HttpResponseMessage>()))
.Return(Task.FromResult(AllAccountsResponseFixture.Create()));

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

It should_have_correct_count = () =>
result.Count().ShouldEqual(1);

It should_have_correct_account_information = () =>
{
result.First().Id.ShouldEqual(new Guid("e316cb9a-0808-4fd7-8914-97829c1925de"));
result.First().Currency.ShouldEqual(Currency.USD);
result.First().Balance.ShouldEqual(80.2301373066930000M);
result.First().Available.ShouldEqual(79.2266348066930000M);
result.First().Hold.ShouldEqual(1.0035025000000000M);
result.First().ProfileId.ShouldEqual(new Guid("75da88c5-05bf-4f54-bc85-5c775bd68254"));
};
}

class with_unknown_currency
{
static IEnumerable<Account> result;

Establish context = () =>
The<IHttpClient>().WhenToldTo(p => p.ReadAsStringAsync(Param.IsAny<HttpResponseMessage>()))
.Return(Task.FromResult(AllAccountsResponseFixture.CreateWithUnknownCurrency()));

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

It should_have_correct_count = () =>
result.Count().ShouldEqual(1);

It should_have_correct_account_information = () =>
{
result.First().Id.ShouldEqual(new Guid("e316cb9a-0808-4fd7-8914-97829c1925de"));
result.First().Currency.ShouldEqual(Currency.Unknown);
result.First().Balance.ShouldEqual(80.2301373066930000M);
result.First().Available.ShouldEqual(79.2266348066930000M);
result.First().Hold.ShouldEqual(1.0035025000000000M);
result.First().ProfileId.ShouldEqual(new Guid("75da88c5-05bf-4f54-bc85-5c775bd68254"));
};
}
}

class when_getting_account_by_id
Expand Down
20 changes: 20 additions & 0 deletions CoinbasePro.Specs/Services/Currencies/CurrenciesServiceSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,25 @@ class when_getting_ethereum_classic
result.First().MinSize.ShouldEqual(0.00000001M);
};
}

class when_getting_an_unknown_currency
{
Establish context = () =>
The<IHttpClient>().WhenToldTo(p => p.ReadAsStringAsync(Param.IsAny<HttpResponseMessage>()))
.Return(Task.FromResult(CurrenciesResponseFixture.CreateUnknown()));

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

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

It should_return_a_correct_response = () =>
{
result.First().Id.ShouldEqual(CoinbasePro.Shared.Types.Currency.Unknown);
result.First().Name.ShouldEqual("Unknown Currency");
result.First().MinSize.ShouldEqual(0.00000001M);
};
}
}
}
1 change: 0 additions & 1 deletion CoinbasePro.Specs/Services/Orders/OrdersServiceSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class OrdersServiceSpecs : WithSubject<OrdersService>
Return(Task.FromResult(new HttpResponseMessage()));
};


class when_placing_a_market_order
{
Establish context = () =>
Expand Down
62 changes: 44 additions & 18 deletions CoinbasePro.Specs/Services/Products/ProductsServiceSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,51 @@ public class ProductsServiceSpecs : WithSubject<ProductsService>

class when_getting_all_products
{
Establish context = () =>
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 = () =>
class with_known_products
{
products_result.First().Id.ShouldEqual(ProductType.BtcUsd);
products_result.First().BaseCurrency.ShouldEqual(Currency.BTC);
products_result.First().QuoteCurrency.ShouldEqual(Currency.USD);
products_result.First().BaseMinSize.ShouldEqual(0.01M);
products_result.First().BaseMaxSize.ShouldEqual(10000.00M);
products_result.First().QuoteIncrement.ShouldEqual(0.01M);
};
Establish context = () =>
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(ProductType.BtcUsd);
products_result.First().BaseCurrency.ShouldEqual(Currency.BTC);
products_result.First().QuoteCurrency.ShouldEqual(Currency.USD);
products_result.First().BaseMinSize.ShouldEqual(0.01M);
products_result.First().BaseMaxSize.ShouldEqual(10000.00M);
products_result.First().QuoteIncrement.ShouldEqual(0.01M);
};
}

class with_unknown_products
{
Establish context = () =>
The<IHttpClient>().WhenToldTo(p => p.ReadAsStringAsync(Param.IsAny<HttpResponseMessage>()))
.Return(Task.FromResult(ProductsResponseFixture.CreateWithUnknownProductType()));

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(ProductType.Unknown);
products_result.First().BaseCurrency.ShouldEqual(Currency.Unknown);
products_result.First().QuoteCurrency.ShouldEqual(Currency.Unknown);
products_result.First().BaseMinSize.ShouldEqual(0.01M);
products_result.First().BaseMaxSize.ShouldEqual(10000.00M);
products_result.First().QuoteIncrement.ShouldEqual(0.01M);
};
}
}

class when_getting_a_product_order_book_for_level_one
Expand Down
4 changes: 2 additions & 2 deletions CoinbasePro/Services/Accounts/Models/Account.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using CoinbasePro.Shared;
using CoinbasePro.Shared.Types;

namespace CoinbasePro.Services.Accounts.Models
Expand All @@ -11,7 +11,7 @@ public class Account

public Guid ProfileId { get; set; }

[JsonConverter(typeof(StringEnumConverter))]
[JsonConverter(typeof(StringEnumWithDefaultConverter))]
public Currency Currency { get; set; }

public decimal Balance { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion CoinbasePro/Services/Accounts/Models/AccountHistory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using CoinbasePro.Services.Accounts.Types;
using CoinbasePro.Shared;
using CoinbasePro.Shared.Types;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
Expand Down Expand Up @@ -29,7 +30,7 @@ public class Details

public string TradeId { get; set; }

[JsonConverter(typeof(StringEnumConverter))]
[JsonConverter(typeof(StringEnumWithDefaultConverter))]
public ProductType ProductId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using CoinbasePro.Services.CoinbaseAccounts.Types;
using CoinbasePro.Shared;
using CoinbasePro.Shared.Types;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
Expand All @@ -14,6 +15,7 @@ public class CoinbaseAccount

public decimal Balance { get; set; }

[JsonConverter(typeof(StringEnumWithDefaultConverter))]
public Currency Currency { get; set; }

[JsonProperty("type")]
Expand Down
6 changes: 5 additions & 1 deletion CoinbasePro/Services/Currencies/Models/Currency.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
namespace CoinbasePro.Services.Currencies.Models
using CoinbasePro.Shared;
using Newtonsoft.Json;

namespace CoinbasePro.Services.Currencies.Models
{
public class Currency
{
[JsonConverter(typeof(StringEnumWithDefaultConverter))]
public Shared.Types.Currency Id { get; set; }

public string Name { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using CoinbasePro.Shared;
using CoinbasePro.Shared.Types;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace CoinbasePro.Services.Deposits.Models.Responses
{
Expand All @@ -11,7 +11,7 @@ public class DepositResponse

public decimal Amount { get; set; }

[JsonConverter(typeof(StringEnumConverter))]
[JsonConverter(typeof(StringEnumWithDefaultConverter))]
public Currency Currency { get; set; }

public DateTime PayoutAt { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion CoinbasePro/Services/Fills/Models/Responses/FillResponse.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using CoinbasePro.Services.Fills.Types;
using CoinbasePro.Services.Orders.Types;
using CoinbasePro.Shared;
using CoinbasePro.Shared.Types;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
Expand All @@ -11,7 +12,7 @@ public class FillResponse
{
public int TradeId { get; set; }

[JsonConverter(typeof(StringEnumConverter))]
[JsonConverter(typeof(StringEnumWithDefaultConverter))]
public ProductType ProductId { get; set; }

public decimal Price { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion CoinbasePro/Services/Fundings/Models/Funding.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using CoinbasePro.Services.Fundings.Types;
using CoinbasePro.Shared;
using CoinbasePro.Shared.Types;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
Expand All @@ -21,7 +22,7 @@ public class Funding

public DateTime CreatedAt { get; set; }

[JsonConverter(typeof(StringEnumConverter))]
[JsonConverter(typeof(StringEnumWithDefaultConverter))]
public Currency Currency { get; set; }

public decimal RepaidAmount { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion CoinbasePro/Services/Orders/Models/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Newtonsoft.Json.Converters;
using System;
using CoinbasePro.Services.Orders.Types;
using CoinbasePro.Shared;
using CoinbasePro.Shared.Types;

namespace CoinbasePro.Services.Orders.Models
Expand All @@ -28,7 +29,7 @@ public class Order
[JsonConverter(typeof(StringEnumConverter))]
public OrderType OrderType { get; set; }

[JsonConverter(typeof(StringEnumConverter))]
[JsonConverter(typeof(StringEnumWithDefaultConverter))]
public ProductType ProductId { get; set; }

[JsonConverter(typeof(StringEnumConverter))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using CoinbasePro.Services.Orders.Types;
using CoinbasePro.Shared;
using CoinbasePro.Shared.Types;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
Expand All @@ -14,7 +15,7 @@ public class OrderResponse

public decimal Size { get; set; }

[JsonConverter(typeof(StringEnumConverter))]
[JsonConverter(typeof(StringEnumWithDefaultConverter))]
public ProductType ProductId { get; set; }

[JsonConverter(typeof(StringEnumConverter))]
Expand Down
Loading

0 comments on commit 48bb4b3

Please sign in to comment.