-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e62de20
commit de4ef26
Showing
12 changed files
with
285 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
GDAXClient.Specs/JsonFixtures/Fundings/FundingsResponseFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
namespace GDAXClient.Specs.JsonFixtures.Fills | ||
{ | ||
class FundingsResponseFixture | ||
{ | ||
public static string Create() | ||
{ | ||
var json = @" | ||
[ | ||
{ | ||
""id"": ""b93d26cd-7193-4c8d-bfcc-446b2fe18f71"", | ||
""order_id"": ""b93d26cd-7193-4c8d-bfcc-446b2fe18f71"", | ||
""profile_id"": ""d881e5a6-58eb-47cd-b8e2-8d9f2e3ec6f6"", | ||
""amount"": ""1057.6519956381537500"", | ||
""status"": ""settled"", | ||
""created_at"": ""2017-03-17T23:46:16.663397Z"", | ||
""currency"": ""USD"", | ||
""repaid_amount"": ""1057.6519956381537500"", | ||
""default_amount"": ""0"", | ||
""repaid_default"": false | ||
}, | ||
{ | ||
""id"": ""280c0a56-f2fa-4d3b-a199-92df76fff5cd"", | ||
""order_id"": ""280c0a56-f2fa-4d3b-a199-92df76fff5cd"", | ||
""profile_id"": ""d881e5a6-58eb-47cd-b8e2-8d9f2e3ec6f6"", | ||
""amount"": ""545.2400000000000000"", | ||
""status"": ""outstanding"", | ||
""created_at"": ""2017-03-18T00:34:34.270484Z"", | ||
""currency"": ""USD"", | ||
""repaid_amount"": ""532.7580047716682500"" | ||
}, | ||
]"; | ||
|
||
return json; | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
GDAXClient.Specs/Services/Fundings/FundingsServiceSpecs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using GDAXClient.Authentication; | ||
using GDAXClient.HttpClient; | ||
using Machine.Fakes; | ||
using Machine.Specifications; | ||
using GDAXClient.Services.Fills; | ||
using GDAXClient.Services.Fills.Models.Responses; | ||
using GDAXClient.Services.HttpRequest; | ||
using GDAXClient.Services.Orders; | ||
using GDAXClient.Specs.JsonFixtures.Fills; | ||
using GDAXClient.Specs.JsonFixtures.HttpResponseMessage; | ||
using GDAXClient.Utilities.Extensions; | ||
using GDAXClient.Services.Fundings; | ||
using GDAXClient.Services.Fundings.Models; | ||
|
||
namespace GDAXClient.Specs.Services | ||
{ | ||
[Subject("FundingsService")] | ||
public class FundingsServiceSpecs : WithSubject<FundingsService> | ||
{ | ||
static Authenticator authenticator; | ||
|
||
static IList<IList<Funding>> fundings_response; | ||
|
||
Establish context = () => | ||
authenticator = new Authenticator("apiKey", new string('2', 100), "passPhrase"); | ||
|
||
class when_requesting_all_fundings | ||
{ | ||
Establish context = () => | ||
{ | ||
The<IHttpRequestMessageService>().WhenToldTo(p => p.CreateHttpRequestMessage(Param.IsAny<HttpMethod>(), Param.IsAny<Authenticator>(), Param.IsAny<string>(), Param.IsAny<string>())) | ||
.Return(new HttpRequestMessage()); | ||
|
||
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(FundingsResponseFixture.Create())); | ||
}; | ||
|
||
Because of = () => | ||
fundings_response = Subject.GetAllFundingsAsync().Result; | ||
|
||
It should_return_a_response = () => | ||
fundings_response.ShouldNotBeNull(); | ||
|
||
It should_return_a_correct_response = () => | ||
{ | ||
fundings_response.First().First().Id.ShouldEqual(new Guid("b93d26cd-7193-4c8d-bfcc-446b2fe18f71")); | ||
fundings_response.First().First().Order_id.ShouldEqual("b93d26cd-7193-4c8d-bfcc-446b2fe18f71"); | ||
fundings_response.First().First().Profile_id.ShouldEqual("d881e5a6-58eb-47cd-b8e2-8d9f2e3ec6f6"); | ||
fundings_response.First().First().Amount.ShouldEqual(1057.6519956381537500M); | ||
fundings_response.First().First().Status.ShouldEqual("settled"); | ||
fundings_response.First().First().Currency.ShouldEqual("USD"); | ||
fundings_response.First().First().Repaid_amount.ShouldEqual(1057.6519956381537500M); | ||
fundings_response.First().First().Default_amount.ShouldEqual(0); | ||
fundings_response.First().First().Repaid_default.ShouldBeFalse(); | ||
|
||
fundings_response.First().Skip(1).First().Id.ShouldEqual(new Guid("280c0a56-f2fa-4d3b-a199-92df76fff5cd")); | ||
fundings_response.First().Skip(1).First().Order_id.ShouldEqual("280c0a56-f2fa-4d3b-a199-92df76fff5cd"); | ||
fundings_response.First().Skip(1).First().Profile_id.ShouldEqual("d881e5a6-58eb-47cd-b8e2-8d9f2e3ec6f6"); | ||
fundings_response.First().Skip(1).First().Amount.ShouldEqual(545.2400000000000000M); | ||
fundings_response.First().Skip(1).First().Status.ShouldEqual("outstanding"); | ||
fundings_response.First().Skip(1).First().Currency.ShouldEqual("USD"); | ||
fundings_response.First().Skip(1).First().Repaid_amount.ShouldEqual(532.7580047716682500M); | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using GDAXClient.Utilities; | ||
using Machine.Fakes; | ||
using Machine.Specifications; | ||
using System.Collections.Generic; | ||
|
||
namespace GDAXClient.Specs.Utilities | ||
{ | ||
[Subject("QueryBuilder")] | ||
public class QueryBuilderSpecs : WithSubject<QueryBuilder> | ||
{ | ||
static string result; | ||
|
||
class when_requesting_with_multiple_parameters | ||
{ | ||
Because of = () => | ||
{ | ||
result = Subject.BuildQuery( | ||
new KeyValuePair<string, string>("limit", "10"), | ||
new KeyValuePair<string, string>("status", "approved"), | ||
new KeyValuePair<string, string>("product_id", "eth-usd")); | ||
}; | ||
|
||
It should_have_built_the_correct_query = () => | ||
{ | ||
result.ShouldEqual("?limit=10&status=approved&product_id=eth-usd"); | ||
}; | ||
} | ||
|
||
class when_requesting_with_an_optional_parameter_and_empty_string_is_passed | ||
{ | ||
Because of = () => | ||
{ | ||
result = Subject.BuildQuery( | ||
new KeyValuePair<string, string>("limit", "10"), | ||
new KeyValuePair<string, string>("status", "approved"), | ||
new KeyValuePair<string, string>("product_id", "")); | ||
}; | ||
|
||
It should_have_built_the_correct_query = () => | ||
{ | ||
result.ShouldEqual("?limit=10&status=approved"); | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace GDAXClient.Services.Fundings | ||
{ | ||
public enum FundingStatus | ||
{ | ||
Outstanding, | ||
Settled, | ||
Rejected | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using GDAXClient.HttpClient; | ||
using GDAXClient.Services.Accounts; | ||
using GDAXClient.Services.Fundings.Models; | ||
using GDAXClient.Services.HttpRequest; | ||
using GDAXClient.Utilities; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
namespace GDAXClient.Services.Fundings | ||
{ | ||
public class FundingsService : AbstractService | ||
{ | ||
private readonly IHttpRequestMessageService httpRequestMessageService; | ||
|
||
private readonly IHttpClient httpClient; | ||
|
||
private readonly IAuthenticator authenticator; | ||
|
||
private readonly IQueryBuilder queryBuilder; | ||
|
||
public FundingsService( | ||
IHttpClient httpClient, | ||
IHttpRequestMessageService httpRequestMessageService, | ||
IAuthenticator authenticator, | ||
IQueryBuilder queryBuilder) | ||
: base(httpClient, httpRequestMessageService, authenticator) | ||
{ | ||
this.httpRequestMessageService = httpRequestMessageService; | ||
this.httpClient = httpClient; | ||
this.authenticator = authenticator; | ||
this.queryBuilder = queryBuilder; | ||
} | ||
|
||
public async Task<IList<IList<Funding>>> GetAllFundingsAsync(int limit = 100, FundingStatus? status = null) | ||
{ | ||
var queryString = queryBuilder.BuildQuery( | ||
new KeyValuePair<string, string>("limit", limit.ToString()), | ||
new KeyValuePair<string, string>("status", status?.ToString())); | ||
|
||
var httpResponseMessage = await SendHttpRequestMessagePagedAsync<Funding>(HttpMethod.Get, authenticator, $"/funding" + queryString); | ||
|
||
return httpResponseMessage; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
|
||
namespace GDAXClient.Services.Fundings.Models | ||
{ | ||
public class Funding | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public string Order_id { get; set; } | ||
|
||
public string Profile_id { get; set; } | ||
|
||
public decimal Amount { get; set; } | ||
|
||
public string Status { get; set; } | ||
|
||
public DateTime Created_at { get; set; } | ||
|
||
public string Currency { get; set; } | ||
|
||
public decimal Repaid_amount { get; set; } | ||
|
||
public decimal Default_amount { get; set; } | ||
|
||
public bool Repaid_default { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace GDAXClient.Utilities | ||
{ | ||
public interface IQueryBuilder | ||
{ | ||
string BuildQuery(params KeyValuePair<string, string>[] queryParameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace GDAXClient.Utilities | ||
{ | ||
public class QueryBuilder : IQueryBuilder | ||
{ | ||
public string BuildQuery(params KeyValuePair<string, string>[] queryParameters) | ||
{ | ||
var queryString = new StringBuilder("?"); | ||
|
||
foreach(var queryParameter in queryParameters) | ||
{ | ||
if(queryParameter.Value != string.Empty) | ||
{ | ||
queryString.Append(queryParameter.Key.ToLower() + "=" + queryParameter.Value.ToLower() + "&"); | ||
} | ||
} | ||
|
||
return queryString.ToString().TrimEnd('&'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters