0

I tried to export tickstory data to a file in CSV, but it came out as bi5 files.

anyways, I am trying to decode bi5 files.

I used 7zip decoding which turned out a bigger garbage.

what should I use in order to decode bi5 file? Moreover how to do it in C#?

Hoy Cheung
  • 1,552
  • 3
  • 19
  • 36

2 Answers2

1

You should find csv file in tickstory directory. It's created by default along with bi5 files.

Bahu5
  • 11
  • 2
0

The Bi5 format background

The size of one Tick record in bi5 file is 5 x 4 bytes. The structure of bi5 record is following:

  1. 1st 4 bytes -> Time part of the timestamp
  2. 2nd 4 bytes -> Bid
  3. 3rd 4 bytes -> Ask
  4. 4th 4 bytes -> Bid Volume
  5. 5th 4 bytes -> Ask Volume

Code Sample

So the code, that translates Bi5 to C# primitives could look like this:

byte[] bytes = new bytes[0]; // this is placeholder for tick data 
var date = DateTime.Now.AddYears(-1); // this is the tick data start date 
var i = 0;
var decimals = 5; // for JPY pairs or other CFD it can be 3 or other
var milliseconds = BitConverter.ToInt32(
    bytes[new Range(new Index(i), new Index(i + 4))]
    .Reverse().ToArray());
var i1 = BitConverter.ToInt32(bytes[new Range(i + 4, i + 8)].Reverse().ToArray());
var i2 = BitConverter.ToInt32(bytes[new Range(i + 8, i + 12)].Reverse().ToArray());
var f1 = BitConverter.ToSingle(bytes[new Range(i + 12, i + 16)].Reverse().ToArray());
var f2 = BitConverter.ToSingle(bytes[new Range(i + 16, i + 20)].Reverse().ToArray());
                 
// resulting data
var tickTimestamp = new DateTime(date.Year, date.Month, date.Day, 
date.Hour, 0, 0).AddMilliseconds(milliseconds);
var Ask = i1 / Math.Pow(10, decimals),
var Bid = i2 / Math.Pow(10, decimals);
var AskVolume = f1,
var BidVolume = f2;

Working sample on github

tomas.r
  • 11
  • 3