public void Setup() { var param = new List <ExchangeParameter> { new ExchangeParameter(ParameterMethod.Post, "symbol", StandardParameter.Pair, "BTCUSD"), new ExchangeParameter(ParameterMethod.Url, "pair", StandardParameter.Pair), new ExchangeParameter(ParameterMethod.QueryString, "price", StandardParameter.Price), new ExchangeParameter(ParameterMethod.Post, "exchange", StandardParameter.None, "bitfinex"), new ExchangeParameter(ParameterMethod.QueryString, "type", StandardParameter.None, "exchange limit"), new ExchangeParameter(ParameterMethod.Url, "side", StandardParameter.None, "sell") }; var values = new Dictionary <StandardParameter, string> { { StandardParameter.Price, "100.00" } }; _command = new LimitOrderCommand( Method.POST, new Uri("/v1/order/new/{pair}/{side}", UriKind.Relative), true, typeof(object), param); _pair = new TradingPair(Currency.LTC, Currency.BTC); _toTest = RequestFactory.GetRequest(_command, _pair, values); }
private void VerifyExchangeCommand(ExchangeCommand command) { Assert.NotNull(command); Assert.NotNull(command.ApiResultSubType); Assert.NotNull(command.IntermediateType); Assert.NotNull(command.Parameters); Assert.NotNull(command.RelativeUri); Assert.IsTrue(command.ReturnsValueType || command.IntermediateType != null); }
public async Task <ExchangeResult> ExecuteAsync(ExchangeCommand cmd) { BlockchainType network = await _assetSettingsService.GetNetworkAsync(cmd.SourceAssetId); if (await _assetSettingsService.GetNetworkAsync(cmd.DestAssetId) != network) { throw new ExchangeOperationNotSupportedException("Assets are being served by different blockchains"); } IAssetPairRate rate = await _assetRatesService.GetCurrentRateAsync(cmd.SourceAssetId, cmd.DestAssetId); if (cmd.ExpectedRate != null && rate.BidPrice != cmd.ExpectedRate) { throw new ExchangeRateChangedException(rate.BidPrice); } string hotwallet = _bcnSettingsResolver.GetExchangeHotWallet(network); string sourceAddress = await GetSourceAddressAsync(cmd); decimal exchangeAmount = cmd.SourceAmount * rate.BidPrice; await _walletBalanceValidator.ValidateTransfer(sourceAddress, cmd.SourceAssetId, cmd.SourceAmount); await _walletBalanceValidator.ValidateTransfer(hotwallet, cmd.DestAssetId, exchangeAmount); TransferResult toHotWallet = await _retryPolicy .ExecuteAsync(() => _transferService.ExchangeThrowFail( cmd.SourceAssetId, sourceAddress, hotwallet, cmd.SourceAmount)); await RegisterTransferTxsAsync(toHotWallet); string destAddress = await GetDestAddressAsync(cmd); TransferResult fromHotWallet = await _retryPolicy .ExecuteAsync(() => _transferService.ExchangeThrowFail( cmd.DestAssetId, hotwallet, destAddress, exchangeAmount)); await RegisterTransferTxsAsync(fromHotWallet, false); return(new ExchangeResult { SourceAssetId = cmd.SourceAssetId, SourceAmount = cmd.SourceAmount, DestAssetId = cmd.DestAssetId, DestAmount = exchangeAmount, Rate = rate.BidPrice }); }
private async Task <IMerchantWallet> GetExchangeWalletAsync(ExchangeCommand cmd, PaymentDirection paymentDirection) { string merchantWalletId = cmd.GetWalletId(paymentDirection); string assetId = cmd.GetAssetId(paymentDirection); return(string.IsNullOrEmpty(merchantWalletId) ? await _merchantWalletService.GetDefaultAsync(cmd.MerchantId, assetId, paymentDirection) : await _merchantWalletService.GetByIdAsync(merchantWalletId)); }
private async Task <string> GetDestAddressAsync(ExchangeCommand cmd) { IMerchantWallet merchantWallet = await GetExchangeWalletAsync(cmd, PaymentDirection.Incoming); if (merchantWallet.MerchantId != cmd.MerchantId) { throw new MerchantWalletOwnershipException(cmd.MerchantId, merchantWallet.WalletAddress); } return(merchantWallet.WalletAddress); }
private void Exchange(string name, Currency ContributedCurrency, Currency TargetCurrency, decimal amount) { var exchangeCommand = new ExchangeCommand(_executorCommands, name, ContributedCurrency, TargetCurrency, amount); if (!InvalidDataFlag) { if (Account.Instance.SendCommand(exchangeCommand)) { return; } _kernel.Get <DialogWindowPresenter>().SendMessage("Invalid command."); } InvalidDataFlag = false; }
public static string GetWalletId(this ExchangeCommand src, PaymentDirection paymentDirection) { string walletId; switch (paymentDirection) { case PaymentDirection.Outgoing: walletId = src.SourceMerchantWalletId; break; case PaymentDirection.Incoming: walletId = src.DestMerchantWalletId; break; default: throw new Exception("Unexpected payment direction value"); } return(walletId); }
public void ExchangeCommand_ShouldBenItializedCorrectly(string command, ExchangeCommand expected) { var result = new ExchangeCommand(command); Assert.AreEqual(expected, result); }