Skip to content

Commit

Permalink
converting the l2 cryptotick sample to universal l2/l3 sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Svisstack committed Jan 22, 2021
1 parent 6f6e184 commit 7e460a6
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 20 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum ELimitUpdateType

static void Main(string[] args)
{
string path = args.Length > 0 ? args[0] : "27606-BITSTAMP_SPOT_BTC_EUR.csv.gz";
string path = args.Length > 0 ? args[0] : "4365242-COINBASE_SPOT_ETC_BTC.csv.gz";

using (GZipStream gz =
new GZipStream(
Expand All @@ -40,7 +40,7 @@ static void Main(string[] args)
private static void ProcessReader(string dateFormat, StreamReader sr)
{
string line;
var book = new Dictionary<(bool, decimal), decimal>();
var book = new Dictionary<(bool, decimal, string), decimal>();
DateTime lastTimeExchange = DateTime.MinValue;
ELimitUpdateType? prevType = null;

Expand All @@ -57,6 +57,7 @@ private static void ProcessReader(string dateFormat, StreamReader sr)
var isSellAsk = int.Parse(columns[3]) == 0;
var price = decimal.Parse(columns[4], NumberStyles.Float, CultureInfo.InvariantCulture);
var size = decimal.Parse(columns[5], NumberStyles.Float, CultureInfo.InvariantCulture);
var order_id = columns.Length > 6 ? columns[6] : "";

// process snapshot book cleaning
if (type == ELimitUpdateType.SNAPSHOT && prevType.HasValue && prevType.Value != ELimitUpdateType.SNAPSHOT)
Expand All @@ -68,29 +69,29 @@ private static void ProcessReader(string dateFormat, StreamReader sr)
// process specific order types
if (type == ELimitUpdateType.SNAPSHOT || type == ELimitUpdateType.SET)
{
book[(isSellAsk, price)] = size;
book[(isSellAsk, price, order_id)] = size;
}
else if (type == ELimitUpdateType.ADD)
{
if (!book.ContainsKey((isSellAsk, price)))
if (!book.ContainsKey((isSellAsk, price, order_id)))
{
book[(isSellAsk, price)] = size;
book[(isSellAsk, price, order_id)] = size;
}
else
{
book[(isSellAsk, price)] = book[(isSellAsk, price)] + size;
book[(isSellAsk, price, order_id)] = book[(isSellAsk, price, order_id)] + size;
}
}
else if (type == ELimitUpdateType.SUB || type == ELimitUpdateType.DELETE || type == ELimitUpdateType.MATCH)
{
if (!book.ContainsKey((isSellAsk, price)))
if (!book.ContainsKey((isSellAsk, price, order_id)))
{
book[(isSellAsk, price)] = 0;
book[(isSellAsk, price, order_id)] = 0;
}
else
{
var newSize = book[(isSellAsk, price)] - size;
book[(isSellAsk, price)] = newSize >= 0 ? newSize : 0;
var newSize = book[(isSellAsk, price, order_id)] - size;
book[(isSellAsk, price, order_id)] = newSize >= 0 ? newSize : 0;
}
}
else
Expand All @@ -99,9 +100,9 @@ private static void ProcessReader(string dateFormat, StreamReader sr)
}

// remove empty levels
if (book.ContainsKey((isSellAsk, price)) && book[(isSellAsk, price)] <= 0)
if (book.ContainsKey((isSellAsk, price, order_id)) && book[(isSellAsk, price, order_id)] <= 0)
{
book.Remove((isSellAsk, price));
book.Remove((isSellAsk, price, order_id));
}

// process book feed forward
Expand All @@ -113,7 +114,7 @@ private static void ProcessReader(string dateFormat, StreamReader sr)
}
}

private static void ProcessOrderbook(DateTime time_exchange, DateTime time_coinapi, Dictionary<(bool, decimal), decimal> book)
private static void ProcessOrderbook(DateTime time_exchange, DateTime time_coinapi, Dictionary<(bool, decimal, string), decimal> book)
{
// processing work
var recv_diff = time_coinapi - time_exchange;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<None Update="27606-BITSTAMP_SPOT_BTC_EUR.csv.gz">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="4365242-COINBASE_SPOT_ETC_BTC.csv.gz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29230.47
VisualStudioVersion = 16.0.30717.126
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "limitbook_full_l2", "limitbook_full_l2.csproj", "{1338BCE4-2432-49FD-9562-9075AF3CB362}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "limitbook_full_l2l3", "limitbook_full_l2l3.csproj", "{4F5425E5-DE39-497D-867F-37B38316E5B2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1338BCE4-2432-49FD-9562-9075AF3CB362}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1338BCE4-2432-49FD-9562-9075AF3CB362}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1338BCE4-2432-49FD-9562-9075AF3CB362}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1338BCE4-2432-49FD-9562-9075AF3CB362}.Release|Any CPU.Build.0 = Release|Any CPU
{4F5425E5-DE39-497D-867F-37B38316E5B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F5425E5-DE39-497D-867F-37B38316E5B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F5425E5-DE39-497D-867F-37B38316E5B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F5425E5-DE39-497D-867F-37B38316E5B2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {70870D46-C6A9-46ED-9FAA-19671E4D3936}
SolutionGuid = {B47CE903-BF3E-43CC-9C77-B55AC6D41558}
EndGlobalSection
EndGlobal

0 comments on commit 7e460a6

Please sign in to comment.