1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-11 16:32:57 +00:00
This commit is contained in:
Jkorf
2022-01-19 16:35:08 +01:00
parent 7427914cb7
commit fe31cf156d
10 changed files with 147 additions and 28 deletions
+10 -10
View File
@@ -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>
+13 -11
View File
@@ -17,19 +17,21 @@
@implements IDisposable
<h3>ETH-BTC books, live updates:</h3>
@foreach(var book in _books.OrderBy(p => p.Key))
{
<div style="margin-bottom: 20px;">
<h4>@book.Key</h4>
@if (book.Value.AskCount >= 3 && book.Value.BidCount >= 3)
{
for (var i = 0; i < 3; i++)
<div style="display:flex; flex-wrap: wrap;">
@foreach(var book in _books.OrderBy(p => p.Key))
{
<div style="margin-bottom: 20px; flex: 1; min-width: 300px;">
<h4>@book.Key</h4>
@if (book.Value.AskCount >= 3 && book.Value.BidCount >= 3)
{
<div>@book.Value.Bids.ElementAt(i).Price - @book.Value.Asks.ElementAt(i).Price</div>
for (var i = 0; i < 3; i++)
{
<div>@book.Value.Bids.ElementAt(i).Price - @book.Value.Asks.ElementAt(i).Price</div>
}
}
}
</div>
}
</div>
}
</div>
@code{
private Dictionary<string, ISymbolOrderBook> _books = new Dictionary<string, ISymbolOrderBook>();
+2 -2
View File
@@ -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"))));
@@ -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>
@@ -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;
}
}
}
@@ -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
View 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}");
}
}
}