Наследование: OptimizedPersistable
Пример #1
0
    /// <summary>
    /// Generate random ticks
    /// </summary>
    public static IEnumerable<Tick> GenerateRandom(ulong count)
    {
      //Some symbols
      string[] symbols = new string[] { "EURUSD", "GBPCHF", "EURGBP", "JPYUSD", "GBPCAD" };
      string[] exchanges = new string[] { "NYSE", "TSE", "NASDAQ", "Euronext", "LSE", "SSE", "ASE", "SE", "NSEI" };
      providers = new string[] { "eSignal", "Gain", "NYSE", "TSE", "NASDAQ", "Euronext", "LSE", "SSE", "ASE", "SE", "NSEI" };
      double[] prices = new double[symbols.Length];
      double[] pipsizes = new double[symbols.Length];
      int[] digits = new int[symbols.Length];

      //Initialize startup data
      for (int i = 0; i < symbols.Length; i++)
      {
        prices[i] = 1.5;
        pipsizes[i] = 0.0001;
        digits[i] = 4;
      }

      DateTime timestamp = DateTime.Now;

      //Generate ticks
      for (ulong i = 0; i < count; i++)
      {
        int id = random.Next(symbols.Length);

        //generate random movement
        int pips = random.Next(0, 10);
        int direction = random.Next() % 2 == 0 ? 1 : -1;
        int spread = random.Next(2, 30);
        int seconds = random.Next(1, 30);

        //generate values
        string symbol = symbols[id];

        timestamp = timestamp.AddSeconds(seconds);

        double bid = prices[id];
        bid += direction * pips * pipsizes[id];
        bid = Math.Round(bid, digits[id]);

        double ask = bid + spread * pipsizes[id];
        ask = Math.Round(ask, digits[id]);

        //create tick
        Tick tick = new Tick();
        tick.Symbol = symbol;
        tick.Timestamp = timestamp;
        tick.Bid = bid;
        tick.Ask = ask;
        int bidSize = random.Next(0, 10000);
        int askSize = random.Next(0, 10000);
        string provider = providers[random.Next(providers.Length)];

        yield return tick;
      }
    }
Пример #2
0
 public TickOptimized(Tick tick)
 {
   symbol = tick.Symbol;
   timestamp = tick.Timestamp;
   bid = tick.Bid;
   ask = tick.Ask;
   askSize = tick.AskSize;
   bidSize = tick.BidSize;
   provider = tick.Provider;
 }