Results 1 to 10 of 10
  1. #1
    Senior Member
    Join Date
    Oct 2007
    Location
    HoChiMinh
    Posts
    69

    Arrow how to add the item into eventData

    Hi all,
    I modified code "ExternalFeed.cs". I changed initial constructor of class "ExternalFeed" by read binary file to get data.

    ------
    ISecurityStructReader reader;
    reader = new ReadSecurityStruct("C:\\TEMP\\SECURITY.DAT");


    if (reader.Open())
    {
    arr = reader.Read();
    _stockSymbol = new string[arr.Count];
    _openprices = new double[arr.Count];
    _stockNames = new string[arr.Count];
    _bid1 = new double[arr.Count];

    for (int i=0; i< arr.Count ;i++)
    {
    Struct_Security item = (Struct_Security)arr[i];
    //_stockNames.Add(item.SecurityName);
    _openprices[i]= item.OpenPrice;
    _stockSymbol[i]= item.StockSymbol;
    _stockNames[i] = item.SecurityName;
    _bid1[i] = item.Best1Bid ;
    }
    }

    reader.Close();

    ---
    and changed in function start() , mark red color

    public void Start() {
    if (_snapshotSender != null) return;

    for (int i = 0; i < 30; i++) {
    string itemName= "item" + (i + 1);
    ExternalFeedProducer myProducer = new ExternalFeedProducer(itemName,
    _openprices[i], _refprices[i], _minprices[i], _maxprices[i],
    _updateTimeMeans[i], _updateTimeStdDevs[i], _stockSymbol[i], _bid1[i]);

    _stockGenerators[itemName]= myProducer;
    myProducer.SetFeedListener(_listener);
    myProducer.Start();
    }

    _snapshotSender= new Thread(new ThreadStart(Run));
    _snapshotSender.Start();
    }
    ---

    and changed in class "ExternalFeedProducer" (mark by red color)


    public ExternalFeedProducer(string name,
    double openPrice, double referPrice, double minPrice, double maxPrice,
    double updateTimeMean, double updateTimeStdDev, string stockSymbol, double bid1) {
    _itemName = name;
    _open = (int) Math.Round(openPrice * 1000);
    _refer = (int) Math.Round(referPrice * 100);
    _min = (int) Math.Ceiling(minPrice * 100);
    _max = (int) Math.Floor(maxPrice * 100);
    _last = _open;
    _mean = updateTimeMean;
    _stddev = updateTimeStdDev;
    _stockSymbol = stockSymbol;
    _bid1 = bid1;

    _random = new Random();
    _haveNextNextGaussian= false;
    _nextNextGaussian= 0.0;

    ComputeNewValues();
    }

    ------

    and changed in function "GetCurrentValues" (mark by red color)

    public IDictionary GetCurrentValues(bool fullData) {
    lock (this) {
    IDictionary eventData = new Hashtable();

    string time = DateTime.Now.ToString("s");
    eventData["time"] = time.Substring(time.Length - 8);
    // this yields us a "HH:mm:ss" format

    AddDecField("last_price", _last, eventData);

    ....

    eventData["bid1"] = _bid1;
    return eventData;
    }
    }

    ------------
    and changed in "Burst.cs" file, function Run() :
    public void Run() {
    long count= 0;

    do {
    Thread.Sleep(1);

    .....
    eventData["bid1"]= _bid1;

    _listener.Update(_name, eventData, (count == 0));
    count++;

    } while (!_stop);
    }



    How to get value "_bid1" in function Run() in "Burst.cs" file?

    Here my code (full) :

    "externalfeed.cs"
    -------------
    /*
    * Copyright (c) 2004-2007 Weswit s.r.l., Via Campanini, 6 - 20124 Milano, Italy.
    * All rights reserved.
    * www.lightstreamer.com
    *
    * This software is the confidential and proprietary information of
    * Weswit s.r.l.
    * You shall not disclose such Confidential Information and shall use it
    * only in accordance with the terms of the license agreement you entered
    * into with Weswit s.r.l.
    */

    using System;
    using System.Threading;
    using System.Collections;

    namespace Lightstreamer.Adapters.Data.StockList {

    /// <summary>
    /// Used by the Stock List Adapter to receive data from the simulated broadcast feed in an
    /// asynchronous way, through the OnEvent method.
    /// </summary>
    public interface IExternalFeedListener {

    /// <summary>
    /// Called by the feed for each update event occurrence on some stock.
    /// If isSnapshot is true, then the event contains a full snapshot,
    /// with the current values of all fields for the stock.
    /// </summary>
    void OnEvent(string itemName, IDictionary currentValues, bool isSnapshot);
    }

    /// <summary>
    /// Used by the Stock List Adapter, it simulates an external data feed that supplies quote values for all the
    /// stocks needed for the demo.
    /// </summary>
    public class ExternalFeed {

    /// <summary>
    /// Used to automatically generate the updates for the 30 stocks:
    /// mean and standard deviation of the times between consecutive
    /// updates for the same stock.
    /// </summary>
    private double [] _updateTimeMeans;
    private double [] _updateTimeStdDevs;

    /// <summary>
    /// Used to generate the initial field values for the 30 stocks
    /// </summary>
    private double [] _refprices = null;
    private double [] _openprices = null;
    private double [] _minprices;
    private double [] _maxprices;
    private string [] _stockSymbol =null;
    private string [] _stockNames = null;

    private string [] _time;
    private string [] _ticker;
    private int [] _ceiling;
    private double [] _floor;
    private double[] _matched;
    private double [] _change;
    private double [] _close;

    private double [] _bid1;
    private double [] _bid2;
    private double [] _bid3;

    private double [] _ask1;
    private double [] _ask2;
    private double [] _ask3;

    private double [] _bid1vol;
    private double [] _bid2vol;
    private double [] _bid3vol;

    private double [] _ask1vol;
    private double [] _ask2vol;
    private double [] _ask3vol;

    private double [] _matchedvol;
    private double [] _openvol;
    private double [] _closevol;
    private double [] _totalvol;
    private double [] _priorroom;
    private double [] _room;

    //ArrayList _stockNames = new ArrayList();


    /// <summary>
    /// Used to keep the contexts of the 30 stocks.
    /// </summary>
    private IDictionary _stockGenerators;

    private IExternalFeedListener _listener;

    private IList _snapshotQueue;
    private Thread _snapshotSender;

    private ArrayList arr;

    public ExternalFeed() {
    /*
    _stockGenerators= new Hashtable();
    _snapshotQueue= new ArrayList();

    _updateTimeMeans = new double [] {30000, 500, 3000, 90000,
    7000, 10000, 3000, 7000,
    7000, 7000, 500, 3000,
    20000, 20000, 20000, 30000,
    500, 3000, 90000, 7000,
    10000, 3000, 7000, 7000,
    7000, 500, 3000, 20000,
    20000, 20000 };

    _updateTimeStdDevs = new double [] {6000, 300, 1000, 1000,
    100, 5000, 1000, 3000,
    1000, 6000, 300, 1000,
    1000, 4000, 1000, 6000,
    300, 1000, 1000, 100,
    5000, 1000, 3000, 1000,
    6000, 300, 1000, 1000,
    4000, 1000 };

    _refprices = new double [] {3.04, 16.09, 7.19, 3.63, 7.61,
    2.30, 15.39, 5.31, 4.86, 7.61,
    10.41, 3.94, 6.79, 26.87, 2.27,
    13.04, 6.09, 17.19, 13.63, 17.61,
    11.30, 5.39, 15.31, 14.86, 17.61,
    5.41, 13.94, 16.79, 6.87,
    11.27 };

    _openprices = new double [] {3.10, 16.20, 7.25, 3.62, 7.65,
    2.30, 15.85, 5.31, 4.97, 7.70,
    10.50, 3.95, 6.84, 27.05, 2.29,
    13.20, 6.20, 17.25, 13.62,
    17.65, 11.30, 5.55, 15.31,
    14.97, 17.70, 5.42, 13.95,
    16.84, 7.05, 11.29 };

    _minprices = new double [] {3.09, 15.78, 7.15, 3.62, 7.53,
    2.28, 15.60, 5.23, 4.89, 7.70,
    10.36, 3.90, 6.81, 26.74, 2.29,
    13.09, 5.78, 17.15, 13.62, 17.53,
    11.28, 5.60, 15.23, 14.89, 17.70,
    5.36, 13.90, 16.81, 6.74,
    11.29 };

    _maxprices = new double [] {3.19, 16.20, 7.26, 3.71, 7.65,
    2.30, 15.89, 5.31, 4.97, 7.86,
    10.50, 3.95, 6.87, 27.05, 2.31,
    13.19, 6.20, 17.26, 13.71, 17.65,
    11.30, 5.89, 15.31, 14.97, 17.86,
    5.50, 13.95, 16.87, 7.05,
    11.31 };

    _stockNames = new string [] {"Anduct", "Ations Europe",
    "Bagies Consulting", "BAY Corporation",
    "CON Consulting", "Corcor PLC",
    "CVS Asia", "Datio PLC",
    "Dentems", "ELE Manufacturing",
    "Exacktum Systems", "KLA Systems Inc",
    "Lted Europe", "Magasconall Capital",
    "MED", "Mice Investments",
    "Micropline PLC", "Nologicroup Devices",
    "Phing Technology", "Pres Partners",
    "Quips Devices", "Ress Devices",
    "Sacle Research", "Seaging Devices",
    "Sems Systems, Inc", "Softwora Consulting",
    "Systeria Develop", "Thewlec Asia",
    "Virtutis", "Yahl" };
    */

    //Modified by Tuong Kha
    //Last update : 24/12/2007
    //Purpose : Get data from "Security.dat" file.

    ISecurityStructReader reader;
    reader = new ReadSecurityStruct("C:\\TEMP\\SECURITY.DAT");


    if (reader.Open())
    {
    arr = reader.Read();
    _stockSymbol = new string[arr.Count];
    _openprices = new double[arr.Count];
    _stockNames = new string[arr.Count];
    _bid1 = new double[arr.Count];

    for (int i=0; i< arr.Count ;i++)
    {
    Struct_Security item = (Struct_Security)arr[i];
    //_stockNames.Add(item.SecurityName);
    _openprices[i]= item.OpenPrice;
    _stockSymbol[i]= item.StockSymbol;
    _stockNames[i] = item.SecurityName;
    _bid1[i] = item.Best1Bid ;

    }
    }

    reader.Close();

    }

    /// <summary>
    /// Starts generating update events for the stocks. Sumulates attaching
    /// and reading from an external broadcast feed.
    /// </summary>
    public void Start() {
    if (_snapshotSender != null) return;

    for (int i = 0; i < 30; i++) {
    string itemName= "item" + (i + 1);
    ExternalFeedProducer myProducer = new ExternalFeedProducer(itemName,
    _openprices[i], _refprices[i], _minprices[i], _maxprices[i],
    _updateTimeMeans[i], _updateTimeStdDevs[i], _stockSymbol[i], _bid1[i]);

    _stockGenerators[itemName]= myProducer;
    myProducer.SetFeedListener(_listener);
    myProducer.Start();
    }

    _snapshotSender= new Thread(new ThreadStart(Run));
    _snapshotSender.Start();
    }

    private void Run() {
    IList snapshots= new ArrayList();
    do {
    lock (_snapshotQueue) {
    if (_snapshotQueue.Count == 0)
    Monitor.Wait(_snapshotQueue);

    snapshots.Clear();
    while (_snapshotQueue.Count > 0) {
    ExternalFeedProducer myProducer= (ExternalFeedProducer) _snapshotQueue[0];
    snapshots.Add(myProducer);
    _snapshotQueue.RemoveAt(0);
    }
    }

    foreach (ExternalFeedProducer myProducer in snapshots) {
    _listener.OnEvent(myProducer.GetItemName(), myProducer.GetCurrentValues(true), true);
    }

    } while (true);
    }

    /// <summary>
    /// Sets an internal listener for the update events.
    /// Since now, the update events were ignored.
    /// </summary>
    public void SetFeedListener(IExternalFeedListener listener) {
    _listener= listener;

    foreach (ExternalFeedProducer myProducer in _stockGenerators.Values) {
    myProducer.SetFeedListener(listener);
    }
    }

    /// <summary>
    /// Forces sending an event with a full snapshot for a stock.
    /// </summary>
    public void SendCurrentValues(string itemName) {
    ExternalFeedProducer myProducer= (ExternalFeedProducer) _stockGenerators[itemName];
    if (myProducer == null) return;

    lock (_snapshotQueue) {
    _snapshotQueue.Add(myProducer);
    Monitor.Pulse(_snapshotQueue);
    }
    }
    }

    public class ExternalFeedProducer {
    public string _itemName;
    private int _open, _refer, _last, _min, _max, _other;
    private double _mean, _stddev, _bid1;
    private string _stockName;
    private string _stockSymbol;


    private Random _random;
    private bool _haveNextNextGaussian;
    private double _nextNextGaussian;

    private IExternalFeedListener _listener;
    private Thread _thread;

    /// <summary>
    /// Initializes stock data based on the already prepared values.
    /// </summary>
    public ExternalFeedProducer(string name,
    double openPrice, double referPrice, double minPrice, double maxPrice,
    double updateTimeMean, double updateTimeStdDev, string stockSymbol, double bid1)
    {
    _itemName = name;
    _open = (int) Math.Round(openPrice * 1000);
    _refer = (int) Math.Round(referPrice * 100);
    _min = (int) Math.Ceiling(minPrice * 100);
    _max = (int) Math.Floor(maxPrice * 100);
    _last = _open;
    _mean = updateTimeMean;
    _stddev = updateTimeStdDev;
    _stockSymbol = stockSymbol;
    _bid1 = bid1;

    _random = new Random();
    _haveNextNextGaussian= false;
    _nextNextGaussian= 0.0;

    ComputeNewValues();
    }

    public string GetItemName() {
    return _itemName;
    }

    public void SetFeedListener(IExternalFeedListener listener) {
    lock (this) {
    _listener = listener;
    }
    }

    public void Start() {
    lock (this) {
    if (_thread != null) return;

    _thread = new Thread(new ThreadStart(Run));
    _thread.Start();
    }
    }

    private void Run() {
    do {
    int waitMillis= ComputeNextWaitTime();
    Thread.Sleep(waitMillis);

    ComputeNewValues();
    if (_listener != null)
    _listener.OnEvent(_itemName, GetCurrentValues(false), false);

    } while (true);
    }

    /// <summary>
    /// Decides, for ease of simulation, the time at which the next
    /// update for the stock will happen.
    /// </summary>
    public int ComputeNextWaitTime() {
    lock (this) {
    int millis;
    do {
    millis = (int) Gaussian(_mean, _stddev);
    } while (millis <= 0);
    return millis;
    }
    }

    /// <summary>
    /// Changes the current data for the stock. This stuff is to ensure that new prices follow a random
    /// but nondivergent path, centered around the reference price
    /// </summary>
    public void ComputeNewValues() {
    lock (this) {
    double limit = _refer / 4.0;
    double relDist = (_last - _refer) / limit;

    int direction = 1;
    if (relDist < 0) {
    direction = -1;
    relDist = -relDist;
    }
    if (relDist > 1) {
    relDist = 1.0;
    }

    double weight = (relDist * relDist * relDist);
    double prob = (1.0 - weight) / 2.0;

    bool goFarther = (_random.NextDouble() < prob);
    if (!goFarther) {
    direction *= -1;
    }

    int jump = _refer / 100;
    int difference = Uniform(0, jump) * direction;
    int gap = _refer / 250;

    int delta;
    if (gap > 0) {
    do {
    delta = Uniform(-gap, gap);
    } while (delta == 0);
    }
    else {
    delta = 1;
    }

    _last += difference;
    _other = _last + delta;

    if (_last < _min) {
    _min = _last;
    }

    if (_last > _max) {
    _max = _last;
    }
    }
    }

    /// <summary>
    /// Picks the stock field values and stores them in a field/value
    /// Hashtable. If fullData is false, then only the fields whose value
    /// is just changed are considered (though this check is not strict).
    /// </summary>
    public IDictionary GetCurrentValues(bool fullData) {
    lock (this) {
    IDictionary eventData = new Hashtable();

    string time = DateTime.Now.ToString("s");
    eventData["time"] = time.Substring(time.Length - 8);
    // this yields us a "HH:mm:ss" format

    AddDecField("last_price", _last, eventData);

    if (_other > _last) {
    AddDecField("ask", _other, eventData);
    AddDecField("bid", _last, eventData);
    }
    else {
    AddDecField("ask", _last, eventData);
    AddDecField("bid", _other, eventData);
    }

    int quantity = Uniform(1, 200) * 500;
    eventData["bid_quantity"]= quantity.ToString();

    quantity = Uniform(1, 200) * 500;
    eventData["ask_quantity"]= quantity.ToString();

    double v = ((double) (_last - _refer)) / ((double) _refer) * 100.0;
    AddDecField("pct_change", (int) (v * 100.0), eventData);

    if ((_last == _min) || fullData) {
    AddDecField("min", _min, eventData);
    }
    if ((_last == _max) || fullData) {
    AddDecField("max", _max, eventData);
    }

    if (fullData) {
    eventData["stock_name"] = _stockName;
    AddDecField("ref_price", _refer, eventData);
    AddDecField("open_price", _open, eventData);
    }

    eventData["bid1"] = _bid1;
    return eventData;
    }
    }

    private static void AddDecField(string fld, int val100, IDictionary target) {
    double v = (((double) val100) / 100);
    target[fld]= v.ToString().Replace(',','.');
    }

    private double Gaussian(double mean, double stddev) {
    lock (this) {
    double b= 0.0;

    if (_haveNextNextGaussian) {
    _haveNextNextGaussian = false;
    b= _nextNextGaussian;

    }
    else {
    double v1, v2, s;
    do {
    v1 = 2.0 * _random.NextDouble() - 1.0;
    v2 = 2.0 * _random.NextDouble() - 1.0;
    s = v1 * v1 + v2 * v2;
    } while (s >= 1.0 || s == 0.0);
    double multiplier = Math.Sqrt(-2.0 * Math.Log(s)/s);
    _nextNextGaussian = v2 * multiplier;
    _haveNextNextGaussian = true;
    b= v1 * multiplier;
    }

    double val= b * stddev + mean;
    return val;
    }
    }

    private int Uniform(int min, int max) {
    lock (this) {
    int b = _random.Next(max + 1 - min);

    int val= b + min;
    return b + min;
    }
    }
    }

    }


    ---------------
    "Burst.cs"
    ---------------

    /*
    * Copyright (c) 2004-2007 Weswit s.r.l., Via Campanini, 6 - 20124 Milano, Italy.
    * All rights reserved.
    * www.lightstreamer.com
    *
    * This software is the confidential and proprietary information of
    * Weswit s.r.l.
    * You shall not disclose such Confidential Information and shall use it
    * only in accordance with the terms of the license agreement you entered
    * into with Weswit s.r.l.
    */

    using System;
    using System.Collections;
    using System.Threading;

    using Lightstreamer.Interfaces.Data;
    using Lightstreamer.Adapters.Data.BurstTest;

    namespace Lightstreamer.Adapters.Data {

    /// <summary>
    /// This Data Adapter accepts a limited set of item names (the names starting
    /// with "item") and produces for each item a coninuus burst of updates, one
    /// every few milliseconds. With 15 items subscribed this adapter is able
    /// to produce about 1000 updates/sec on a regular 2.0 GHz Pentium IV machine.
    /// Internal structure is not much different from the Stock List Demo Adapter,
    /// and it is client-compatible with it. Use it for performance testing purpuoses.
    /// </summary>
    public class BurstTestAdapter : IDataProvider {
    private IDictionary _items;
    private IItemEventListener _listener;

    public BurstTestAdapter() {
    _items= new Hashtable();
    _listener= null;
    }

    // ////////////////////////////////////////////////////////////////////////
    // IDataProvider methods

    public void Init(IDictionary parameters, string configFile) {}

    public void SetListener(IItemEventListener eventListener) {
    _listener= eventListener;
    }

    public void Subscribe(string itemName) {
    if (!itemName.StartsWith("item"))
    throw new SubscriptionException("Unexpected item: " + itemName);

    BurstProducer producer= new BurstProducer(itemName, _listener);
    lock (_items) {
    if (_items.Contains(itemName)) return;
    _items[itemName]= producer;
    }

    Thread t= new Thread(new ThreadStart(producer.Run));
    t.Start();
    }

    public void Unsubscribe(string itemName) {
    if (!itemName.StartsWith("item"))
    throw new SubscriptionException("Unexpected item: " + itemName);

    BurstProducer producer= null;
    lock (_items) {
    if (!_items.Contains(itemName)) return;
    producer= (BurstProducer) _items[itemName];
    _items.Remove(itemName);
    }

    producer.Stop();
    }

    public bool IsSnapshotAvailable(string itemName) {
    if (!itemName.StartsWith("item"))
    throw new SubscriptionException("Unexpected item: " + itemName);

    return true;
    }
    }

    }

    namespace Lightstreamer.Adapters.Data.BurstTest {

    // ////////////////////////////////////////////////////////////////////////
    // BurstProducer class

    public class BurstProducer {
    private string _name;
    private IItemEventListener _listener;
    private bool _stop;

    /// <summary>
    /// Used to timestamp each update with a Java-compatible millisecond-fine system time. In this
    /// way the "time" field of the update can be compared with the system time on the client-side
    /// to obtain a complete begin-to-end delay measure.
    /// </summary>
    private long _jan1_1970_utc_ticks;

    public BurstProducer(string name, IItemEventListener eventListener) {
    _name= name;
    _listener= eventListener;
    _stop= false;

    DateTime jan1_1970= new DateTime(1970, 1, 1, 1, 00, 00, 00); // Change hour accordignly to your timezone
    DateTime jan1_1970_utc= jan1_1970.ToUniversalTime();
    _jan1_1970_utc_ticks= jan1_1970_utc.Ticks;
    }

    public void Run() {
    long count= 0;

    do {
    Thread.Sleep(1);

    IDictionary eventData= new Hashtable();

    eventData["time"]= ((DateTime.UtcNow.Ticks - _jan1_1970_utc_ticks) / 10000).ToString();
    eventData["last_price"]= count.ToString();
    eventData["ask"]= count.ToString();
    eventData["bid"]= count.ToString();
    eventData["bid_quantity"]= count.ToString();
    eventData["ask_quantity"]= count.ToString();
    eventData["pct_change"]= (count % 100).ToString();
    eventData["min"]= 0.ToString();
    eventData["max"]= count.ToString();
    eventData["ref_price"]= 0.ToString();
    eventData["open_price"]= 0.ToString();
    eventData["stock_name"]= _name;
    eventData["bid1"]= _bid1; --> Error here : how to get value for eventData["bid1"]?

    _listener.Update(_name, eventData, (count == 0));
    count++;

    } while (!_stop);
    }

    public void Stop() {
    _stop= true;
    }
    }

    }

  2. #2
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    975
    Hi

    I didn't read all the reported code, but I can say that "bursts.cs" is an alternative Data Adapter which is not related with the StockList demo sample Data Adapter. This source was provided together with the StockList demo Data Adapter code, but this only caused confusion and it has been removed in the latest distribution packages.

  3. #3
    Senior Member
    Join Date
    Oct 2007
    Location
    HoChiMinh
    Posts
    69
    Hi darioCrivelli,
    I mean in your sample code (StockList demo), in "ExternalFeed.cs", you have :

    public ExternalFeedSimulator() {
    _stockGenerators= new Hashtable();
    _snapshotQueue= new ArrayList();
    ...

    _refprices = new double [] {3.04, 16.09, 7.19, 3.63, 7.61,
    2.30, 15.39, 5.31, 4.86, 7.61,
    10.41, 3.94, 6.79, 26.87, 2.27,
    13.04, 6.09, 17.19, 13.63, 17.61,
    11.30, 5.39, 15.31, 14.86, 17.61,
    5.41, 13.94, 16.79, 6.87,
    11.27 };
    }

    Now, I replace your code by read data from file. I want to add more varialbe, something like that (mark by red color) :

    {
    ISecurityStructReader reader;
    reader = new ReadSecurityStruct("C:\\TEMP\\SECURITY.DAT");


    if (reader.Open())
    {
    arr = reader.Read();
    _stockSymbol = new string[arr.Count];
    _openprices = new double[arr.Count];
    _stockNames = new string[arr.Count];
    _bid1 = new double[arr.Count];
    for (int i=0; i< arr.Count ;i++)
    {
    Struct_Security item = (Struct_Security)arr[i];
    //_stockNames.Add(item.SecurityName);
    _openprices[i]= item.OpenPrice;
    _stockSymbol[i]= item.StockSymbol;
    _stockNames[i] = item.SecurityName;
    _bid1[i] = item.Best1Bid ;
    }
    }
    reader.Close();
    }

    and in "default.html", i have :

    ////////////////Global var declaration
    var schema = "last_price time pct_change bid_quantity bid1 ask ask_quantity min max ref_price open_price stock_name item_status";

    My question: I want to show the _bid1[i] = item.Best1Bid value in html. how to get (or what code I can modified) value _bid1[] to show on "default.html" file ?

  4. #4
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    975
    Hi,

    The extension seems correct. Therefore, just ensure that suitable cells are also added to "default.html" to display the new field data. The cells can be defined in several ways; the best way depends on the current code in "default.html".
    You can easily check if your new field is sent to the client through the Server log, by setting the priority for the "LightstreamerLogger.pump" category as "DEBUG".

  5. #5
    Senior Member
    Join Date
    Oct 2007
    Location
    HoChiMinh
    Posts
    69
    Hi DarioCrivelli,
    You said "You can easily check if your new field is sent to the client through the Server log, by setting the priority for the "LightstreamerLogger.pump" category as "DEBUG". and How i can setting the priority for the the "LightstreamerLogger.pump" category as "DEBUG" to check new field when it sent to client through the Server?

  6. #6
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    975
    The Server log configuration settings are in the "lightstreamer_log_conf.xml" file, under the "conf" directory. The configuration is in "log4j" format.
    Just find an existing element for the "LightstreamerLogger.pump" category and change the priority value. The change is affective after a few seconds.

    Dario

  7. #7
    Senior Member
    Join Date
    Oct 2007
    Location
    HoChiMinh
    Posts
    69
    Hi Dario,
    First, thanks for your help. I followed by your instruction, and it has error :
    07.Jan.08 09:02:51,656 < INFO> Reused HTTP connection on Lightstreamer HTTP Serv
    er from 127.0.0.1:1206
    07.Jan.08 09:02:51,765 < INFO> Serving request: /lightstreamer/control.html?LS_s
    ession=S-1255625151N1&LS_window=0&LS_win_phase=5&LS_op=add& LS_req_phase=57&LS_mo
    de1=MERGE&LS_id1=item1%20item2%20item3%20item4%20i tem5%20item6%20item7%20item8%2
    0item9%20item10%20item11%20item12%20item13%20item1 4%20item15%20&LS_schema1=last_
    price%20time%20pct_change%20bid_quantity%20bid%20a sk%20ask_quantity%20min%20max%
    20ref_price%20open_price%20stock_name%20item_statu s%20ceiling%20floor&LS_snapsho
    t1=true&LS_requested_max_frequency1=0.5&LS_unique= 1 from 127.0.0.1:1206
    07.Jan.08 09:02:51,765 < INFO> Controlling session: S-1255625151N1 from 127.0.0.
    1:1206
    07.Jan.08 09:02:51,843 < INFO> Reused HTTP connection on Lightstreamer HTTP Serv
    er from 127.0.0.1:1206
    07.Jan.08 09:02:51,859 <TRACE> Pumping event in session S-1255625151N1: c(6,5,0)
    ;setWin(0,5);
    07.Jan.08 09:02:52,078 <ERROR> Failure invoked by Data Adapter
    com.lightstreamer.interfaces.data.FailureException : Unknown value '9450' found w
    hile building a UD3 request
    at com.lightstreamer.adapters.remote.data.DataProvide rProtocol.readFailu
    re(DataProviderProtocol.java:161)
    at com.lightstreamer.adapters.remote.data.RemoteDataP rovider.onNotifyRec
    eived(RemoteDataProvider.java:159)
    at com.lightstreamer.adapters.remote.request_reply.No tifyReceiver.onNoti
    fyReceived(NotifyReceiver.java:165)
    at com.lightstreamer.adapters.remote.request_reply.No tifyReceiver.run(No
    tifyReceiver.java:89)
    07.Jan.08 09:02:52,078 <FATAL> Failure in a Data Adapter
    07.Jan.08 09:02:52,078 < INFO> Exiting.....
    07.Jan.08 09:02:52,546 < INFO> Serving request: /tutorial_demo/ls/lsblank.html f
    rom 127.0.0.1:1206
    07.Jan.08 09:02:52,546 < INFO> Reused HTTP connection on Lightstreamer HTTP Serv
    er from 127.0.0.1:1206
    07.Jan.08 09:02:53,890 <TRACE> Sending probe in session S-1255625151N1
    Press any key to continue . . .

    -------
    In your code (StockList Demo) :

    public ExternalFeedSimulator() {
    _stockGenerators= new Hashtable();
    _snapshotQueue= new ArrayList();
    ...

    _refprices = new double [] {3.04, 16.09, 7.19, 3.63, 7.61,
    2.30, 15.39, 5.31, 4.86, 7.61,
    10.41, 3.94, 6.79, 26.87, 2.27,
    13.04, 6.09, 17.19, 13.63, 17.61,
    11.30, 5.39, 15.31, 14.86, 17.61,
    5.41, 13.94, 16.79, 6.87,
    11.27 };
    }

    and i changed something by add more variable :

    ISecurityStructReader reader;
    reader = new ReadSecurityStruct("C:\\TEMP\\BACKUP03\\SECURITY.D AT");


    if (reader.Open())
    {
    arr = reader.Read();
    _stockSymbol = new string[arr.Count];
    _openprices = new double[arr.Count];
    _stockNames = new string[arr.Count];
    _bid1 = new double[arr.Count];
    _maxprices = new double[arr.Count];
    _minprices = new double[arr.Count];
    _ceiling = new int [arr.Count];
    _floor = new double[arr.Count];
    _refprices = new double[arr.Count];

    for (int i=0; i< arr.Count ;i++)
    {
    Struct_Security item = (Struct_Security)arr[i];
    //_stockNames.Add(item.SecurityName);
    _openprices[i]= item.OpenPrice;
    _stockSymbol[i]= item.StockSymbol;
    _stockNames[i] = item.SecurityName;
    _maxprices[i] = item.Highest;
    _minprices[i] = item.Lowest;
    _ceiling[i] = item.Ceiling;
    _floor[i]= item.Floor;

    //gia tham chieu
    _refprices[i] = item.PriorClosePrice;
    //_bid1[i]= item.Best1Bid;

    }
    }

    reader.Close();

    in your code :
    ---------------------
    public void Start() {
    if (_snapshotSender != null) return;

    for (int i = 0; i < 30; i++) {
    string itemName= "item" + (i + 1);
    ExternalFeedProducer myProducer = new ExternalFeedProducer(itemName,
    _openprices[i], _refprices[i], _minprices[i], _maxprices[i],
    _updateTimeMeans[i], _updateTimeStdDevs[i], _stockNames[i]);

    _stockGenerators[itemName]= myProducer;
    myProducer.SetFeedListener(_listener);
    myProducer.Start();
    }

    _snapshotSender= new Thread(new ThreadStart(Run));
    _snapshotSender.Start();
    }

    my changed :
    ---------------
    ExternalFeedProducer myProducer = new ExternalFeedProducer(itemName,
    _openprices[i], _refprices[i], _minprices[i], _maxprices[i],
    _updateTimeMeans[i], _updateTimeStdDevs[i], _stockSymbol[i], _ceiling[i], _floor[i]);

    -------
    your code :
    -------
    public ExternalFeedProducer(string name,
    double openPrice, double referPrice, double minPrice, double maxPrice,
    double updateTimeMean, double updateTimeStdDev, string stockSymbol, int ceiling, double floor) {
    _itemName = name;
    _open = (int) Math.Round(openPrice / 1000);
    _refer = (int) Math.Round(referPrice / 100);
    ...
    }

    ---
    my changed :
    ---
    public ExternalFeedProducer(string name,
    double openPrice, double referPrice, double minPrice, double maxPrice,
    double updateTimeMean, double updateTimeStdDev, string stockSymbol, int ceiling, double floor) {
    _itemName = name;
    _open = (int) Math.Round(openPrice / 1000);
    _refer = (int) Math.Round(referPrice / 100);
    ...
    _min = minPrice;
    _max = maxPrice;
    _last = _open;
    _mean = updateTimeMean;
    _stddev = updateTimeStdDev;
    _stockSymbol = stockSymbol;
    _stockName = stockSymbol;
    _ceiling = ceiling;
    _floor = floor;

    }
    ------
    in your code :
    ------
    public IDictionary GetCurrentValues(bool fullData) {
    lock (this) {
    IDictionary eventData = new Hashtable();
    string time = DateTime.Now.ToString("s");
    eventData["time"] = time.Substring(time.Length - 8);
    ...
    }
    }

    ---
    my changed
    ----
    public IDictionary GetCurrentValues(bool fullData) {
    lock (this) {
    IDictionary eventData = new Hashtable();
    string time = DateTime.Now.ToString("s");
    eventData["time"] = time.Substring(time.Length - 8);

    eventData["ceiling"] = _ceiling;
    eventData["floor"] = _floor;

    ...
    }
    }

    and in default.html, i changed (mark by red color):

    <script>
    for (var i = 1; i <= 15; i++) {
    var suff = (i % 2 == 1) ? "A" : "B";
    document.write('<tr class="lscold'+suff+'">');
    document.write('<td nowrap style="text-align: left"><a href="#" onClick="return openPopup('+i+')"><img src="images/popup.gif" width="16" height="16" border="0" align="left" hspace="1" alt="Graphic Chart"><div class="stockname'+suff+'" source="lightstreamer" table="1" item="'+i+'" field="12">Loading...</div></a></td>');
    document.write('<td><div source="lightstreamer" table="1" item="'+i+'" field="1">-</div></td>');
    document.write('<td><div source="lightstreamer" table="1" item="'+i+'" field="2">-</div></td>');
    document.write('<td><span source="lightstreamer" table="1" item="'+i+'" field="16"><img src="images/spacer_4px.gif" width="20" height="8" border="0"></span></td>');
    document.write('<td nowrap><div source="lightstreamer" table="1" item="'+i+'" field="3">-</div></td>');
    document.write('<td><div source="lightstreamer" table="1" item="'+i+'" field="4">-</div></td>');
    document.write('<td><div source="lightstreamer" table="1" item="'+i+'" field="5">-</div></td>');
    document.write('<td><div source="lightstreamer" table="1" item="'+i+'" field="6">-</div></td>');
    document.write('<td><div source="lightstreamer" table="1" item="'+i+'" field="7">-</div></td>');
    document.write('<td><div source="lightstreamer" table="1" item="'+i+'" field="8">-</div></td>');
    document.write('<td><div source="lightstreamer" table="1" item="'+i+'" field="9">-</div></td>');
    document.write('<td><div source="lightstreamer" table="1" item="'+i+'" field="10">-</div></td>');
    document.write('<td><div source="lightstreamer" table="1" item="'+i+'" field="11">-</div></td>');
    document.write('<td><div source="lightstreamer" table="1" item="'+i+'" field="14">-</div></td>');
    document.write('<td><div source="lightstreamer" table="1" item="'+i+'" field="15">-</div></td>');

    document.write('</tr>');
    }
    </script>
    ////////////////Global var declaration
    var schema = "last_price time pct_change bid_quantity bid ask ask_quantity min max ref_price open_price stock_name item_status ceiling floor";
    var page1 = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
    var page2 = new Array(16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30);

    What my fault? Can u help me?

  8. #8
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    975
    The IItemEventListener.Update method specifications require that only String objects or byte arrays can be used as field values. You have to perform the conversions from numbers to strings in Data Adapter code, before populating the IDictionary object.
    (We might think about improving the error message.)
    Dario

  9. #9
    Senior Member
    Join Date
    Oct 2007
    Location
    HoChiMinh
    Posts
    69
    Thanks Dario. I convert from numbers to strings, it's ok.

    public IDictionary GetCurrentValues(bool fullData) {
    lock (this) {
    IDictionary eventData = new Hashtable();
    ...
    eventData["ceiling"] = _ceiling.ToString();
    eventData["floor"] = _floor.ToString();

    }
    }

  10. #10
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    975
    The remaining part of the thread has been moved as
    /vb/showthread.php?t=238

 

 

Similar Threads

  1. Replies: 2
    Last Post: December 24th, 2010, 08:51 AM
  2. how to add the item into eventData
    By tuongkha in forum Client APIs
    Replies: 6
    Last Post: January 10th, 2008, 10:26 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT +1. The time now is 03:45 AM.