Esempio n. 1
0
        /// <summary>
        /// 购买
        /// </summary>
        /// <param name="_vol">数量</param>
        /// <param name="_price">价格</param>
        /// <returns></returns>
        protected bool Buy(int _vol, double _price, bool beIsMust = false)
        {
            try
            {
                double limit = _price;
                if (limit > upLimitPrice)
                {
                    limit = upLimitPrice;
                }
                if (limit < lowLimitPrice)
                {
                    limit = lowLimitPrice;
                }

                string             orderId = ProduceOrderID.GetOrderID(EnumBuySellType.购买); //订单ID
                request_OrderLimit ol      = SYRequest.QureyBuy(userId, coinSymbol, _vol + "", limit + "", orderId);
                if (ol != null)
                {
                    Print("订单【买入】成功!商品编号:" + coinSymbol + ", 数量:" + _vol + ", 价格:" + limit + ", 订单号:" + orderId);
                    if (beIsMust == false)
                    {
                        orderLimitBuys.Add(ol);
                    }
                    return(true);
                }
                return(false);
            } catch
            {
                return(false);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 转让
 /// </summary>
 /// <param name="_vol">数量</param>
 /// <param name="_price">价格</param>
 /// <returns></returns>
 protected bool Sell(long _vol, double _price, bool beIsMust = false)
 {
     try
     {
         if (position == null)
         {
             position = SYRequest.QureyPosition(userId, coinSymbol);
             if (position == null)
             {
                 Print("转卖仓位不足,无法进行转卖。");
                 return(false);
             }
         }
         if (position.balance <= 0)
         {
             position = SYRequest.QureyPosition(userId, coinSymbol);
             if (position.balance == 0)
             {
                 Print("转卖仓位不足,无法进行转卖。");
                 return(false);
             }
         }
         if (_vol > position.balance)
         {
             Print("转卖数量大于实际持有量,已按实际拥有数量专卖。");
             _vol = (long)position.balance;
         }
         double limit = _price;
         if (limit < lowLimitPrice)
         {
             limit = lowLimitPrice;
         }
         if (limit > upLimitPrice)
         {
             limit = upLimitPrice;
         }
         string             orderId = ProduceOrderID.GetOrderID(EnumBuySellType.转让); //订单ID
         request_OrderLimit ol      = SYRequest.QureySell(userId, coinSymbol, _vol + "", limit + "", orderId);
         if (ol != null)
         {
             position.balance -= _vol;
             Print("订单【转卖】成功!商品编号:" + coinSymbol + ", 数量:" + _vol + ", 价格:" + limit + ", 订单号:" + orderId);
             if (beIsMust == false)
             {
                 orderLimitSells.Add(ol);
             }
             return(true);
         }
         return(false);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 请求卖出
        /// </summary>
        /// <param name="_userId">用户ID</param>
        /// <param name="_symbol">产品编号</param>
        /// <param name="_vol">数量</param>
        /// <param name="_price">价格</param>
        /// <returns>返回报单信息---Json 格式</returns>
        public static request_OrderLimit QureySell(long _userId, string _coinSymbol, string _vol, string _price, string orderId = "")
        {
            string URL = "exchange/order/trade";

            try
            {
                request_OrderLimit orderLimit = new request_OrderLimit();
                orderLimit.baseSymbol      = "CNY";
                orderLimit.coinSymbol      = _coinSymbol;
                orderLimit.symbol          = _coinSymbol + "/CNY";
                orderLimit.direction       = request_OrderLimit.direction_SELL;        //卖出
                orderLimit.type            = request_OrderLimit.type_LIMIT;            //限价
                orderLimit.orderCate       = request_OrderLimit.orderCate_TRADE;       //交易
                orderLimit.orderMemberType = request_OrderLimit.orderMemberType_ROBOT; //机器人
                if (orderId == "")
                {
                    orderLimit.orderId = ProduceOrderID.GetOrderID(EnumBuySellType.转让); //订单ID
                }
                else
                {
                    orderLimit.orderId = orderId;
                }
                orderLimit.memberId = _userId;     //用户ID
                orderLimit.price    = _price;      //价格
                orderLimit.amount   = _vol;        //数量

                var         jsonReq = JsonConvert.SerializeObject(orderLimit);
                RestRequest r       = new RestRequest(URL, Method.POST);
                r.AddParameter("application/json", jsonReq, ParameterType.RequestBody);
                IRestResponse restResponse = HttpRestQurey(r);
                if (restResponse == null)
                {
                    return(null);
                }

                string         json = restResponse.Content;
                response_Order rol  = JsonConvert.DeserializeObject <response_Order>(json);

                if (rol != null && rol.code == 0)
                {
                    return(orderLimit);
                }
                return(null);
            }catch
            {
                return(null);
            }
        }