コード例 #1
0
        /// <summary>
        /// Get the most recent trades from trade (EXCLUSIVE).
        /// </summary>
        /// <param name="api"></param>
        /// <param name="trade"></param>
        /// <param name="limit"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static Task <IEnumerable <AggregateTrade> > GetAggregateTradesAsync(this IKucoinApi api, AggregateTrade trade, int limit = default, CancellationToken token = default)
        {
            Throw.IfNull(api, nameof(api));
            Throw.IfNull(trade, nameof(trade));

            return(api.GetAggregateTradesFromAsync(trade.Symbol, trade.Id + 1, limit, token));
        }
コード例 #2
0
        /// <summary>
        /// Get all symbols.
        /// </summary>
        /// <param name="api"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static async Task <IEnumerable <string> > SymbolsAsync(this IKucoinApi api, CancellationToken token = default)
        {
            Throw.IfNull(api, nameof(api));

            return((await api.GetPricesAsync(token).ConfigureAwait(false))
                   .Select(p => p.Symbol));
        }
コード例 #3
0
        /// <summary>
        /// Get older (non-compressed) trades.
        /// </summary>
        /// <param name="api"></param>
        /// <param name="user"></param>
        /// <param name="symbol"></param>
        /// <param name="fromId"></param>
        /// <param name="limit"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static Task <IEnumerable <Trade> > GetTradesFromAsync(this IKucoinApi api, IKucoinApiUser user, string symbol, long fromId, int limit = default, CancellationToken token = default)
        {
            Throw.IfNull(api, nameof(api));
            Throw.IfNull(user, nameof(user));

            return(api.GetTradesFromAsync(user.ApiKey, symbol, fromId, limit, token));
        }
コード例 #4
0
        /// <summary>
        /// Get current server time.
        /// </summary>
        /// <param name="api"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static async Task <DateTime> GetTimeAsync(this IKucoinApi api, CancellationToken token = default)
        {
            Throw.IfNull(api, nameof(api));

            var timestamp = await api.GetTimestampAsync(token).ConfigureAwait(false);

            return(timestamp.ToDateTimeK());
        }
コード例 #5
0
        protected WebSocketClientCache(IKucoinApi api, TClient client, ILogger logger = null)
        {
            Throw.IfNull(api, nameof(api));
            Throw.IfNull(client, nameof(client));

            Api    = api;
            Client = client;
            Logger = logger;
        }
コード例 #6
0
ファイル: OrderBookCache.cs プロジェクト: domibu/MarketTool
 public OrderBookCache(IKucoinApi api, IDepthWebSocketClient client, ILogger <OrderBookCache> logger = null)
     : base(api, client, logger)
 {
 }
コード例 #7
0
 public TradeCache(IKucoinApi api, ITradeWebSocketClient client, ILogger <TradeCache> logger = null)
     : base(api, client, logger)
 {
     _trades = new Queue <Trade>();
 }
