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:
- 1st 4 bytes -> Time part of the timestamp
- 2nd 4 bytes -> Bid
- 3rd 4 bytes -> Ask
- 4th 4 bytes -> Bid Volume
- 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