Ejemplo n.º 1
0
        private void button_GetRecentTrades_Click(object sender, EventArgs e)
        {
            RecentTrades trades = new RecentTrades();
            string       Symbol = comboBox_RecentTradesSymbol.Text;

            trades.GetRecentTrades(A, Symbol);
        }
Ejemplo n.º 2
0
        protected void ProcessPublicTrades(IEnumerable <PublicTrade> trades)
        {
            var tradesList = trades as List <PublicTrade> ?? trades.ToList();

            if (RecentTrades.All(x => x.SymbolInformation.Symbol != CurrentSymbol.Symbol))
            {
                RecentTrades.Clear();
            }
            long?lastId = RecentTrades.FirstOrDefault()?.Id;

            if (lastId != null)
            {
                tradesList.RemoveAll(x => x.Id <= lastId);
            }
            using (RecentTrades.SuppressChangeNotifications())
            {
                if (tradesList.Count > 0)
                {
                    RecentTrades.InsertRange(0, tradesList);
                    if (RecentTrades.Count > TradesMaxItemCount)
                    {
                        RecentTrades.RemoveRange(TradesMaxItemCount, Math.Abs(TradesMaxItemCount - RecentTrades.Count));
                    }
                }
                CalcQuantityPercentageTotal(RecentTrades);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Gets the recent trades.
        /// </summary>
        /// <param name="pair">The pair.</param>
        public RecentTrades GetRecentTrades(string pair)
        {
            var param = new Dictionary <string, string>();

            param.Add("pair", pair);

            var res = QueryPublic("Trades", param);

            var obj = (JObject)JsonConvert.DeserializeObject(res);

            var result = obj["result"].Value <JObject>();
            var trades = result[pair].Value <JArray>();

            var ret = new RecentTrades();

            ret.trades = new List <Trade>();
            foreach (var t in trades)
            {
                ret.trades.Add(new Trade
                {
                    price       = t[0].Value <decimal>(),
                    volume      = t[1].Value <decimal>(),
                    time        = t[2].Value <decimal>(),
                    buysell     = t[3].Value <char>(),
                    marketlimit = t[4].Value <char>(),
                    misc        = t[5].Value <string>()
                }
                               );
            }

            return(ret);
        }
Ejemplo n.º 4
0
        public MarketInfo(MarketInfo sourceMarket, MarketInfo additionalData, bool deepCopy)
            : this(sourceMarket.Time, sourceMarket.Ticker, sourceMarket.MarketDepth, sourceMarket.RecentTrades, deepCopy)
        {
            Id            = sourceMarket.Id;
            Label         = sourceMarket.Label;
            PrimaryName   = sourceMarket.PrimaryName;
            PrimaryCode   = sourceMarket.PrimaryCode;
            SecondaryCode = sourceMarket.SecondaryCode;
            SecondaryName = sourceMarket.SecondaryName;

            if (additionalData != null)
            {
                RecentTrades.AddRange(additionalData.RecentTrades);
                MarketDepth.AskOrders.AddRange(additionalData.MarketDepth.AskOrders);
                MarketDepth.BidOrders.AddRange(additionalData.MarketDepth.BidOrders);
            }
        }
Ejemplo n.º 5
0
        private void Run()
        {
            //var subServerTime = Observable.Interval(TimeSpan.FromSeconds(2)).Publish();
            //var subExchangeInfo = Observable.Interval(TimeSpan.FromMinutes(5)).Publish();
            //subServerTime.Subscribe(
            //   (long x) =>
            //   {
            //       var result = client.GetServerTime2();
            //       UpdateStatus();
            //       if (result.Success)
            //       {
            //           ServerTime = result.Data.serverTime.FromUnixTimestamp();
            //       }
            //   }).DisposeWith(Disposables);
            //subExchangeInfo.Subscribe(
            //    (long x) =>
            //    {
            //        var result = client.GetExchangeInfo2();
            //        UpdateStatus();
            //        if (result.Success)
            //        {
            //            ProcessExchangeInfo(result.Data.symbols.Select(CreateSymbolInformation));
            //        }
            //    }).DisposeWith(Disposables);

            var subServerTime   = client.SubscribeServerTime().Publish();
            var subExchangeInfo = client.SubscribeExchangeInfo().Publish();

            var sub24hrPriceTicker   = Observable.Interval(TimeSpan.FromSeconds(10)).Publish();
            var subCurrentSymbol     = this.WhenAnyValue(vm => vm.CurrentSymbol).Where(id => id != null).DistinctUntilChanged().Publish();
            var sub24hrPriceTickerWs = client.SubscribeMarketSummariesAsync(null).Publish();

            subServerTime.Subscribe(
                (Binance.ServerTime x) =>
            {
                ServerTime = x.serverTime.FromUnixTimestamp();
                UpdateStatus();
            }).DisposeWith(Disposables);

            subExchangeInfo.Subscribe(
                (Binance.ExchangeInfo x) =>
            {
                ProcessExchangeInfo(x.symbols.Select(CreateSymbolInformation));
                UpdateStatus();
            }).DisposeWith(Disposables);

            sub24hrPriceTicker.Subscribe(
                (long x) =>
            {
                var result = client.Get24hrPriceTicker2();
                UpdateStatus();
                if (result.Success)
                {
                    Process24hrPriceTicker(result.Data.Select(ToPriceTicker));
                }
            }).DisposeWith(Disposables);

            sub24hrPriceTickerWs.Subscribe(
                (Binance.WsPriceTicker24hr ticker) =>
            {
                OnRefreshMarketSummary2(ToPriceTicker(ticker));
            }).DisposeWith(Disposables);

            subCurrentSymbol.Subscribe(
                (string symbol) =>
            {
                RecentTrades.Clear();
                OrderBook.Clear();
                if (HasTradesPush)
                {
                    var obs = SubscribeRecentTrades(symbol, TradesMaxItemCount);
                    TradesHandle.Disposable = obs.Subscribe(OnTrade);
                }
                if (HasTradesPull)
                {
                    //var obs = Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(10));
                    //PublicTradesHandle.Disposable = obs.Subscribe(
                    //    (long x) =>
                    //    {
                    //        var result = client.GetRecentTrades2(symbol, TradesMaxItemCount);
                    //        if (result.Success)
                    //        {
                    //            var trades = result.Data.Select(ToPublicTrade).Reverse().ToList();
                    //            trades.ForEach(t => t.Symbol = symbol);
                    //            ProcessPublicTrades(trades);
                    //        }
                    //    });
                }

                if (HasOrderBookPull)
                {
                    var obs2 = Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(2));
                    DepthHandle.Disposable = obs2.Subscribe(
                        (long x) =>
                    {
                        var result = client.GetDepth2(symbol, OrderBookMaxItemCount);
                        if (result.Success)
                        {
                            var depth = result.Data;
                            var asks  = depth.asks.Select(a => new OrderBookEntry()
                            {
                                Price = decimal.Parse(a[0]), Quantity = decimal.Parse(a[1]), Side = TradeSide.Sell
                            });
                            var bids = depth.bids.Select(b => new OrderBookEntry()
                            {
                                Price = decimal.Parse(b[0]), Quantity = decimal.Parse(b[1]), Side = TradeSide.Buy
                            });
                            ProcessOrderBook(asks.Reverse().Concat(bids));
                        }
                    });
                }
            }).DisposeWith(Disposables);

            subServerTime.Connect().DisposeWith(Disposables);
            subExchangeInfo.Connect().DisposeWith(Disposables);
            //sub24hrPriceTicker.Connect().DisposeWith(Disposables);
            subCurrentSymbol.Connect().DisposeWith(Disposables);
            sub24hrPriceTickerWs.Connect().DisposeWith(Disposables);

            TradesHandle.DisposeWith(Disposables);
            DepthHandle.DisposeWith(Disposables);
        }