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 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 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);
        }
Example #7
0
        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");
        }
Example #8
0
        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");
        }