Пример #1
0
        public GetAccountHoldsResponse(ExchangeResponse response) : base(response)
        {
            var json   = response.ContentBody;
            var jArray = JArray.Parse(json);

            AccountHolds = jArray.Select(elem => new AccountHold(elem)).ToList();
        }
Пример #2
0
        public GetProductsResponse(ExchangeResponse response) : base(response)
        {
            var json   = response.ContentBody;
            var jArray = JArray.Parse(json);

            Products = jArray.Select(elem => new Product(elem)).ToList();
        }
Пример #3
0
        public async Task<ExchangeResponse> ExchangeMoney(ExchangeRequest exchangeReq)
        {


            var rate = await _ratesService.
                GetExchangeRateAsync(exchangeReq.FromCurrency, exchangeReq.ToCurrency);

            var exchanged = CalculateExchangeAmount(exchangeReq, rate);

            var exchange = new Exchange()
            {
                Id = Guid.NewGuid(),
                FromCurrency = exchanged.FromCurrency,
                ToCurrency = exchanged.ToCurrency,
                FromAmount = exchanged.FromAmount,
                ToAmount = exchanged.ToAmount,
                Date = DateTime.Now
            };

            Save(exchange);

            var resp = new ExchangeResponse()
            {
                FromCurrency = exchanged.FromCurrency,
                ToCurrency = exchanged.ToCurrency,
                FromAmount = exchanged.FromAmount,
                ToAmount = exchanged.ToAmount,
                ToCurrencyRate = exchanged.ToCurrencyRate
            };


            return resp;
        }
        public ActionResult <Exchange> GetExchange(string from, string to, decimal amount)
        {
            if (!String.IsNullOrEmpty(from) && !String.IsNullOrEmpty(to))
            {
                if (amount > 0)
                {
                    ExchangeResponse r = new ExchangeResponse();
                    var exchangeInfo   = _context.Exchanges.SingleOrDefault(x => x.from == from && x.to == to && x.isActive);

                    if (exchangeInfo != null)
                    {
                        r = FormatterResponse.getInfoResponse(from, to, amount, exchangeInfo);
                    }
                    else
                    {
                        return(BadRequest(new { message = "There is not info with those money codes" }));
                    }
                    return(Ok(r));
                }
                else
                {
                    return(BadRequest(new { message = "please enter a valid amount" }));
                }
            }
            else
            {
                return(BadRequest(new { message = "the money codes are invalid" }));
            }
        }
Пример #5
0
        public GetFillsResponse(ExchangeResponse response) : base(response)
        {
            var json   = response.ContentBody;
            var jArray = JArray.Parse(json);

            this.Fills = jArray.Select(elem => new Fill(elem)).ToList();
        }
Пример #6
0
        public GetAccountHistoryResponse(ExchangeResponse response) : base(response)
        {
            var json   = response.ContentBody;
            var jArray = JArray.Parse(json);

            this.AccountHistoryRecords = jArray.Select(AccountHistory.FromJToken).ToList();
        }
        public IActionResult GetMoneyPriceAndValue([FromBody] Exchange exchangeInput)
        {
            if (!String.IsNullOrEmpty(exchangeInput.from) && !String.IsNullOrEmpty(exchangeInput.to))
            {
                if (exchangeInput.amount > 0)
                {
                    ExchangeResponse r = new ExchangeResponse();
                    var exchangeInfo   = _context.Exchanges.SingleOrDefault(x => x.from == exchangeInput.from && x.to == exchangeInput.to && x.isActive);

                    if (exchangeInfo != null)
                    {
                        r = FormatterResponse.getInfoResponse(exchangeInput, exchangeInfo);
                    }
                    else
                    {
                        return(BadRequest(new { message = "There is not info with those money codes" }));
                    }
                    return(Ok(r));
                }
                else
                {
                    return(BadRequest(new { message = "please enter a valid amount" }));
                }
            }
            else
            {
                return(BadRequest(new { message = "the money codes are invalid" }));
            }
        }
Пример #8
0
        public GetCurrenciesResponse(ExchangeResponse response) : base(response)
        {
            var json   = response.ContentBody;
            var jArray = JArray.Parse(json);

            Currencies = jArray.Select(elem => new GDAX_Currency(elem)).ToList();
        }
