开发者

List Variable in WinForm C#

I'm still learning C# .Net 4 and this is my first WinForms so please be kind.

Continuing in my project, my financial DataFeed is streaming into my application by use of 'Asynchronous Sockets?'. Anyway, the data I am getting is tick per tick data, which is basically 1 order/transaction. So now I need t开发者_StackOverflowo build bars with this tick by tick data, in particular Range Bars.

My problem is I don't want to go to the database and grab this data, so I am looking to do this in memory, like a list variable. Eventually, this system on the main server will do all the number crunching etc... and will have clients connected via Sockets to interrogate or set their own predefined algos on the in coming data and build their own charts using different ranges and indicators.

I wouldn't want to offload this to the client because I would like to keep the indicators technology proprietary.

How would I go about implementing this?

I already have my class called Tick

class Tick
{
    public double Last { get; set; }
    public double Bid { get; set; }
    public double Ask { get; set; }
    public double BidSize { get; set; }
    public double AskSize { get; set; }
    public DateTime TimeStampInternal { get; set; }
    public int DTNTickID { get; set; }
    public int UpdateTypeID { get; set; }
} 

I'm thinking of a

Static List<Tick> Ticks 

but I don't think this is the way to go because

  1. I need to be able to hold only a certain amount of ticks and as new data comes in, old data gets thrown away, FIFO to keep memory usage down.
  2. I will only be able to hold 1 Static List and I need something dynamic, e.g. have a List for each user that connects which would be identifiable to them only.

Please help me architect this correctly with best practices for speed and efficiency.


Sounds like a circular buffer is what you're looking for.

http://circularbuffer.codeplex.com/

Or perhaps a queue.


I hope that I correctly understand what you want, so here is very pseudocode :

public class User {

     private UserTickList<Tick> _userTicks = new UserTickList<Tick>();

     public void AddUserTick(Tick t) {
              _userTicks.Add(t);
     }

     /*remove, update if need*/
}

 public class UserTickList {

    private List<Tick> _list = new List<Tick>();

    public void AddTick(Tick tick) {
         if(_list.Count == 10){
               /*perform what you need*/
         }
         else 
           _list.Add(tick);
    }
 }

I repeat this probabbly will not compile, but just to give an idea what it can look like.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