public TinkoffService(IConfiguration configuration, TinkoffApiContext context, Microsoft.Extensions.Hosting.IHostedService backgroundService)
        {
            _configuration     = configuration;
            _backgroundService = (BackgroundService)backgroundService;
            _context           = context;
            var mode = GetCurrentMode();

            _contextApi = new ContextApi(
                _configuration["Tinkoff:Sandbox:Token"], _configuration["Tinkoff:Bourse:Token"], mode
                );
            Connection();
        }
Пример #2
0
 public static extern void glfwWindowHint(WindowHintContextApi hint, ContextApi value);
Пример #3
0
 public void Init()
 {
     instance = new ContextApi();
 }
Пример #4
0
 /// <inheritdoc />
 public abstract void WindowHint(WindowHintContextApi hint, ContextApi value);
        public void TaskFindOperation(ContextApi contextApi, string figi, string operationId)
        {
            var task = Task.Run(async() =>
            {
                while (!IsStop)
                {
                    var operation = await contextApi.GetOperation(figi, operationId);
                    if (operation != null)
                    {
                        using (var contextDb = _scope.ServiceProvider.GetRequiredService <TinkoffApiContext>())
                        {
                            var operationDb = contextDb.OperationsHistory.Where(x => x.orderId == operationId).FirstOrDefault();
                            if (operation.Status == OperationStatus.Decline)
                            {
                                contextDb.Remove(operationDb);
                                return;
                            }

                            // get values
                            var orderType1 = operationDb.orderType;
                            var orderType2 = (orderType1 == Data.Enums.OrderType.Buy) ? Data.Enums.OrderType.Sell : Data.Enums.OrderType.Buy;
                            var price      = (double)operation.Price;

                            var operationLastDb = contextDb.OperationsHistory.Where(x =>
                                                                                    x.figi == operationDb.figi &&
                                                                                    x.lots == operationDb.lots &&
                                                                                    x.operationStatus == Data.Enums.OperationStatus.Done &&
                                                                                    x.orderType == orderType2
                                                                                    ).FirstOrDefault();

                            //operationDb
                            if (operationLastDb != null)
                            {
                                operationDb.operationStatus = (Data.Enums.OperationStatus)operation.Status;
                                operationDb.Commission      = new Data.Models.MoneyAmount()
                                {
                                    Currency = 0, // (Data.Enums.CurrencyEnum)operation.Commission.Currency,
                                    Value    = 0  //(double)operation.Commission.Value
                                };
                                operationDb.Price  = price;
                                operationDb.Status = Data.Enums.Status.Open;

                                operationDb.TakeProfit = operationDb.TakeProfit.SetValue(price);
                                operationDb.StopLoss   = operationDb.StopLoss.SetValue(price);

                                OperationsHistoryCache.AddOrUpdate(operationDb);
                            }

                            //operationLastDb
                            if (operationLastDb != null)
                            {
                                operationLastDb.Status = Data.Enums.Status.Close;
                            }

                            await contextDb.SaveChangesAsync();
                            return;
                        }
                    }
                    Thread.Sleep(5000);
                }
            });

            _tasks.Add(task);
        }