public MethodResult <OrderStatus> GetOrderStatus(string orderId)
        {
            RateLimit();
            var client  = new RestClient(_baseUrl);
            var request = new RestRequest("/order_status", Method.POST);

            Authenticate(request);
            request.AddParameter("id", orderId);
            var response = client.Execute <BitstampOrderStatusResponse>(request);

            if (response.IsSuccessful)
            {
                var orderStatus = _orderStatusMapper.GetOrderStatus(response.Data.status);
                return(new MethodResult <OrderStatus>()
                {
                    IsSuccessful = true, Data = orderStatus
                });
            }
            else
            {
                var errorMessage = $"GetOrderStatus failed, OrderId:{orderId} remote:{response.ErrorMessage}";
                _logger.LogCritical(errorMessage);
                return(MethodResult <OrderStatus> .Failed(errorMessage));
            }
        }
        private MethodResult <OrderResult> MarketOrder(OrderRequest order)
        {
            RateLimit();
            var tradeType    = order.TradeType == TradeType.Buy ? "buy" : "sell";
            var currencyPair = _currencyMapper.GetPairName(order.CurrencyPair);
            var resource     = $"{tradeType}/market/{currencyPair}/";
            var client       = new RestClient(_baseUrlV2);
            var request      = new RestRequest(resource, Method.POST);

            Authenticate(request);
            request.AddParameter("amount", order.Volume.ToString(_enCulture));
            var response = client.Execute <BitstampOrderResponse>(request);

            if (response.IsSuccessful)
            {
                return(new MethodResult <OrderResult>()
                {
                    IsSuccessful = true, Data = response.Data.Convert()
                });
            }
            else
            {
                var errorMessage = $"MarketOrder failed, Order:{order} remote:{response.ErrorMessage}";
                _logger.LogCritical(errorMessage);
                return(MethodResult <OrderResult> .Failed(errorMessage));
            }
        }
示例#3
0
        public MethodResult <UserTdm> Login(string username, string password)
        {
            return(DbSessionManager.Execute <MethodResult <UserTdm> >((IDbSession sess) => {
                UserTdm u = userWorker.FindByUserName(sess, username);
                if (null == u || String.IsNullOrEmpty(password))
                {
                    return MethodResult <UserTdm> .Failed("用户名或密码错误!");
                }

                if (u.Kind == UserKind.Virtual)
                {
                    return MethodResult <UserTdm> .Failed("账户不存在!");
                }

                if (u.RowState != RowState.Normal ||
                    (u.Locked && u.TimeLocked > DateTime.Now))
                {
                    return MethodResult <UserTdm> .Failed("账户已经被锁定,请稍后再试!");
                }

                password = password.MD5();
                if (password == u.Password)
                {
                    userWorker.SetLoginSuccess(sess, u.Id);
                    return MethodResult <UserTdm> .Successful(u);
                }

                userWorker.SetLoginFailed(sess, u.Id, u.FailCount > WebApp.PasswordFailCount);
                return MethodResult <UserTdm> .Failed("用户名或密码错误!");
            }));
        }
        /// <summary>
        /// Test the method should be in VPN. no China's IP
        ///
        /// Bitstamp does not support stop order
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public MethodResult <OrderResult> MakeANewOrder(OrderRequest order)
        {
            switch (order.OrderType)
            {
            //case OrderType.Stop:
            //    var errorMesage = "Bitstamp does not support 'stop' order";
            //    _logger.LogCritical(errorMesage);
            //    return MethodResult<OrderResult>.Failed(errorMesage);
            case OrderType.Limit:
                return(LimitOrder(order));

            case OrderType.Market:
                return(MarketOrder(order));
            }

            return(MethodResult <OrderResult> .Failed("Argument tradetype is incorrect!"));
        }
示例#5
0
        public MethodResult <OrderStatus> GetOrderStatus(string orderId)
        {
            RateLimit();
            var request = new RestRequest($"/orders/{orderId}", Method.GET);

            AddAuthenticationHeader(request);
            var client   = new RestClient(baseUrl);
            var response = client.Execute <GdaxOrderResponse>(request);

            if (response.IsSuccessful)
            {
                return(new MethodResult <OrderStatus>()
                {
                    IsSuccessful = true, Data = _orderStatusMapper.GetOrderStatus(response.Data.status)
                });
            }
            return(MethodResult <OrderStatus> .Failed(response.ErrorMessage));
        }
示例#6
0
        public MethodResult <OrderResult> MakeANewOrder(OrderRequest order)
        {
            RateLimit();
            var request = new RestRequest("/orders", Method.POST);

            request.AddJsonBody(GdaxOrderRequest.ConvertFrom(order, _currencyMapper));
            AddAuthenticationHeader(request);
            var client = new RestClient(baseUrl);
            //client.Proxy = new WebProxy("127.0.0.1", 8888); for fiddler trace
            var response = client.Execute <GdaxOrderResponse>(request);

            if (response.IsSuccessful)
            {
                var result = new OrderResult();
                return(new MethodResult <OrderResult>()
                {
                    IsSuccessful = true,
                    Data = response.Data.Convert()
                });
            }
            return(MethodResult <OrderResult> .Failed(response.ErrorMessage));
        }