Skip to content

Commit

Permalink
[Refactor] Fills service (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
dougdellolio authored Dec 16, 2017
1 parent 8b562c4 commit 1ac5907
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion GDAXClient.Specs/Services/Fills/FillsServiceSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class when_requesting_fills_by_product_id
};

Because of = () =>
fill_response = Subject.GetFillsByProductIdAsync(ProductType.BtcUsd.ToDasherizedUpper(), 1).Result;
fill_response = Subject.GetFillsByProductIdAsync(ProductType.BtcUsd, 1).Result;

It should_return_a_response = () =>
fill_response.ShouldNotBeNull();
Expand Down
25 changes: 7 additions & 18 deletions GDAXClient/Services/Fills/FillsService.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using GDAXClient.HttpClient;
using GDAXClient.Services.Accounts;
using GDAXClient.Services.Fills.Models;
using GDAXClient.Services.Fills.Models.Responses;
using GDAXClient.Services.HttpRequest;
using Newtonsoft.Json;
using GDAXClient.Services.Orders;
using GDAXClient.Utilities.Extensions;

namespace GDAXClient.Services.Fills
{
Expand All @@ -32,31 +31,21 @@ public FillsService(

public async Task<IList<IList<FillResponse>>> GetAllFillsAsync(int limit = 100)
{
var fills = await SendHttpRequestMessagePagedAsync<FillResponse>(HttpMethod.Post, authenticator, $"/fills?limit={limit}");
var fills = await SendHttpRequestMessagePagedAsync<FillResponse>(HttpMethod.Get, authenticator, $"/fills?limit={limit}");

return fills;
}

public async Task<IList<IList<FillResponse>>> GetFillsByOrderIdAsync(string orderId, int limit = 100)
{
var fill = JsonConvert.SerializeObject(new Fill
{
order_id = new Guid(orderId)
});

var fills = await SendHttpRequestMessagePagedAsync<FillResponse>(HttpMethod.Post, authenticator, $"/fills?limit={limit}", fill);
var fills = await SendHttpRequestMessagePagedAsync<FillResponse>(HttpMethod.Get, authenticator, $"/fills?limit={limit}&order_id={orderId}");

return fills;
}

public async Task<IList<IList<FillResponse>>> GetFillsByProductIdAsync(string productId, int limit = 100)
public async Task<IList<IList<FillResponse>>> GetFillsByProductIdAsync(ProductType productId, int limit = 100)
{
var fill = JsonConvert.SerializeObject(new Fill
{
product_id = productId.ToUpper()
});

var fills = await SendHttpRequestMessagePagedAsync<FillResponse>(HttpMethod.Post, authenticator, $"/fills?limit={limit}", fill);
var fills = await SendHttpRequestMessagePagedAsync<FillResponse>(HttpMethod.Get, authenticator, $"/fills?limit={limit}&product_id={productId.ToDasherizedUpper()}");

return fills;
}
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ var allAccounts = await gdaxClient.AccountsService.GetAllAccountsAsync();
###### Currencies ######
- GetAllCurrenciesAsync() - gets a list of known currencies

###### Fills ######
- GetAllFillsAsync(limit) - gets a list of all recent fills (paged response)
- GetFillsByOrderIdAsync(orderId, limit) - gets a list of all recent fills by order id (paged response)
- GetFillsByProductIdAsync(productType, limit) - gets a list of all recent fills by product type (paged response)

<h1>Sandbox Support</h1>

<i>Generate your key at https://public.sandbox.gdax.com/settings/api</i>
Expand Down Expand Up @@ -107,5 +112,13 @@ var firstAccountHistoryOnFirstPage = firstPage.ToList()[0];
var secondAccountHistoryOnFirstPage = firstPage.ToList()[1];
````

<h1>Contributors</h1>

Thanks for contributing!

- @dgelineau

<h1>Bugs or questions?</h1>

Please open an issue for any bugs or questions

0 comments on commit 1ac5907

Please sign in to comment.