mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-11 16:32:57 +00:00
Squashed commit of the following:
commit9450d447b9Author: Jkorf <jankorf91@gmail.com> Date: Fri Feb 18 11:05:46 2022 +0100 Updated version commitbc0b55f337Author: Jkorf <jankorf91@gmail.com> Date: Fri Feb 18 10:09:26 2022 +0100 Added clientOrderId parameter to common clients commit31111006c7Author: Jkorf <jankorf91@gmail.com> Date: Thu Feb 17 16:32:53 2022 +0100 Update SpotClient.razor commite7400ce334Author: Jkorf <jankorf91@gmail.com> Date: Thu Feb 17 16:10:49 2022 +0100 Made some names more generic commit9bdef400daAuthor: Jkorf <jankorf91@gmail.com> Date: Tue Feb 15 11:38:41 2022 +0100 Updated vesrion commit3b80a945eeAuthor: Jkorf <jankorf91@gmail.com> Date: Tue Feb 15 11:34:50 2022 +0100 docs commit0268e211e9Author: Jkorf <jankorf91@gmail.com> Date: Tue Feb 15 09:56:45 2022 +0100 Immediate initial reconnect attempt when connection is lost commit6eb43c5218Author: Jkorf <jankorf91@gmail.com> Date: Fri Feb 11 13:59:05 2022 +0100 Re-added recalculation interval commit1df63ab60cAuthor: Jkorf <jankorf91@gmail.com> Date: Wed Feb 9 14:32:00 2022 +0100 Updated version commit9461b57daaAuthor: Jkorf <jankorf91@gmail.com> Date: Wed Feb 9 13:37:12 2022 +0100 Fix for time offset calculation not updating when offset is < 500ms commit105547d6b1Author: Jan Korf <jankorf91@gmail.com> Date: Sat Feb 5 21:05:10 2022 +0100 Updated version commit379ded6832Author: Jan Korf <jankorf91@gmail.com> Date: Sat Feb 5 20:29:57 2022 +0100 Fixed tests commitb18204a52dAuthor: Jan Korf <jankorf91@gmail.com> Date: Sat Feb 5 20:28:08 2022 +0100 Added CancellationToken support on Common client interface and SymbolOrderBook, improved SymbolOrderBook start/stop robustness commitbaa23c2eccAuthor: Jan Korf <jankorf91@gmail.com> Date: Sat Feb 5 14:56:32 2022 +0100 Added GetSubscriptionByRequest method on socket connection commit7aad9482a5Author: Jkorf <jankorf91@gmail.com> Date: Wed Feb 2 10:57:06 2022 +0100 Updated version commit6e4d9d225eAuthor: Jkorf <jankorf91@gmail.com> Date: Wed Feb 2 09:42:22 2022 +0100 Fixed exception when deserializing non-nullable datetime value '0' in .net framework commitfd1a2bbda9Author: Jkorf <jankorf91@gmail.com> Date: Tue Jan 25 13:19:10 2022 +0100 Updated version commit2ece04dd58Author: Jkorf <jankorf91@gmail.com> Date: Tue Jan 25 13:17:25 2022 +0100 Refactored use of AutoResetEvent to AsyncResetEvent in SymbolOrderBook commit893d0c723dAuthor: Jkorf <jankorf91@gmail.com> Date: Tue Jan 25 13:01:21 2022 +0100 Fixed DateTime converter for nanosecond times in string format commit2c43ee7554Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 24 15:56:24 2022 +0100 Updated version version; fixed dependencies commit100a34d1a0Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 24 14:37:15 2022 +0100 Updated version commitbb1071472fAuthor: Jkorf <jankorf91@gmail.com> Date: Mon Jan 24 14:31:57 2022 +0100 Re-added Common prefix for common enums to avoid conflicts with library namespaces commit37b1d18104Author: Jkorf <jankorf91@gmail.com> Date: Fri Jan 21 15:25:33 2022 +0100 Updated version commit325389cdf8Author: Jan Korf <jankorf91@gmail.com> Date: Thu Jan 20 21:08:51 2022 +0100 Added FTX to console example commit3e23882572Author: Jkorf <jankorf91@gmail.com> Date: Thu Jan 20 16:21:42 2022 +0100 Replaced Debug.WriteLine with Trace.WriteLine commit3cf5480cadAuthor: Jan Korf <jankorf91@gmail.com> Date: Wed Jan 19 22:07:22 2022 +0100 Example commitfe31cf156dAuthor: Jkorf <jankorf91@gmail.com> Date: Wed Jan 19 16:35:08 2022 +0100 Examples commit7427914cb7Author: Jkorf <jankorf91@gmail.com> Date: Tue Jan 18 16:46:43 2022 +0100 Update index.md commit1bc6225814Author: Jkorf <jankorf91@gmail.com> Date: Tue Jan 18 16:45:10 2022 +0100 docs commit259fe6bfd1Author: Jkorf <jankorf91@gmail.com> Date: Tue Jan 18 14:25:20 2022 +0100 Update index.md commit5f9c075ac7Author: Jkorf <jankorf91@gmail.com> Date: Tue Jan 18 14:22:33 2022 +0100 Update index.md commita26514016aAuthor: Jkorf <jankorf91@gmail.com> Date: Tue Jan 18 14:13:35 2022 +0100 Update index.md commit01a97412bfAuthor: Jkorf <jankorf91@gmail.com> Date: Tue Jan 18 14:12:02 2022 +0100 docs commit24b503ca8cAuthor: Jkorf <jankorf91@gmail.com> Date: Tue Jan 18 13:42:12 2022 +0100 docs commit008b15b055Author: Jkorf <jankorf91@gmail.com> Date: Tue Jan 18 13:32:55 2022 +0100 docs commit66fce6cb84Author: Jan Korf <jankorf91@gmail.com> Date: Mon Jan 17 21:31:53 2022 +0100 docs commit0f65701f90Author: Jan Korf <jankorf91@gmail.com> Date: Mon Jan 17 21:25:33 2022 +0100 docs commitf7a405a2e6Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 17 16:32:50 2022 +0100 docs commit55284c0549Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 17 15:51:03 2022 +0100 docs commit5bfbcca25bAuthor: Jkorf <jankorf91@gmail.com> Date: Mon Jan 17 14:04:08 2022 +0100 docs commitcdbc0ba215Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 17 13:58:51 2022 +0100 docs commite33e7c6775Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 17 13:47:58 2022 +0100 docs commitb65669659dAuthor: Jkorf <jankorf91@gmail.com> Date: Mon Jan 17 13:44:45 2022 +0100 docs commite51b863242Merge:dbfe34f088f35dAuthor: Jkorf <jankorf91@gmail.com> Date: Mon Jan 17 13:36:51 2022 +0100 Merge branch 'feature/new-cc' of https://github.com/JKorf/CryptoExchange.Net into feature/new-cc commitdbfe34f534Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 17 13:35:46 2022 +0100 Docs commit088f35d420Author: Jan Korf <jankorf91@gmail.com> Date: Mon Jan 17 13:34:40 2022 +0100 Set theme jekyll-theme-cayman commite77add4d1cAuthor: Jan Korf <jankorf91@gmail.com> Date: Sat Jan 15 15:26:38 2022 +0100 Updated version commita37a2d6e31Author: Jan Korf <jankorf91@gmail.com> Date: Sat Jan 15 15:23:52 2022 +0100 Added CallResult tests, fixed response time not set commit8f6e853e13Author: Jkorf <jankorf91@gmail.com> Date: Fri Jan 14 16:47:49 2022 +0100 Added Request info and ResponseTime to WebCallResult, refactored CallResult ctors commitc6bf0d67a4Author: Jkorf <jankorf91@gmail.com> Date: Fri Jan 7 16:30:02 2022 +0100 Fix typo commit996f3c2cedAuthor: Jkorf <jankorf91@gmail.com> Date: Fri Jan 7 16:23:42 2022 +0100 Some options logging commitfb9e9f9aa6Author: Jkorf <jankorf91@gmail.com> Date: Fri Jan 7 15:10:27 2022 +0100 Updated version commit52ebacaa21Author: Jkorf <jankorf91@gmail.com> Date: Fri Jan 7 15:05:51 2022 +0100 Fixed symbol order book tostring not locking thread, Potential fix for request timeout showing unclear message commit6b45859934Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 3 14:08:35 2022 +0100 Updated example commitebe332b724Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 3 12:05:47 2022 +0100 Updated version commit8c24b46fb3Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 3 11:33:07 2022 +0100 Fixed typo Comon -> Common commit7a195f662cAuthor: Jkorf <jankorf91@gmail.com> Date: Mon Jan 3 09:37:50 2022 +0100 Updated example, removed global.json commit120132c45bAuthor: Jan Korf <jankorf91@gmail.com> Date: Sat Jan 1 20:30:35 2022 +0100 Reverted conditional refs commitb3b4ed3f3fAuthor: Jan Korf <jankorf91@gmail.com> Date: Sat Jan 1 19:45:59 2022 +0100 Updated version commitf4b4c93e64Author: Jan Korf <jankorf91@gmail.com> Date: Sat Jan 1 19:40:50 2022 +0100 Added new shared interface implementation commitf8c3b37cdfAuthor: Jan Korf <jankorf91@gmail.com> Date: Tue Dec 28 14:14:15 2021 +0100 wip example commit0117737dfaAuthor: Jan Korf <jankorf91@gmail.com> Date: Tue Dec 28 14:13:14 2021 +0100 Added conditional refs for Microsoft.Extensions, added DependencyInjection.Abstractions to support extension method on IServiceCollection commit02c1f874e1Author: Jan Korf <jankorf91@gmail.com> Date: Mon Dec 27 15:32:07 2021 +0100 Updated version commitb212842ec8Author: Jan Korf <jankorf91@gmail.com> Date: Mon Dec 27 15:27:14 2021 +0100 Added ExchangeName to IExchangeClient interface commitc96e75d6c3Author: Jkorf <jankorf91@gmail.com> Date: Tue Dec 21 16:22:51 2021 +0100 Updated version commitc62fbda3d7Author: Jkorf <jankorf91@gmail.com> Date: Fri Dec 17 14:17:30 2021 +0100 Added ApiClients list for managing api credentials, requests made and dispose commit04b43257a5Author: Jkorf <jankorf91@gmail.com> Date: Thu Dec 16 16:17:26 2021 +0100 Update .gitignore commit8ba0ded16dAuthor: Jkorf <jankorf91@gmail.com> Date: Mon Dec 13 12:57:31 2021 +0100 Fixed api credentials getting disposed, fixed DateTimeConverter losing precision commit5c665ad54cAuthor: Jkorf <jankorf91@gmail.com> Date: Fri Dec 10 16:35:42 2021 +0100 Refactoring and comments commitb7cd6a866aAuthor: Jan Korf <jankorf91@gmail.com> Date: Wed Dec 8 21:49:25 2021 +0100 Auth work commitc2105fe690Author: Jkorf <jankorf91@gmail.com> Date: Wed Dec 8 16:20:44 2021 +0100 Wip, support for time syncing, refactoring authentication commit8b479547abAuthor: Jkorf <jankorf91@gmail.com> Date: Tue Dec 7 15:47:55 2021 +0100 Fixed release name commit2ab032b871Author: Jkorf <jankorf91@gmail.com> Date: Tue Dec 7 15:47:14 2021 +0100 Updated version commit48baaeb2d8Author: Jkorf <jankorf91@gmail.com> Date: Mon Dec 6 16:18:18 2021 +0100 Added periodic identifier commit60ec18919aAuthor: Jan Korf <jankorf91@gmail.com> Date: Sun Dec 5 17:26:55 2021 +0100 Added quotes to log commit0818c6277bAuthor: Jkorf <jankorf91@gmail.com> Date: Fri Dec 3 16:23:05 2021 +0100 Small changes commit6d0120d564Author: Jkorf <jankorf91@gmail.com> Date: Wed Dec 1 16:26:34 2021 +0100 Comments, fix test commit3c3b5639f5Author: Jkorf <jankorf91@gmail.com> Date: Wed Dec 1 13:31:54 2021 +0100 Refactor clients/options commit49de7e89ccAuthor: Jkorf <jankorf91@gmail.com> Date: Tue Nov 30 10:31:45 2021 +0100 Disposable changes, fixed tests commit69a6fabb79Author: Jkorf <jankorf91@gmail.com> Date: Mon Nov 29 16:43:27 2021 +0100 Restruct commit9a266e44ceAuthor: Jkorf <jankorf91@gmail.com> Date: Fri Nov 26 09:32:26 2021 +0100 Added enum converter commit78f81393a4Author: Jkorf <jankorf91@gmail.com> Date: Thu Nov 25 10:25:56 2021 +0100 Removed old timestamp converters commit9ebe5de825Author: Jan Korf <jankorf91@gmail.com> Date: Wed Nov 24 19:32:37 2021 +0100 Added AppendPath method commit8b619e82f2Author: Jkorf <jankorf91@gmail.com> Date: Wed Nov 24 16:39:14 2021 +0100 Added DateTimeConverter as replacement for individual converters, fix for not closing socket when auth fails commit7ac7a11dfeAuthor: Jkorf <jankorf91@gmail.com> Date: Wed Nov 17 10:23:01 2021 +0100 Resolved some code issues commit3784b0c62bAuthor: Jkorf <jankorf91@gmail.com> Date: Mon Nov 15 16:36:30 2021 +0100 Ratelimiter rework commitcb1826da7aAuthor: Jkorf <jankorf91@gmail.com> Date: Fri Nov 12 09:40:42 2021 +0100 Documentation commitf7445543f2Author: Jkorf <jankorf91@gmail.com> Date: Wed Nov 10 16:44:46 2021 +0100 Exposed order book id commit6c3462403fAuthor: Jkorf <jankorf91@gmail.com> Date: Wed Nov 10 13:18:52 2021 +0100 Fixed tests commitf83127590aAuthor: Jkorf <jankorf91@gmail.com> Date: Wed Nov 3 08:27:03 2021 +0100 wip commit23bbf0ef88Author: Jkorf <jankorf91@gmail.com> Date: Wed Oct 27 12:57:23 2021 +0200 Added cancellation token support for socket subscriptions commitb7f1619aecMerge:6ce6a46f6af235Author: Jkorf <jankorf91@gmail.com> Date: Tue Oct 26 15:39:52 2021 +0200 Merge branch 'master' of https://github.com/JKorf/CryptoExchange.Net commit6ce6a46ca3Author: Jkorf <jankorf91@gmail.com> Date: Tue Oct 26 15:39:50 2021 +0200 Some renames
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Binance.Net.Clients;
|
||||
using Binance.Net.Objects;
|
||||
using ConsoleClient.Exchanges;
|
||||
using CryptoExchange.Net.Authentication;
|
||||
using CryptoExchange.Net.Sockets;
|
||||
using FTX.Net.Clients;
|
||||
using FTX.Net.Objects;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ConsoleClient
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static Dictionary<string, IExchange> _exchanges = new Dictionary<string, IExchange>
|
||||
{
|
||||
{ "Binance", new BinanceExchange() },
|
||||
{ "FTX", new FTXExchange() }
|
||||
};
|
||||
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
BinanceClient.SetDefaultOptions(new BinanceClientOptions
|
||||
{
|
||||
LogLevel = LogLevel.Trace,
|
||||
ApiCredentials = new ApiCredentials("APIKEY", "APISECRET")
|
||||
});
|
||||
FTXClient.SetDefaultOptions(new FTXClientOptions
|
||||
{
|
||||
LogLevel = LogLevel.Trace,
|
||||
ApiCredentials = new ApiCredentials("APIKEY", "APISECRET")
|
||||
});
|
||||
|
||||
while (true)
|
||||
{
|
||||
Console.WriteLine("> Available commands: PlaceOrder, GetBalances, GetOpenOrders, CancelOrder, GetPrice, SubscribePrice");
|
||||
var input = Console.ReadLine();
|
||||
|
||||
switch (input)
|
||||
{
|
||||
case "PlaceOrder":
|
||||
await ProcessPlaceOrder();
|
||||
break;
|
||||
case "GetBalances":
|
||||
await ProcessGetBalances();
|
||||
break;
|
||||
case "GetOpenOrders":
|
||||
await ProcessGetOpenOrders();
|
||||
break;
|
||||
case "CancelOrder":
|
||||
await ProcessCancelOrder();
|
||||
break;
|
||||
case "GetPrice":
|
||||
await ProcessGetPrice();
|
||||
break;
|
||||
case "SubscribePrice":
|
||||
var sub = await ProcessSubscribePrice();
|
||||
Console.ReadLine();
|
||||
await sub.CloseAsync();
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("> Unknown command");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static async Task ProcessPlaceOrder()
|
||||
{
|
||||
var exchange = GetInput("Exchange?");
|
||||
var symbol = GetInput("Symbol?");
|
||||
var side = GetInput("Buy/Sell?");
|
||||
var type = GetInput("Limit/Market?");
|
||||
var quantity = GetDecimalInput("Quantity?");
|
||||
decimal? price = null;
|
||||
if (type != "Market")
|
||||
price = GetDecimalInput("Price?");
|
||||
var result = await _exchanges[exchange].PlaceOrder(symbol, side, type, quantity, price);
|
||||
if (result.Success)
|
||||
Console.WriteLine("Order placed, ID: " + result.Data);
|
||||
else
|
||||
Console.WriteLine("Failed to place order: " + result.Error);
|
||||
}
|
||||
|
||||
static async Task ProcessGetBalances()
|
||||
{
|
||||
var exchange = GetInput("Exchange?");
|
||||
Console.WriteLine("Requesting balances...");
|
||||
var balances = await _exchanges[exchange].GetBalances();
|
||||
foreach (var balance in balances.Where(b => b.Value != 0))
|
||||
Console.WriteLine($"> {balance.Key}: {balance.Value}");
|
||||
}
|
||||
|
||||
static async Task ProcessGetOpenOrders()
|
||||
{
|
||||
var exchange = GetInput("Exchange?");
|
||||
Console.WriteLine("Requesting open orders...");
|
||||
var orders = await _exchanges[exchange].GetOpenOrders();
|
||||
if (!orders.Any())
|
||||
Console.WriteLine("No open orders found");
|
||||
else
|
||||
{
|
||||
foreach(var openOrder in orders)
|
||||
Console.WriteLine($"> {openOrder.OrderTime} - {openOrder.Symbol} {openOrder.OrderType} {openOrder.OrderSide} {openOrder.QuantityFilled}/{openOrder.Quantity} @ {openOrder.Price}");
|
||||
}
|
||||
}
|
||||
|
||||
static async Task ProcessCancelOrder()
|
||||
{
|
||||
var exchange = GetInput("Exchange?");
|
||||
var symbol = GetInput("Symbol?");
|
||||
var id = GetInput("Order id?");
|
||||
var result = await _exchanges[exchange].CancelOrder(symbol, id);
|
||||
if (result)
|
||||
Console.WriteLine("Order canceled");
|
||||
else
|
||||
Console.WriteLine("Order cancel failed: " + result.Error);
|
||||
}
|
||||
|
||||
static async Task ProcessGetPrice()
|
||||
{
|
||||
var exchange = GetInput("Exchange?");
|
||||
var symbol = GetInput("Symbol?");
|
||||
Console.WriteLine("Requesting price...");
|
||||
var price = await _exchanges[exchange].GetPrice(symbol);
|
||||
Console.WriteLine($"> {exchange} price for {symbol}: {price}");
|
||||
}
|
||||
|
||||
static async Task<UpdateSubscription> ProcessSubscribePrice()
|
||||
{
|
||||
var exchange = GetInput("Exchange?");
|
||||
var symbol = GetInput("Symbol?");
|
||||
Console.WriteLine("Subscribing price...");
|
||||
return await _exchanges[exchange].SubscribePrice(symbol, price => HandlePriceUpdate(exchange,symbol, price));
|
||||
}
|
||||
|
||||
static void HandlePriceUpdate(string exchange, string symbol, decimal price)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine($"> {exchange} price for {symbol}: {price}");
|
||||
Console.WriteLine("Press enter to stop live price updates");
|
||||
}
|
||||
|
||||
static decimal GetDecimalInput(string question)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Console.WriteLine("> " + question);
|
||||
var response = Console.ReadLine();
|
||||
if (decimal.TryParse(response, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var answer))
|
||||
return answer;
|
||||
else
|
||||
Console.WriteLine("Invalid decimal value");
|
||||
}
|
||||
}
|
||||
|
||||
static string GetInput(string question)
|
||||
{
|
||||
Console.WriteLine("> " + question);
|
||||
return Console.ReadLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user