Results 1 to 10 of 17

Hybrid View

  1. #1
    Senior Member
    Join Date
    Oct 2007
    Location
    HoChiMinh
    Posts
    69

    Could you explain more about _stockGenerators, _snapshotQueue, _snapshotSender?

    Could you explain more about _stockGenerators, _snapshotQueue, _snapshotSender in StockList demo code?

    In "ExternalFeed.cs" file, StockListDemo code (mark by red color) :

    public ExternalFeed() {

    _stockGenerators= new Hashtable();
    _snapshotQueue= new ArrayList();
    ...
    }

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

    for (int i = 0; i < 30; i++) --> purpose of for statement? Why it loop from 1 to 30?
    {
    string itemName= "item" + (i + 1);
    ...

    _stockGenerators[itemName]= myProducer;
    myProducer.SetFeedListener(_listener);
    myProducer.Start();
    }
    _snapshotSender= new Thread(new ThreadStart(Run)); --> I don't understand
    _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);

    }

  2. #2
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    1,090
    This sample class "simulates" a broadcast feed, which is one of the most common types of data feed, especially in a trading scenario.
    Once you connect to such a feed, you immediately receive the current real-time update flow for all available data (the IExternalFeedListener interface).
    Some broacast feed may also allow you to request the current state of a data item. Our sample feed class does support this (the SendCurrentValues method).

    In our sample feed class, all available data consists of 30 fake stocks, which is what is needed by the StockList demo front-end. For each of the above stocks/items, we create a specific object, of type ExternalFeedProducer, whose job is to create a thread and generate the updates for the item. We collect all these objects in the _stockGenerators hash table.

    In order to manage SendCurrentValues request, the feed does not return the current state to the caller, but it rather sends a redundant event to the IExternalFeedListener interface (i.e. an event which does not carry updated data but just the current state). We do this in a separate thread (we call this thread _snapshotSender; it runs the Run method reported above) and use the _snapshotQueue queue to send the SendCurrentValues requests to that thread.

    Hope This Helps
    Dario

  3. #3
    Senior Member
    Join Date
    Oct 2007
    Location
    HoChiMinh
    Posts
    69
    Hi Dario,
    You mean, StockListDemo work-flow :
    Step 1: Get feed data (simulate) from "ExternalFeed" class

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

    Step 2 : Starts generating update events for the stocks. attaching and reading from an external broadcast feed (in step 1).

    public void Start()
    {
    if (_snapshotSender != null) return;
    //all available data consists of 30 fake stocks, which is what is needed by the StockList demo front-end.
    for (int i = 0; i < 30; i++)
    {
    ....
    //For each of the above stocks/items, you create a specific object, of type ExternalFeedProducer, whose job is to create a thread and generate the updates for the item.
    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();
    }
    ...
    }


    private void Run()
    {
    ...
    }


    Now, I want to call my function every 5 seconds, it starts generating update events for the stocks, attaching and reading from an external broadcast feed (in step 1). How do I do?

    Can u help me?

  4. #4
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    1,090
    Provided that you still think that the demo architecture fits your needs, in order to send your custom data, you should customize only the "ExternalFeedProducer" class.
    Each object instance of this class owns an update thread, which waits for randomly generated times, produced by the "ComputeNextWaitTime" method; you can rewrite the latter to always return 5000 milliseconds.
    Then, you should only rewrite the "ComputeNewValues" and "GetCurrentValues" methods. The first one produces new data for the instance-related stock and stores it in the object; the second one collects the stored data in an "IDictionary", suitable for being sent forward.

    If, however, you can only read data for all your stocks, from outside, as an atomic operation, then some adjustments would be needed (it is still unclear to me which are your requirements).

    Dario

  5. #5
    Senior Member
    Join Date
    Oct 2007
    Location
    HoChiMinh
    Posts
    69
    Hi Dario,
    I tried follow your instruction, but it has error : Out of memory.

    Here my changed
    -------

    public int ComputeNextWaitTime()
    {
    lock (this)
    {
    return 5000;
    }
    }

    public void ComputeNewValues()
    {
    ISecurityStructReader reader;
    reader = new ReadSecurityStruct("C:\\TEMP\\BACKUP14\\SECURITY.D AT");

    nStock = 0;

    if (reader.Open())
    {
    arr = reader.Read();

    nStock = arr.Count;

    _stockSymbol = new string[nStock];

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

    string itemName= "item" + (i + 1);
    ExternalFeedProducer myProducer = new ExternalFeedProducer(itemName, m_openprices[i], m_refprices[i], m_minprices[i], m_maxprices[i], m_stockSymbol[i], m_stockNames[i], m_ceiling[i], m_floor[i], m_bid1[i], m_bid2[i], m_bid3[i], m_bid1vol[i], m_bid2vol[i], m_bid3vol[i], m_ask1[i], m_ask2[i], m_ask3[i],m_ask1vol[1], m_ask2vol[i], m_ask3vol[i], m_last[i], m_lastVal[i], m_lastVol[i], m_projectOpen[i]);

    _stockGenerators[itemName]= myProducer;

    myProducer.SetFeedListener(_listener);
    myProducer.Start();
    }
    ...
    }

    }

    -----------
    My step is correct?

    In my case, stock data i get from outside and it is a binary file and has a structure. I read it and store it in array list.

    In your code, u stored data in an "IDictionay" because you change only 01 value of item in the same time, but my data has many change in many item (in the same time).

    Example :
    10:00 AM I have :
    stock_symbol[1] = STB , price[1] = 100, volume[1] = 99
    stock_symbol[2]= ACB, price[2] = 80, volume[2] = 89

    10:01 AM, I have
    stock_symbol[1] = STB , price[1] = 101, volume[1] = 90
    stock_symbol[2]= ACB, price[2] = 82, volume[2] = 80

    How to rewrite "GetCurrentValues" and "ComputeNewValues" to store this? Can u help me?

  6. #6
    Administrator
    Join Date
    Jul 2006
    Location
    Milan
    Posts
    1,090
    I assume from the above that the answer to my doubt
    If, however, you can only read data for all your stocks, from outside, as an atomic operation, then some adjustments would be needed (it is still unclear to me which are your requirements).
    is yes; you can only read updates for several or all stocks alltogether from a file. Then I'm afraid that the demo Data Adapter architecture is not suitable for you as a starting point.

    What do you exactly read from your files?
    Do you get values for all stocks or only for the modified stocks?
    And, for each stock read, do you get values for all fields or only for the modified fields?

    Dario

 

 

Similar Threads

  1. Replies: 8
    Last Post: May 7th, 2008, 10:53 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 11:01 AM.