mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-11 16:32:57 +00:00
Examples
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user