Skip to content

Commit 82bd416

Browse files
author
iman nemati
committed
Add IExchangeService Map endpoint
1 parent 6b0720c commit 82bd416

File tree

7 files changed

+180
-0
lines changed

7 files changed

+180
-0
lines changed

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[*.cs]
2+
3+
# CS1591: Missing XML comment for publicly visible type or member
4+
dotnet_diagnostic.CS1591.severity = none

CoinMarketCapAPI.sln

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{95D3
1111
EndProject
1212
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Emun.CoinMarketCap.CliSample", "samples\Emun.CoinMarketCap.CliSample\Emun.CoinMarketCap.CliSample.csproj", "{EBB012C0-481A-41E0-A9B8-68E7C03A570D}"
1313
EndProject
14+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{20387BF7-0BC5-45E2-B4CE-416E238C68DA}"
15+
ProjectSection(SolutionItems) = preProject
16+
.editorconfig = .editorconfig
17+
EndProjectSection
18+
EndProject
1419
Global
1520
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1621
Debug|Any CPU = Debug|Any CPU
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using System.Collections.Generic;
5+
using Emun.CoinMarketCap.Models;
6+
7+
namespace Emun.CoinMarketCap
8+
{
9+
/// <summary>
10+
///
11+
/// </summary>
12+
public interface IExchangeService
13+
{
14+
15+
/// <summary>
16+
/// Returns a paginated list of all active cryptocurrency exchanges by CoinMarketCap ID.
17+
/// We recommend using this convenience endpoint to lookup and utilize our unique exchange id across all endpoints
18+
/// as typical exchange identifiers may change over time. As a convenience you may pass a comma-separated list of
19+
/// exchanges by slug to filter this list to only those you require or the aux parameter to slim down the payload.
20+
/// This endpoint is available on the following API plans:
21+
/// [Startup, Standard, Professional, Enterprise]
22+
/// </summary>
23+
/// <param name="request"></param>
24+
/// <param name="cancellationToken"></param>
25+
/// <returns></returns>
26+
Task<ExchangeMapResult> MapAsync(
27+
ExchangeMapQuery request,
28+
CancellationToken cancellationToken);
29+
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Emun.CoinMarketCap.Models;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Net.Http;
5+
using System.Text;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
9+
namespace Emun.CoinMarketCap.Internal {
10+
11+
/// <inheritdoc/>
12+
internal class ExchangeService : CoinMarketCapBaseService, IExchangeService {
13+
14+
public ExchangeService(HttpClient httpClient, string apiKey)
15+
: base(httpClient, apiKey) { }
16+
17+
18+
/// <inheritdoc/>
19+
public async Task<ExchangeMapResult> MapAsync(
20+
ExchangeMapQuery request,
21+
CancellationToken cancellationToken) {
22+
23+
request.CheckArgumentIsNull(nameof(request));
24+
25+
var api_result = await getApiResponseAsync<List<ExchangeMapData>>
26+
(request, "exchange/map", cancellationToken);
27+
28+
return ExchangeMapResult.From(api_result);
29+
}
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Newtonsoft.Json;
5+
6+
namespace Emun.CoinMarketCap.Models
7+
{
8+
public class ExchangeMapData
9+
{
10+
[JsonProperty("id")]
11+
public int Id { get; set; }
12+
13+
[JsonProperty("name")]
14+
public string Name { get; set; }
15+
16+
[JsonProperty("slug")]
17+
public string Slug { get; set; }
18+
19+
[JsonProperty("is_active")]
20+
public bool IsActive { get; set; }
21+
22+
[JsonProperty("status")]
23+
public string Status { get; set; }
24+
25+
[JsonProperty("first_historical_data")]
26+
public DateTimeOffset FirstHistoricalDate { get; set; }
27+
28+
[JsonProperty("last_historical_data")]
29+
public DateTimeOffset LastHistoricalDate { get; set; }
30+
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Newtonsoft.Json;
5+
6+
namespace Emun.CoinMarketCap {
7+
8+
public class ExchangeMapQuery {
9+
10+
/// <summary>
11+
/// Only active exchanges are returned by default. Pass inactive to get a list of exchanges that are no longer active.
12+
/// Pass untracked to get a list of exchanges that are registered but do not currently meet methodology requirements
13+
/// to have active markets tracked. You may pass one or more comma-separated values.
14+
/// default : `active`
15+
/// </summary>
16+
[JsonIgnore]
17+
public ListingStatus ListingStatus { get; set; }
18+
19+
[JsonProperty]
20+
public string listing_status => this.ListingStatus.ToStrValue();
21+
22+
/// <summary>
23+
/// Optionally pass a comma-separated list of exchange slugs (lowercase URL friendly shorthand name with spaces replaced with dashes)
24+
/// to return CoinMarketCap IDs for. If this option is passed, other options will be ignored.
25+
/// </summary>
26+
public string Slug { get; set; }
27+
28+
/// <summary>
29+
/// Optionally offset the start (1-based index) of the paginated list of items to return.
30+
/// </summary>
31+
public int Start { get; set; } = 1;
32+
33+
/// <summary>
34+
/// Optionally specify the number of results to return. Use this parameter and the "start" parameter to determine your own pagination size.
35+
/// </summary>
36+
public int Limit { get; set; }
37+
38+
/// <summary>
39+
/// What field to sort the list of exchanges by.
40+
/// Valid values : "volume_24h", "id"
41+
/// </summary>
42+
[JsonProperty("sort")]
43+
public string Sort { get; set; } = "id";
44+
45+
/// <summary>
46+
/// Default : "first_historical_data,last_historical_data,is_active"
47+
/// Optionally specify a comma-separated list of supplemental data fields to return.
48+
/// Pass first_historical_data, last_historical_data, is_active, status to include all auxiliary fields.
49+
/// </summary>
50+
[JsonProperty("aux")]
51+
public string Aux { get; set; }
52+
53+
/// <summary>
54+
/// Optionally include one fiat or cryptocurrency IDs to filter market pairs by.
55+
/// For example ?crypto_id=1 would only return exchanges that have BTC.
56+
/// </summary>
57+
public string CryptoId { get; set; }
58+
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Emun.CoinMarketCap.Models;
5+
6+
namespace Emun.CoinMarketCap {
7+
8+
public class ExchangeMapResult : ApiResponse<List<ExchangeMapData>> {
9+
10+
public static ExchangeMapResult From(ApiResponse<List<ExchangeMapData>> model)
11+
=> new ExchangeMapResult {
12+
Data = model.Data,
13+
Status = model.Status
14+
};
15+
16+
}
17+
}

0 commit comments

Comments
 (0)