Example #1
0
        public override TradeLast GetTradeLastEnd(string parameters, string ticker)
        {
            string response = DoPublicRequest(parameters);

            CheckResponseAndThrow(response);

            dynamic jdata = null;

            try
            {
                jdata = Newtonsoft.Json.JsonConvert.DeserializeObject(response);
            }
            catch (Exception ex)
            { throw new MarketAPIException("Parsing Response Error" + " >>>> " + ex.Message + " ## Response: ## " + response); }

            Pair tickerinfo = new Pair(ticker);

            TradeLast tradelast = new TradeLast();

            foreach (var item in jdata)
            {
                Pair iteminfo = new Pair(item.Name);
                if (tickerinfo.currency1 == iteminfo.currency1 && tickerinfo.currency2 == iteminfo.currency2)
                {
                    tradelast = new TradeLast {
                        ask = Helper.ToDouble((string)item.Value["lowestAsk"]), bid = Helper.ToDouble((string)item.Value["highestBid"]), last = Helper.ToDouble((string)item.Value["last"])
                    };
                    break;
                }
            }

            return(tradelast);
        }
Example #2
0
        public override TradeLast GetTradeLastEnd(string parameters, string ticker)
        {
            string response = DoPublicRequest(parameters);

            CheckResponseAndThrow(response);

            dynamic stuff = Newtonsoft.Json.JsonConvert.DeserializeObject(response);

            Pair tickerinfo = new Pair(ticker);

            TradeLast tradelast = new TradeLast();

            foreach (var item in stuff)
            {
                Pair iteminfo = new Pair(item.Name);
                if (tickerinfo.currency1 == iteminfo.currency1 && tickerinfo.currency2 == iteminfo.currency2)
                {
                    tradelast = new TradeLast {
                        ask = Helper.ToDouble((string)item.Value["lowestAsk"]), bid = Helper.ToDouble((string)item.Value["highestBid"]), last = Helper.ToDouble((string)item.Value["last"])
                    };
                    break;
                }
            }

            return(tradelast);
        }
Example #3
0
        public void UpdateTradeState_UIResultHandler(RequestItemGroup resultResponse)
        {
            if (RequestManager.IsResultHasErrors(resultResponse))
            {
                return;
            }

            Dictionary <string, Balance> balances = (Dictionary <string, Balance>)resultResponse.items[0].result.resultData;

            tradeLogic.UpdateBalance(balances);

            if (labelBalanceBase.Text != "_")
            {
                if (tradeLogic.balanceBase.balance != tradeLogic.prevBalanceBase.balance)
                {
                    labelBalanceBaseBold.Start();
                }
                if (tradeLogic.balanceCounter.balance != tradeLogic.prevBalanceCounter.balance)
                {
                    labelBalanceMarketBold.Start();
                }
            }
            labelBalanceBase.Text        = tradeLogic.baseCurrencyName;
            labelBalanceMarket.Text      = tradeLogic.counterCurrencyName;
            labelBalanceBaseValue.Text   = Helper.PriceToStringBtc(tradeLogic.balanceBase.balance);
            labelBalanceMarketValue.Text = Helper.PriceToStringBtc(tradeLogic.balanceCounter.balance);
            labelAmountBuy.Text          = tradeLogic.counterCurrencyName;
            labelAmountSell.Text         = tradeLogic.counterCurrencyName;

            TradeLast tradelast = (TradeLast)resultResponse.items[1].result.resultData;

            tradeLogic.lastMarketPrice = tradelast;

            TradeLast lastbtcInUsdtPrice = (TradeLast)resultResponse.items[2].result.resultData;
            TradeLast trade = tradeLogic.lastMarketPrice;

            buttonBuy.Text       = "BUY  " + Helper.PriceToStringBtc(trade.ask);
            buttonSell.Text      = "SELL  " + Helper.PriceToStringBtc(trade.bid);
            buttonBuy.BackColor  = Color.FromArgb(buttoncolor.ToArgb());
            buttonSell.BackColor = Color.FromArgb(buttoncolor.ToArgb());
            if (trade.last >= trade.ask)
            {
                buttonBuy.BackColor = Color.Aquamarine;
            }
            if (trade.last <= trade.bid)
            {
                buttonSell.BackColor = Color.LightPink;//Color.LightPink;;
            }
            labelSpread.Text = Helper.CalcSpread(trade.ask, trade.bid).ToString("0.00") + " %";
            double averageBtcPrice = (trade.ask + trade.bid) / 2;
            double btcInUsd        = (lastbtcInUsdtPrice.bid + lastbtcInUsdtPrice.ask) / 2;
            double averageUsdPrice = averageBtcPrice;

            if (tradeLogic.baseCurrencyName != "USDT" && tradeLogic.baseCurrencyName != "USD")
            {
                averageUsdPrice = averageBtcPrice * btcInUsd;
            }
            labelAverage.Text = "Average: " + Helper.PriceToStringBtc(averageBtcPrice) + " = " + Helper.PriceToString(averageUsdPrice) + "$";
        }