コード例 #8
0
ファイル: Program.cs プロジェクト: domibu/MarketTool
        public static async Task Main(string[] args)
        {
            // Un-comment to run...
            //await AccountBalancesExample.ExampleMain(args);
            //await MinimalWithDependencyInjection.ExampleMain(args);
            //await MinimalWithoutDependencyInjection.ExampleMain(args);
            //await SerializationExample.ExampleMain(args);
            //await OrderBookCacheAccountBalanceExample.ExampleMain(args);

            var cts = new CancellationTokenSource();

            try
            {
                // Load configuration.
                Configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json", true, false)
                                .AddUserSecrets <Program>() // for access to API key and secret.
                                .Build();

                // Configure services.
                ServiceProvider = new ServiceCollection()
                                  .AddBinance()
                                  .AddKucoin()
                                  // Use a single web socket stream for combined streams (optional).
                                  .AddSingleton <IWebSocketStream, BinanceWebSocketStream>()
                                  // Change low-level web socket client implementation.
                                  //.AddTransient<IWebSocketClient, WebSocket4NetClient>()
                                  //.AddTransient<IWebSocketClient, WebSocketSharpClient>()
                                  .AddOptions()
                                  .AddLogging(builder => builder.SetMinimumLevel(LogLevel.Trace))
                                  .Configure <BinanceApiOptions>(Configuration.GetSection("ApiOptions"))
                                  .Configure <KucoinApiOptions>(Configuration.GetSection("ApiOptions"))
                                  .Configure <Binance.UserDataWebSocketManagerOptions>(Configuration.GetSection("UserDataOptions"))
                                  .BuildServiceProvider();

                // Configure logging.
                ServiceProvider
                .GetService <ILoggerFactory>()
                .AddConsole(Configuration.GetSection("Logging:Console"))
                .AddFile(Configuration.GetSection("Logging:File"));

                var apiKey = Configuration["BinanceApiKey"]                              // user secrets configuration.
                             ?? Configuration.GetSection("BinanceUser")["ApiKey"];       // appsettings.json configuration.

                var apiSecret = Configuration["BinanceApiSecret"]                        // user secrets configuration.
                                ?? Configuration.GetSection("BinanceUser")["ApiSecret"]; // appsettings.json configuration.

                if (string.IsNullOrWhiteSpace(apiKey) || string.IsNullOrWhiteSpace(apiSecret))
                {
                    PrintApiNotice();
                }

                if (!string.IsNullOrEmpty(apiKey))
                {
                    User = ServiceProvider
                           .GetService <IBinanceApiUserProvider>()
                           .CreateUser(apiKey, apiSecret);
                }

                BinanceApi = ServiceProvider.GetService <IBinanceApi>();
                KucoinApi  = ServiceProvider.GetService <IKucoinApi>();

                ClientManager        = ServiceProvider.GetService <IBinanceWebSocketManager>();
                ClientManager.Error += (s, e) =>
                {
                    lock (ConsoleSync)
                    {
                        Console.WriteLine();
                        Console.WriteLine($"! Client Manager Error: \"{e.Exception.Message}\"");
                        Console.WriteLine();
                    }
                };

                // Instantiate all assembly command handlers.
                foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
                {
                    if (typeof(IHandleCommand).IsAssignableFrom(type) && !type.IsAbstract)
                    {
                        CommandHandlers.Add((IHandleCommand)Activator.CreateInstance(type));
                    }
                }

                await SuperLoopAsync(cts.Token);
            }
            catch (Exception e)
            {
                lock (ConsoleSync)
                {
                    Console.WriteLine($"! FAIL: \"{e.Message}\"");
                    if (e.InnerException != null)
                    {
                        Console.WriteLine($"  -> Exception: \"{e.InnerException.Message}\"");
                    }
                }
            }
            finally
            {
                await DisableLiveTask();

                cts.Cancel();
                cts.Dispose();

                User?.Dispose();

                ClientManager?.Dispose();

                lock (ConsoleSync)
                {
                    Console.WriteLine();
                    Console.WriteLine("  ...press any key to close window.");
                    Console.ReadKey(true);
                }
            }
        }
コード例 #9
0
 /// <summary>
 /// Get aggregate/compressed trades within a time interval (INCLUSIVE).
 /// </summary>
 /// <param name="api"></param>
 /// <param name="symbol"></param>
 /// <param name="timeInterval"></param>
 /// <param name="token"></param>
 /// <returns></returns>
 public static Task <IEnumerable <AggregateTrade> > GetAggregateTradesAsync(this IKucoinApi api, string symbol, (DateTime, DateTime) timeInterval, CancellationToken token = default)
コード例 #10
0
 public SymbolStatisticsCache(IKucoinApi api, ISymbolStatisticsWebSocketClient client, ILogger <SymbolStatisticsCache> logger = null)
     : base(api, client, logger)
 {
 }
コード例 #11
0
ファイル: CandlestickCache.cs プロジェクト: domibu/MarketTool
 public CandlestickCache(IKucoinApi api, ICandlestickWebSocketClient client, ILogger <CandlestickCache> logger = null)
     : base(api, client, logger)
 {
     _candlesticks = new List <Candlestick>();
 }
コード例 #12
0
 public AccountInfoCache(IKucoinApi api, IUserDataWebSocketManager manager, ILogger <AccountInfoCache> logger = null)
     : base(api, manager, logger)
 {
 }