Skip to content

Commit

Permalink
Initial framework for IB to BBG code conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
gavbrennan committed Mar 18, 2021
1 parent be49651 commit 791c818
Show file tree
Hide file tree
Showing 11 changed files with 12,852 additions and 40 deletions.
524 changes: 523 additions & 1 deletion clients/Qwack.Excel/futuresettings.json

Large diffs are not rendered by default.

172 changes: 170 additions & 2 deletions data/futuresettings.json

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions src/Qwack.Futures/CodeConversion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Qwack.Futures
{
public static class CodeConversion
{
public static string ConvertBbgToIB(this string bbg, IFutureSettingsProvider provider)
{
switch (bbg.ToLower().Right(6))
{
case "comdty":
if(bbg.Length<13) //its not an option
{
if(bbg.Length==11 && bbg.Substring(4,1)==" ") // ccMY Comdty format
{
var bbgCode = bbg.Left(2);
if (provider.TryGet(bbgCode, "BBG", out var fs))
{
var monthYear = bbg.Substring(2, 2);
var qCode = fs.CodeConversions["BBG"].Where(x => x.Value == bbgCode.ToUpper()).First().Key;
var ibCode = fs.CodeConversions["IB"][qCode];
return $"{ibCode}{monthYear}";
}
}
else if (bbg.Length == 12 && bbg.Substring(5, 1) == " ") // ccMY Comdty format
{
var bbgCode = bbg.Left(3);
if (provider.TryGet(bbgCode, "BBG", out var fs))
{
var monthYear = bbg.Substring(3, 2);
var qCode = fs.CodeConversions["BBG"].Where(x => x.Value == bbgCode.ToUpper()).First().Key;
var ibCode = fs.CodeConversions["IB"][qCode];
return $"{ibCode}{monthYear}";
}
}
}
else //its an option
{

}
break;
case "curncy":
break;
case "equity":
break;
case " index":
break;

}

return null;
}

public static string Right(this string str, int n)
{
return str.Substring(str.Length - n, n);
}

public static string Left(this string str, int n)
{
return str.Substring(0, n);
}
}
}
2 changes: 2 additions & 0 deletions src/Qwack.Futures/FutureSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class FutureSettings
public List<MarketShutRuleSet> MarketShutRules { get; set; }
public List<DateTime> MarketShutRulesValidUntil { get; set; }

public Dictionary<string,Dictionary<string,string>> CodeConversions { get; set; }

public double LotSize { get; set; }
public double PriceMultiplier { get; set; }
public double TickSize { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions src/Qwack.Futures/IFutureSettingsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ public interface IFutureSettingsProvider
{
FutureSettings this[string futureName] { get; }
bool TryGet(string futureName, out FutureSettings futureSettings);

bool TryGet(string code, string codeProvider, out FutureSettings futureSettings);
}
}
12 changes: 11 additions & 1 deletion src/Qwack.Providers/Json/FutureSettingsFromJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public FutureSettingsFromJson(ICalendarProvider calendarProvider, string fileNam
}
}
}
catch(Exception ex)
catch (Exception ex)
{
_logger.LogError(ex, "Error loading future settings from json");
}
Expand All @@ -51,5 +51,15 @@ public FutureSettingsFromJson(ICalendarProvider calendarProvider, string fileNam
public FutureSettings this[string futureName] => _allSettingsByName[futureName];

public bool TryGet(string futureName, out FutureSettings futureSettings) => _allSettingsByName.TryGetValue(futureName, out futureSettings);

public bool TryGet(string code, string codeProvider, out FutureSettings futureSettings)
{
futureSettings = _allFutureSettings.FirstOrDefault(
x => x.CodeConversions != null &&
x.CodeConversions.TryGetValue(codeProvider, out var result) &&
result.Values.Contains(code));

return futureSettings != null;
}
}
}
9 changes: 3 additions & 6 deletions test/Qwack.Core.Tests/Qwack.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@
<DefineConstants>DEBUG;TRACE;RELEASE;NETCOREAPP;NETCOREAPP2_1</DefineConstants>
<Optimize>false</Optimize>
</PropertyGroup>
<ItemGroup>
<None Remove="futuresettings.json" />
</ItemGroup>

<ItemGroup>
<Content Include="..\..\data\Calendars.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="futuresettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -59,6 +53,9 @@
<None Update="Currencies.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="futuresettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down

0 comments on commit 791c818

Please sign in to comment.