public TradingInstrumentsService(
     IProductsRepository productsRepository,
     IClientProfilesRepository clientProfilesRepository,
     IClientProfileSettingsRepository clientProfileSettingsRepository,
     IUnderlyingsCache underlyingsCache,
     DefaultTradingInstrumentSettings defaultTradingInstrumentSettings)
 {
     _productsRepository              = productsRepository;
     _clientProfilesRepository        = clientProfilesRepository;
     _clientProfileSettingsRepository = clientProfileSettingsRepository;
     _underlyingsCache = underlyingsCache;
     _defaultTradingInstrumentSettings = defaultTradingInstrumentSettings;
 }
 public TradingInstrumentsController(
     IAssetsRepository assetsRepository,
     IAssetPairsRepository assetPairsRepository,
     ITradingConditionsRepository tradingConditionsRepository,
     ITradingInstrumentsRepository tradingInstrumentsRepository,
     ITradingService tradingService,
     IConvertService convertService,
     IEventSender eventSender,
     DefaultTradingInstrumentSettings defaultTradingInstrumentSettings)
 {
     _assetsRepository             = assetsRepository;
     _assetPairsRepository         = assetPairsRepository;
     _tradingConditionsRepository  = tradingConditionsRepository;
     _tradingInstrumentsRepository = tradingInstrumentsRepository;
     _tradingService = tradingService;
     _convertService = convertService;
     _eventSender    = eventSender;
     _defaultTradingInstrumentSettings = defaultTradingInstrumentSettings;
 }
Exemplo n.º 3
0
        public async Task <IEnumerable <ITradingInstrument> > CreateDefaultTradingInstruments(string tradingConditionId,
                                                                                              IEnumerable <string> assetPairsIds, DefaultTradingInstrumentSettings defaults)
        {
            var objectsToAdd = assetPairsIds.Select(x => new TradingInstrument
                                                    (
                                                        tradingConditionId,
                                                        x,
                                                        defaults.LeverageInit,
                                                        defaults.LeverageMaintenance,
                                                        defaults.SwapLong,
                                                        defaults.SwapShort,
                                                        defaults.Delta,
                                                        defaults.DealMinLimit,
                                                        defaults.DealMaxLimit,
                                                        defaults.PositionLimit,
                                                        true,
                                                        defaults.LiquidationThreshold,
                                                        defaults.OvernightMarginMultiplier,
                                                        defaults.CommissionRate,
                                                        defaults.CommissionMin,
                                                        defaults.CommissionMax,
                                                        defaults.CommissionCurrency,
                                                        defaults.HedgeCost,
                                                        defaults.Spread
                                                    )).ToList();
            var entitiesToAdd = objectsToAdd.Select(x =>
            {
                var entity = ConvertService.Convert(x, DefaultAzureMappingOpts);
                entity.SetKeys();
                return(entity);
            });

            await TableStorage.InsertAsync(entitiesToAdd);

            return(objectsToAdd);
        }
        public async Task <IEnumerable <ITradingInstrument> > CreateDefaultTradingInstruments(string tradingConditionId,
                                                                                              IEnumerable <string> assetPairsIds, DefaultTradingInstrumentSettings defaults)
        {
            var objectsToAdd = assetPairsIds.Select(x => new TradingInstrument
                                                    (
                                                        tradingConditionId,
                                                        x,
                                                        defaults.LeverageInit,
                                                        defaults.LeverageMaintenance,
                                                        defaults.SwapLong,
                                                        defaults.SwapShort,
                                                        defaults.Delta,
                                                        defaults.DealMinLimit,
                                                        defaults.DealMaxLimit,
                                                        defaults.PositionLimit,
                                                        true,
                                                        defaults.LiquidationThreshold,
                                                        defaults.OvernightMarginMultiplier,
                                                        defaults.CommissionRate,
                                                        defaults.CommissionMin,
                                                        defaults.CommissionMax,
                                                        defaults.CommissionCurrency,
                                                        defaults.HedgeCost,
                                                        defaults.Spread
                                                    )).ToList();


            using (var conn = new SqlConnection(_connectionString))
            {
                SqlTransaction transaction = null;
                try
                {
                    transaction = conn.BeginTransaction();

                    await conn.ExecuteAsync(
                        $"insert into {TableName} ({GetColumns}) values ({GetFields})",
                        objectsToAdd.Select(_convertService.Convert <TradingInstrument, TradingInstrumentEntity>),
                        transaction);

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction?.Rollback();
                    await _log.WriteErrorAsync(nameof(TradingInstrumentsRepository),
                                               nameof(CreateDefaultTradingInstruments), "Failed to create default trading instruments", ex);
                }
            }


            return(objectsToAdd);
        }