public async Task MarketCandlesDefaultDateTimeKind()
        {
            const string figi = Figi;
            var          from = DateTime.Now.AddDays(-1);
            var          to   = DateTime.Now;

            _handler.Expect(HttpMethod.Get, $"{BaseUri}market/candles")
            .WithQueryString(new Dictionary <string, string>
            {
                ["figi"]     = figi,
                ["from"]     = from.ToString("O"),
                ["to"]       = to.ToString("O"),
                ["interval"] = "1min"
            })
            .WithoutContent()
            .RespondJsonFromFile("market-candles-response");

            await _context.MarketCandlesAsync(figi, from.AsUnspecified(), to.AsUnspecified(), CandleInterval.Minute);
        }
Exemplo n.º 2
0
        public async Task StartAsync()
        {
            // register new sandbox account
            var sandboxAccount = await _context.RegisterAsync(BrokerAccountType.Tinkoff);

            _accountId = sandboxAccount.BrokerAccountId;

            // set balance
            foreach (var currency in new[] { Currency.Rub, Currency.Usd, Currency.Eur })
            {
                await _context.SetCurrencyBalanceAsync(currency, Random.Next(1, 10) * 100_000,
                                                       sandboxAccount.BrokerAccountId);
            }

            await CheckBalanceAsync();

            // select random instrument
            var instrumentList = await _context.MarketStocksAsync();

            var randomInstrumentIndex = Random.Next(instrumentList.Total);
            var randomInstrument      = instrumentList.Instruments[randomInstrumentIndex];

            Console.WriteLine($"Selected Instrument:\n{randomInstrument.ToString().Replace(", ", "\n")}");
            Console.WriteLine();

            // get candles
            var now        = DateTime.Now;
            var candleList = await _context.MarketCandlesAsync(randomInstrument.Figi, now.AddMinutes(-5), now, CandleInterval.Minute);

            foreach (var candle in candleList.Candles)
            {
                Console.WriteLine(candle);
            }
            Console.WriteLine();

            Console.WriteLine("Buy 1 lot");
            await _context.PlaceMarketOrderAsync(new MarketOrder(randomInstrument.Figi, 1, OperationType.Buy,
                                                                 _accountId));

            await CheckBalanceAsync();

            await Task.Delay(1000);

            Console.WriteLine("Sell 1 lot");
            await _context.PlaceMarketOrderAsync(new MarketOrder(randomInstrument.Figi, 1, OperationType.Sell,
                                                                 _accountId));

            await CheckBalanceAsync();
        }
        public async Task Collect(SandboxContext context)
        {
            foreach (var metadata in _metadataManager.GetAll())
            {
                if (metadata.Figi == null)
                {
                    continue;
                }
                var isin      = metadata.Isin;
                var intervals = _intervalCalculator.TryCalculateRequiredIntervals(isin);
                foreach (var(startDate, endDate) in intervals)
                {
                    var candles = await context.MarketCandlesAsync(
                        metadata.Figi, startDate, endDate, CandleInterval.Day);

                    _logger.LogTrace($"Found asset candles: {string.Join("\n", candles.Candles.Select(c => c.ToString()))}");
                    if (candles.Candles.Count > 0)
                    {
                        await _priceManager.AddOrAppendCandles(isin, candles);
                    }
                }
            }
        }