/// <summary>
 /// Event Handler for Bitcoin Data Events: These Bitcoin objects are created from our
 /// "Bitcoin" type below and fired into this event handler.
 /// </summary>
 /// <param name="data">One(1) Bitcoin 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 bitcoin "SHARES" -- invest"
     if (!Portfolio.Invested)
     {
         //Bitcoin used as a tradable asset, like stocks, futures etc.
         if (data.Close != 0)
         {
             Order("BTC", Portfolio.MarginRemaining / Math.Abs(data.Close + 1));
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Event Handler for Bitcoin Data Events: These Bitcoin objects are created from our
 /// "Bitcoin" type below and fired into this event handler.
 /// </summary>
 /// <param name="data">One(1) Bitcoin Object, streamed into our algorithm synchronized in time with our other data streams</param>
 public void OnData(Bitcoin data)
 {
     //If we don't have any bitcoin "SHARES" -- invest"
     if (!Portfolio.Invested)
     {
         //Bitcoin used as a tradable asset, like stocks, futures etc.
         if (data.Close != 0)
         {
             //Access custom data symbols using <ticker>.<custom-type>
             Order("BTC.Bitcoin", Portfolio.MarginRemaining / Math.Abs(data.Close + 1));
         }
     }
 }
Ejemplo n.º 3
0
 /// <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>
 /// 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)
         {
             // It's only OK to use SetHoldings with crypto when using custom data. When trading with built-in crypto data,
             // use the cashbook. Reference https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/BasicTemplateCryptoAlgorithm.py
             SetHoldings("BTC", 1);
         }
         Console.WriteLine("Buying BTC 'Shares': BTC: " + data.Close);
     }
     Console.WriteLine("Time: " + Time.ToStringInvariant("T") + " " + Time.ToStringInvariant("T") + data.Close.ToStringInvariant());
 }
Ejemplo n.º 5
0
        /// <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.");
            }
        }
Ejemplo n.º 6
0
        /// <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="isLiveMode">true if we're in live mode, false for backtesting mode</param>
        /// <returns>New Bitcoin Object which extends BaseData.</returns>
        public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
        {
            var coin = new Bitcoin();

            if (isLiveMode)
            {
                //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"}
                try
                {
                    coin         = JsonConvert.DeserializeObject <Bitcoin>(line);
                    coin.EndTime = DateTime.UtcNow;
                    coin.Time    = coin.EndTime - config.Increment;
                    coin.Value   = coin.Close;
                }
                catch { /* Do nothing, possible error in json decoding */ }
                return(coin);
            }

            //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
            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], CultureInfo.InvariantCulture);
                coin.VolumeUSD     = Convert.ToDecimal(data[6], CultureInfo.InvariantCulture);
                coin.WeightedPrice = Convert.ToDecimal(data[7], CultureInfo.InvariantCulture);
                coin.Value         = coin.Close;
            }
            catch { /* Do nothing, skip first title row */ }

            return(coin);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Custom data event handler:
 /// </summary>
 /// <param name="data">Bitcoin - dictionary of TradeBarlike Bars of Bitcoin Data</param>
 public void OnData(Bitcoin data)
 {
 }