Пример #9
0
 public SubmitPersonalOrderResponse(ExchangeResponse response, SubmitPersonalOrderRequest request) : base(response)
 {
     if (response.ErrorMessage != null)
     {
         Message = response.ErrorMessage;
     }
     else
     {
         var json = response.ContentBody;
         try
         {
             var jToken = JToken.Parse(json);
             //{"message":"Insufficient funds"}
             var msgToken = jToken["message"];
             if (msgToken != null)
             {
                 Message = "SubmitPersonalOrderResponse: " + msgToken.Value <string>() + ", request: " + request.RequestUrl;
             }
             else
             {
                 SubmittedOrder = new PersonalOrder(jToken);
             }
         }
         catch (Newtonsoft.Json.JsonReaderException e)
         {
             Message = "Error w/ SubmitPersonalOrderResponse() " + e.Message + ": " + json;
         }
     }
 }
Пример #10
0
        public async Task <decimal> GetRealtimePrice(string product)
        {
            if (String.IsNullOrWhiteSpace(product))
            {
                throw new ArgumentNullException("product");
            }

            TickerRequest tickerRequest = new TickerRequest(product);

            ExchangeResponse response = null;

            try
            {
                response = await this.GetResponse(tickerRequest);
            }
            catch (Exception)
            {
                throw new Exception("RealTimePriceError");
            }

            decimal price = 0;

            if (response.IsSuccessStatusCode)
            {
                var jToken     = JObject.Parse(response.ContentBody);
                var tokenPrice = jToken["price"];
                if (tokenPrice == null)
                {
                    return(price);
                }
                price = tokenPrice.Value <decimal>();
            }

            return(price);
        }
Пример #11
0
        private static async Task <double> ExchangeRateFromTo(string From, string To)
        {
            HttpClient          client   = new HttpClient();
            HttpResponseMessage response = await client.GetAsync(string.Format(APIURL, Uri.EscapeDataString(From)));

            ExchangeResponse ExchangeResponse = JsonConvert.DeserializeObject <ExchangeResponse>(await response.Content.ReadAsStringAsync());

            return(ExchangeResponse.rates[To]);
        }
Пример #12
0
        public FillResponse(ExchangeResponse response) : base(response)
        {
            if (!response.IsSuccessStatusCode)
            {
                throw new Exception("FillRequestError");
            }

            var json   = response.ContentBody;
            var jArray = JArray.Parse(json);

            Fills = jArray.Select(elem => new Fill(elem)).ToList();
        }
Пример #13
0
        public GetProductOrderBookResponse(ExchangeResponse response) : base(response)
        {
            var json    = response.ContentBody;
            var jObject = JObject.Parse(json);

            var bids = jObject["bids"].Select(x => (JArray)x).ToArray();
            var asks = jObject["asks"].Select(x => (JArray)x).ToArray();

            Sequence = jObject["sequence"].Value <Int64>();

            Sells = asks.Select(a => GetBidAskOrderFromJToken(a)).ToList();
            Buys  = bids.Select(b => GetBidAskOrderFromJToken(b)).ToList();
        }
        public GetPersonalOrdersResponse(ExchangeResponse response) : base(response)
        {
            var json  = response.ContentBody;
            var token = JToken.Parse(json);

            if (token is JArray)
            {
                PersonalOrders = token.Select(elem => new PersonalOrder(elem)).ToList();
            }
            else if (token is JObject)
            {
                this.Message = "GetPersonalOrdersResponse: " + token["message"].Value <string>();
            }
        }
Пример #15
0
        public IHttpActionResult Exchange(string from, string to, double?amount)
        {
            if (String.IsNullOrWhiteSpace(from) || String.IsNullOrWhiteSpace(to) || !amount.HasValue)
            {
                return(BadRequest("Invalid parameters."));
            }

            if (amount < 0)
            {
                return(BadRequest("Amount must be a positive number."));
            }

            var exchange = new ExchangeRequest()
            {
                From   = from,
                To     = to,
                Amount = amount.Value
            };

            var FromCurrency = _currencies
                               .Where(curr => curr.Code.Equals(exchange.From))
                               .SingleOrDefault();

            if (FromCurrency == null)
            {
                return(BadRequest($"Unknown currency: {exchange.From}"));
            }

            var ToCurrency = _currencies
                             .Where(curr => curr.Code.Equals(exchange.To))
                             .SingleOrDefault();

            if (ToCurrency == null)
            {
                return(BadRequest($"Unknown currency: {exchange.To}"));
            }



            var exchangeResponse = new ExchangeResponse()
            {
                Request = exchange
            };

            exchangeResponse.Ratio  = FromCurrency.Rate / ToCurrency.Rate;
            exchangeResponse.Result = exchangeResponse.Ratio * exchange.Amount;

            return(Ok(exchangeResponse));
        }
