简体   繁体   English

在 WinForm C# 中列出变量

[英]List Variable in WinForm C#

I'm still learning C#.Net 4 and this is my first WinForms so please be kind.我还在学习 C#.Net 4,这是我的第一个 WinForms,所以请善待。

Continuing in my project, my financial DataFeed is streaming into my application by use of 'Asynchronous Sockets?'.继续我的项目,我的财务 DataFeed 通过使用“异步 Sockets?”流入我的应用程序。 Anyway, the data I am getting is tick per tick data, which is basically 1 order/transaction.无论如何,我得到的数据是每分时数据,基本上是 1 个订单/交易。 So now I need to 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.我的问题是我不想 go 到数据库并获取这些数据,所以我希望在 memory 中执行此操作,就像列表变量一样。 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.最终,主服务器上的这个系统将完成所有的数字运算等......并将通过 Sockets 连接客户端,以查询或设置自己的预定义算法,并使用不同的范围和指标构建自己的图表。

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?我将如何 go 来实现这个?

I already have my class called Tick我已经有了名为 Tick 的 class

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但我不认为这是通往 go 的方式,因为

  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.我只需要能够保持一定数量的滴答声,并且随着新数据的进入,旧数据被丢弃,FIFO 以降低 memory 的使用率。
  2. I will only be able to hold 1 Static List and I need something dynamic, eg have a List for each user that connects which would be identifiable to them only.我只能持有 1 个 Static 列表,我需要一些动态的东西,例如,为每个连接的用户都有一个列表,只有他们可以识别。

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/ 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.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM