예제 #1
0
        public object aspect_spread(object rowObject)
        {
            ExchangeOrder order = (ExchangeOrder)rowObject;
            //LogManager.AddLogMessage(Name, "aspect_spread", "rate=" + order.symbol + " | " + order.market + " | " + order.amount, LogManager.LogMessageType.DEBUG);

            ExchangeTicker ticker = Tickers.FirstOrDefault(item => item.exchange == order.exchange && item.symbol == order.symbol && item.market == order.market);

            if (ticker != null)
            {
                if (order.market.Contains("USD"))
                {
                    return(ticker.last.ToString("C"));
                }
                else
                {
                    return(ticker.last.ToString("N8"));
                }

                //LogManager.AddLogMessage(Name, "aspect_spread", "rate=" + order.rate + " | " + ticker.last, LogManager.LogMessageType.DEBUG);
                //return 0;
            }
            else
            {
                return(0);
            }

            //return "10%";
        }
예제 #2
0
        public override bool UpdateTickersInfo() {
            byte[] bytes = null;
            try {
                bytes = GetDownloadBytes(TickersUpdateAddress);
            }
            catch(Exception e) {
                Debug.WriteLine(e.ToString());
                return false;
            }
            if(bytes == null)
                return false;

            int startIndex = 0;
            List<string[]> list = JSonHelper.Default.DeserializeArrayOfArrays(bytes, ref startIndex, 11);
            for(int i = 0; i < list.Count; i++) {
                string[] item = list[i];
                BitFinexTicker ticker = (BitFinexTicker)Tickers.FirstOrDefault(t => t.CurrencyPair == item[0]);
                ticker.HighestBid = FastValueConverter.Convert(item[1]);
                ticker.LowestAsk = FastValueConverter.Convert(item[3]);
                ticker.Change = FastValueConverter.Convert(item[6]);
                ticker.Last = FastValueConverter.Convert(item[7]);
                ticker.Volume = FastValueConverter.Convert(item[8]);
                ticker.Hr24High = FastValueConverter.Convert(item[9]);
                ticker.Hr24Low = FastValueConverter.Convert(item[10]);
            }
            return true;
        }
예제 #3
0
        public void UpdateTickersInfo()
        {
            string address = "https://poloniex.com/public?command=returnTicker";
            string text    = GetDownloadString(address);

            if (string.IsNullOrEmpty(text))
            {
                return;
            }
            JObject res = (JObject)JsonConvert.DeserializeObject(text);

            foreach (JProperty prop in res.Children())
            {
                PoloniexTicker t   = Tickers.FirstOrDefault((i) => i.CurrencyPair == prop.Name);
                JObject        obj = (JObject)prop.Value;
                t.Last       = obj.Value <double>("last");
                t.LowestAsk  = obj.Value <double>("lowestAsk");
                t.HighestBid = obj.Value <double>("highestBid");
                t.Change     = obj.Value <double>("percentChange");
                t.BaseVolume = obj.Value <double>("baseVolume");
                t.Volume     = obj.Value <double>("quoteVolume");
                t.IsFrozen   = obj.Value <int>("isFrozen") != 0;
                t.Hr24High   = obj.Value <double>("high24hr");
                t.Hr24Low    = obj.Value <double>("low24hr");
            }
        }
        public override bool GetTickersInfo()
        {
            string address = "https://www.bitmex.com/api/v1/instrument?columns=typ,symbol,rootSymbol,quoteCurrency,highPrice,lowPrice,bidPrice,askPrice,lastChangePcnt,hasLiquidity,volume,tickSize,takerFee&start=0&count=500";
            string text    = string.Empty;

            try {
                text = GetDownloadString(address);

                if (string.IsNullOrEmpty(text))
                {
                    return(false);
                }
                Tickers.Clear();
                JArray res   = JsonConvert.DeserializeObject <JArray>(text);
                int    index = 0;
                foreach (JObject obj in res.Children())
                {
                    if (!obj.Value <bool>("hasLiquidity"))
                    {
                        continue;
                    }
                    string       pair = obj.Value <string>("symbol");
                    BitmexTicker t    = (BitmexTicker)Tickers.FirstOrDefault(tt => tt.CurrencyPair == pair);
                    if (t == null)
                    {
                        t = new BitmexTicker(this);
                    }
                    t.Index          = index;
                    t.ContractTicker = true;
                    t.ContractValue  = 1; // 1 USD
                    t.CurrencyPair   = pair;
                    t.MarketCurrency = obj.Value <string>("rootSymbol");
                    t.BaseCurrency   = obj.Value <string>("quoteCurrency");
                    t.TickSize       = ToDouble(obj, "tickSize");
                    t.Last           = ToDouble(obj, "lastPrice");
                    t.Hr24High       = ToDouble(obj, "highPrice");
                    t.Hr24Low        = ToDouble(obj, "lowPrice");
                    t.HighestBid     = ToDouble(obj, "bidPrice");
                    t.LowestAsk      = ToDouble(obj, "askPrice");
                    t.Timestamp      = Convert.ToDateTime(obj.Value <string>("timestamp"));
                    t.Change         = ToDouble(obj, "lastChangePcnt");
                    t.Volume         = ToDouble(obj, "volume24h");
                    t.Fee            = ToDouble(obj, "takerFee") * 100;
                    Tickers.Add(t);
                    index++;
                }
            }
            catch (Exception) {
                return(false);
            }
            IsInitialized = true;
            return(true);
        }
예제 #5
0
 private void GetTickerItem(PoloniexTicker item)
 {
     lock (Tickers) {
         PoloniexTicker t = Tickers.FirstOrDefault((i) => i.CurrencyPair == item.CurrencyPair);
         if (t != null)
         {
             lock (t) {
                 t.Assign(item);
                 t.UpdateHistoryItem();
                 RaiseTickerUpdate(t);
             }
         }
         else
         {
             Tickers.Add(item);
             RaiseTickerUpdate(item);
         }
     }
 }
예제 #6
0
        public object aspect_rate(object rowObject)
        {
            ExchangeOrder order = (ExchangeOrder)rowObject;

            /*
             * if (order.market.Contains("USD"))
             * {
             *  return order.rate.ToString("C");
             * }
             * else
             * {
             *  double rate = order.rate * 100000000;
             *  return rate + "B";
             * }
             */
            //List<ExchangeTicker> list = Tickers.Where(item => item.exchange == order.exchange).ToList();
            //LogManager.AddLogMessage(Name, "aspect_spread", order.exchange + " | " + order.symbol + " | " + order.market + " | " + order.rate + " | " + list.Count, LogManager.LogMessageType.DEBUG);
            ExchangeTicker ticker = Tickers.FirstOrDefault(item => item.exchange == order.exchange && item.symbol == order.symbol && item.market == order.market);

            if (ticker != null)
            {
                if (order.market.Contains("USD"))
                {
                    return(ticker.last.ToString("C") + " / " + order.rate.ToString("C"));
                }
                else
                {
                    decimal rate = Convert.ToDecimal(order.rate) * 100000000;
                    decimal last = ticker.last * 100000000;
                    return(last.ToString("N0") + " / " + rate.ToString("N0"));
                }

                //column_symbol.Width +=
                //LogManager.AddLogMessage(Name, "aspect_spread", "rate=" + order.rate + " | " + ticker.last, LogManager.LogMessageType.DEBUG);
                //return 0;
            }
            else
            {
                //LogManager.AddLogMessage(Name, "aspect_spread", "NO TICKER=" + order.exchange + " | " + order.symbol + " | " + order.market, LogManager.LogMessageType.DEBUG);
                return(0);
            }
        }
예제 #7
0
        public override bool UpdateTickersInfo()
        {
            if (!IsInitialized)
            {
                return(true);
            }
            Context cc = GetContext(DefaultAccount);

            cc.MarketStocksAsync().ContinueWith(t => {
                MarketInstrumentList list = t.Result;
                foreach (MarketInstrument i in list.Instruments)
                {
                    TinknoffInvestTicker ticker = (TinknoffInvestTicker)Tickers.FirstOrDefault(tt => tt.Name == i.Name);
                    if (ticker != null)
                    {
                        ticker.Instrument = i;
                        continue;
                    }
                    Tickers.Add(new Tinkoff.TinknoffInvestTicker(this, i));
                }
            });
            return(true);
        }
예제 #8
0
        protected void On24HourTickerRecv(string[] item)
        {
            string        symbolName = item[2];
            BinanceTicker t          = (BinanceTicker)Tickers.FirstOrDefault(tt => tt.Name == symbolName);

            if (t == null)
            {
                throw new DllNotFoundException("binance symbol not found " + symbolName);
            }
            t.Change     = FastValueConverter.Convert(item[4]);
            t.HighestBid = FastValueConverter.Convert(item[9]);
            t.LowestAsk  = FastValueConverter.Convert(item[11]);
            t.Hr24High   = FastValueConverter.Convert(item[14]);
            t.Hr24Low    = FastValueConverter.Convert(item[15]);
            t.BaseVolume = FastValueConverter.Convert(item[16]);
            t.Volume     = FastValueConverter.Convert(item[17]);

            t.UpdateTrailings();

            lock (t) {
                RaiseTickerUpdate(t);
            }
        }
예제 #9
0
        public override bool UpdateTickersInfo()
        {
            string address = "https://api.binance.com/api/v1/ticker/24hr";
            string text    = string.Empty;

            try {
                text = GetDownloadString(address);
            }
            catch (Exception) {
                return(false);
            }
            if (string.IsNullOrEmpty(text))
            {
                return(false);
            }
            JArray res = JsonConvert.DeserializeObject <JArray>(text);

            foreach (JObject item in res)
            {
                string        currencyPair = item.Value <string>("symbol");
                BinanceTicker t            = (BinanceTicker)Tickers.FirstOrDefault(tr => tr.CurrencyPair == currencyPair);
                if (t == null)
                {
                    continue;
                }
                t.Last       = item.Value <double>("lastPrice");
                t.LowestAsk  = item.Value <double>("askPrice");
                t.HighestBid = item.Value <double>("bidPrice");
                t.Change     = item.Value <double>("priceChangePercent");
                t.BaseVolume = item.Value <double>("volume");
                t.Volume     = item.Value <double>("quoteVolume");
                t.Hr24High   = item.Value <double>("highPrice");
                t.Hr24Low    = item.Value <double>("lowPrice");
            }
            return(true);
        }
