Example #1
0
        public static Ticker GetTicker(TradePair pair)
        {
            var url  = TickerUrl(pair.ToString());
            var json = Get(url);

            return(JsonTicker.Parse(json));
        }
        internal TradePair MapPair(TradePair pair)
        {
            var pairs = pair.UrlSlug.Split('_');

            _currencies.Items.First(i => String.Equals(i.Name, pairs[0], StringComparison.CurrentCultureIgnoreCase));
            return(pair);
        }
Example #3
0
        /// <summary>Add the spot price to the chart</summary>
        public void BuildScene(TradePair pair, ChartControl chart)
        {
            // Add b2q first, so green is above red
            var spot_b2q = pair.SpotPrice[ETradeType.B2Q];
            var spot_q2b = pair.SpotPrice[ETradeType.Q2B];

            if (spot_b2q != null)
            {
                var pt0 = chart.ChartToClient(new Point(chart.XAxis.Min, spot_b2q.Value.ToDouble()));
                var pt1 = chart.ChartToClient(new Point(chart.XAxis.Max, spot_b2q.Value.ToDouble()));

                // Add the line
                B2QLine.X1 = pt0.X;
                B2QLine.Y1 = pt0.Y;
                B2QLine.X2 = pt1.X;
                B2QLine.Y2 = pt1.Y;
                chart.Overlay.Adopt(B2QLine);

                // Add the price label
                var pt = chart.TransformToDescendant(chart.YAxisPanel).Transform(pt1);
                Canvas.SetLeft(B2QPrice, 0);
                Canvas.SetTop(B2QPrice, pt.Y - B2QPrice.RenderSize.Height / 2);
                B2QPrice.Text = spot_b2q.Value.ToString(8);
                chart.YAxisPanel.Adopt(B2QPrice);
            }
            else
            {
                B2QLine.Detach();
                B2QPrice.Detach();
            }

            if (spot_q2b != null)
            {
                var pt0 = chart.ChartToClient(new Point(chart.XAxis.Min, spot_q2b.Value.ToDouble()));
                var pt1 = chart.ChartToClient(new Point(chart.XAxis.Max, spot_q2b.Value.ToDouble()));

                // Add the line
                Q2BLine.X1 = pt0.X;
                Q2BLine.Y1 = pt0.Y;
                Q2BLine.X2 = pt1.X;
                Q2BLine.Y2 = pt1.Y;
                chart.Overlay.Adopt(Q2BLine);

                // Add the price label
                var pt = chart.TransformToDescendant(chart.YAxisPanel).Transform(pt1);
                Canvas.SetLeft(Q2BPrice, 0);
                Canvas.SetTop(Q2BPrice, pt.Y - Q2BPrice.RenderSize.Height / 2);
                Q2BPrice.Text = spot_q2b.Value.ToString(8);
                chart.YAxisPanel.Adopt(Q2BPrice);
            }
            else
            {
                Q2BLine.Detach();
                Q2BPrice.Detach();
            }
        }
Example #4
0
        public List <TradePair> extractRawRecord(string filePath)
        {
            try
            {
                //use FileReader class with option FileAccess = Read and Share = System.IO.FileShare.ReadWrite to prevent locking the file and deal with file changes.
                using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    Dictionary <String, TradePair> dict = new Dictionary <string, TradePair>();

                    using (StreamReader reader = new StreamReader(file, Encoding.GetEncoding("gb2312")))
                    {
                        // skip the first header line
                        string line = reader.ReadLine();
                        while ((line = reader.ReadLine()) != null)
                        {
                            String[] tokens = String.Copy(line).Split('\t');
                            if (tokens.Length <= 1)
                            {
                                continue;
                            }
                            string    ticker = tokens[1];
                            TradePair pair   = null;
                            if (!dict.ContainsKey(ticker))
                            {
                                pair         = new TradePair();
                                pair.ticker  = ticker;
                                dict[ticker] = pair;
                            }
                            pair = dict[ticker];

                            Trade trade = new Trade(ticker, Convert.ToInt32(tokens[4]), Convert.ToSingle(tokens[5]), TradeType.UNKNOWN);
                            if (BUY_FLAG.Equals(tokens[3]))
                            {
                                trade.type    = TradeType.BUY;
                                pair.buyTrade = trade;
                            }
                            else if (LENDSELL_FLAG.Equals(tokens[10]))
                            {
                                trade.type         = TradeType.LENDSELL;
                                pair.lendSellTrade = trade;
                            }
                        }
                        reader.Close();
                    }
                    file.Close();
                    return(dict.Values.ToList());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                return(null);
            }
        }
Example #5
0
 public string GetLocalTradingPairString(TradePair t, SubscribeTypes st = CommonLab.SubscribeTypes.RESTAPI)
 {
     if (t.FromSymbol.ToLower() == "bch")
     {
         return("BCC" + t.ToSymbol.ToUpper());
     }
     if (t.ToSymbol.ToLower() == "bch")
     {
         return(t.FromSymbol.ToUpper() + "BCC");
     }
     return(t.FromSymbol.ToUpper() + t.ToSymbol.ToUpper());
 }
