/// <summary> /// 3. READER METHOD: Read 1 line from data source and convert it into Object. /// Each line of the CSV File is presented in here. The backend downloads your file, loads it into memory and then line by line /// feeds it into your algorithm /// </summary> /// <param name="line">string line from the data source file submitted above</param> /// <param name="config">Subscription data, symbol name, data type</param> /// <param name="date">Current date we're requesting. This allows you to break up the data source into daily files.</param> /// <param name="datafeed">Datafeed type - Backtesting or LiveTrading</param> /// <returns>New Bitcoin Object which extends BaseData.</returns> public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, DataFeedEndpoint datafeed) { //New bitcoin object Bitcoin coin = new Bitcoin(); try { //Example File 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 string[] data = line.Split(','); coin.Time = DateTime.Parse(data[0]); 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], CultureInfo.InvariantCulture); coin.VolumeUSD = Convert.ToDecimal(data[6], CultureInfo.InvariantCulture); coin.WeightedPrice = Convert.ToDecimal(data[7], CultureInfo.InvariantCulture); coin.Symbol = "BTC"; coin.Value = coin.Close; } catch { /* Do nothing, skip first title row */ } return(coin); }
/// <summary> /// Event Handler for Bitcoin Data Events: These weather objects are created from our /// "Weather" type below and fired into this event handler. /// </summary> /// <param name="data">One(1) Weather Object, streamed into our algorithm synchronised in time with our other data streams</param> public void OnData(Bitcoin data) { //If we don't have any weather "SHARES" -- invest" if (!Portfolio.Invested) { //Weather used as a tradable asset, like stocks, futures etc. if (data.Close != 0) { Order("BTC", (Portfolio.Cash / Math.Abs(data.Close + 1))); } Console.WriteLine("Buying BTC 'Shares': BTC: " + data.Close); } Console.WriteLine("Time: " + Time.ToLongDateString() + " " + Time.ToLongTimeString() + data.Close.ToString()); }
/// <summary> /// Event Handler for Bitcoin Data Events: These weather objects are created from our /// "Weather" type below and fired into this event handler. /// </summary> /// <param name="data">One(1) Weather Object, streamed into our algorithm synchronised in time with our other data streams</param> public void OnData(Bitcoin data) { //If we don't have any weather "SHARES" -- invest" if (!Portfolio.Invested) { //Weather used as a tradable asset, like stocks, futures etc. if (data.Close != 0) { Order("BTC", (Portfolio.MarginRemaining / Math.Abs(data.Close + 1))); } Console.WriteLine("Buying BTC 'Shares': BTC: " + data.Close); } Console.WriteLine("Time: " + Time.ToLongDateString() + " " + Time.ToLongTimeString() + data.Close.ToString()); }
/// <summary> /// 3. READER METHOD: Read 1 line from data source and convert it into Object. /// Each line of the CSV File is presented in here. The backend downloads your file, loads it into memory and then line by line /// feeds it into your algorithm /// </summary> /// <param name="line">string line from the data source file submitted above</param> /// <param name="config">Subscription data, symbol name, data type</param> /// <param name="date">Current date we're requesting. This allows you to break up the data source into daily files.</param> /// <param name="datafeed">Datafeed type - Backtesting or LiveTrading</param> /// <returns>New Bitcoin Object which extends BaseData.</returns> public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, DataFeedEndpoint datafeed) { //New bitcoin object Bitcoin coin = new Bitcoin(); try { //Example File 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 string[] data = line.Split(','); coin.Time = DateTime.Parse(data[0]); coin.Open = Convert.ToDecimal(data[1]); coin.High = Convert.ToDecimal(data[2]); coin.Low = Convert.ToDecimal(data[3]); coin.Close = Convert.ToDecimal(data[4]); coin.VolumeBTC = Convert.ToDecimal(data[5]); coin.VolumeUSD = Convert.ToDecimal(data[6]); coin.WeightedPrice = Convert.ToDecimal(data[7]); coin.Symbol = "BTC"; coin.Value = coin.Close; } catch { /* Do nothing, skip first title row */ } return coin; }