Assembly Documentation

The API class documentation is available online at discretelogics.com/doc/teafiles.net

Examples

A set of examples is available as part of the source code. Download the source, open the solution and find them in the examples folder. This folder also holds a project named “Usage”, that has a runable version of this sample usage code.

How to store time series using TeaFiles.Net

1. Create the item type as a struct

public struct Tick
{ public Time Time; public double Price; public int Volume; }

The type must be a struct. For time values, use TeaTime.Time. It has same semantics as System.DateTime but counts milliseconds since 1.1.1970, which is important for data exchange with other applications. Support of System.DateTime might be added to the API in the future.

2. Use TeaFile<T> to create a new file:

using (var tf = TeaFile<Tick>.Create("acme.tea"))
{
    tf.Write(new Tick { Time = new DateTime(2000, 3, 4), Price = 42 });
tf.Write(new Tick { Time = new DateTime(2000, 3, 5), Price = 43 }); tf.Write(new Tick { Time = new DateTime(2000, 3, 6), Price = 44 }); }

The Create call will create the file “acme.tea” and write the file header. This header will include information about the item type “Tick”, including name of its fields and their offsets.

The Write calls then write values into the file. Note we use System.DateTime values above and assign them to the Time field of Tick which is actually of type TeaTime.Time. Conversion operators allow this. Alternatively, this can be written as:

using (var tf = TeaFile<Tick>.Create("acme.tea"))
{
    tf.Write(new Tick { Time = new Time(2000, 3, 4), Price = 42 });
    tf.Write(new Tick { Time = new Time(2000, 3, 5), Price = 43 });
    tf.Write(new Tick { Time = new Time(2000, 3, 6), Price = 44 });
}

This yields exactly the same file content.

3. Use TeaFileT to read a file

using (var tf = TeaFile<Tick>.OpenRead("acme.tea"))
{
    foreach (Tick tick in tf.Items)
    {
        Console.WriteLine(tick);
    }
}

4. More Examples

See the samples in the source code, or this sample usage code

Last edited Mar 16, 2012 at 3:49 PM by discretelogics, version 16

Comments

No comments yet.