Example #6
0
        public ITradePair GetTickersWithCandlesticks(ITradePair poltickers)
        {
            var ticker = new TradePair()
            {
                Id       = poltickers.Id,
                Exchange = CryptoExchange.Poloniex,
            };

            var candlesticks_4H   = GetCandleSticks(poltickers, 0, 0, CandlestickInterval.Hours_4).ToList();
            var candlesticksDaily = GetCandleSticks(poltickers, 0, 0, CandlestickInterval.Daily).ToList();

            var count = candlesticks_4H.Count() > candlesticksDaily.Count() ? candlesticks_4H.Count() : candlesticksDaily.Count();

            for (var j = 0; j < count; j++)
            {
                if (j < candlesticks_4H.Count())
                {
                    ticker.CandleSticks_4h.Add(new CandleStick()
                    {
                        CandleInterval = CandlestickInterval.Hours_4,
                        Close          = candlesticks_4H.ElementAt(j).Close,
                        High           = candlesticks_4H.ElementAt(j).High,
                        Low            = candlesticks_4H.ElementAt(j).Low,
                        Open           = candlesticks_4H.ElementAt(j).Open,
                        Volume         = candlesticks_4H.ElementAt(j).Volume,
                        Date           = candlesticks_4H.ElementAt(j).Date
                    });
                    ticker.CandleSticks_4h.Last().CCI   = ticker.CandleSticks_4h.GetCCI(3, 10);
                    ticker.CandleSticks_4h.Last().SMA20 = ticker.CandleSticks_4h.GetMovingAvarage(20);
                }

                if (j < candlesticksDaily.Count())
                {
                    ticker.CandleSticks_Daily.Add(new CandleStick()
                    {
                        CandleInterval = CandlestickInterval.Daily,
                        Close          = candlesticksDaily.ElementAt(j).Close,
                        High           = candlesticksDaily.ElementAt(j).High,
                        Low            = candlesticksDaily.ElementAt(j).Low,
                        Open           = candlesticksDaily.ElementAt(j).Open,
                        Volume         = candlesticksDaily.ElementAt(j).Volume,
                        Date           = candlesticksDaily.ElementAt(j).Date
                    });
                    ticker.CandleSticks_Daily.Last().CCI   = ticker.CandleSticks_Daily.GetCCI(3, 10);
                    ticker.CandleSticks_Daily.Last().SMA20 = ticker.CandleSticks_Daily.GetMovingAvarage(20);
                }
            }
            ticker.GetCCICrossToPositive();
            ticker.SetLastHighest();
            ticker.LastUpdated = DateTime.Now;

            return(ticker);
        }
Example #7
0
        // Note: a closed loop is one that starts and ends at the same currency
        // but not necessarily on the same exchange.

        public Loop(TradePair pair)
        {
            Pairs          = new List <TradePair>();
            Rate           = null;
            Direction      = 0;
            TradeScale     = 1m;
            TradeVolume    = 0m._(pair.Base);
            Profit         = 0m._(pair.Base);
            ProfitRatioFwd = 0;
            ProfitRatioBck = 0;

            Pairs.Add(pair);
        }
Example #8
0
 private Market getMarketByTicker(TradePair pair)
 {
     if (pair.ticker.StartsWith(SHANGHAI_PREFIX))
     {
         return(Market.SHANGHAI);
     }
     else if (pair.ticker.StartsWith(SHENZHEN_PREFIX) || pair.ticker.StartsWith(CHUANGYE_PREFIX))
     {
         return(Market.SHENZHEN);
     }
     else
     {
         return(Market.UNKNOWN);
     }
 }
Example #9
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            IExchange cryptopia = new Cryptopia();
            TradePair tp        = new TradePair()
            {
                BaseLabel = "BTC", CurrencyLabel = "ETN"
            };
            MarketOrdersResponse r = cryptopia.GetMarketOrders(new MarketOrdersRequest(tp));

            //IExchange bittrex = new Bittrex();
            //TradePair tp = new TradePair() { BaseLabel = "BTC", CurrencyLabel = "RDD" };
            //MarketOrdersRequest mr = new MarketOrdersRequest(tp);
            //MarketOrdersResponse r = bittrex.GetMarketOrders(mr);
            int i = 1;
        }
Example #10
0
 public string GetLocalTradingPairString(TradePair t, SubscribeTypes st = CommonLab.SubscribeTypes.RESTAPI)
 {
     if (st == SubscribeTypes.WSS)
     {
         if (t.FromSymbol.ToLower() == "btc" && t.ToSymbol.ToLower() == "usd")
         {
             return("");
         }
         return(t.FromSymbol.ToLower() + t.ToSymbol.ToLower());
     }
     else if (st == SubscribeTypes.RESTAPI)
     {
         return(t.FromSymbol.ToLower() + t.ToSymbol.ToLower());
     }
     return(t.FromSymbol.ToLower() + t.ToSymbol.ToLower());
 }
