mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-08 00:16:27 +00:00
Examples
This commit is contained in:
parent
7427914cb7
commit
fe31cf156d
@ -9,7 +9,7 @@
|
||||
<packagereference Include="Microsoft.NET.Test.Sdk" Version="17.1.0-preview-20211130-02"></packagereference>
|
||||
<PackageReference Include="Moq" Version="4.16.1" />
|
||||
<packagereference Include="NUnit" Version="3.13.2"></packagereference>
|
||||
<packagereference Include="NUnit3TestAdapter" Version="4.2.0-beta.4"></packagereference>
|
||||
<packagereference Include="NUnit3TestAdapter" Version="4.2.0"></packagereference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -7,7 +7,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CryptoExchange.Net", "Crypt
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CryptoExchange.Net.UnitTests", "CryptoExchange.Net.UnitTests\CryptoExchange.Net.UnitTests.csproj", "{FBFE1651-D43D-4D67-89B7-6C4AE9BA4496}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorClient", "Examples\BlazorClient\BlazorClient.csproj", "{AF4F5C19-162E-48F4-8B0B-BA5A2D7CE06A}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorClient", "Examples\BlazorClient\BlazorClient.csproj", "{AF4F5C19-162E-48F4-8B0B-BA5A2D7CE06A}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{5734C2A9-F12C-4754-A8B9-640C24DC4E02}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleClient", "Examples\ConsoleClient\ConsoleClient.csproj", "{23480C58-23BF-4EBF-A173-B7F51A043A99}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -27,10 +31,18 @@ Global
|
||||
{AF4F5C19-162E-48F4-8B0B-BA5A2D7CE06A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AF4F5C19-162E-48F4-8B0B-BA5A2D7CE06A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AF4F5C19-162E-48F4-8B0B-BA5A2D7CE06A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{23480C58-23BF-4EBF-A173-B7F51A043A99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{23480C58-23BF-4EBF-A173-B7F51A043A99}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{23480C58-23BF-4EBF-A173-B7F51A043A99}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{23480C58-23BF-4EBF-A173-B7F51A043A99}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{AF4F5C19-162E-48F4-8B0B-BA5A2D7CE06A} = {5734C2A9-F12C-4754-A8B9-640C24DC4E02}
|
||||
{23480C58-23BF-4EBF-A173-B7F51A043A99} = {5734C2A9-F12C-4754-A8B9-640C24DC4E02}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {0D1B9CE9-E0B7-4B8B-88BF-6EA2CC8CA3D7}
|
||||
EndGlobalSection
|
||||
|
@ -45,10 +45,10 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="[3.1.0,)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="[3.1.0,)" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -5,16 +5,16 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Binance.Net" Version="8.0.0-alpha5" />
|
||||
<PackageReference Include="Bitfinex.Net" Version="5.0.0-alpha5" />
|
||||
<PackageReference Include="Bittrex.Net" Version="7.0.0-alpha5" />
|
||||
<PackageReference Include="Bybit.Net" Version="0.0.1-alpha5" />
|
||||
<PackageReference Include="CoinEx.Net" Version="5.0.0-alpha5" />
|
||||
<PackageReference Include="FTX.Net" Version="1.0.0-alpha5" />
|
||||
<PackageReference Include="Huobi.Net" Version="4.0.0-alpha6" />
|
||||
<PackageReference Include="KrakenExchange.Net" Version="3.0.0-alpha5" />
|
||||
<PackageReference Include="Kucoin.Net" Version="4.0.0-alpha5" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="4.1.1-dev-00241" />
|
||||
<PackageReference Include="Binance.Net" Version="8.0.0-beta1" />
|
||||
<PackageReference Include="Bitfinex.Net" Version="5.0.0-beta1" />
|
||||
<PackageReference Include="Bittrex.Net" Version="7.0.0-beta1" />
|
||||
<PackageReference Include="Bybit.Net" Version="0.0.1-beta2" />
|
||||
<PackageReference Include="CoinEx.Net" Version="5.0.0-beta1" />
|
||||
<PackageReference Include="FTX.Net" Version="1.0.0-beta1" />
|
||||
<PackageReference Include="Huobi.Net" Version="4.0.0-beta1" />
|
||||
<PackageReference Include="KrakenExchange.Net" Version="3.0.0-beta1" />
|
||||
<PackageReference Include="Kucoin.Net" Version="4.0.0-beta3" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="4.1.1-dev-00250" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -17,9 +17,10 @@
|
||||
@implements IDisposable
|
||||
|
||||
<h3>ETH-BTC books, live updates:</h3>
|
||||
<div style="display:flex; flex-wrap: wrap;">
|
||||
@foreach(var book in _books.OrderBy(p => p.Key))
|
||||
{
|
||||
<div style="margin-bottom: 20px;">
|
||||
<div style="margin-bottom: 20px; flex: 1; min-width: 300px;">
|
||||
<h4>@book.Key</h4>
|
||||
@if (book.Value.AskCount >= 3 && book.Value.BidCount >= 3)
|
||||
{
|
||||
@ -30,6 +31,7 @@
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code{
|
||||
private Dictionary<string, ISymbolOrderBook> _books = new Dictionary<string, ISymbolOrderBook>();
|
||||
|
@ -36,12 +36,12 @@
|
||||
binanceClient.SpotApi.ComonSpotClient,
|
||||
bitfinexClient.SpotApi.ComonSpotClient,
|
||||
bittrexClient.SpotApi.ComonSpotClient,
|
||||
bybitClient.SpotApi.ComonSpotClient,
|
||||
bybitClient.SpotApi.CommonSpotClient,
|
||||
coinexClient.SpotApi.ComonSpotClient,
|
||||
ftxClient.TradeApi.ComonSpotClient,
|
||||
huobiClient.SpotApi.ComonSpotClient,
|
||||
krakenClient.SpotApi.ComonSpotClient,
|
||||
kucoinClient.SpotApi.ComonSpotClient
|
||||
kucoinClient.SpotApi.CommonSpotClient
|
||||
};
|
||||
|
||||
var tasks = clients.Select(c => (c.ExchangeName, c.GetTickerAsync(c.GetSymbolName("ETH", "BTC"))));
|
||||
|
20
Examples/ConsoleClient/ConsoleClient.csproj
Normal file
20
Examples/ConsoleClient/ConsoleClient.csproj
Normal file
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Binance.Net" Version="8.0.0-beta1" />
|
||||
<PackageReference Include="Bitfinex.Net" Version="5.0.0-beta1" />
|
||||
<PackageReference Include="Bittrex.Net" Version="7.0.0-beta1" />
|
||||
<PackageReference Include="Bybit.Net" Version="0.0.1-beta2" />
|
||||
<PackageReference Include="CoinEx.Net" Version="5.0.0-beta1" />
|
||||
<PackageReference Include="FTX.Net" Version="1.0.0-beta1" />
|
||||
<PackageReference Include="Huobi.Net" Version="4.0.0-beta1" />
|
||||
<PackageReference Include="KrakenExchange.Net" Version="3.0.0-beta1" />
|
||||
<PackageReference Include="Kucoin.Net" Version="4.0.0-beta3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
20
Examples/ConsoleClient/Exchanges/BinanceExchange.cs
Normal file
20
Examples/ConsoleClient/Exchanges/BinanceExchange.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Binance.Net.Clients;
|
||||
|
||||
namespace ConsoleClient.Exchanges
|
||||
{
|
||||
internal class BinanceExchange : IExchange
|
||||
{
|
||||
public async Task<decimal> GetPrice(string symbol)
|
||||
{
|
||||
using var client = new BinanceClient();
|
||||
var result = await client.SpotApi.ExchangeData.GetPriceAsync(symbol);
|
||||
// Should check result success status here
|
||||
return result.Data.Price;
|
||||
}
|
||||
}
|
||||
}
|
13
Examples/ConsoleClient/Exchanges/IExchange.cs
Normal file
13
Examples/ConsoleClient/Exchanges/IExchange.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConsoleClient.Exchanges
|
||||
{
|
||||
public interface IExchange
|
||||
{
|
||||
Task<decimal> GetPrice(string symbol);
|
||||
}
|
||||
}
|
52
Examples/ConsoleClient/Program.cs
Normal file
52
Examples/ConsoleClient/Program.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using ConsoleClient.Exchanges;
|
||||
|
||||
namespace ConsoleClient
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static Dictionary<string, IExchange> _exchanges = new Dictionary<string, IExchange>
|
||||
{
|
||||
{ "Binance", new BinanceExchange() }
|
||||
};
|
||||
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("> Available commands: PlaceOrder, GetOrders, GetPrice");
|
||||
while (true)
|
||||
{
|
||||
var input = Console.ReadLine();
|
||||
|
||||
switch (input)
|
||||
{
|
||||
case "PlaceOrder":
|
||||
|
||||
break;
|
||||
case "GetOrders":
|
||||
|
||||
break;
|
||||
case "GetPrice":
|
||||
await ProcessGetPrice();
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("> Unknown command");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static async Task ProcessGetPrice()
|
||||
{
|
||||
Console.WriteLine("> Exchange?");
|
||||
var exchange = Console.ReadLine();
|
||||
|
||||
Console.WriteLine("> Symbol?");
|
||||
var symbol = Console.ReadLine();
|
||||
|
||||
var price = await _exchanges[exchange].GetPrice(symbol);
|
||||
Console.WriteLine($"> {exchange} price for {symbol}: {price}");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user