public async Task PostInvalidAlgoId(AlgoInstanceType algoInstanceType) { WalletDTO walletDTO = null; if (algoInstanceType == AlgoInstanceType.Live) { walletDTO = await GetExistingWallet(); } // Create algo var algoData = await CreateAlgo(); // Build days offset DaysOffsetDTO daysOffsetDTO = BuildDaysOffsetByInstanceType(algoInstanceType); // Build InstanceParameters InstanceParameters instanceParameters = InstanceConfig.UseInvalidAlgoId; // Build instance request payload var instanceForAlgo = InstanceDataBuilder.BuildInstanceData(algoData, walletDTO, algoInstanceType, instanceParameters, daysOffsetDTO); var url = algoInstanceType == AlgoInstanceType.Live ? ApiPaths.ALGO_STORE_SAVE_ALGO_INSTANCE : ApiPaths.ALGO_STORE_FAKE_TRADING_INSTANCE_DATA; var postInstanceDataResponse = await Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgo), Method.POST); Assert.That(postInstanceDataResponse.Status, Is.EqualTo(HttpStatusCode.NotFound), "we should receive not found response code"); }
public async Task <InstanceDataDTO> SaveInstance(AlgoDataDTO algoData, AlgoInstanceType instanceType, bool useExistingWallet = true) { if (instanceType == AlgoInstanceType.Live) { walletDTO = useExistingWallet == true ? await GetExistingWallet() : await CreateTestWallet(); } // Build days offset DaysOffsetDTO daysOffsetDTO = BuildDaysOffsetByInstanceType(instanceType); // Build InstanceParameters instanceParameters = InstanceConfig.ValidMetaData; // Build instance request payload var instanceForAlgo = InstanceDataBuilder.BuildInstanceData(algoData, walletDTO, instanceType, instanceParameters, daysOffsetDTO); // Build save instance url var url = instanceType == AlgoInstanceType.Live ? ApiPaths.ALGO_STORE_SAVE_ALGO_INSTANCE : ApiPaths.ALGO_STORE_FAKE_TRADING_INSTANCE_DATA; string requestBody = JsonUtils.SerializeObject(instanceForAlgo); var saveInstanceResponse = await Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, requestBody, Method.POST); message = $"POST {url} returned status: {saveInstanceResponse.Status} and response: {saveInstanceResponse.ResponseJson}. Expected: {HttpStatusCode.OK}"; Assert.That(saveInstanceResponse.Status, Is.EqualTo(HttpStatusCode.OK), message); var instanceData = JsonUtils.DeserializeJson <InstanceDataDTO>(saveInstanceResponse.ResponseJson); // Add Instance to the list so that it can be deleted in the the TearDown instancesList.Add(instanceData); return(instanceData); }
public async Task PostInvalidInstanceTradedAsset(AlgoInstanceType algoInstanceType) { WalletDTO walletDTO = null; if (algoInstanceType == AlgoInstanceType.Live) { walletDTO = await GetExistingWallet(); } // Create algo var algoData = await CreateAlgo(); // Build days offset DaysOffsetDTO daysOffsetDTO = BuildDaysOffsetByInstanceType(algoInstanceType); // Build InstanceParameters InstanceParameters instanceParameters = InstanceConfig.InvalidInstanceTradedAsset; // Build instance request payload var instanceForAlgo = InstanceDataBuilder.BuildInstanceData(algoData, walletDTO, algoInstanceType, instanceParameters, daysOffsetDTO); var url = algoInstanceType == AlgoInstanceType.Live ? ApiPaths.ALGO_STORE_SAVE_ALGO_INSTANCE : ApiPaths.ALGO_STORE_FAKE_TRADING_INSTANCE_DATA; var postInstanceDataResponse = await Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgo), Method.POST); AlgoErrorDTO postInstanceDataResponseDTO = JsonUtils.DeserializeJson <AlgoErrorDTO>(postInstanceDataResponse.ResponseJson); Assert.That(postInstanceDataResponse.Status, Is.EqualTo(HttpStatusCode.BadRequest), "should be bad response erorr code"); Assert.That(postInstanceDataResponseDTO.ErrorMessage, Does.Contain("ValidationError Message:Asset <USD> is not valid for asset pair <BTCEUR>"), "we should receive erorr for the invalid traded asset"); }
public async Task PostInvalidInstanceAssetPair(AlgoInstanceType algoInstanceType) { WalletDTO walletDTO = null; if (algoInstanceType == AlgoInstanceType.Live) { walletDTO = await GetExistingWallet(); } // Create algo var algoData = await CreateAlgo(); // Build days offset DaysOffsetDTO daysOffsetDTO = BuildDaysOffsetByInstanceType(algoInstanceType); // Build InstanceParameters InstanceParameters instanceParameters = InstanceConfig.InvalidInstanceAssetPair; // Build instance request payload var instanceForAlgo = InstanceDataBuilder.BuildInstanceData(algoData, walletDTO, algoInstanceType, instanceParameters, daysOffsetDTO); var url = algoInstanceType == AlgoInstanceType.Live ? ApiPaths.ALGO_STORE_SAVE_ALGO_INSTANCE : ApiPaths.ALGO_STORE_FAKE_TRADING_INSTANCE_DATA; var postInstanceDataResponse = await Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgo), Method.POST); AlgoErrorDTO postInstanceDataResponseDTO = JsonUtils.DeserializeJson <AlgoErrorDTO>(postInstanceDataResponse.ResponseJson); Assert.That(postInstanceDataResponse.Status, Is.EqualTo(HttpStatusCode.InternalServerError), "responce should equals internal server erorr"); Assert.That(postInstanceDataResponseDTO.ErrorMessage, Does.Contain("NotFound from asset service calling AssetPairGetWithHttpMessagesAsync"), "we should receive erorr for not found asset pair"); }
public async Task BackTestWithLongFunctionPeriod(AlgoInstanceType algoInstanceType) { WalletDTO walletDTO = null; if (algoInstanceType == AlgoInstanceType.Live) { walletDTO = await GetExistingWallet(); } // Create algo var algoData = await CreateAlgo(); // Build days offset DaysOffsetDTO daysOffsetDTO = BuildDaysOffsetByInstanceType(algoInstanceType); // Set Instance start date to be three years ago and end date to be 10 days ago int start = 365 * -3; int end = -10; daysOffsetDTO.AlgoStartOffset = start; daysOffsetDTO.AlgoEndOffset = end; daysOffsetDTO.SmaShortStartOffset = start; daysOffsetDTO.SmaShortEndOffset = end; daysOffsetDTO.SmaShortStartOffset = start; daysOffsetDTO.SmaLongEndOffset = end; // Build InstanceParameters InstanceParameters instanceParameters = InstanceConfig.ValidMetaData; // Build instance request payload var instanceForAlgo = InstanceDataBuilder.BuildInstanceData(algoData, walletDTO, algoInstanceType, instanceParameters, daysOffsetDTO); // Build save instance url var url = algoInstanceType == AlgoInstanceType.Live ? ApiPaths.ALGO_STORE_SAVE_ALGO_INSTANCE : ApiPaths.ALGO_STORE_FAKE_TRADING_INSTANCE_DATA; var postInstanceDataResponse = await Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgo), Method.POST); AlgoErrorDTO postInstanceDataResponseDTO = JsonUtils.DeserializeJson <AlgoErrorDTO>(postInstanceDataResponse.ResponseJson); // Get instance data from DB ClientInstanceEntity instanceDataFromDB = await ClientInstanceRepository.TryGetAsync(t => t.AlgoId == algoData.Id) as ClientInstanceEntity; Assert.Multiple(() => { Assert.That(postInstanceDataResponse.Status, Is.EqualTo(HttpStatusCode.InternalServerError)); Assert.That(postInstanceDataResponseDTO.ErrorMessage, Does.StartWith("Code:511-InitialWalletBalanceNotCalculated Message:Initial wallet balance could not be calculated. Could not get history price for")); // Verify intance is not created in DB Assert.That(instanceDataFromDB, Is.Null); }); }
public async Task <InstanceDataDTO> SaveInstance(AlgoDataDTO algoData, AlgoInstanceType instanceType, bool useExistingWallet = true) { if (instanceType == AlgoInstanceType.Live) { walletDTO = useExistingWallet == true ? await GetExistingWallet() : await CreateTestWallet(); } // Build days offset DaysOffsetDTO daysOffsetDTO = BuildDaysOffsetByInstanceType(instanceType); // Build InstanceParameters instanceParameters = new InstanceParameters() { AssetPair = "BTCUSD", TradedAsset = "USD", InstanceTradeVolume = 4, InstanceCandleInterval = CandleTimeInterval.Minute, FunctionCandleInterval = CandleTimeInterval.Day, FunctionCandleOperationMode = CandleOperationMode.CLOSE, FunctionCapacity = 4, InstanceFunctions = new List <FunctionType>() { FunctionType.SMA_Short, FunctionType.SMA_Long } }; // Build instance request payload var instanceForAlgo = InstanceDataBuilder.BuildInstanceData(algoData, walletDTO, instanceType, instanceParameters, daysOffsetDTO); // Build save instance url var url = instanceType == AlgoInstanceType.Live ? ApiPaths.ALGO_STORE_SAVE_ALGO_INSTANCE : ApiPaths.ALGO_STORE_FAKE_TRADING_INSTANCE_DATA; string requestBody = JsonUtils.SerializeObject(instanceForAlgo); var saveInstanceResponse = await Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, requestBody, Method.POST); message = $"POST {url} returned status: {saveInstanceResponse.Status} and response: {saveInstanceResponse.ResponseJson}. Expected: {HttpStatusCode.OK}"; Assert.That(saveInstanceResponse.Status, Is.EqualTo(HttpStatusCode.OK), message); var instanceData = JsonUtils.DeserializeJson <InstanceDataDTO>(saveInstanceResponse.ResponseJson); // Add Instance to the list so that it can be deleted in the the TearDown instancesList.Add(instanceData); return(instanceData); }
public async Task PostInvalidInstanceTradedAsset(AlgoInstanceType algoInstanceType) { WalletDTO walletDTO = null; if (algoInstanceType == AlgoInstanceType.Live) { walletDTO = await GetExistingWallet(); } // Create algo var algoData = await CreateAlgo(); // Build days offset DaysOffsetDTO daysOffsetDTO = BuildDaysOffsetByInstanceType(algoInstanceType); // Build InstanceParameters InstanceParameters instanceParameters = new InstanceParameters() { AssetPair = "BTCUSD", TradedAsset = "EUR", InstanceTradeVolume = 2, InstanceCandleInterval = CandleTimeInterval.Minute, FunctionCandleInterval = CandleTimeInterval.Day, FunctionCandleOperationMode = CandleOperationMode.CLOSE, FunctionCapacity = 4, InstanceFunctions = new List <FunctionType>() { FunctionType.SMA_Short, FunctionType.SMA_Long } }; // Build instance request payload var instanceForAlgo = InstanceDataBuilder.BuildInstanceData(algoData, walletDTO, algoInstanceType, instanceParameters, daysOffsetDTO); string url = ApiPaths.ALGO_STORE_ALGO_INSTANCE_DATA; var postInstanceDataResponse = await Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgo), Method.POST); AlgoErrorDTO postInstanceDataResponseDTO = JsonUtils.DeserializeJson <AlgoErrorDTO>(postInstanceDataResponse.ResponseJson); Assert.That(postInstanceDataResponse.Status, Is.EqualTo(HttpStatusCode.BadRequest), "should be bad response erorr code"); Assert.That(postInstanceDataResponseDTO.ErrorMessage, Does.Contain("ValidationError Message:Asset <USD> is not valid for asset pair <BTCEUR>"), "we should receive erorr for the invalid traded asset"); }
public async Task PostInvalidAlgoId(AlgoInstanceType algoInstanceType) { WalletDTO walletDTO = null; if (algoInstanceType == AlgoInstanceType.Live) { walletDTO = await GetExistingWallet(); } // Create algo var algoData = await CreateAlgo(); // Build days offset DaysOffsetDTO daysOffsetDTO = BuildDaysOffsetByInstanceType(algoInstanceType); // Build InstanceParameters InstanceParameters instanceParameters = new InstanceParameters() { AssetPair = "BTCUSD", TradedAsset = "EUR", InstanceTradeVolume = 2, InstanceCandleInterval = CandleTimeInterval.Minute, FunctionCandleInterval = CandleTimeInterval.Day, FunctionCandleOperationMode = CandleOperationMode.CLOSE, FunctionCapacity = 4, InstanceFunctions = new List <FunctionType>() { FunctionType.SMA_Short, FunctionType.SMA_Long } }; // Build instance request payload var instanceForAlgo = InstanceDataBuilder.BuildInstanceData(algoData, walletDTO, algoInstanceType, instanceParameters, daysOffsetDTO, true); string url = ApiPaths.ALGO_STORE_ALGO_INSTANCE_DATA; var postInstanceDataResponse = await Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, JsonUtils.SerializeObject(instanceForAlgo), Method.POST); Assert.That(postInstanceDataResponse.Status, Is.EqualTo(HttpStatusCode.NotFound), "we should receive not found response code"); }
private static AlgoMetaDataInformation BuildAlgoMetaDataInformation(InstanceParameters instanceParameters, DaysOffsetDTO daysOffsetDTO) { FunctionParamsDTO smaShortFunctionParamsDTO = null; FunctionParamsDTO smaLongFunctionParamsDTO = null; FunctionParamsDTO adxFunctionParamsDTO = null; FunctionParamsDTO macdFunctionParamsDTO = null; AlgoParamsDTO algoParamsDTO = new AlgoParamsDTO(daysOffsetDTO.AlgoStartOffset, daysOffsetDTO.AlgoEndOffset, instanceParameters.AssetPair, instanceParameters.TradedAsset, instanceParameters.InstanceTradeVolume, instanceParameters.InstanceCandleInterval); // Create SMA_SHORT function parameters if (instanceParameters.InstanceFunctions.Contains(FunctionType.SMA_Short)) { smaShortFunctionParamsDTO = new FunctionParamsDTO(FunctionType.SMA_Short, daysOffsetDTO.SmaShortStartOffset, daysOffsetDTO.SmaShortEndOffset, instanceParameters.AssetPair, instanceParameters.FunctionPeriod, instanceParameters.FunctionCandleOperationMode, instanceParameters.FunctionCandleInterval); // Add the function params to the functionsDictionary AddToFunctionsDictionary(FunctionType.SMA_Short, smaShortFunctionParamsDTO); } // Create SMA_Long function parameters if (instanceParameters.InstanceFunctions.Contains(FunctionType.SMA_Long)) { smaLongFunctionParamsDTO = new FunctionParamsDTO(FunctionType.SMA_Long, daysOffsetDTO.SmaLongStartOffset, daysOffsetDTO.SmaLongEndOffset, instanceParameters.AssetPair, instanceParameters.FunctionPeriod, instanceParameters.FunctionCandleOperationMode, instanceParameters.FunctionCandleInterval); // Add the function params to the functionsDictionary AddToFunctionsDictionary(FunctionType.SMA_Long, smaLongFunctionParamsDTO); } // Create ADX function parameters if (instanceParameters.InstanceFunctions.Contains(FunctionType.ADX)) { throw new NotImplementedException("Creating parameters for ADX function is not yet implemented"); // Add the function params to the functionsDictionary //AddToFunctionsDictionary(FunctionType.ADX, adxFunctionParamsDTO); } // Create MACD function parameters if (instanceParameters.InstanceFunctions.Contains(FunctionType.MACD)) { throw new NotImplementedException("Creating parameters for MACD function is not yet implemented"); // Add the function params to the functionsDictionary //AddToFunctionsDictionary(FunctionType.MACD, macdFunctionParamsDTO); } // Build Algo Metadata return(GetAlgoMetaDataBuilder() .CreateAlgoMetaData() .WithAlgoParams(algoParamsDTO) .WithFunction(smaShortFunctionParamsDTO, FunctionType.SMA_Short) .WithFunction(smaLongFunctionParamsDTO, FunctionType.SMA_Long) .WithFunction(adxFunctionParamsDTO, FunctionType.ADX) .WithFunction(macdFunctionParamsDTO, FunctionType.MACD) .Build()); }
public static InstanceDataDTO BuildInstanceData(AlgoDataDTO algoData, WalletDTO walletDTO, AlgoInstanceType instanceType, InstanceParameters instanceParameters, DaysOffsetDTO daysOffsetDTO, string instanceName = null) { AlgoMetaDataInformation algoMetaDataInformation = BuildAlgoMetaDataInformation(instanceParameters, daysOffsetDTO); if (instanceParameters.UseInvalidAlgoId) { algoData.Id = $"NonExistingAlgoId - {Helpers.GetFullUtcTimestamp()}"; } return(new InstanceDataDTO(algoData, walletDTO, instanceType, algoMetaDataInformation, instanceName)); }
public static InstanceDataDTO BuildInstanceData(AlgoDataDTO algoData, WalletDTO walletDTO, AlgoInstanceType instanceType, InstanceParameters instanceParameters, DaysOffsetDTO daysOffsetDTO, bool withInvalidAlgoId = false, bool withoutMetadaData = false) { AlgoMetaDataInformation algoMetaDataInformation = BuildAlgoMetaDataInformation(instanceParameters, daysOffsetDTO); if (withInvalidAlgoId) { algoData.Id = $"NonExistingAlgoId - {Helpers.GetFullUtcTimestamp()}"; } return(new InstanceDataDTO(algoData, walletDTO, instanceType, algoMetaDataInformation)); }