Skip to content

Commit

Permalink
[Feature] Add Fees service for new Fees API (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
dougdellolio authored Aug 17, 2019
1 parent 5c3c486 commit 272ebf6
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace CoinbasePro.Specs.JsonFixtures.Services.Fees
{
public static class FeesResponseFixture
{
public static string Create()
{
var json = @"
[
{
""maker_fee_rate"": ""0.0015"",
""taker_fee_rate"": ""0.0025"",
""usd_volume"": ""25000.00""
}
]";

return json;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CoinbasePro.Specs.JsonFixtures.Services.Fills
{
class FillsResponseFixture
public static class FillsResponseFixture
{
public static string Create()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CoinbasePro.Specs.JsonFixtures.Services.Fundings
{
class FundingsResponseFixture
public static class FundingsResponseFixture
{
public static string Create()
{
Expand Down
44 changes: 44 additions & 0 deletions CoinbasePro.Specs/Services/Fees/FeesServiceSpecs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using CoinbasePro.Network.HttpClient;
using CoinbasePro.Services.Fees;
using CoinbasePro.Services.Fees.Models;
using CoinbasePro.Specs.JsonFixtures.Network.HttpResponseMessage;
using CoinbasePro.Specs.JsonFixtures.Services.Fees;
using Machine.Fakes;
using Machine.Specifications;

namespace CoinbasePro.Specs.Services.Fees
{
[Subject("FeesService")]
public class FeesServiceSpecs : WithSubject<FeesService>
{
Establish context = () =>
The<IHttpClient>().WhenToldTo(p => p.SendAsync(Param.IsAny<HttpRequestMessage>()))
.Return(Task.FromResult(HttpResponseMessageFixture.CreateWithEmptyValue()));

class when_getting_current_fees
{
static IEnumerable<Fee> fee_response;

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

Because of = () =>
fee_response = Subject.GetCurrentFeesAsync().Result;

It should_return_a_response = () =>
fee_response.ShouldNotBeNull();

It should_return_a_correct_response = () =>
{
fee_response.First().MakerFeeRate.ShouldEqual(0.0015m);
fee_response.First().TakerFeeRate.ShouldEqual(0.0025m);
fee_response.First().UsdVolume.ShouldEqual(25000);
};
}
}
}
4 changes: 4 additions & 0 deletions CoinbasePro/CoinbaseProClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using CoinbasePro.Services.CoinbaseAccounts;
using CoinbasePro.Services.Currencies;
using CoinbasePro.Services.Deposits;
using CoinbasePro.Services.Fees;
using CoinbasePro.Services.Fills;
using CoinbasePro.Services.Fundings;
using CoinbasePro.Services.Orders;
Expand Down Expand Up @@ -60,6 +61,7 @@ public CoinbaseProClient(
ReportsService = new ReportsService(httpClient, httpRequestMessageService);
UserAccountService = new UserAccountService(httpClient, httpRequestMessageService);
StablecoinConversionsService = new StablecoinConversionsService(httpClient, httpRequestMessageService);
FeesService = new FeesService(httpClient, httpRequestMessageService);
WebSocket = new WebSocket.WebSocket(createWebSocketFeed, authenticator, clock);

Log.Information("CoinbaseProClient constructed");
Expand All @@ -85,6 +87,8 @@ public CoinbaseProClient(

public IFundingsService FundingsService { get; }

public IFeesService FeesService { get; }

public IReportsService ReportsService { get; }

public IUserAccountService UserAccountService { get; }
Expand Down
26 changes: 26 additions & 0 deletions CoinbasePro/Services/Fees/FeesService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using CoinbasePro.Network.HttpClient;
using CoinbasePro.Network.HttpRequest;
using CoinbasePro.Services.Fees.Models;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;

namespace CoinbasePro.Services.Fees
{
public class FeesService : AbstractService, IFeesService
{
public FeesService(
IHttpClient httpClient,
IHttpRequestMessageService httpRequestMessageService)
: base(httpClient, httpRequestMessageService)
{
}

public async Task<IEnumerable<Fee>> GetCurrentFeesAsync()
{
var fees = await SendServiceCall<IEnumerable<Fee>>(HttpMethod.Get, "/fees");

return fees;
}
}
}
11 changes: 11 additions & 0 deletions CoinbasePro/Services/Fees/IFeesService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using CoinbasePro.Services.Fees.Models;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace CoinbasePro.Services.Fees
{
public interface IFeesService
{
Task<IEnumerable<Fee>> GetCurrentFeesAsync();
}
}
11 changes: 11 additions & 0 deletions CoinbasePro/Services/Fees/Models/Fee.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace CoinbasePro.Services.Fees.Models
{
public class Fee
{
public decimal MakerFeeRate { get; set; }

public decimal TakerFeeRate { get; set; }

public decimal UsdVolume { get; set; }
}
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ var allAccounts = await coinbaseProClient.AccountsService.GetAllAccountsAsync();
###### User Account ######
- GetTrailingVolumeAsync() - get 30-day trailing volume for all products

###### Fees ######
- GetCurrentFeesAsync() - get your current maker & taker fee rates, as well as your 30-day trailing volume

###### Stablecoin Conversions ######
- CreateConversion(currencyFrom, currencyTo, amount) - convert bank-based dollars to blockchain-based digital dollars

Expand Down

0 comments on commit 272ebf6

Please sign in to comment.