Пример #16
0
        public CancelAllPersonalOrdersResponse(ExchangeResponse response) : base(response)
        {
            // + use response.IsSuccessStatusCode;
            var json  = response.ContentBody;
            var token = JToken.Parse(json);

            if (token is JArray)
            {
                DeletedOrderIDs = token.Select(elem => (Guid)elem).ToList();
            }
            else if (token is JObject)
            {
                this.Message = "CancelAllPersonalOrdersResponse: " + token["message"].Value <string>();
            }
        }
Пример #17
0
        private ExchangeResponse CalculateExchangeAmount(ExchangeRequest req, decimal rate)
        {
            var resAmount = Math.Round(req.FromAmount * rate, 5);

            var resp = new ExchangeResponse()
            {
                FromAmount = req.FromAmount,
                FromCurrency = req.FromCurrency,
                ToCurrency = req.ToCurrency,
                ToCurrencyRate = Math.Round(rate, 5),
                ToAmount = resAmount
            };

            return resp;
        }
        public SubmitPersonalOrderResponse(ExchangeResponse response) : base(response)
        {
            var json   = response.ContentBody;
            var jToken = JToken.Parse(json);

            //{"message":"Insufficient funds"}
            var msgToken = jToken["message"];

            if (msgToken != null)
            {
                Message = "SubmitPersonalOrderResponse: " + msgToken.Value <string>();
            }
            else
            {
                SubmittedOrder = new PersonalOrder(jToken);
            }
        }
Пример #19
0
        public GetPersonalOrderResponse(ExchangeResponse response) : base(response)
        {
            this.ContentBody = response.ContentBody;
            var jToken = JToken.Parse(ContentBody);

            //{"message":"NotFound"}
            var msgToken = jToken["message"];

            if (msgToken != null)
            {
                Message = "GetPersonalOrderResponse: " + msgToken.Value <string>();
            }
            else
            {
                FoundOrder = new PersonalOrder(jToken);
            }
        }
Пример #20
0
        public async Task <List <String> > CancelAllOrders()
        {
            MyDeleteOrdersRequest request = new MyDeleteOrdersRequest("/orders");

            ExchangeResponse genericResponse = null;

            try
            {
                genericResponse = await this.GetResponse(request);
            }
            catch (Exception)
            {
                throw new Exception("CancelAllOrderError");
            }


            List <string> cancelledOrderList = new List <string>();

            if (genericResponse.IsSuccessStatusCode)
            {
                var json        = genericResponse.ContentBody;
                var orders_jArr = JArray.Parse(json).ToArray <JToken>();

                foreach (var obj in orders_jArr)
                {
                    cancelledOrderList.Add(obj.Value <string>());
                }
            }
            else
            {
                if (genericResponse.StatusCode == System.Net.HttpStatusCode.Forbidden)
                {
                    Logger.WriteLog("cancel order permissions denied");
                    throw new Exception("PermissionDenied");
                }
                else
                {
                    Logger.WriteLog("cancel order error: " + genericResponse.ContentBody);
                    throw new Exception("CancelOrderError");
                }
            }

            return(cancelledOrderList);
        }
Пример #21
0
        public async Task <GetAccountHoldsResponse> GetAccountHolds(string accountId)
        {
            var request = new GetAccountHoldsRequest(accountId);

            ExchangeResponse response = null;

            try
            {
                response = await this.GetResponse(request);
            }
            catch (Exception)
            {
                throw new Exception("GetAcHoldsError");
            }

            var accountHoldsResponse = new GetAccountHoldsResponse(response);

            return(accountHoldsResponse);
        }
Пример #22
0
        public async Task <GetProductOrderBookResponse> GetProductOrderBook(string productId, int level = 1)
        {
            var request = new GetProductOrderBookRequest(productId, level);

            ExchangeResponse response = null;

            try
            {
                response = await this.GetResponse(request);
            }
            catch (Exception)
            {
                throw new Exception("GetProductOrderBookError");
            }

            var orderBookResponse = new GetProductOrderBookResponse(response);

            return(orderBookResponse);
        }
Пример #23
0
        public async Task <List <Order> > GetAllOpenOrders(string endpoint)
        {
            var requestEndPoint = string.Format(endpoint);

            ExchangeResponse genericResponse = null;

            try
            {
                genericResponse = await this.GetResponse(new MyGetOrdersRequest(requestEndPoint));
            }
            catch (Exception)
            {
                throw new Exception("GetOpenOrderError");
            }

            var json      = genericResponse.ContentBody;
            var allOrders = GetOrderListFromJson(json);

            return(allOrders);
        }