예제 #10
0
        public override bool ObtainExchangeSettings()
        {
            string address = "https://api.binance.com/api/v1/exchangeInfo";
            string text    = string.Empty;

            try {
                text = GetDownloadString(address);
            }
            catch (Exception e) {
                Telemetry.Default.TrackException(e);
                return(false);
            }
            if (string.IsNullOrEmpty(text))
            {
                return(false);
            }

            JObject settings   = JsonConvert.DeserializeObject <JObject>(text);
            JArray  rateLimits = settings.Value <JArray>("rateLimits");

            RequestRate = new List <RateLimit>();
            OrderRate   = new List <RateLimit>();
            for (int i = 0; i < rateLimits.Count; i++)
            {
                JObject rateLimit = (JObject)rateLimits[i];
                string  rateType  = rateLimit.Value <string>("rateLimitType");
                if (rateType == "REQUESTS")
                {
                    RequestRate.Add(GetRateLimit(rateLimit));
                }
                if (rateType == "ORDERS")
                {
                    OrderRate.Add(GetRateLimit(rateLimit));
                }
            }
            JArray symbols = settings.Value <JArray>("symbols");

            for (int i = 0; i < symbols.Count; i++)
            {
                JObject       s = (JObject)symbols[i];
                BinanceTicker t = new BinanceTicker(this);
                t.CurrencyPair   = s.Value <string>("symbol");
                t.MarketCurrency = s.Value <string>("baseAsset");
                t.BaseCurrency   = s.Value <string>("quoteAsset");
                if (Tickers.FirstOrDefault(tt => tt.CurrencyPair == t.CurrencyPair) != null)
                {
                    continue;
                }
                Tickers.Add(t);
                JArray filters = s.Value <JArray>("filters");
                for (int fi = 0; fi < filters.Count; fi++)
                {
                    JObject filter     = (JObject)filters[fi];
                    string  filterType = filter.Value <string>("filterType");
                    if (filterType == "PRICE_FILTER")
                    {
                        t.PriceFilter = new TickerFilter()
                        {
                            MinValue = filter.Value <double>("minPrice"), MaxValue = filter.Value <double>("maxPrice"), TickSize = filter.Value <double>("tickSize")
                        }
                    }
                    ;
                    else if (filterType == "LOT_SIZE")
                    {
                        t.QuantityFilter = new TickerFilter()
                        {
                            MinValue = filter.Value <double>("minQty"), MaxValue = filter.Value <double>("maxQty"), TickSize = filter.Value <double>("stepSize")
                        }
                    }
                    ;
                    else if (filterType == "MIN_NOTIONAL")
                    {
                        t.NotionalFilter = new TickerFilter()
                        {
                            MinValue = filter.Value <double>("minNotional"), MaxValue = double.MaxValue
                        }
                    }
                    ;
                }
            }
            return(true);
        }
예제 #11
0
 public Ticker GetTicker(PinnedTickerInfo info)
 {
     return(Tickers.FirstOrDefault(t => t.BaseCurrency == info.BaseCurrency && t.MarketCurrency == info.MarketCurrency));
 }
        protected void OnTickersInfoRecv(JObject jObject)
        {
            JArray items = jObject.Value <JArray>("data");

            if (items == null)
            {
                return;
            }
            foreach (JObject item in items)
            {
                string       tickerName = item.Value <string>("symbol");
                BitmexTicker t          = (BitmexTicker)Tickers.FirstOrDefault(tt => tt.CurrencyPair == tickerName);
                if (t == null)
                {
                    continue;
                }

                JEnumerable <JToken> props = item.Children();
                foreach (JProperty prop in props)
                {
                    string name  = prop.Name;
                    string value = prop.Value == null? null: prop.Value.ToString();
                    switch (name)
                    {
                    case "lastPrice":
                        t.Last = FastValueConverter.Convert(value);
                        break;

                    case "highPrice":
                        t.Hr24High = FastValueConverter.Convert(value);
                        break;

                    case "lowPrice":
                        t.Hr24Low = FastValueConverter.Convert(value);
                        break;

                    case "bidPrice":
                        t.HighestBid = FastValueConverter.Convert(value);
                        break;

                    case "askPrice":
                        t.LowestAsk = FastValueConverter.Convert(value);
                        break;

                    case "timestamp":
                        t.Timestamp = t.Time = Convert.ToDateTime(value);
                        break;

                    case "lastChangePcnt":
                        t.Change = FastValueConverter.Convert(value);
                        break;

                    case "volume24h":
                        t.Volume = FastValueConverter.Convert(value);
                        break;
                    }
                }
                t.UpdateTrailings();

                lock (t) {
                    RaiseTickerUpdate(t);
                }
            }
        }