Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BL3P.eu: added exchange support #462

Merged
merged 5 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ExchangeSharp.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2027
Expand All @@ -16,6 +16,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt
LICENSE.txt = LICENSE.txt
logo.png = logo.png
README.md = README.md
.gitignore = .gitignore
.editorconfig = .editorconfig
.travis.yml = .travis.yml
azure-pipelines.yml = azure-pipelines.yml
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExchangeSharpTests", "ExchangeSharpTests\ExchangeSharpTests.csproj", "{85BBD19C-5702-4394-BD7C-CE08309F6F49}"
Expand Down
85 changes: 85 additions & 0 deletions ExchangeSharp/API/Exchanges/Bl3p/ExchangeBl3pAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

// ReSharper disable once CheckNamespace
namespace ExchangeSharp
{
// ReSharper disable once InconsistentNaming
public sealed class ExchangeBL3PAPI : ExchangeAPI
{
public override string BaseUrl { get; set; } = "https://api.bl3p.eu/1/";

public ExchangeBL3PAPI()
{
}

public ExchangeBL3PAPI(ref string publicApiKey, ref string privateApiKey)
{
if (publicApiKey == null)
throw new ArgumentNullException(nameof(publicApiKey));
if (privateApiKey == null)
throw new ArgumentNullException(nameof(privateApiKey));

PublicApiKey = publicApiKey.ToSecureString();
publicApiKey = null;
PrivateApiKey = privateApiKey.ToSecureString();
privateApiKey = null;
}

protected override Task<IEnumerable<string>> OnGetMarketSymbolsAsync()
{
return Task.FromResult(new[]
{
// For now we only support these two coins
"BTCEUR",
"LTCEUR"
} as IEnumerable<string>);
}

protected override async Task<ExchangeTicker> OnGetTickerAsync(string marketSymbol)
{
var result = await MakeJsonRequestAsync<JObject>($"/{marketSymbol}/ticker");

return ParseTickerResponse(result, marketSymbol);
}

protected override Task<IEnumerable<KeyValuePair<string, ExchangeTicker>>> OnGetTickersAsync()
{
return Task.WhenAll(
OnGetTickerAsync("BTCEUR"),
OnGetTickerAsync("LTCEUR")
).ContinueWith(
r => r.Result.ToDictionary(t => t.MarketSymbol, t => t).AsEnumerable(),
TaskContinuationOptions.OnlyOnRanToCompletion
);
}

private ExchangeTicker ParseTickerResponse(JObject result, string marketSymbol)
{
if (result == null)
return null;

return new ExchangeTicker
{
Ask = result["ask"].ConvertInvariant<decimal>(),
Bid = result["bid"].ConvertInvariant<decimal>(),
Last = result["last"].ConvertInvariant<decimal>(),
Volume = new ExchangeVolume
{
Timestamp = CryptoUtility.UtcNow,
BaseCurrency = marketSymbol.Substring(0, 3),
BaseCurrencyVolume = result["volume"]["24h"].ConvertInvariant<decimal>()
},
MarketSymbol = marketSymbol
};
}

public partial class ExchangeName
{
public const string Bl3p = "BL3P";
}
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The following cryptocurrency exchanges are supported:
| BitMEX | x | x | R O |
| Bitstamp | x | x | R |
| Bittrex | x | x | T R |
| BL3P | x | | |
| Bleutrade | x | x | |
| Coinbase | x | x | T R |
| Digifinex | x | x | R B |
Expand Down