Skip to content

Commit

Permalink
Merge pull request #116 from DennisPitallano/feture/#81
Browse files Browse the repository at this point in the history
Add Get BNB Last Price
  • Loading branch information
DennisPitallano authored Mar 4, 2022
2 parents 93c0875 + 51355b3 commit 185149b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/BscScan.NetCore/Constants/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ internal static class GasStatsModuleAction
{
public const string BNB_SUPPLY = "bnbsupply";
public const string VALIDATOR_LIST = "validators";
public const string BNB_PRICE = "bnbprice";
}

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions src/BscScan.NetCore/Contracts/IBscScanStatsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ public interface IBscScanStatsService
/// </summary>
/// <returns>Returns the top 21 validators for the BNB Smart Chain.</returns>
Task<ValidatorsList?> GetValidatorsList();

/// <summary>
/// Get BNB Last Price
/// </summary>
/// <returns>Returns the latest price of 1 BNB.</returns>
Task<BnbLastPrice?> GetBnbLastPrice();
}
46 changes: 46 additions & 0 deletions src/BscScan.NetCore/Models/Response/Stats/BnbLastPrice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Text.Json.Serialization;

namespace BscScan.NetCore.Models.Response.Stats
{
/// <summary>
/// BnbLastPrice
/// </summary>
public class BnbLastPrice : BaseResponse
{
/// <summary>
/// BnbLastPriceData
/// </summary>
[JsonPropertyName("result")]
public BnbLastPriceData? Result { get; set; }
}

/// <summary>
/// BnbLastPriceData
/// </summary>
public class BnbLastPriceData
{
/// <summary>
/// ethbtc
/// </summary>
[JsonPropertyName("ethbtc")]
public string? EthBtc { get; set; }

/// <summary>
/// ethbtc_timestamp
/// </summary>
[JsonPropertyName("ethbtc_timestamp")]
public string? EthBtcTimestamp { get; set; }

/// <summary>
/// ethusd
/// </summary>
[JsonPropertyName("ethusd")]
public string? EthUsd { get; set; }

/// <summary>
/// ethusd_timestamp
/// </summary>
[JsonPropertyName("ethusd_timestamp")]
public string? EthUsdTimestamp { get; set; }
}
}
13 changes: 13 additions & 0 deletions src/BscScan.NetCore/Services/BscScanStatsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,17 @@ public BscScanStatsService(HttpClient bscScanHttpClient, BscScanConfiguration bs
var result = await JsonSerializer.DeserializeAsync<ValidatorsList>(responseStream);
return result;
}

/// <inheritdoc />
public async Task<BnbLastPrice?> GetBnbLastPrice()
{
var queryParameters = $"{_bscScanStatsModule}".AddAction(GasStatsModuleAction.BNB_PRICE);
using var response = await BscScanHttpClient.GetAsync($"{queryParameters}")
.ConfigureAwait(false);

response.EnsureSuccessStatusCode();
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
var result = await JsonSerializer.DeserializeAsync<BnbLastPrice>(responseStream);
return result;
}
}

0 comments on commit 185149b

Please sign in to comment.