53 lines
1.8 KiB
C#
53 lines
1.8 KiB
C#
using Google.Protobuf.WellKnownTypes;
|
|
using KLHZ.Trader.Core.Common.Messaging.Contracts;
|
|
using KLHZ.Trader.Core.Common.Messaging.Contracts.Messages;
|
|
using KLHZ.Trader.Core.DataLayer;
|
|
using KLHZ.Trader.Core.DataLayer.Entities.Prices;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Internal;
|
|
using Tinkoff.InvestApi;
|
|
using Tinkoff.InvestApi.V1;
|
|
using Candle = KLHZ.Trader.Core.DataLayer.Entities.Prices.Candle;
|
|
|
|
namespace KLHZ.Trader.Service.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("[controller]/[action]")]
|
|
public class PlayController : ControllerBase
|
|
{
|
|
private readonly IDataBus _dataBus;
|
|
private readonly IDbContextFactory<TraderDbContext> _dbContextFactory;
|
|
|
|
public PlayController(IDataBus dataBus, IDbContextFactory<TraderDbContext> dbContextFactory)
|
|
{
|
|
_dbContextFactory = dbContextFactory;
|
|
_dataBus = dataBus;
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task Run(string figi)
|
|
{
|
|
using var context1 = await _dbContextFactory.CreateDbContextAsync();
|
|
context1.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
|
var data = await context1.Candles
|
|
.Where(c => c.Figi == figi)
|
|
.OrderBy(c=>c.Time)
|
|
.Select(c => new NewPriceMessage()
|
|
{
|
|
Figi = figi,
|
|
Ticker = c.Ticker,
|
|
Time = c.Time,
|
|
Value = c.Close,
|
|
IsHistoricalData = true
|
|
})
|
|
.ToArrayAsync();
|
|
|
|
foreach (var mess in data)
|
|
{
|
|
await _dataBus.BroadcastNewPrice(mess);
|
|
}
|
|
}
|
|
}
|
|
}
|