Skip to content

Commit

Permalink
[Feature] Add conversion account entry type (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
dougdellolio authored Dec 7, 2018
1 parent 29db407 commit 5e41fec
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
{
public static class AccountsHistoryResponseFixture
{
public static string Create()
public static string Create(string type)
{
var json = @"
var json = $@"
[
{
{{
""id"": ""100"",
""created_at"": ""2014-11-07T08:19:27.028459Z"",
""amount"": ""0.001"",
""balance"": ""239.669"",
""type"": ""fee"",
""details"": {
""type"": ""{type}"",
""details"": {{
""order_id"": ""d50ec984-77a8-460a-b958-66f114b0de9b"",
""trade_id"": ""74"",
""product_id"": ""BTC-USD""
}
}
}}
}}
]";

return json;
Expand Down
69 changes: 50 additions & 19 deletions CoinbasePro.Specs/Services/Accounts/AccountsServiceSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,61 @@ class when_getting_account_by_id

class when_getting_account_history
{
static IList<IList<AccountHistory>> result;

Establish context = () =>
class with_conversion_account_entry_type
{
The<IHttpClient>().WhenToldTo(p => p.SendAsync(Param.IsAny<HttpRequestMessage>()))
.Return(Task.FromResult(HttpResponseMessageFixture.CreateWithEmptyValue()));
static IList<IList<AccountHistory>> result;

The<IHttpClient>().WhenToldTo(p => p.ReadAsStringAsync(Param.IsAny<HttpResponseMessage>()))
.Return(Task.FromResult(AccountsHistoryResponseFixture.Create()));
};
Establish context = () =>
{
The<IHttpClient>().WhenToldTo(p => p.SendAsync(Param.IsAny<HttpRequestMessage>()))
.Return(Task.FromResult(HttpResponseMessageFixture.CreateWithEmptyValue()));

Because of = () =>
result = Subject.GetAccountHistoryAsync("a1b2c3d4", 1).Result;
The<IHttpClient>().WhenToldTo(p => p.ReadAsStringAsync(Param.IsAny<HttpResponseMessage>()))
.Return(Task.FromResult(AccountsHistoryResponseFixture.Create(AccountEntryType.Conversion.ToString())));
};

It should_have_correct_account_information = () =>
Because of = () =>
result = Subject.GetAccountHistoryAsync("a1b2c3d4", 1).Result;

It should_have_correct_account_information = () =>
{
result.First().First().Id.ShouldEqual("100");
result.First().First().Amount.ShouldEqual(0.001M);
result.First().First().Balance.ShouldEqual(239.669M);
result.First().First().AccountEntryType.ShouldEqual(AccountEntryType.Conversion);
result.First().First().Details.OrderId.ShouldEqual(new Guid("d50ec984-77a8-460a-b958-66f114b0de9b"));
result.First().First().Details.TradeId.ShouldEqual("74");
result.First().First().Details.ProductId.ShouldEqual(ProductType.BtcUsd);
};
}

class with_unknown_conversion_account_entry_type
{
result.First().First().Id.ShouldEqual("100");
result.First().First().Amount.ShouldEqual(0.001M);
result.First().First().Balance.ShouldEqual(239.669M);
result.First().First().AccountEntryType.ShouldEqual(AccountEntryType.Fee);
result.First().First().Details.OrderId.ShouldEqual(new Guid("d50ec984-77a8-460a-b958-66f114b0de9b"));
result.First().First().Details.TradeId.ShouldEqual("74");
result.First().First().Details.ProductId.ShouldEqual(ProductType.BtcUsd);
};
static IList<IList<AccountHistory>> result;

Establish context = () =>
{
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(AccountsHistoryResponseFixture.Create("UNKNOWNTYPE")));
};

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

It should_have_correct_account_information = () =>
{
result.First().First().Id.ShouldEqual("100");
result.First().First().Amount.ShouldEqual(0.001M);
result.First().First().Balance.ShouldEqual(239.669M);
result.First().First().AccountEntryType.ShouldEqual(AccountEntryType.Unknown);
result.First().First().Details.OrderId.ShouldEqual(new Guid("d50ec984-77a8-460a-b958-66f114b0de9b"));
result.First().First().Details.TradeId.ShouldEqual("74");
result.First().First().Details.ProductId.ShouldEqual(ProductType.BtcUsd);
};
}
}

class when_getting_account_holds
Expand Down
3 changes: 1 addition & 2 deletions CoinbasePro/Services/Accounts/Models/AccountHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using CoinbasePro.Shared;
using CoinbasePro.Shared.Types;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace CoinbasePro.Services.Accounts.Models
{
Expand All @@ -18,7 +17,7 @@ public class AccountHistory
public decimal Balance { get; set; }

[JsonProperty("type")]
[JsonConverter(typeof(StringEnumConverter))]
[JsonConverter(typeof(StringEnumWithDefaultConverter))]
public AccountEntryType AccountEntryType { get; set; }

public Details Details { get; set; }
Expand Down
6 changes: 5 additions & 1 deletion CoinbasePro/Services/Accounts/Types/AccountEntryType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ namespace CoinbasePro.Services.Accounts.Types
{
public enum AccountEntryType
{
[EnumMember(Value = "Unknown")]
Unknown,
[EnumMember(Value = "transfer")]
Transfer,
[EnumMember(Value = "match")]
Match,
[EnumMember(Value = "fee")]
Fee,
[EnumMember(Value = "rebate")]
Rebate
Rebate,
[EnumMember(Value = "conversion")]
Conversion
}
}

0 comments on commit 5e41fec

Please sign in to comment.