Пример #24
0
        public async Task <FillResponse> GetFills()
        {
            var endpoint = String.Format("/fills");
            var request  = new GetFillsRequest(endpoint);

            ExchangeResponse response = null;

            try
            {
                response = await this.GetResponse(request);
            }
            catch (Exception)
            {
                throw new Exception("GetFillsError");
            }

            var accountHistoryResponse = new FillResponse(response);

            return(accountHistoryResponse);
        }
Пример #25
0
        public HttpResponseMessage Post(ExchangeRequest request)
        {
            if (ModelState.IsValid)
            {
                if (request == null)
                {
                    request = new ExchangeRequest();
                    request.CurrencyCode = "USD";
                    request.Amount       = 1.0;
                }
                Exchange objExchange = this.objExchangeRepository.GetExchangeRate(request);

                ExchangeResponse objExchangeResponse = new ExchangeResponse();
                try
                {
                    if (objExchange != null)
                    {
                        objExchangeResponse.SourceCurrency = objExchange.SourceCurrency;
                        objExchangeResponse.ConversionRate = Math.Round(objExchange.ConversionRate, 2);
                        objExchangeResponse.Amount         = request.Amount;
                        objExchangeResponse.Total          = Math.Round(objExchange.ConversionRate, 2) * request.Amount;
                        objExchangeResponse.TimeStamp      = objExchange.TimeStamp;
                        objExchangeResponse.ReturnCode     = "1";
                        objExchangeResponse.Error          = "Success";
                        return(Request.CreateResponse(System.Net.HttpStatusCode.OK, objExchangeResponse));;
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotFound, "Requested currency code does not found"));
                    }
                }
                catch (Exception ex)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, ex.Message));
                }
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
Пример #26
0
        public async Task <Order> PlaceOrder(JObject messageBody)
        {
            var orderEndpoint = string.Format(@"/orders");

            MyPostOrdersRequest request = new MyPostOrdersRequest(orderEndpoint, messageBody);

            ExchangeResponse genericResponse = null;

            try
            {
                genericResponse = await this.GetResponse(request);
            }
            catch (Exception)
            {
                throw new Exception("PlaceOrderError");
            }


            Order newOrderDetails = null;

            if (genericResponse.IsSuccessStatusCode)
            {
                try
                {
                    newOrderDetails = JsonConvert.DeserializeObject <Order>(genericResponse.ContentBody);
                }
                catch (Exception)
                {
                    throw new Exception("JsonParseError");
                }
            }
            else
            {
                Logger.WriteLog("OrderPlacer Error: " + genericResponse.ContentBody);
                throw new Exception("OrderUnsuccessfullError: " + genericResponse.ContentBody);
            }

            return(newOrderDetails);
        }
Пример #27
0
        public async Task <ListAccountsResponse> ListAccounts(string accountId = null, string cursor = null, long recordCount = 100, RequestPaginationType paginationType = RequestPaginationType.After)
        {
            var request = new ListAccountsRequest(accountId, cursor, recordCount, paginationType);



            ExchangeResponse response = null;

            try
            {
                response = await this.GetResponse(request);
            }
            catch (Exception)
            {
                throw new Exception("ListAccountError");
            }


            var accountResponse = new ListAccountsResponse(response);

            return(accountResponse);
        }
Пример #28
0
        public async Task <FillResponse> GetFillStatus(string orderId)
        {
            var endpoint = string.Format(@"/fills?order_id={0}", orderId);
            var request  = new GetFillsRequest(endpoint);


            ExchangeResponse response = null;

            try
            {
                response = await this.GetResponse(request);
            }
            catch (Exception)
            {
                throw new Exception("GetFillsStatusError");
            }


            var orderStats = new FillResponse(response);

            return(orderStats);
        }
Пример #29
0
        async void start()
        {
            Console.Title = "Fortnite-Exchange made By SirSloth";


            if (!File.Exists(fileName))
            {
                System.Diagnostics.Process.Start(authcodeUrl);
                Console.WriteLine("You need to create a Device.Json in order to keep getting the Exchange");
                Console.Write("Authorization Code: ");
                var input = Console.ReadLine();
                this.aRsp = await this.GetAuthResponse(input, false);
            }
            else
            {
                var file = File.ReadAllText(this.fileName);
                this.devRsp = JsonConvert.DeserializeObject <DeviceResponse>(file);
                this.aRsp   = await this.GetDeviceResponse();
            }

            this.excRsp = await this.GetExchangeCode();

            Console.WriteLine($"Account Name: {this.aRsp.displayName}");
            Console.WriteLine($"Exchange Code: {this.excRsp.code}");
            Clipboard.SetText(this.excRsp.code);


            if (!File.Exists(fileName))
            {
                var rsp = await CreateDevice(await this.GetAuthResponse(this.excRsp.code, true));

                var text = JsonConvert.SerializeObject(rsp);
                File.WriteAllText(this.fileName, text);
                Console.WriteLine("Succesfully written all text to Device.Json\nYou can now generate the exchange token over and over again");
            }
            this.excep("");
        }
