public static MeNewLimitOrderModel ToNewMeModel(this StopLimitOrderModel model) { return(MeNewLimitOrderModel.CreateMeStopLimitOrder( model.Id, model.ClientId, model.AssetPairId, model.OrderAction, model.Volume, model.CancelPreviousOrders, model.Fee?.ToMeModel(), model.Fees?.Select(item => item.ToMeModel()).ToArray(), model.LowerLimitPrice, model.LowerPrice, model.UpperLimitPrice, model.UpperPrice)); }
///<inheritdoc cref="IMatchingEngineClient"/> public Task <MeResponseModel> PlaceStopLimitOrderAsync(StopLimitOrderModel model, CancellationToken cancellationToken = default) { if (model == null) { throw new ArgumentNullException(nameof(model)); } return(SendData( model.ToNewMeModel(), _newTasksManager, x => x.ToDomainModel(), _meResponsePolicy, cancellationToken, model.Id, $"{model.OrderAction} {model.AssetPairId}" )); }
public async Task <ResponseModel <LimitOrderResponseModel> > PlaceStopLimitOrderAsync( string clientId, AssetPair assetPair, OrderAction orderAction, decimal volume, decimal?lowerPrice, decimal?lowerLimitPrice, decimal?upperPrice, decimal?upperLimitPrice, bool cancelPreviousOrders = false) { var requestId = GetNextRequestId(); var fees = _calculateOrderFees ? await _feeCalculator.GetLimitOrderFees(clientId, assetPair, orderAction) : Array.Empty <LimitOrderFeeModel>(); var order = new StopLimitOrderModel { Id = requestId.ToString(), AssetPairId = assetPair.Id, ClientId = clientId, LowerPrice = (double?)lowerPrice, LowerLimitPrice = (double?)lowerLimitPrice, UpperPrice = (double?)upperPrice, UpperLimitPrice = (double?)upperLimitPrice, CancelPreviousOrders = cancelPreviousOrders, Volume = (double)Math.Abs(volume), OrderAction = orderAction.ToMeOrderAction(), Fees = fees }; var response = await _matchingEngineClient.PlaceStopLimitOrderAsync(order); CheckResponseAndThrowIfNull(response); var result = new LimitOrderResponseModel { Id = requestId }; return(ConvertToApiModel(response.Status, result)); }
public async Task PlaceStopLimitOrder() { var client = CreateConnection(Url); var model = new StopLimitOrderModel { Id = GenerateUid(), ClientId = ClientId, CancelPreviousOrders = true, AssetPairId = "BTCUSD", OrderAction = OrderAction.Buy, LowerLimitPrice = 450, LowerPrice = 500, UpperLimitPrice = 650, UpperPrice = 600, Volume = 0.001 }; // Check that valid request is accepted var response = await client.Retry(x => x.PlaceStopLimitOrderAsync(model)); ValidateResponse(response, MeStatusCodes.Ok); // Check that resend results in duplicate response = await client.Retry(x => x.PlaceStopLimitOrderAsync(model)); ValidateResponse(response, MeStatusCodes.Duplicate); // Check that sending only upper prices is fine model.Id = GenerateUid(); model.LowerLimitPrice = null; model.LowerPrice = null; model.UpperLimitPrice = 650; model.UpperPrice = 600; response = await client.PlaceStopLimitOrderAsync(model); ValidateResponse(response, MeStatusCodes.Ok); // Check that sending only upper limit price is wrong model.Id = GenerateUid(); model.LowerLimitPrice = null; model.LowerPrice = null; model.UpperLimitPrice = 650; model.UpperPrice = null; response = await client.PlaceStopLimitOrderAsync(model); ValidateResponse(response, MeStatusCodes.InvalidPrice); // Check that sending only upper price is wrong model.Id = GenerateUid(); model.LowerLimitPrice = null; model.LowerPrice = null; model.UpperLimitPrice = null; model.UpperPrice = 600; response = await client.PlaceStopLimitOrderAsync(model); ValidateResponse(response, MeStatusCodes.InvalidPrice); // Check that sending only lower prices is fine model.Id = GenerateUid(); model.LowerLimitPrice = 450; model.LowerPrice = 500; model.UpperLimitPrice = null; model.UpperPrice = null; response = await client.PlaceStopLimitOrderAsync(model); ValidateResponse(response, MeStatusCodes.Ok); // Check that sending only lower limit price is wrong model.Id = GenerateUid(); model.LowerLimitPrice = 450; model.LowerPrice = null; model.UpperLimitPrice = null; model.UpperPrice = null; response = await client.PlaceStopLimitOrderAsync(model); ValidateResponse(response, MeStatusCodes.InvalidPrice); // Check that sending only lower price is wrong model.Id = GenerateUid(); model.LowerLimitPrice = null; model.LowerPrice = 500; model.UpperLimitPrice = null; model.UpperPrice = null; response = await client.PlaceStopLimitOrderAsync(model); ValidateResponse(response, MeStatusCodes.InvalidPrice); // Check that missing price gives InvalidPrice model.Id = GenerateUid(); model.LowerLimitPrice = null; model.LowerPrice = null; model.UpperLimitPrice = null; model.UpperPrice = null; response = await client.PlaceStopLimitOrderAsync(model); ValidateResponse(response, MeStatusCodes.InvalidPrice); // Check that negative prices gives InvalidPrice model.Id = GenerateUid(); model.LowerLimitPrice = -1; model.LowerPrice = -1; model.UpperLimitPrice = -1; model.UpperPrice = -1; response = await client.PlaceStopLimitOrderAsync(model); ValidateResponse(response, MeStatusCodes.InvalidPrice); }