/// <summary> /// Initializes a new instance of the <see cref="QuoteBar"/> class. /// </summary> public QuoteBar() { Ticker = TickerSymbol.NIL(""); Occured = new DateTime(); Bid = new BarImpl(); Ask = new BarImpl(); Price = 0; Period = TimeSpan.FromMinutes(1); DataType = DataType.QuoteBar; }
/// <summary> /// Gets the name of the ticker at quantler. /// </summary> /// <param name="ticker">The ticker.</param> /// <returns></returns> public override TickerSymbol GetQuantlerTicker(string ticker) { try { var splitted = ticker.Split('.'); return(new TickerSymbol(splitted[0] + splitted[1], splitted[0], (CurrencyType)Enum.Parse(typeof(CurrencyType), splitted[2]))); } catch (Exception exc) { _log.Error(exc, $"Could not get quantler ticker name for ticker: {ticker}"); } //If all fails return(TickerSymbol.NIL(ticker)); }
/// <summary> /// Gets the name of the ticker at quantler. /// </summary> /// <param name="ticker">The ticker.</param> /// <returns></returns> public override TickerSymbol GetQuantlerTicker(string ticker) { try { //Check if item is ready in cache if (!_tickerSymbols.ContainsKey(ticker)) { //Initial objects CurrencyType currency = CurrencyType.USD; string commodity = string.Empty; //Check combination if (ticker.EndsWith("BTC")) { currency = CurrencyType.BTC; commodity = ticker.Replace("BTC", ""); } else if (ticker.EndsWith("ETH")) { currency = CurrencyType.ETH; commodity = ticker.Replace("ETH", ""); } else if (ticker.EndsWith("USDT")) { currency = CurrencyType.USDT; commodity = ticker.Replace("USDT", ""); } else if (ticker.EndsWith("BNB")) { return(TickerSymbol.NIL(ticker)); //We currently do not support BNB denominated currencies } //Check for symbol changes on binance //Create tickersymbol object based on information supplied _tickerSymbols.Add(ticker, new TickerSymbol(commodity + ".BC", commodity, currency)); } //Return what we have return(_tickerSymbols[ticker]); } catch (Exception exc) { _log.Error(exc, $"Cannot convert feed name ticker to quantler ticker: {ticker}"); } //Unknown? return(TickerSymbol.NIL(ticker)); }
/// <summary> /// Gets the name of the ticker at quantler. /// </summary> /// <param name="ticker">The ticker.</param> /// <returns></returns> public override TickerSymbol GetQuantlerTicker(string ticker) { try { //Check if item is ready in cache if (!_tickerSymbols.ContainsKey(ticker)) { string[] splitted = ticker.Split('-'); _tickerSymbols.Add(ticker, new TickerSymbol(splitted[1] + ".BC", splitted[1], (CurrencyType)Enum.Parse(typeof(CurrencyType), splitted[0]))); } //Return what we have return(_tickerSymbols[ticker]); } catch (Exception exc) { _log.Error(exc, $"Cannot convert feed name ticker to quantler ticker: {ticker}"); } return(TickerSymbol.NIL(ticker)); }
/// <summary> /// Gets the name of the ticker at quantler. /// </summary> /// <param name="ticker">The ticker.</param> /// <returns></returns> public override TickerSymbol GetQuantlerTicker(string ticker) { try { //Check if we already have this ticker if (_tickerSymbols.ContainsKey(ticker)) { return(_tickerSymbols[ticker]); } //Get currency names string commodity = ""; string basecurrency = ""; TickerSymbol created = TickerSymbol.NIL(ticker); var found = _currencyNames.FirstOrDefault(ticker.EndsWith); if (found != null) { commodity = $"{ticker.Replace(found, "")}"; basecurrency = found; created = new TickerSymbol(commodity + ".BC", commodity, (CurrencyType)Enum.Parse(typeof(CurrencyType), basecurrency)); } //Return what we know _tickerSymbols.Add(ticker, created); return(_tickerSymbols[ticker]); } catch (Exception exc) { _log.Error(exc, $"Could not get quantler ticker name for ticker: {ticker}"); } //If all fails return(TickerSymbol.NIL(ticker)); }
/// <summary> /// Initializes a new instance of the <see cref="TradeBar"/> class. /// </summary> public TradeBar() { Ticker = TickerSymbol.NIL(""); DataType = DataType.TradeBar; Period = TimeSpan.FromMinutes(1); }
public void AggregatesNewQuoteBarProperly() { //Arrange QuoteBar quoteBar = null; var quoteBarAggregator = new QuoteBarAggregator(4); quoteBarAggregator.DataAggregated += (sender, args) => { quoteBar = args; }; //Act var time = DateTime.Today; var tickersymbol = TickerSymbol.NIL("TST"); var bar1 = new QuoteBar { Occured = time, Ticker = tickersymbol, Bid = new BarImpl(1, 2, 0.75m, 1.25m), LastBidSize = 3, Ask = null, LastAskSize = 0 }; quoteBarAggregator.Feed(bar1); quoteBar.Should().BeNull(); var bar2 = new QuoteBar { Occured = time, Ticker = tickersymbol, Bid = new BarImpl(1.1m, 2.2m, 0.9m, 2.1m), LastBidSize = 3, Ask = new BarImpl(2.2m, 4.4m, 3.3m, 3.3m), LastAskSize = 0 }; quoteBarAggregator.Feed(bar2); quoteBar.Should().BeNull(); var bar3 = new QuoteBar { Occured = time, Ticker = tickersymbol, Bid = new BarImpl(1, 2, 0.5m, 1.75m), LastBidSize = 3, Ask = null, LastAskSize = 0 }; quoteBarAggregator.Feed(bar3); quoteBar.Should().BeNull(); var bar4 = new QuoteBar { Occured = time, Ticker = tickersymbol, Bid = null, LastBidSize = 0, Ask = new BarImpl(1, 7, 0.5m, 4.4m), LastAskSize = 4, }; //Assert quoteBarAggregator.Feed(bar4); quoteBar.Should().NotBeNull(); bar1.Ticker.Should().Be(quoteBar.Ticker); bar1.Bid.Open.Should().Be(quoteBar.Bid.Open); bar2.Ask.Open.Should().Be(quoteBar.Ask.Open); bar2.Bid.High.Should().Be(quoteBar.Bid.High); bar4.Ask.High.Should().Be(quoteBar.Ask.High); bar3.Bid.Low.Should().Be(quoteBar.Bid.Low); bar4.Ask.Low.Should().Be(quoteBar.Ask.Low); bar3.Bid.Close.Should().Be(quoteBar.Bid.Close); bar4.Ask.Close.Should().Be(quoteBar.Ask.Close); bar3.LastBidSize.Should().Be(quoteBar.LastBidSize); bar4.LastAskSize.Should().Be(quoteBar.LastAskSize); bar1.Price.Should().Be(quoteBar.Price); }
public void AggregatesNewTicksInPeriodWithRoundedTime() { //Arrange TradeBar tradeBar = null; var tickersymbol = TickerSymbol.NIL("TST"); var tickAggregator = new TickAggregator(TimeSpan.FromMinutes(1)); tickAggregator.DataAggregated += (sender, bar) => { tradeBar = bar; }; //Act var reference = new DateTime(2015, 06, 02); var tick1 = new Tick { Ticker = tickersymbol, Occured = reference.AddSeconds(3), Price = 1.1000m }; tickAggregator.Feed(tick1); tradeBar.Should().BeNull(); var tick2 = new Tick { Ticker = tickersymbol, Occured = reference.AddSeconds(10), Price = 1.1005m }; tickAggregator.Feed(tick2); tradeBar.Should().BeNull(); var tick3 = new Tick { Ticker = tickersymbol, Occured = reference.AddSeconds(61), Price = 1.1010m }; tickAggregator.Feed(tick3); tradeBar.Should().NotBeNull(); tradeBar.Occured.Should().Be(reference); tradeBar.Open.Should().Be(tick1.Price); tradeBar.Close.Should().Be(tick2.Price); var tick4 = new Tick { Ticker = tickersymbol, Occured = reference.AddSeconds(70), Price = 1.1015m }; tickAggregator.Feed(tick4); tradeBar.Should().NotBeNull(); var tick5 = new Tick { Ticker = tickersymbol, Occured = reference.AddSeconds(118), Price = 1.1020m }; tickAggregator.Feed(tick5); tradeBar.Should().NotBeNull(); var tick6 = new Tick { Ticker = tickersymbol, Occured = reference.AddSeconds(140), Price = 1.1025m }; tickAggregator.Feed(tick6); //Assert tradeBar.Should().NotBeNull(); tradeBar.Occured.Should().Be(reference.AddSeconds(60)); tradeBar.Open.Should().Be(tick3.Price); tradeBar.Close.Should().Be(tick5.Price); }
public void AggregatesNewTradeBarsProperly() { //Arrange TradeBar newTradeBar = null; var tickAggregator = new TickAggregator(4); tickAggregator.DataAggregated += (sender, tradeBar) => { newTradeBar = tradeBar; }; //Act var reference = DateTime.Today; var tickersymbol = TickerSymbol.NIL("TST"); var bar1 = new Tick { Ticker = tickersymbol, Occured = reference, Price = 5, Size = 10 }; tickAggregator.Feed(bar1); newTradeBar.Should().BeNull(); var bar2 = new Tick { Ticker = tickersymbol, Occured = reference.AddHours(1), Price = 10, Size = 20 }; tickAggregator.Feed(bar2); newTradeBar.Should().BeNull(); var bar3 = new Tick { Ticker = tickersymbol, Occured = reference.AddHours(2), Price = 1, Size = 10 }; tickAggregator.Feed(bar3); newTradeBar.Should().BeNull(); var bar4 = new Tick { Ticker = tickersymbol, Occured = reference.AddHours(3), Price = 9, Size = 20 }; tickAggregator.Feed(bar4); //Assert newTradeBar.Should().NotBeNull(); newTradeBar.Ticker.Should().Be(tickersymbol); bar1.Occured.Should().Be(newTradeBar.Occured); bar1.Price.Should().Be(newTradeBar.Open); bar2.Price.Should().Be(newTradeBar.High); bar3.Price.Should().Be(newTradeBar.Low); bar4.Price.Should().Be(newTradeBar.Close); (bar1.Size + bar2.Size + bar3.Size + bar4.Size).Should().Be(newTradeBar.Volume); }