private void ValidateId(string id, MatchingEngineRouteContract contract) { if (contract?.Id != id) { throw new ArgumentException("Id must match with contract id"); } }
//private static async Task CheckTradingConditionsApiWorking(IHttpClientGenerator clientGenerator) //{ // var tradingCondition = new TradingConditionContract // { // Id = "t1", // Name = "1", // LegalEntity = "1", // MarginCall1 = 1, // MarginCall2 = 1, // StopOut = 1, // DepositLimit = 1, // WithdrawalLimit = 1, // LimitCurrency = "1", // BaseAssets = new List<string>(){"1"}, // }; // var tradingConditionApiClient = clientGenerator.Generate<ITradingConditionsApi>(); // await tradingConditionApiClient.List().Dump(); // if (await tradingConditionApiClient.Get("t1") == null) // await tradingConditionApiClient.Insert(tradingCondition).Dump(); // await tradingConditionApiClient.Get("t1").Dump(); // tradingCondition.Name = "11111"; // await tradingConditionApiClient.Update("t1", tradingCondition).Dump(); //} //private static async Task CheckTradingInstrumentsApiWorking(IHttpClientGenerator clientGenerator) //{ // var tradingInstrument = new TradingInstrumentContract // { // TradingConditionId = "t1", // Instrument = "BTCUSD", // LeverageInit = 1, // LeverageMaintenance = 1, // SwapLong = 1, // SwapShort = 1, // Delta = 1, // DealMinLimit = 1, // DealMaxLimit = 1, // PositionLimit = 1, // ShortPosition = true, // LiquidationThreshold = 1000, // CommissionRate = 1, // CommissionMin = 1, // CommissionMax = 1, // CommissionCurrency = "1", // }; // var tradingInstrumentApiClient = clientGenerator.Generate<ITradingInstrumentsApi>(); // await tradingInstrumentApiClient.List(null).Dump(); // await tradingInstrumentApiClient.Insert(tradingInstrument).Dump(); // tradingInstrument.LeverageInit = 2; // await tradingInstrumentApiClient.Update("t1", "BTCUSD", tradingInstrument).Dump(); // await tradingInstrumentApiClient.AssignCollection("t1", new[] {"EURUSD", "EURCHF", "BTCUSD"}).Dump(); // foreach (var tradingInstrumentContract in await tradingInstrumentApiClient.List(null)) // { // await tradingInstrumentApiClient.Delete(tradingInstrumentContract.TradingConditionId, // tradingInstrumentContract.Instrument); // } //} private static async Task CheckTradingRoutesApiWorking(IHttpClientGenerator clientGenerator) { var tradingRoute = new MatchingEngineRouteContract { Id = "t1", Rank = 100, TradingConditionId = "t1", ClientId = "1", Instrument = "BTCUSD", Type = OrderDirectionContract.Buy, MatchingEngineId = "m1", Asset = "BTC", RiskSystemLimitType = "11", RiskSystemMetricType = "11", }; var tradingRouteApiClient = clientGenerator.Generate <ITradingRoutesApi>(); await tradingRouteApiClient.List().Dump(); await tradingRouteApiClient.Insert(tradingRoute).Dump(); tradingRoute.Rank = 10000; await tradingRouteApiClient.Update("t1", tradingRoute).Dump(); await tradingRouteApiClient.Delete("t1"); }
public async Task <MatchingEngineRouteContract> Insert([FromBody] MatchingEngineRouteContract route) { await ValidateRoute(route); if (!await _tradingRoutesRepository.TryInsertAsync( _convertService.Convert <MatchingEngineRouteContract, TradingRoute>(route))) { throw new ArgumentException($"Trading route with id {route.Id} already exists", nameof(route.Id)); } await _eventSender.SendSettingsChangedEvent($"{Request.Path}", SettingsChangedSourceType.TradingRoute, route.Id); return(route); }
public async Task <MatchingEngineRouteContract> Update(string routeId, [FromBody] MatchingEngineRouteContract route) { await ValidateRoute(route); ValidateId(routeId, route); await _tradingRoutesRepository.UpdateAsync( _convertService.Convert <MatchingEngineRouteContract, TradingRoute>(route)); await _eventSender.SendSettingsChangedEvent($"{Request.Path}", SettingsChangedSourceType.TradingRoute, routeId); return(route); }
private async Task ValidateRoute(MatchingEngineRouteContract route) { if (route == null) { throw new ArgumentNullException(nameof(route), "Model is incorrect"); } if (string.IsNullOrWhiteSpace(route?.Id)) { throw new ArgumentNullException(nameof(route.Id), "Route Id must be set"); } if (route.Type != null && !Enum.IsDefined(typeof(OrderDirectionContract), route.Type)) { throw new ArgumentNullException(nameof(route.Type), "Route Type is set to an incorrect value"); } if (!string.IsNullOrEmpty(route.TradingConditionId) && await _tradingConditionsRepository.GetAsync(route.TradingConditionId) == null) { throw new InvalidOperationException($"Trading condition {route.TradingConditionId} does not exist"); } if (!string.IsNullOrEmpty(route.Instrument) && await _assetPairsRepository.GetAsync(route.Instrument) == null) { throw new InvalidOperationException($"Asset pair {route.Instrument} does not exist"); } if (string.IsNullOrEmpty(route.Asset) || route.Asset == AnyValue) { route.Asset = AnyValue; } else if (await _assetsRepository.GetAsync(route.Asset) == null) { throw new InvalidOperationException($"Asset {route.Asset} does not exist"); } }