Last active
June 10, 2022 13:11
-
-
Save tomas-rampas/ce3690b0a59ed87b2f6a2c849e40674f to your computer and use it in GitHub Desktop.
The bi5 translation to C# primitives
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
namespace Bi5Translator | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var bytes = new byte[]{ 0,29,177,144,0,0,48,57,0,0,48,58,63,147,51,51,64,19,51,51}; | |
var date = DateTime.Now.AddHours(-1); // this mimics the tick data start date | |
var i = 0; // position | |
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; | |
Console.WriteLine($"{tickTimestamp} {bid}/{ask} {bidVolume}/{askVolume}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment