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 TradeOrderStatusInfo GetOrderStatus(string lUuid) { if (!IsCredentialsSet) { throw new Exception("No Credentials were set"); } using (var lClient = new BitfinexClient()) { var lResponse = lClient.GetOrderAsync(Convert.ToInt64(lUuid)).Result; if (!lResponse.Success) { throw new Exception($"Failed to retrieve order status. Id: {lUuid}"); } return(new TradeOrderStatusInfo { ID = lUuid, Completed = lResponse.Data.RemainingAmount == 0, Cancelled = lResponse.Data.Canceled, Rate = lResponse.Data.Price }); } }