/// <summary> /// Backtesting & Live Bitcoin Decoder: /// </summary> public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, DataFeedEndpoint datafeed) { Bitcoin coin = new Bitcoin(); switch (datafeed) { //Example Line Format: //Date Open High Low Close Volume (BTC) Volume (Currency) Weighted Price //2011-09-13 5.8 6.0 5.65 5.97 58.37138238, 346.0973893944 5.929230648356 case DataFeedEndpoint.Backtesting: try { string[] data = line.Split(','); coin.Time = DateTime.Parse(data[0], CultureInfo.InvariantCulture); coin.Open = Convert.ToDecimal(data[1], CultureInfo.InvariantCulture); coin.High = Convert.ToDecimal(data[2], CultureInfo.InvariantCulture); coin.Low = Convert.ToDecimal(data[3], CultureInfo.InvariantCulture); coin.Close = Convert.ToDecimal(data[4], CultureInfo.InvariantCulture); coin.VolumeBTC = Convert.ToDecimal(data[5]); coin.WeightedPrice = Convert.ToDecimal(data[7]); coin.Symbol = "BTC"; coin.Value = coin.Close; } catch { } break; //Example Line Format: //{"high": "441.00", "last": "421.86", "timestamp": "1411606877", "bid": "421.96", "vwap": "428.58", "volume": "14120.40683975", "low": "418.83", "ask": "421.99"} case DataFeedEndpoint.Tradier: case DataFeedEndpoint.LiveTrading: try { var liveBTC = JsonConvert.DeserializeObject <LiveBitcoin>(line); coin.Time = DateTime.Now; coin.Open = liveBTC.Last; coin.High = liveBTC.High; coin.Low = liveBTC.Low; coin.Close = liveBTC.Last; coin.VolumeBTC = liveBTC.Volume; coin.WeightedPrice = liveBTC.VWAP; coin.Symbol = "BTC"; coin.Value = coin.Close; } catch { } break; } return(coin); }
/// <summary> /// Clone the bitcoin object, required for live data. /// </summary> /// <returns></returns> public override BaseData Clone() { Bitcoin coin = new Bitcoin(); coin.Close = this.Close; coin.High = this.High; coin.Low = this.Low; coin.Open = this.Open; coin.Symbol = this.Symbol; coin.Value = this.Close; coin.Time = this.Time; coin.VolumeBTC = this.VolumeBTC; coin.WeightedPrice = this.WeightedPrice; return(coin); }
/// <summary> /// New Bitcoin Data Event. /// </summary> /// <param name="data">Data.</param> public void OnData(Bitcoin data) { if (LiveMode) //Live Mode Property { //Configurable title header statistics numbers SetRuntimeStatistic("BTC", data.Close.ToString("C")); } if (!Portfolio.HoldStock) { Order("BTC", 100); //Send a notification email/SMS/web request on events: Notify.Email("*****@*****.**", "Test", "Test Body", "test attachment"); Notify.Sms("+11233456789", Time.ToString("u") + ">> Test message from live BTC server."); Notify.Web("http://api.quantconnect.com", Time.ToString("u") + ">> Test data packet posted from live BTC server."); } }
/// <summary> /// Custom data event handler: /// </summary> /// <param name="data">Bitcoin - dictionary of TradeBarlike Bars of Bitcoin Data</param> public void OnData(Bitcoin data) { }
//Bitcoin Handler: public void OnData(Bitcoin data) { Debug(Time.ToLongTimeString() + " >> ALGO >> OnData(BTC) >> BTC: " + data.Close); }