public void CancelOrder(UserTradeOrder aOrder, bool aUseProxy = true)
        {
            if (!IsCredentialsSet)
            {
                throw new Exception("No Credentials were set");
            }

            if (aOrder == null)
            {
                throw new ArgumentNullException(nameof(aOrder), "Invalid argument: " + nameof(aOrder));
            }

            BittrexClientOptions lBittrexClientOptions = new BittrexClientOptions()
            {
                Proxy          = PandoraProxy.GetApiProxy(),
                ApiCredentials = new ApiCredentials(FUserCredentials.Item1, FUserCredentials.Item2)
            };

            using (BittrexClient lClient = aUseProxy ? new BittrexClient(lBittrexClientOptions) : new BittrexClient())
            {
                var lResponse = lClient.CancelOrderAsync(aOrder.ID).Result;
                if (!lResponse.Success)
                {
                    throw new Exception("Failed to cancel order in exchange. Message: " + lResponse.Error.Message);
                }
            }
        }
Example #2
0
        public bool RefundOrder(UserTradeOrder aOrder, string aAddress, bool aUseProxy = true)
        {
            if (!IsCredentialsSet)
            {
                throw new Exception("No Credentials were set");
            }

            if (aOrder.Status == OrderStatus.Withdrawn)
            {
                return(false);
            }

            BitfinexClientOptions lBittrexClientOptions = new BitfinexClientOptions()
            {
                Proxy          = PandoraProxy.GetApiProxy(),
                ApiCredentials = new ApiCredentials(FUserCredentials.Item1, FUserCredentials.Item2)
            };

            using (BitfinexClient lClient = aUseProxy ? new BitfinexClient(lBittrexClientOptions) : new BitfinexClient())
            {
                var lResponse = lClient.WithdrawAsync(aOrder.Market.SellingCurrencyInfo.Name.ToLowerInvariant(), WithdrawWallet.Exchange, aOrder.SentQuantity, aAddress).Result;
                if (!lResponse.Success)
                {
                    throw new Exception("Failed to withdraw. Error message:" + lResponse.Error.Message);
                }
            }

            return(true);
        }
Example #3
0
        public void CancelOrder(UserTradeOrder aOrder, bool aUseProxy = true)
        {
            if (!IsCredentialsSet)
            {
                throw new Exception("No Credentials were set");
            }

            if (aOrder == null)
            {
                throw new ArgumentNullException(nameof(aOrder), "Invalid argument: " + nameof(aOrder));
            }

            PoloniexClientOptions lPoloniexClientOptions = new PoloniexClientOptions()
            {
                Proxy          = PandoraProxy.GetApiProxy(),
                ApiCredentials = new ApiCredentials(FUserCredentials.Item1, FUserCredentials.Item2)
            };

            using (PoloniexClient lClient = aUseProxy ? new PoloniexClient(lPoloniexClientOptions) : new PoloniexClient())
            {
                var lResponse = lClient.CancelOrder(Convert.ToInt64(aOrder.ID));
                if (!lResponse.Success || !Convert.ToBoolean(lResponse.Data.success))
                {
                    throw new Exception($"Failed to cancel order in exchange. Message: {lResponse.Data?.message ?? lResponse.Error.Message}");
                }
            }
        }
Example #4
0
        public bool RefundOrder(UserTradeOrder aOrder, string aAddress, bool aUseProxy = true)
        {
            if (!IsCredentialsSet)
            {
                throw new Exception("No Credentials were set");
            }

            if (aOrder.Status == OrderStatus.Withdrawn)
            {
                return(false);
            }

            PoloniexClientOptions lPoloniexClientOptions = new PoloniexClientOptions()
            {
                Proxy          = PandoraProxy.GetApiProxy(),
                ApiCredentials = new ApiCredentials(FUserCredentials.Item1, FUserCredentials.Item2)
            };

            using (PoloniexClient lClient = aUseProxy ? new PoloniexClient(lPoloniexClientOptions) : new PoloniexClient())
            {
                var lResponse = lClient.Withdraw(aOrder.Market.SellingCurrencyInfo.Ticker, aOrder.SentQuantity, aAddress);
                if (!lResponse.Success)
                {
                    throw new Exception("Failed to refund order. Error message:" + lResponse.Error.Message);
                }
                if (!string.IsNullOrEmpty(lResponse.Data.error))
                {
                    throw new Exception($"Failed to refund order. Error message: {lResponse.Data.error}");
                }
            }

            return(true);
        }