Пример #30
0
        /// <summary>
        /// 360礼包
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="packStr"></param>
        /// <param name="exchangeId"></param>
        /// <returns></returns>
        private ExchangeResponse Send360GoodsBay(NbManagerEntity manager, string packStr, string exchangeId, int type)
        {
            var response = new ExchangeResponse();
            var entity   = NbManagercommonpackageMgr.Select(manager.Idx);//公用字段1   为360礼包  字段2为888kkk礼包

            if (entity != null)
            {
                switch (type)
                {
                case 1:
                    var i       = entity.Common1;
                    var common1 = ConvertHelper.ConvertToInt(i);
                    if (common1 >= 1)
                    {
                        response.Code = (int)MessageCode.NbPrizeRepeat;
                        return(response);
                    }
                    else
                    {
                        entity.Common1 = "1";
                    }
                    break;


                case 2:
                    var i2      = entity.Common2;
                    var common2 = ConvertHelper.ConvertToInt(i2);
                    if (common2 >= 1)
                    {
                        response.Code = (int)MessageCode.NbPrizeRepeat;
                        return(response);
                    }
                    else
                    {
                        entity.Common2 = "1";
                    }
                    break;
                }
            }
            var            packId         = ConvertHelper.ConvertToInt(packStr);
            var            package        = ItemCore.Instance.GetPackage(manager.Idx, EnumTransactionType.ExchangeCodePrize);
            int            effectCoin     = 0;
            int            curValue       = 0;
            int            effectPoint    = 0;
            int            bindPoint      = 0;
            ExchangeEntity exchangeEntity = new ExchangeEntity();

            exchangeEntity.PrizeList = new List <ExchangePrizeEntity>();

            response.Code = (int)MallCore.Instance.UseNewPlayerPack(manager.Idx, packId, package, EnumCoinChargeSourceType.Exchange, ref manager, ref effectCoin,
                                                                    ref curValue, ref effectPoint, ref bindPoint, exchangeEntity);
            if (response.Code != (int)MessageCode.Success)
            {
                return(response);
            }
            try
            {
                using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
                {
                    transactionManager.BeginTransaction();
                    response.Code = (int)MessageCode.Exception;


                    if (entity != null)
                    {
                        if (NbManagercommonpackageMgr.Update(entity, transactionManager.TransactionObject))
                        {
                            response.Code = (int)MessageCode.Success;
                        }
                    }
                    if (response.Code == (int)MessageCode.Success)
                    {
                        if (effectCoin > 0)
                        {
                            ManagerUtil.SaveManagerData(manager, null, transactionManager.TransactionObject);
                            ManagerUtil.SaveManagerAfter(manager);
                        }
                        if (package.Save(transactionManager.TransactionObject))
                        {
                            package.Shadow.Save();
                        }
                        else
                        {
                            response.Code = (int)MessageCode.ItemNoShadow;
                        }
                        if (effectPoint > 0)
                        {
                            response.Code = (int)PayCore.Instance.AddBonus(manager.Account, effectPoint,
                                                                           EnumChargeSourceType.ExchangePrize, exchangeId, transactionManager.TransactionObject);
                        }
                    }
                    if (response.Code == (int)MessageCode.Success)
                    {
                        transactionManager.Commit();
                    }
                    else
                    {
                        transactionManager.Rollback();
                    }
                }


                if (response.Code != 0)
                {
                    return(ResponseHelper.Create <ExchangeResponse>(response.Code));
                }
                exchangeEntity.ExchangeType = 1;
                response.Data           = new ExchangeEntity();
                response.Data.PrizeList = new List <ExchangePrizeEntity>();
                response.Data.PrizeList = exchangeEntity.PrizeList;
                response.Code           = 0;

                return(response);
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("SaveItemException", ex);
                return(ResponseHelper.Create <ExchangeResponse>(MessageCode.Exception));
            }



            return(response);
        }