Example #4
0
        public void LastMarketPrice_UIResultHandler(RequestItemGroup resultResponse)
        {
            if (Helper.IsResultHasErrors(resultResponse))
            {
                return;
            }
            TradeLast tradelast = (TradeLast)resultResponse.items[0].result.resultData;

            if (chart == null)
            {
                return;
            }
            chart.UpdatePrice(tradelast.last);
            chart.ReDrawFull();
            timerLastPrice.Start();
        }
Example #5
0
        public override TradeLast GetTradeLastEnd(string parameters, string ticker)
        {
            string response = DoPublicRequest(parameters);

            //  BTradeLast jdata = Newtonsoft.Json.JsonConvert.DeserializeObject<BTradeLast>(response);
            //lastRequestMsg = jdata.message;
            //lastRequestStatus = jdata.success;
            // if (!jdata.success)
            //     throw new MarketAPIException("Market API Error:" + jdata.message);

            string     errmsg     = "";
            string     errcaption = "";
            BTradeLast jdata      = null;

            try
            {
                jdata = Newtonsoft.Json.JsonConvert.DeserializeObject <BTradeLast>(response);
                if (!jdata.success)
                {
                    errcaption = "Market API Error:";
                    errmsg     = jdata.message;
                }
                if (jdata.result == null)
                {
                    errcaption += "Market API Error:";
                    errmsg     += "DataResult=Null >>> " + response;
                }
            }
            catch (Exception ex)
            {
                errcaption = "Parsing Response Error:";
                errmsg     = ex.Message + " >>> " + response;
            }
            if (errmsg != "")
            {
                throw new MarketAPIException(errcaption + " >> " + errmsg);
            }



            TradeLast tradelast = new TradeLast {
                ask = jdata.result.Ask, bid = jdata.result.Bid, last = jdata.result.Last
            };

            return(tradelast);
        }
Example #6
0
        public override TradeLast GetTradeLastEnd(string parameters, string ticker)
        {
            string response = DoPublicRequest(parameters);

            BTradeLast jdata = Newtonsoft.Json.JsonConvert.DeserializeObject <BTradeLast>(response);

            //lastRequestMsg = jdata.message;
            //lastRequestStatus = jdata.success;
            if (!jdata.success)
            {
                throw new MarketAPIException("Market API Error:" + jdata.message);
            }

            TradeLast tradelast = new TradeLast {
                ask = jdata.result.Ask, bid = jdata.result.Bid, last = jdata.result.Last
            };

            return(tradelast);
        }
Example #7
0
        public override TradeLast GetTradeLastEnd(string parameters, string ticker)
        {
            string response = DoPublicRequest(parameters);

            CheckResponseAndThrow(response);
            Dictionary <string, YTickerCurrency> jdata = null;

            try
            {
                jdata = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, YTickerCurrency> >(response);
            }
            catch (Exception ex)
            { throw new MarketAPIException("Parsing Response Error" + " >>>> " + ex.Message + " ## Response: ## " + response); }

            YTickerCurrency item = jdata.Values.ToList()[0];
            TradeLast       tradelast;

            tradelast = new TradeLast {
                ask = item.sell, bid = item.buy, last = item.last
            };

            return(tradelast);
        }