Example #1
0
        private OrderResponse GDAXOrderResponseToOrderResponse(GDAXOrderResponse order, string symbol)
        {
            var orderStatus = order.executed_value > 0 ? OrderStatus.PARTIALLY_FILLED : OrderStatus.NEW;
            var response    = new OrderResponse
            {
                clientOrderId = order.id,
                executedQty   = order.executed_value,
                price         = order.price,
                side          = order.side.Equals("buy") ? TradeType.BUY : TradeType.SELL,
                status        = orderStatus,
                symbol        = symbol,
                time          = _dtHelper.LocalTimetoUnixTimeMilliseconds(order.created_at),
                type          = OrderType.LIMIT
            };

            return(response);
        }
Example #2
0
        /// <summary>
        /// Convert GDAX OrderResponse to TradeResponse
        /// </summary>
        /// <param name="response">GDAX OrderReponse object</param>
        /// <returns>TradeReponse object</returns>
        private TradeResponse GdaxRestOrderResponseToTradeResponse(GDAXOrderResponse response)
        {
            if (response == null)
            {
                TradeResponse nullResponse = null;

                return(nullResponse);
            }

            TradeType tradeType;

            Enum.TryParse(response.side, out tradeType);
            OrderStatus orderStatus;

            Enum.TryParse(response.status, out orderStatus);
            TimeInForce tif;

            Enum.TryParse(response.time_in_force.ToString(), out tif);
            OrderType orderType;

            Enum.TryParse(response.type, out orderType);

            var tradeResponse = new TradeResponse
            {
                clientOrderId = response.id,
                executedQty   = response.filled_size,
                orderId       = 0,
                origQty       = response.size,
                price         = response.price,
                side          = tradeType,
                status        = orderStatus,
                symbol        = response.product_id,
                timeInForce   = tif,
                transactTime  = _dtHelper.LocalToUnixTime(response.created_at.UtcDateTime),
                type          = orderType
            };

            return(tradeResponse);
        }
Example #3
0
        /// <summary>
        /// Place a Trade
        /// </summary>
        /// <param name="tradeParams">TradeParams object</param>
        /// <returns>TradeResponse object</returns>
        public TradeResponse PlaceTrade(TradeParams tradeParams)
        {
            if (_thisExchange == Exchange.BINANCE)
            {
                var response = _bianceRepo.PostTrade(tradeParams).Result;

                return(response);
            }
            else if (_thisExchange == Exchange.GDAX)
            {
                // TODO use new trade api
                if (tradeParams.type == "STOPLOSS")
                {
                    var gdaxParams = new GDAXStopLossParams
                    {
                        stop       = "loss",
                        stop_price = tradeParams.price,
                        price      = tradeParams.price,
                        product_id = tradeParams.symbol,
                        side       = tradeParams.side.ToLower(),
                        size       = tradeParams.quantity,
                        post_only  = true
                    };
                    GDAXOrderResponse response = _gdaxRepo.PlaceStopLimit(gdaxParams).Result;

                    return(GdaxRestOrderResponseToTradeResponse(response));
                }
                else
                {
                    var gdaxParams = new GDAXTradeParams
                    {
                        price      = tradeParams.price,
                        product_id = tradeParams.symbol,
                        side       = tradeParams.side.ToLower(),
                        size       = tradeParams.quantity,
                        type       = "limit",
                        post_only  = true
                    };
                    GDAXOrderResponse response = _gdaxRepo.PlaceRestTrade(gdaxParams).Result;

                    return(GdaxRestOrderResponseToTradeResponse(response));
                }
            }
            else if (_thisExchange == Exchange.KUCOIN)
            {
                var response = _kuRepo.PostTrade(tradeParams).Result;

                if (response.msg.Equals("Operation succeeded.") || response.msg.Equals("OK"))
                {
                    var tradeResponse = new TradeResponse
                    {
                        clientOrderId = response.data["orderOid"],
                        origQty       = tradeParams.quantity,
                        price         = tradeParams.price,
                        side          = (TradeType)Enum.Parse(typeof(TradeType), tradeParams.side),
                        symbol        = tradeParams.symbol,
                        type          = (OrderType)Enum.Parse(typeof(OrderType), tradeParams.type)
                    };
                    return(tradeResponse);
                }
                return(null);
            }
            else
            {
                return(null);
            }
        }