Example #11
0
 public string GetLocalTradingPairString(TradePair t, SubscribeTypes st = CommonLab.SubscribeTypes.RESTAPI)
 {
     //if (st == SubscribeTypes.WSS)
     //{
     //    if (t.FromSymbol.ToLower() == "btc" && t.ToSymbol.ToLower() == "usd")
     //        return "";
     //    return "_" + t.FromSymbol.ToLower() + t.ToSymbol.ToLower();
     //}
     //else if (st == SubscribeTypes.RESTAPI)
     //{
     //    return t.FromSymbol.ToLower() + "_" + t.ToSymbol.ToLower();
     //}
     //if (t.FromSymbol.ToLower() == "bch")
     //    return "bcc" + t.ToSymbol.ToLower();
     //if (t.ToSymbol.ToLower() == "bch")
     //    return t.FromSymbol.ToLower()+ "bcc" ;
     return(t.FromSymbol.ToLower() + t.ToSymbol.ToLower());
 }
Example #12
0
 public static TradePairOrders GetOrders(TradePair pair)
 {
     using (var w = new WebClient())
     {
         w.Headers.Add("User-Agent", "Mozilla/5.0");
         var json_data = string.Empty;
         // attempt to download JSON data as a string
         try
         {
             json_data = w.DownloadString("https://coinex.pw/api/v2/orders?tradePair=" + pair.Id);
         }
         catch (Exception e)
         {
             throw new Exception("Unable to query coinex: " + e.Message);
         }
         // if string with JSON data is not empty, deserialize it to class and return its instance
         return(new TradePairOrders(!string.IsNullOrEmpty(json_data) ? JsonConvert.DeserializeObject <TradePairOrdersJson>(json_data) : new TradePairOrdersJson()));
     }
 }
Example #13
0
        static void Main(string[] args)
        {
            log       = new Log(DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt");
            prices    = new List <double>(15);
            TradeBook = new List <Trade>();
            for (int i = 0; i < 15; i++)
            {
                prices.Add(0);
            }
            LastBalanceTime = DateTime.Now;
            FromSymbol      = "LTC";
            ToSymbol        = "BTC";
            tradepair       = new TradePair(FromSymbol, ToSymbol);
            exchange        = new KFCC.Exchanges.EOkCoin.OkCoinExchange("a8716cf5-8e3d-4037-9a78-6ad59a66d6c4", "CF44F1C9F3BB23B148523B797B862D4C", "", "");
            exchange.Subscribe(tradepair, CommonLab.SubscribeTypes.WSS);
            exchange.TradeEvent += Exchange_TradeEvent;
            exchange.DepthEvent += Exchange_DepthEvent;

            MainLoop();
            Console.ReadKey();
        }
Example #14
0
 /// <summary>
 /// From a generic trade pair, this method will return the list of tradepairs from all exchanges
 /// </summary>
 /// <param name="tradePair"></param>
 public static HashSet <ExchangeTradePair> GetExchangeTradePairs(TradePair tradePair)
 {
     return(indexByTradePair[tradePair]);
 }
Example #15
0
 private static void Exchange_TradeEvent(object sender, Trade t, EventTypes et, TradePair tp)
 {
     if (TradeBook.Count == 15)
     {
         TradeBook.RemoveAt(0);
     }
     TradeBook.Add(t);
     Vol         = 0.7 * Vol + 0.3 * t.Amount;
     LastTradeID = Convert.ToInt32(t.TradeID);
 }
Example #16
0
        private static void Exchange_DepthEvent(object sender, Depth d, EventTypes et, TradePair tp)
        {
            OrderBook = d;
            bidPrice  = OrderBook.Bids[0].Price * 0.618 + OrderBook.Asks[0].Price * 0.382;//需要调整价格
            askPrice  = OrderBook.Bids[0].Price * 0.382 + OrderBook.Asks[0].Price * 0.618;

            //prices = prices[1.. - 1] + [(
            //    (orderBook.bids[0].limitPrice + orderBook.asks[0].limitPrice) / 2 * 0.7 +
            //    (orderBook.bids[1].limitPrice + orderBook.asks[1].limitPrice) / 2 * 0.2 +
            //    (orderBook.bids[2].limitPrice + orderBook.asks[2].limitPrice) / 2 * 0.1)]
            prices.RemoveAt(0);
            prices.Add(((OrderBook.Bids[0].Price + OrderBook.Asks[0].Price) / 2 * 0.7) + ((OrderBook.Bids[1].Price + OrderBook.Asks[1].Price) / 2 * 0.2) + ((OrderBook.Bids[2].Price + OrderBook.Asks[2].Price) / 2 * 0.1));
        }
Example #17
0
 public Task <decimal> GetPriceAsync(TradePair tradePair)
 {
     throw new NotImplementedException();
 }
Example #18
0
 public Task <(decimal ask, decimal bid)> GetBookOrderPriceAsync(TradePair tradePair)
 {
     throw new NotImplementedException();
 }
Example #19
0
 public ArbTradePairSpread(TradePair tradePair)
 {
     this.TradePair         = tradePair;
     priceDic               = new ConcurrentDictionary <Exchange, TradePairPrice>();
     this.MaximumValuedPair = this.MinimumValuedPair = null;
 }
Example #20
0
 public void DisSubcribe(TradePair tp, SubscribeTypes st)
 {
     throw new NotImplementedException();
 }