Example #5
0
        public bool PlaceOrder(UserTradeOrder aOrder, bool aUseProxy = true)
        {
            if (!IsCredentialsSet)
            {
                throw new Exception("No Credentials were set");
            }

            if (aOrder == null || aOrder.Market == null)
            {
                throw new ArgumentNullException(aOrder == null ? nameof(aOrder) : nameof(aOrder.Market), "Invalid argument: " + aOrder == null ? nameof(aOrder) : nameof(aOrder.Market));
            }

            if (aOrder.Status != OrderStatus.Waiting)
            {
                return(false);
            }

            BitfinexClientOptions lBitfinexClientOptions = new BitfinexClientOptions()
            {
                Proxy          = PandoraProxy.GetApiProxy(),
                ApiCredentials = new ApiCredentials(FUserCredentials.Item1, FUserCredentials.Item2)
            };

            using (BitfinexClient lClient = aUseProxy ? new BitfinexClient(lBitfinexClientOptions) : new BitfinexClient())
            {
                if (!aOrder.Market.TryCastToLocalMarket(out ExchangeMarket lExchangeMarket))
                {
                    throw new ArgumentException(nameof(aOrder.Market), "Invalid Market");
                }
                var lResponse = lClient.PlaceOrderAsync(lExchangeMarket.MarketPairID, lExchangeMarket.MarketDirection == MarketDirection.Sell ? OrderSide.Sell : OrderSide.Buy, OrderType.ExchangeLimit, lExchangeMarket.MarketDirection == MarketDirection.Sell ? aOrder.SentQuantity : aOrder.SentQuantity / aOrder.Rate, aOrder.Rate).Result;
                if (!lResponse.Success)
                {
                    throw new Exception($"Bitfinex Error. Message: {lResponse.Error.Message}");
                }
                long lUuid = lResponse.Data.Id;

                var lVerifyResponse = lClient.GetOrderAsync(lUuid).Result;
                if (!lResponse.Success)
                {
                    throw new Exception("Failed to verify order with exchange server");
                }
                aOrder.ID        = lUuid.ToString();
                aOrder.OpenTime  = lVerifyResponse.Data.Timestamp;
                aOrder.Cancelled = lVerifyResponse.Data.Canceled;
                aOrder.Completed = lVerifyResponse.Data.RemainingAmount == 0;
            }

            return(true);
        }
        public bool PlaceOrder(UserTradeOrder aOrder, bool aUseProxy = true)
        {
            if (!IsCredentialsSet)
            {
                throw new Exception("No Credentials were set");
            }

            if (aOrder == null)
            {
                throw new ArgumentNullException(nameof(aOrder), $"Invalid order{aOrder.ID}");
            }

            if (aOrder.Status != OrderStatus.Waiting)
            {
                return(false);
            }

            BittrexClientOptions lBittrexClientOptions = new BittrexClientOptions()
            {
                Proxy          = PandoraProxy.GetApiProxy(),
                ApiCredentials = new ApiCredentials(FUserCredentials.Item1, FUserCredentials.Item2)
            };

            using (BittrexClient lClient = aUseProxy ? new BittrexClient(lBittrexClientOptions) : new BittrexClient())
            {
                if (!aOrder.Market.TryCastToLocalMarket(out ExchangeMarket lExchangeMarket))
                {
                    throw new ArgumentException(nameof(aOrder.Market), "Invalid Market");
                }
                CallResult <BittrexOrder> lResponse;
                if (aOrder.Market.MarketDirection == MarketDirection.Sell)
                {
                    lResponse = lClient.PlaceOrderAsync(lExchangeMarket.MarketPairID, OrderSide.Sell, OrderType.Limit, TimeInForce.GoodTillCancelled, aOrder.SentQuantity, limit: aOrder.Rate).Result;
                }
                else
                {
                    lResponse = lClient.PlaceOrderAsync(lExchangeMarket.MarketPairID, OrderSide.Buy, OrderType.Limit, TimeInForce.GoodTillCancelled, aOrder.SentQuantity / aOrder.Rate, limit: aOrder.Rate).Result;
                }
                if (!lResponse.Success)
                {
                    throw new Exception("Bittrex Error. Message: " + lResponse.Error.Message);
                }

                string lUuid = lResponse.Data.Id;
                CallResult <BittrexOrder> lResponse2 = lClient.GetOrderAsync(lUuid).Result;
                if (!lResponse.Success)
                {
                    throw new Exception("Failed to verify order with server");
                }

                BittrexOrder lReceivedOrder = lResponse2.Data;

                aOrder.ID = lUuid;

                aOrder.OpenTime  = lReceivedOrder.CreatedAt;
                aOrder.Cancelled = lReceivedOrder.OrderToCancel != null;
                aOrder.Completed = lReceivedOrder.ClosedAt.HasValue;

                return(true);
            }
        }