-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
238 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<InvariantGlobalization>true</InvariantGlobalization> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CoinEx.Net" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\CoinEx.Net\CoinEx.Net.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
Examples/CoinEx.Examples.OrderBook/CoinEx.Examples.OrderBook.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\CoinEx.Net\CoinEx.Net.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using CoinEx.Net.Interfaces; | ||
using CryptoExchange.Net; | ||
using CryptoExchange.Net.SharedApis; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Spectre.Console; | ||
|
||
var collection = new ServiceCollection(); | ||
collection.AddCoinEx(); | ||
var provider = collection.BuildServiceProvider(); | ||
|
||
var bookFactory = provider.GetRequiredService<ICoinExOrderBookFactory>(); | ||
|
||
// Create and start the order book | ||
var book = bookFactory.Create(new SharedSymbol(TradingMode.Spot, "ETH", "USDT")); | ||
var result = await book.StartAsync(); | ||
if (!result.Success) | ||
{ | ||
Console.WriteLine(result); | ||
return; | ||
} | ||
|
||
// Create Spectre table | ||
var table = new Table(); | ||
table.ShowRowSeparators = true; | ||
table.AddColumn("Bid Quantity", x => { x.RightAligned(); }) | ||
.AddColumn("Bid Price", x => { x.RightAligned(); }) | ||
.AddColumn("Ask Price", x => { x.LeftAligned(); }) | ||
.AddColumn("Ask Quantity", x => { x.LeftAligned(); }); | ||
|
||
for(var i = 0; i < 10; i++) | ||
table.AddEmptyRow(); | ||
|
||
await AnsiConsole.Live(table) | ||
.StartAsync(async ctx => | ||
{ | ||
while (true) | ||
{ | ||
var snapshot = book.Book; | ||
for (var i = 0; i < 10; i++) | ||
{ | ||
var bid = snapshot.bids.ElementAt(i); | ||
var ask = snapshot.asks.ElementAt(i); | ||
table.UpdateCell(i, 0, ExchangeHelpers.Normalize(bid.Quantity).ToString()); | ||
table.UpdateCell(i, 1, ExchangeHelpers.Normalize(bid.Price).ToString()); | ||
table.UpdateCell(i, 2, ExchangeHelpers.Normalize(ask.Price).ToString()); | ||
table.UpdateCell(i, 3, ExchangeHelpers.Normalize(ask.Quantity).ToString()); | ||
} | ||
ctx.Refresh(); | ||
await Task.Delay(500); | ||
} | ||
}); |
18 changes: 18 additions & 0 deletions
18
Examples/CoinEx.Examples.Tracker/CoinEx.Examples.Tracker.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\CoinEx.Net\CoinEx.Net.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using CoinEx.Net.Interfaces; | ||
using CryptoExchange.Net.Objects; | ||
using CryptoExchange.Net.SharedApis; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Spectre.Console; | ||
using System.Globalization; | ||
|
||
var collection = new ServiceCollection(); | ||
collection.AddCoinEx(); | ||
collection.AddLogging(x => | ||
{ | ||
x.SetMinimumLevel(LogLevel.Trace); | ||
x.AddProvider(new TraceLoggerProvider()); | ||
}); | ||
var provider = collection.BuildServiceProvider(); | ||
|
||
var trackerFactory = provider.GetRequiredService<ICoinExTrackerFactory>(); | ||
|
||
// Create and start the tracker, keep track of the last 10 minutes | ||
var tracker = trackerFactory.CreateTradeTracker(new SharedSymbol(TradingMode.Spot, "ETH", "USDT"), period: TimeSpan.FromMinutes(10)); | ||
var result = await tracker.StartAsync(); | ||
if (!result.Success) | ||
{ | ||
Console.WriteLine(result); | ||
return; | ||
} | ||
|
||
// Create Spectre table | ||
var table = new Table(); | ||
table.ShowRowSeparators = true; | ||
table.AddColumn("5 Min Data").AddColumn("-5 Min", x => { x.RightAligned(); }) | ||
.AddColumn("Now", x => { x.RightAligned(); }) | ||
.AddColumn("Dif", x => { x.RightAligned(); }); | ||
|
||
table.AddRow("Count", "", "", ""); | ||
table.AddRow("Average price", "", "", ""); | ||
table.AddRow("Average weighted price", "", "", ""); | ||
table.AddRow("Buy/Sell Ratio", "", "", ""); | ||
table.AddRow("Volume", "", "", ""); | ||
table.AddRow("Value", "", "", ""); | ||
table.AddRow("Complete", "", "", ""); | ||
table.AddRow("", "", "", ""); | ||
table.AddRow("Status", "", "", ""); | ||
table.AddRow("Synced From", "", "", ""); | ||
|
||
// Set default culture for currency display | ||
CultureInfo ci = new CultureInfo("en-US"); | ||
Thread.CurrentThread.CurrentCulture = ci; | ||
Thread.CurrentThread.CurrentUICulture = ci; | ||
|
||
await AnsiConsole.Live(table) | ||
.StartAsync(async ctx => | ||
{ | ||
while (true) | ||
{ | ||
// Get the stats from 10 minutes until 5 minutes ago | ||
var secondLastMinute = tracker.GetStats(DateTime.UtcNow.AddMinutes(-10), DateTime.UtcNow.AddMinutes(-5)); | ||
// Get the stats from 5 minutes ago until now | ||
var lastMinute = tracker.GetStats(DateTime.UtcNow.AddMinutes(-5)); | ||
// Get the differences between them | ||
var compare = secondLastMinute.CompareTo(lastMinute); | ||
// Update the columns | ||
UpdateDec(0, 1, secondLastMinute.TradeCount); | ||
UpdateDec(0, 2, lastMinute.TradeCount); | ||
UpdateStr(0, 3, $"[{(compare.TradeCountDif.Difference < 0 ? "red" : "green")}]{compare.TradeCountDif.Difference} / {compare.TradeCountDif.PercentageDifference}%[/]"); | ||
UpdateStr(1, 1, secondLastMinute.AveragePrice?.ToString("C")); | ||
UpdateStr(1, 2, lastMinute.AveragePrice?.ToString("C")); | ||
UpdateStr(1, 3, $"[{(compare.AveragePriceDif?.Difference < 0 ? "red" : "green")}]{compare.AveragePriceDif?.Difference?.ToString("C")} / {compare.AveragePriceDif?.PercentageDifference}%[/]"); | ||
UpdateStr(2, 1, secondLastMinute.VolumeWeightedAveragePrice?.ToString("C")); | ||
UpdateStr(2, 2, lastMinute.VolumeWeightedAveragePrice?.ToString("C")); | ||
UpdateStr(2, 3, $"[{(compare.VolumeWeightedAveragePriceDif?.Difference < 0 ? "red" : "green")}]{compare.VolumeWeightedAveragePriceDif?.Difference?.ToString("C")} / {compare.VolumeWeightedAveragePriceDif?.PercentageDifference}%[/]"); | ||
UpdateDec(3, 1, secondLastMinute.BuySellRatio); | ||
UpdateDec(3, 2, lastMinute.BuySellRatio); | ||
UpdateStr(3, 3, $"[{(compare.BuySellRatioDif?.Difference < 0 ? "red" : "green")}]{compare.BuySellRatioDif?.Difference} / {compare.BuySellRatioDif?.PercentageDifference}%[/]"); | ||
UpdateDec(4, 1, secondLastMinute.Volume); | ||
UpdateDec(4, 2, lastMinute.Volume); | ||
UpdateStr(4, 3, $"[{(compare.VolumeDif.Difference < 0 ? "red" : "green")}]{compare.VolumeDif.Difference} / {compare.VolumeDif.PercentageDifference}%[/]"); | ||
UpdateStr(5, 1, secondLastMinute.QuoteVolume.ToString("C")); | ||
UpdateStr(5, 2, lastMinute.QuoteVolume.ToString("C")); | ||
UpdateStr(5, 3, $"[{(compare.QuoteVolumeDif.Difference < 0 ? "red" : "green")}]{compare.QuoteVolumeDif.Difference?.ToString("C")} / {compare.QuoteVolumeDif.PercentageDifference}%[/]"); | ||
UpdateStr(6, 1, secondLastMinute.Complete.ToString()); | ||
UpdateStr(6, 2, lastMinute.Complete.ToString()); | ||
UpdateStr(8, 1, tracker.Status.ToString()); | ||
UpdateStr(9, 1, tracker.SyncedFrom?.ToString()); | ||
ctx.Refresh(); | ||
await Task.Delay(500); | ||
} | ||
}); | ||
|
||
|
||
void UpdateDec(int row, int col, decimal? val) | ||
{ | ||
table.UpdateCell(row, col, val?.ToString() ?? string.Empty); | ||
} | ||
|
||
void UpdateStr(int row, int col, string? val) | ||
{ | ||
table.UpdateCell(row, col, val ?? string.Empty); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters