Merge branch 'master' of bitbucket.org:bluetradesys/spark
This commit is contained in:
commit
14c18e459c
61 files changed
+2322
-2216
No files matched your search
Vendored
+62
@@ -0,0 +1,62 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"/usr/include",
|
||||
"/usr/local/include",
|
||||
"${workspaceRoot}"
|
||||
],
|
||||
"defines": [],
|
||||
"intelliSenseMode": "clang-x64",
|
||||
"browse": {
|
||||
"path": [
|
||||
"/usr/include",
|
||||
"/usr/local/include",
|
||||
"${workspaceRoot}"
|
||||
],
|
||||
"limitSymbolsToIncludedHeaders": true,
|
||||
"databaseFilename": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Win32",
|
||||
"includePath": [
|
||||
"C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.11.25503/include/*",
|
||||
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/um",
|
||||
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/ucrt",
|
||||
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/shared",
|
||||
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/winrt",
|
||||
"${workspaceRoot}/src",
|
||||
"${workspaceRoot}/externals/windows/include",
|
||||
"${workspaceRoot}/externals/linux/include",
|
||||
"${localappdata}/lxss/rootfs/usr/include/c++/5",
|
||||
"${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu/c++/5",
|
||||
"${localappdata}/lxss/rootfs/usr/include/c++/5/backward",
|
||||
"${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include",
|
||||
"${localappdata}/lxss/rootfs/usr/local/include",
|
||||
"${localappdata}/lxss/rootfs/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed",
|
||||
"${localappdata}/lxss/rootfs/usr/include/x86_64-linux-gnu",
|
||||
"${localappdata}/lxss/rootfs/usr/include"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
"UNICODE"
|
||||
],
|
||||
"intelliSenseMode": "msvc-x64",
|
||||
"browse": {
|
||||
"path": [
|
||||
"C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.11.25503/include/*",
|
||||
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/um",
|
||||
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/ucrt",
|
||||
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/shared",
|
||||
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.15063.0/winrt",
|
||||
"${workspaceRoot}"
|
||||
],
|
||||
"limitSymbolsToIncludedHeaders": true,
|
||||
"databaseFilename": ""
|
||||
}
|
||||
}
|
||||
],
|
||||
"version": 3
|
||||
}
|
||||
@@ -159,7 +159,7 @@ namespace mbts.spark
|
||||
synthetic = SyntheticDataHelper.Defaults.Security(find_unique_synthetic_name(), s);
|
||||
strategy = _synthetic_strategy_map.TryGetValue(s.Id, out SyntheticExecutionStrategy ses) ? ses.ExecutionStrategy.Clone() : SyntheticDataHelper.Defaults.ExecutionStrategy(s);
|
||||
} else {
|
||||
synthetic = SyntheticDataHelper.Defaults.Security(find_unique_synthetic_name(), securities);
|
||||
synthetic = SyntheticDataHelper.Defaults.Security(find_unique_synthetic_name(), securities.Ordered());
|
||||
strategy = SyntheticDataHelper.Defaults.ExecutionStrategy(securities);
|
||||
}
|
||||
show_synthetic_editor(synthetic, strategy);
|
||||
|
||||
@@ -19,9 +19,9 @@ namespace mbts.spark
|
||||
/// <summary>
|
||||
/// Creates a new Security if synthetic's Id is 0, otherwise modifies the already existing synthetic's execution strategy.
|
||||
/// </summary>
|
||||
/// <exception cref="System.ArgumentException">synthetic parameter is not a synthetic security.</exception>
|
||||
/// <param name="synthetic"></param>
|
||||
/// <param name="strategy"></param>
|
||||
/// <exception cref="System.ArgumentException">The synthetic parameter is not a synthetic security.</exception>
|
||||
/// <param name="synthetic">The new synthetic security to create, or existing synthetic security who's strategy to modify</param>
|
||||
/// <param name="strategy">The new strategy to create, or existing strategy modify</param>
|
||||
public async void save(Security synthetic, ExecutionStrategy strategy) {
|
||||
if (synthetic.ContractCase != Security.ContractOneofCase.Synthetic) throw new ArgumentException("Must be a synthetic security.", nameof(synthetic));
|
||||
var map = await _bus.subscribe<MDMap>(SparkTags.SecuritiesTag).FirstAsync();
|
||||
@@ -30,6 +30,7 @@ namespace mbts.spark
|
||||
var curr_secmap = new HashSet<uint>(map.Keys);
|
||||
uint id = uint.MaxValue;
|
||||
while (curr_secmap.Contains(id)) id--;
|
||||
synthetic.Id = id;
|
||||
var sec_strategy = new SyntheticExecutionStrategy { Security = synthetic, ExecutionStrategy = strategy };
|
||||
_bus.post(SparkTags.PersistCommandTag, new SparkBusData.PersistMessage(1, "SyntheticSecurity", String.Empty, sec_strategy.ToByteArray()));
|
||||
} else {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using mbts.ui.spark;
|
||||
using bts.api;
|
||||
using mbts.ui.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace mbts.spark
|
||||
@@ -10,8 +12,22 @@ namespace mbts.spark
|
||||
void set_value(LegSpreaderParamsTuple leg_tup, T value);
|
||||
}
|
||||
|
||||
internal static class SectionNames { public const string LegDef = "Leg", Quote = "Quote", PreHedge = "PreHedge", PostHedge = "PostHedge"; }
|
||||
internal static class SubsectionNames { public const string Mute = "Mute", InsideMarketDistance = "Mute Inside Mkt", InsideMarketDistanceWithTravel = "Mute Inside Mkt & Move"; }
|
||||
internal static class SectionNames {
|
||||
public const string
|
||||
LegDef = "Leg",
|
||||
Quote = "Quote",
|
||||
PreHedge = "PreHedge",
|
||||
PostHedge = "PostHedge";
|
||||
}
|
||||
|
||||
internal static class SubsectionNames {
|
||||
public const string
|
||||
Mute = "Mute",
|
||||
InsideMarketDistance = "Mute Inside Mkt",
|
||||
InsideMarketDistanceWithTravel = "Mute Inside Mkt & Move",
|
||||
MarketForcedCross = "Outside Mkt Forced Cross",
|
||||
TimeForcedCross = "Time Forced Cross";
|
||||
}
|
||||
|
||||
internal abstract class ParameterBase<T> : IParameter<T> {
|
||||
protected ParameterBase() { }
|
||||
@@ -23,9 +39,12 @@ namespace mbts.spark
|
||||
public object create_cell(LegSpreaderParamsTuple leg_tup) { return new ParameterRowCell<T>(this, leg_tup); }
|
||||
}
|
||||
|
||||
internal class SizeRowModel : ParameterBase<uint> {
|
||||
public override uint get_value(LegSpreaderParamsTuple leg_tup) { return leg_tup.leg.Quantity; }
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { leg_tup.leg.Quantity = value; }
|
||||
internal class SizeRowModel : ParameterBase<int> {
|
||||
public override int get_value(LegSpreaderParamsTuple leg_tup) { return leg_tup.leg.Side == BuySell.Buy ? (int)leg_tup.leg.Quantity : -(int)leg_tup.leg.Quantity; }
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, int value) {
|
||||
leg_tup.leg.Side = value > 0 ? BuySell.Buy : BuySell.Sell;
|
||||
leg_tup.leg.Quantity = (uint)Math.Abs(value);
|
||||
}
|
||||
public override string display_name { get; } = "Size";
|
||||
public override string[] section_path { get; } = new[] { SectionNames.LegDef };
|
||||
}
|
||||
@@ -59,14 +78,14 @@ namespace mbts.spark
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { leg_tup.leg_params.QuoteParams.QuoteMaxOrderMove.MaxOrderMoveThreshold = value; }
|
||||
}
|
||||
|
||||
internal class QuoteMuteZoneInsideTicksRoleModel : ParameterBase<uint> {
|
||||
internal class QuoteMuteZoneInsideTicksRowModel : ParameterBase<uint> {
|
||||
public override string display_name { get; } = "Inside Ticks";
|
||||
public override string[] section_path { get; } = new[] { SectionNames.Quote, SubsectionNames.Mute };
|
||||
public override uint get_value(LegSpreaderParamsTuple leg_tup) { return leg_tup.leg_params.QuoteParams.QuoteMuteZone.InsideTicks; }
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { leg_tup.leg_params.QuoteParams.QuoteMuteZone.InsideTicks = value; }
|
||||
}
|
||||
|
||||
internal class QuoteMuteZoneOutsideTicksRoleModel : ParameterBase<uint> {
|
||||
internal class QuoteMuteZoneOutsideTicksRowModel : ParameterBase<uint> {
|
||||
public override string display_name { get; } = "Outside Ticks";
|
||||
public override string[] section_path { get; } = new[] { SectionNames.Quote, SubsectionNames.Mute };
|
||||
public override uint get_value(LegSpreaderParamsTuple leg_tup) { return leg_tup.leg_params.QuoteParams.QuoteMuteZone.OutsideTicks; }
|
||||
@@ -83,8 +102,8 @@ namespace mbts.spark
|
||||
internal class QuoteInsideMarketDistanceWithTravelTicksRowModel : ParameterBase<uint> {
|
||||
public override string display_name { get; } = "Ticks";
|
||||
public override string[] section_path { get; } = new[] { SectionNames.Quote, SubsectionNames.InsideMarketDistanceWithTravel };
|
||||
public override uint get_value(LegSpreaderParamsTuple leg_tup) { return leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistance.TicksFromInside; }
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistance.TicksFromInside = value; }
|
||||
public override uint get_value(LegSpreaderParamsTuple leg_tup) { return leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistanceWithTravel.TicksFromInside; }
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistanceWithTravel.TicksFromInside = value; }
|
||||
}
|
||||
|
||||
internal class QuoteInsideMarketDistanceWithTravelLimitRowModel : ParameterBase<uint> {
|
||||
@@ -92,7 +111,7 @@ namespace mbts.spark
|
||||
public override string[] section_path { get; } = new[] { SectionNames.Quote, SubsectionNames.InsideMarketDistanceWithTravel };
|
||||
public override uint get_value(LegSpreaderParamsTuple leg_tup) { return leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistanceWithTravel.Limit; }
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { leg_tup.leg_params.QuoteParams.QuoteInsideMarketDistanceWithTravel.Limit = value; }
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PreHedge
|
||||
@@ -110,28 +129,49 @@ namespace mbts.spark
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { leg_tup.leg_params.PreHedgeParams.QuantityBasedPaylessTicks.PaylessTicks = value; }
|
||||
}
|
||||
|
||||
internal class MaxTicksInsideMarket : ParameterBase<uint> {
|
||||
internal class MaxTicksInsideMarketRowModel : ParameterBase<uint> {
|
||||
public override string display_name { get; } = "Max Inside Ticks";
|
||||
public override string[] section_path { get; } = new[] { SectionNames.PreHedge };
|
||||
public override uint get_value(LegSpreaderParamsTuple leg_tup) { return leg_tup.leg_params.PreHedgeParams.MaxPriceFromInsideMarket.HedgeTickLimit; }
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { leg_tup.leg_params.PreHedgeParams.MaxPriceFromInsideMarket.HedgeTickLimit = value; }
|
||||
}
|
||||
|
||||
internal class SendHedgeAsMarketOrderRowModel : ParameterBase<bool> {
|
||||
public override string display_name { get; } = "Send Mkt Order Hedge";
|
||||
public override string[] section_path { get; } = new[] { SectionNames.PreHedge };
|
||||
public override bool get_value(LegSpreaderParamsTuple leg_tup) { return leg_tup.leg_params.PreHedgeParams.SendHedgeAsMarketOrder.SendHedgeAsMarketOrder; }
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, bool value) { leg_tup.leg_params.PreHedgeParams.SendHedgeAsMarketOrder.SendHedgeAsMarketOrder = value; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PostHedge
|
||||
internal class PostHedgePriceBasedCrossTicks : ParameterBase<uint> {
|
||||
public override string display_name { get; } = "Price Cross Ticks";
|
||||
public override string[] section_path { get; } = new[] { SectionNames.PostHedge };
|
||||
public override string display_name { get; } = "Max Outside Ticks";
|
||||
public override string[] section_path { get; } = new[] { SectionNames.PostHedge, SubsectionNames.MarketForcedCross };
|
||||
public override uint get_value(LegSpreaderParamsTuple leg_tup) { return leg_tup.leg_params.PostHedgeParams.PriceBasedCross.TicksThreshold; }
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { leg_tup.leg_params.PostHedgeParams.PriceBasedCross.TicksThreshold = value; }
|
||||
}
|
||||
|
||||
internal class PostHedgePriceBasedCrossMarketTicks : ParameterBase<uint> {
|
||||
public override string display_name { get; } = "Market Cross Ticks";
|
||||
public override string[] section_path { get; } = new[] { SectionNames.PostHedge };
|
||||
public override string display_name { get; } = "Mkt Cross Ticks";
|
||||
public override string[] section_path { get; } = new[] { SectionNames.PostHedge, SubsectionNames.MarketForcedCross };
|
||||
public override uint get_value(LegSpreaderParamsTuple leg_tup) { return leg_tup.leg_params.PostHedgeParams.PriceBasedCross.MarketCrossTicks; }
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { leg_tup.leg_params.PostHedgeParams.PriceBasedCross.MarketCrossTicks = value; }
|
||||
}
|
||||
|
||||
internal class PostHedgeTimeBasedCrossTicks : ParameterBase<uint> {
|
||||
public override string display_name { get; } = "Max Outside Time(ms)";
|
||||
public override string[] section_path { get; } = new[] { SectionNames.PostHedge, SubsectionNames.TimeForcedCross };
|
||||
public override uint get_value(LegSpreaderParamsTuple leg_tup) { return leg_tup.leg_params.PostHedgeParams.TimeBasedForcedCross.TimeInMsThreshold; }
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { leg_tup.leg_params.PostHedgeParams.TimeBasedForcedCross.TimeInMsThreshold = value; }
|
||||
}
|
||||
|
||||
internal class PostHedgeTimeBasedCrossMarketTicks : ParameterBase<uint> {
|
||||
public override string display_name { get; } = "Mkt Cross Ticks";
|
||||
public override string[] section_path { get; } = new[] { SectionNames.PostHedge, SubsectionNames.TimeForcedCross };
|
||||
public override uint get_value(LegSpreaderParamsTuple leg_tup) { return leg_tup.leg_params.PostHedgeParams.TimeBasedForcedCross.MarketCrossTicks; }
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, uint value) { leg_tup.leg_params.PostHedgeParams.TimeBasedForcedCross.MarketCrossTicks = value; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
internal class ParameterRowCell<T> {
|
||||
|
||||
@@ -16,6 +16,11 @@
|
||||
<TextBlock Text="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateSelector.DoubleTemplate>
|
||||
<usp:DataGridParameterCellTemplateSelector.IntTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateSelector.IntTemplate>
|
||||
<usp:DataGridParameterCellTemplateSelector.UIntTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding value}"/>
|
||||
@@ -33,6 +38,11 @@
|
||||
<c:TickUpDownDouble Value="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateSelector.DoubleTemplate>
|
||||
<usp:DataGridParameterCellTemplateSelector.IntTemplate>
|
||||
<DataTemplate>
|
||||
<c:TickUpDownInt Value="{Binding value}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateSelector.IntTemplate>
|
||||
<usp:DataGridParameterCellTemplateSelector.UIntTemplate>
|
||||
<DataTemplate>
|
||||
<c:TickUpDownUInt Value="{Binding value}"/>
|
||||
@@ -147,7 +157,7 @@
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
HeadersVisibility="All"
|
||||
RowHeaderWidth="160"
|
||||
RowHeaderWidth="180"
|
||||
RowStyle="{StaticResource DataGridRowStyle}"
|
||||
ItemsSource="{Binding ParameterRowsView, RelativeSource={RelativeSource TemplatedParent}}">
|
||||
<DataGrid.Resources>
|
||||
|
||||
@@ -28,8 +28,12 @@ namespace mbts.ui.spark
|
||||
object create_cell(LegSpreaderParamsTuple leg_tup);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty SyntheticNameProperty = DependencyProperty.Register("SyntheticName", typeof(string), typeof(SyntheticEditor2), new PropertyMetadata(string.Empty));
|
||||
#region SyntheticName
|
||||
public static readonly DependencyProperty SyntheticNameProperty = DependencyProperty.Register("SyntheticName", typeof(string), typeof(SyntheticEditor2),
|
||||
new FrameworkPropertyMetadata(string.Empty, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
|
||||
|
||||
public string SyntheticName { get => GetValue(SyntheticNameProperty) as string; set => SetValue(SyntheticNameProperty, value); }
|
||||
#endregion
|
||||
|
||||
#region LegTuples
|
||||
public static readonly DependencyProperty LegTuplesProperty = DependencyProperty.Register("LegTuples", typeof(IReadOnlyCollection<LegSpreaderParamsTuple>), typeof(SyntheticEditor2),
|
||||
@@ -148,6 +152,7 @@ namespace mbts.ui.spark
|
||||
{
|
||||
public DataTemplate DoubleTemplate { get; set; }
|
||||
public DataTemplate BooleanTemplate { get; set; }
|
||||
public DataTemplate IntTemplate { get; set; }
|
||||
public DataTemplate UIntTemplate { get; set; }
|
||||
|
||||
public override DataTemplate SelectTemplate(object item, DependencyObject container) {
|
||||
@@ -157,6 +162,7 @@ namespace mbts.ui.spark
|
||||
Type gt = t.GenericTypeArguments[0];
|
||||
if (gt == typeof(bool)) return BooleanTemplate;
|
||||
if (gt == typeof(double)) return DoubleTemplate;
|
||||
if (gt == typeof(int)) return IntTemplate;
|
||||
if (gt == typeof(uint)) return UIntTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,17 @@ using System.Windows.Input;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
/// <summary>
|
||||
/// The view model designed to serve as the DataContext for the SyntheticEditor2 control
|
||||
/// </summary>
|
||||
internal partial class SyntheticEditorVM2
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of SyntheticEditorVM2 class. The commit command will create a new Synthetic if synthetic's Id is 0, otherwise it will modify the existing synthetic's strategy.
|
||||
/// </summary>
|
||||
/// <param name="bus"></param>
|
||||
/// <param name="synthetic">the synthetic security to create, or existing strategy modify, on commit</param>
|
||||
/// <param name="strategy">the new or existing strategy to modify</param>
|
||||
/// <param name="bus">The application bus</param>
|
||||
/// <param name="synthetic">The new synthetic security to create, or existing synthetic security who's strategy to modify, on commit</param>
|
||||
/// <param name="strategy">The new strategy to create, or existing strategy to modify, on commit</param>
|
||||
public SyntheticEditorVM2(IBus bus, Security synthetic, ExecutionStrategy strategy) {
|
||||
_synthetic = synthetic;
|
||||
leg_tuples = _synthetic.Synthetic.Legs.Select(l => new LegSpreaderParamsTuple(l, strategy.LegParamsMap[l.Security.Id])).ToList();
|
||||
@@ -24,18 +27,24 @@ namespace mbts.spark
|
||||
new PriceMultiplierRowModel(),
|
||||
new IsQuoteRowModel(),
|
||||
new MaxOrderMoveRowModel(),
|
||||
new QuoteMuteZoneInsideTicksRoleModel(),
|
||||
new QuoteMuteZoneOutsideTicksRoleModel(),
|
||||
new QuoteMuteZoneInsideTicksRowModel(),
|
||||
new QuoteMuteZoneOutsideTicksRowModel(),
|
||||
new QuoteInsideMarketDistanceTicksRowModel(),
|
||||
new QuoteInsideMarketDistanceWithTravelTicksRowModel(),
|
||||
new QuoteInsideMarketDistanceWithTravelLimitRowModel(),
|
||||
new PayupRowModel(),
|
||||
new PaylessRowModel(),
|
||||
new LeanRatioRowModel(),
|
||||
new MaxTicksInsideMarket()
|
||||
new MaxTicksInsideMarketRowModel(),
|
||||
new SendHedgeAsMarketOrderRowModel(),
|
||||
new PostHedgePriceBasedCrossTicks(),
|
||||
new PostHedgePriceBasedCrossMarketTicks(),
|
||||
new PostHedgeTimeBasedCrossTicks(),
|
||||
new PostHedgeTimeBasedCrossMarketTicks()
|
||||
};
|
||||
commit = new DelegateCommand(() => new SyntheticEditorModel(bus).save(_synthetic, strategy));
|
||||
}
|
||||
|
||||
private readonly Security _synthetic;
|
||||
|
||||
public string name { get => _synthetic.Synthetic.Name; set => _synthetic.Synthetic.Name = value; }
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace mbts.spark
|
||||
|
||||
public void set_securities(IEnumerable<Security> securities) {
|
||||
foreach (var r in _channels.Keys.Except(securities).ToList()) _channels.Remove(r);
|
||||
foreach (var a in securities.Except(_channels.Keys).ToList()) _channels.Add(a, Co2RelayControl.instance.consumer.get_channel(a.symbol, get_type(a.ContractCase), get_exchange(a.Exchange)));
|
||||
foreach (var a in securities.Except(_channels.Keys).ToList()) _channels.Add(a, Co2RelayControl.instance.consumer.get_channel(a.Symbol, get_type(a.ContractCase), get_exchange(a.Exchange)));
|
||||
}
|
||||
|
||||
public void Dispose() { _work_loop.Dispose(); }
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace mbts.ui.spark
|
||||
public static string get_display_name(Security s) { return s.ContractCase == ContractOneofCase.Synthetic ? "{0} ({1:q/n:./m:c})".fmt(s.Synthetic.Name, s) : s.ToString("q/n:./m:c"); }
|
||||
private static string _get_symbol(Security s) {
|
||||
if (s.ContractCase == ContractOneofCase.Synthetic) return _get_symbol(s.Synthetic.Legs.First().Security);
|
||||
else return s.symbol;
|
||||
else return s.Symbol;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,8 +55,8 @@ namespace bts.api
|
||||
#region Extensions
|
||||
public static string SecurityName(this Security security) {
|
||||
switch (security.ContractCase) {
|
||||
case Security.ContractOneofCase.Future: return security.Future.Symbol;
|
||||
case Security.ContractOneofCase.Spread: return security.Spread.Legs.Count > 0 ? SecurityName(security.Spread.Legs[0].Security) : string.Empty;
|
||||
case Security.ContractOneofCase.Future:
|
||||
case Security.ContractOneofCase.Spread: return security.Symbol;
|
||||
case Security.ContractOneofCase.Synthetic: return security.Synthetic.Legs.Count > 0 ? SecurityName(security.Synthetic.Legs[0].Security) : string.Empty;
|
||||
case Security.ContractOneofCase.None: return "N/A";
|
||||
default: return "Unknown";
|
||||
|
||||
@@ -7,7 +7,7 @@ using static bts.api.Security;
|
||||
using O2Security=bts.security_model.OldSecurity;
|
||||
|
||||
namespace bts.api {
|
||||
public partial class Security : IComparable<Security>, IComparable, IFormattable {
|
||||
public partial class Security : IFormattable {
|
||||
|
||||
internal Security(O2Security other) {
|
||||
// Logger.assert(other != null);
|
||||
@@ -33,8 +33,8 @@ namespace bts.api {
|
||||
ExpirationDay = other.future.expiration_day,
|
||||
ExpirationMonth = other.future.expiration_month,
|
||||
ExpirationYear = other.future.expiration_year,
|
||||
Symbol = other.future.symbol
|
||||
};
|
||||
Symbol = other.future.symbol;
|
||||
break;
|
||||
case security_model.SecurityType.type.SPREAD:
|
||||
Spread = new SpreadContract();
|
||||
@@ -54,22 +54,6 @@ namespace bts.api {
|
||||
}
|
||||
}
|
||||
|
||||
public string symbol {
|
||||
get {
|
||||
switch (ContractCase) {
|
||||
case ContractOneofCase.Future:
|
||||
return Future.Symbol;
|
||||
case ContractOneofCase.Spread:
|
||||
return Spread.Legs.First().Security.symbol;
|
||||
case ContractOneofCase.Synthetic:
|
||||
return Synthetic.Name;
|
||||
default:
|
||||
case ContractOneofCase.None:
|
||||
return "Invalid";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static BuySell ofSide(security_model.Side.type side) {
|
||||
switch (side) {
|
||||
case security_model.Side.type.BUY: return BuySell.Buy;
|
||||
@@ -169,10 +153,6 @@ namespace bts.api {
|
||||
get_base_exchange_securities (leg.Security, resolve_side (side, leg.Side), leg.Quantity * mult, ref legs);
|
||||
}
|
||||
|
||||
public int CompareTo(Security other) { return SecurityComparer.Compare(this, other); }
|
||||
|
||||
public int CompareTo(object obj) { return CompareTo(obj as Security); }
|
||||
|
||||
public static readonly Security Empty = new Security {
|
||||
Exchange = Venue.Bts,
|
||||
ContractSpec = new ContractSpecification { CashPerPoint = double.NaN, HighTick = double.NaN, LowTick = double.NaN, PriceBreak = double.NaN, PriceMultiplier = double.NaN }
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using static bts.api.Security;
|
||||
|
||||
namespace bts.api
|
||||
{
|
||||
public static class SecurityComparer
|
||||
{
|
||||
public static int Compare(Security x, Security y) {
|
||||
if (x == null) return y == null ? 0 : -1;
|
||||
if (y == null) return 1;
|
||||
if (x.ContractCase == ContractOneofCase.Future) return y.ContractCase == ContractOneofCase.Future ? Compare(x.Future, y.Future) : -1;
|
||||
if (y.ContractCase == ContractOneofCase.Future) return 1;
|
||||
var xlegs = SecurityHelper.get_flat_future_legs(x).ToArray();
|
||||
var ylegs = SecurityHelper.get_flat_future_legs(y).ToArray();
|
||||
int max = Math.Min(xlegs.Length, ylegs.Length);
|
||||
for(int i = 0; i < max; i++) {
|
||||
int rv = Compare(xlegs[i].Item2, ylegs[i].Item2);
|
||||
if (rv != 0) return rv;
|
||||
}
|
||||
for (int i = 0; i < max; i++) {
|
||||
int rv = xlegs[i].Item3.CompareTo(ylegs[i].Item3);
|
||||
if (rv != 0) return rv;
|
||||
}
|
||||
for (int i = 0; i < max; i++) {
|
||||
int rv = xlegs[i].Item1.CompareTo(ylegs[i].Item1);
|
||||
if (rv != 0) return rv;
|
||||
}
|
||||
return xlegs.Length.CompareTo(ylegs.Length);
|
||||
}
|
||||
|
||||
public static int Compare(FutureContract x, FutureContract y) {
|
||||
int sym_comp = x.Symbol.CompareTo(y.Symbol);
|
||||
return sym_comp == 0 ? x.RawExpDate().CompareTo(y.RawExpDate()) : sym_comp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ namespace bts.api
|
||||
if (part_formatters.Count > 0 && part_formatters[0].separator == "!") {
|
||||
if (part_formatters[0].add_part(s, out string result)) return result;
|
||||
}
|
||||
return string.Join("", SecurityHelper.get_flat_future_legs(s).Select(flt => _format_future_leg(flt, part_formatters)));
|
||||
return string.Join("", SecurityHelper.get_flat_future_legs(s).Select(flt => _format_future_leg(flt, s.Symbol, part_formatters)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,18 +52,18 @@ namespace bts.api
|
||||
}
|
||||
}
|
||||
|
||||
private static string _format_future(Security s, IEnumerable<IPartFormatter> part_formatters) { return _format(s, part_formatters, _add_future); }
|
||||
private static string _format_future_leg(FutureLeg l, IEnumerable<IPartFormatter> part_formatters) { return _format(l, part_formatters, _add_future_leg); }
|
||||
private static string _format_future(Security s, IEnumerable<IPartFormatter> part_formatters) { return _format(s, s.Symbol, part_formatters, _add_future); }
|
||||
private static string _format_future_leg(FutureLeg l, string symbol, IEnumerable<IPartFormatter> part_formatters) { return _format(l, symbol, part_formatters, _add_future_leg); }
|
||||
|
||||
private delegate bool AddPart<T>(T t, IPartFormatter part_formatter, out string result);
|
||||
private static bool _add_future(Security s, IPartFormatter part_formatter, out string result) { return part_formatter.add_part(s, out result); }
|
||||
private static bool _add_future_leg(FutureLeg l, IPartFormatter part_formatter, out string result) { return part_formatter.add_part(l, out result); }
|
||||
private delegate bool AddPart<T>(string symbol, T t, IPartFormatter part_formatter, out string result);
|
||||
private static bool _add_future(string symbol, Security s, IPartFormatter part_formatter, out string result) { return part_formatter.add_part(s, out result); }
|
||||
private static bool _add_future_leg(string symbol, FutureLeg l, IPartFormatter part_formatter, out string result) { return part_formatter.add_part(l, symbol, out result); }
|
||||
|
||||
private static string _format<T>(T t, IEnumerable<IPartFormatter> part_formatters, AddPart<T> add_part) {
|
||||
private static string _format<T>(T t, string symbol, IEnumerable<IPartFormatter> part_formatters, AddPart<T> add_part) {
|
||||
var adds = new List<Tuple<string, IPartFormatter>>();
|
||||
foreach (var pf in part_formatters) {
|
||||
string p;
|
||||
if(add_part(t, pf, out p)) adds.Add(Tuple.Create(p, pf));
|
||||
if(add_part(symbol, t, pf, out p)) adds.Add(Tuple.Create(p, pf));
|
||||
}
|
||||
string result = string.Empty;
|
||||
if (adds.Count > 0) {
|
||||
@@ -76,7 +76,7 @@ namespace bts.api
|
||||
private interface IPartFormatter
|
||||
{
|
||||
string separator { get; }
|
||||
bool add_part(FutureLeg fl, out string result);
|
||||
bool add_part(FutureLeg fl, string symbol, out string result);
|
||||
bool add_part(Security s, out string result);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace bts.api
|
||||
this.separator = separator;
|
||||
}
|
||||
public string separator { get; }
|
||||
public bool add_part(FutureLeg fl, out string result) {
|
||||
public bool add_part(FutureLeg fl, string symbol, out string result) {
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
@@ -138,7 +138,7 @@ namespace bts.api
|
||||
}
|
||||
private bool _first_leg = true;
|
||||
public string separator { get; }
|
||||
public bool add_part(FutureLeg fl, out string result) {
|
||||
public bool add_part(FutureLeg fl, string symbol, out string result) {
|
||||
if (_first_leg) {
|
||||
if (fl.Item3 > 0) result = fl.Item3 == 1 ? string.Empty : fl.Item3.ToString();
|
||||
else result = fl.Item3 == -1 ? "-" : fl.Item3.ToString("-0");
|
||||
@@ -160,8 +160,8 @@ namespace bts.api
|
||||
this.separator = separator;
|
||||
}
|
||||
public string separator { get; }
|
||||
public bool add_part(FutureLeg fl, out string result) { result = fl.Item2.Symbol; return true; }
|
||||
public bool add_part(Security s, out string result) { result = s.Future.Symbol; return true; }
|
||||
public bool add_part(FutureLeg fl, string symbol, out string result) { result = symbol; return true; }
|
||||
public bool add_part(Security s, out string result) { result = s.Symbol; return true; }
|
||||
}
|
||||
private class Formatter<T> : IPartFormatter {
|
||||
public Formatter(Func<Security, T> get_sec_value, Func<FutureLeg, T> get_leg_value, string separator) : this(get_sec_value, get_leg_value, t => t.ToString(), separator) { }
|
||||
@@ -188,7 +188,7 @@ namespace bts.api
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool add_part(FutureLeg fl, out string result) {
|
||||
public bool add_part(FutureLeg fl, string symbol, out string result) {
|
||||
T val = _get_leg_value(fl);
|
||||
if (!val.Equals(_last_val)) {
|
||||
result = _format(_last_val = val);
|
||||
|
||||
@@ -174,7 +174,7 @@ namespace mbts.co2.tests
|
||||
//Assert.That(s.security.numeric_id == s.handle.numeric_id);
|
||||
}
|
||||
Assert.That(securities.Count() == 24);
|
||||
var dict = securities.Select(s => s.security).GroupBy(s => s.symbol).ToDictionary(group => group.Key, group => group.ToList());
|
||||
var dict = securities.Select(s => s.security).GroupBy(s => s.Symbol).ToDictionary(group => group.Key, group => group.ToList());
|
||||
Assert.That(dict.Count == 2);
|
||||
Assert.That(dict.All(kvp => kvp.Value.Count == 12));
|
||||
}
|
||||
@@ -200,8 +200,8 @@ namespace mbts.co2.tests
|
||||
consumer.scan_securities();
|
||||
System.Threading.Thread.Sleep(100);
|
||||
Assert.AreEqual(24, securities.Count);
|
||||
Assert.That(securities.Find(s => s.symbol == "FOOM") != null);
|
||||
Assert.That(securities.Find(s => s.symbol == "FOOXM") != null);
|
||||
Assert.That(securities.Find(s => s.Symbol == "FOOM") != null);
|
||||
Assert.That(securities.Find(s => s.Symbol == "FOOXM") != null);
|
||||
|
||||
foreach (var sec in securities) {
|
||||
var handle = consumer.try_get_handle(sec.Id);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using bts.security_model;
|
||||
using bts.api;
|
||||
using bts.security_model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -34,12 +35,11 @@ namespace mbts.co2
|
||||
|
||||
unsafe void init() {
|
||||
_raw_sec_cb = (key, buf, len, handle) => {
|
||||
var security = Co2NativeMethods.deserialize<bts.security_model.OldSecurity>(buf, len);
|
||||
var next = new SecurityAndHandle() { security = new bts.api.Security(security), handle = new MDConsumerHandle(handle) };
|
||||
_securities.Add(next);
|
||||
var cb = _on_security;
|
||||
if (cb != null) cb(new List<SecurityAndHandle>(1) { next });
|
||||
};
|
||||
var security = Co2NativeMethods.deserialize<Security>(buf, len);
|
||||
var next = new SecurityAndHandle() { security = security, handle = new MDConsumerHandle(handle) };
|
||||
_securities.Add(next);
|
||||
_on_security?.Invoke(new List<SecurityAndHandle>(1) { next });
|
||||
};
|
||||
Co2NativeMethods.md_consumer_set_on_security(_consumer, _raw_sec_cb);
|
||||
|
||||
on_security = Observable.Create<List<SecurityAndHandle>>(observer => {
|
||||
@@ -75,7 +75,7 @@ namespace mbts.co2
|
||||
public unsafe IEnumerable<SecurityAndHandle> all_securities() {
|
||||
List<SecurityAndHandle> result = new List<SecurityAndHandle>();
|
||||
Co2NativeMethods.raw_security_callback cb = (key, buf, len, handle) => {
|
||||
var security = Co2NativeMethods.deserialize<OldSecurity>(buf, len);
|
||||
var security = Co2NativeMethods.deserialize<Security>(buf, len);
|
||||
result.Add(new SecurityAndHandle() { security = new bts.api.Security(security), handle = new MDConsumerHandle(handle) });
|
||||
};
|
||||
Co2NativeMethods.md_consumer_walk_security_list(_consumer, cb);
|
||||
@@ -105,7 +105,7 @@ namespace mbts.co2
|
||||
|
||||
struct SecurityAndHandle
|
||||
{
|
||||
public bts.api.Security security;
|
||||
public Security security;
|
||||
public MDConsumerHandle handle;
|
||||
public override string ToString() {
|
||||
return security.ToString();
|
||||
@@ -129,7 +129,7 @@ namespace mbts.co2
|
||||
return "{0}-{1}".fmt(symbol, type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static List<UserSymbol> get_all() {
|
||||
List<UserSymbol> symbols = new List<UserSymbol>();
|
||||
Co2NativeMethods.md_consumer_get_system_md_symbols(us => symbols.Add(us));
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using security_key = System.UInt32;
|
||||
using bts.api;
|
||||
|
||||
namespace mbts.co2
|
||||
{
|
||||
@@ -22,10 +23,10 @@ namespace mbts.co2
|
||||
|
||||
// The exchange key can change at CBOE. This numeric_id will always be correct
|
||||
public ulong numeric_id { get { return _cold->numeric_id; } }
|
||||
public bts.api.Security get_security() {
|
||||
bts.security_model.OldSecurity result = null;
|
||||
Co2NativeMethods.md_consumer_get_single_security(_cold, (key, buffer, length) => result = ProtoBuf.Serializer.Deserialize<OldSecurity>(new UnmanagedMemoryStream(buffer, (long)length)));
|
||||
return new bts.api.Security(result);
|
||||
public Security get_security() {
|
||||
Security result = null;
|
||||
Co2NativeMethods.md_consumer_get_single_security(_cold, (key, buffer, length) => result = ProtoBuf.Serializer.Deserialize<Security>(new UnmanagedMemoryStream(buffer, (long)length)));
|
||||
return result;
|
||||
}
|
||||
|
||||
// This property exists for specific performance optimization purposes
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
# generated by make process
|
||||
set(sources api/apicore.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/services/ApiUnitTestService.proto;api/services/HelloService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/UserService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/Account.conf;config/defaults/Executor.conf;config/defaults/MarketData.conf;config/defaults/Symbols.conf;config/defaults/User.conf;config/defaults/edge.conf;config/defaults/expiration_display_offset.conf;config/defaults/logging.conf;config/defaults/testkeys.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/Account.proto;config/protos/Executor.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/User.proto;config/protos/environment.proto;config/protos/expiration_display_offset.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/quickbus_cfg.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.proto;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPriceLantencyTester.cpp;md/Diag/ShmDumper.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MDRecoverableConsumer.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/SecurityIDRecorder.cpp;md/SettlementRecorder.cpp;md/Structure/FixedSecurity.cpp;md/Structure/PriceSize.cpp;md/common.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2TestInstrument.cpp;md/test/md2_tests.cpp;order_man/protos/OrderMan.proto;os/os.cpp;os/tests/os_tests.cpp;quickbus/core/LocalNode.cpp;quickbus/core/Quickbus.cpp;quickbus/core/SubscriptionID.cpp;quickbus/core/TableID.cpp;quickbus/message_model/Update.cpp;quickbus/message_model/merge_updates.cpp;quickbus/network/QBConnection.cpp;quickbus/network/QBConnectionManager.cpp;quickbus/network/endpoint_description.cpp;quickbus/network/quickbus_msgs.proto;quickbus/pubsub/TablePublisher.cpp;quickbus/pubsub/TableSubscriber.cpp;quickbus/pubsub/tests/qb_pubsub_tests.cpp;quickbus/routing/INode.cpp;quickbus/routing/NodeID.cpp;quickbus/routing/Router.cpp;quickbus/rpc/RPCClient.cpp;quickbus/rpc/RPCServer.cpp;quickbus/rpc/RPCSessionID.cpp;quickbus/rpc/rpc_utils.cpp;quickbus/rpc/tests/qb_rpc_tests.cpp;quickbus/tests/quickbus_tests.cpp;security_model/SecurityHelper.cpp;security_model/old_security.proto;sparkproto/SparkProtos.proto;testing/windows_test_driver.cpp;utils/Dispatcher.cpp;utils/HTTPStream.cpp;utils/PBUtils.cpp;utils/Puid.cpp;utils/SharedMemory.cpp;utils/Sqlite_utils.cpp;utils/Uuid.cpp;utils/datetime.cpp;utils/file_utils.cpp;utils/init_spark_lib.cpp;utils/is_unittest_environment.cpp)
|
||||
set(sources api/apicore.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/services/ApiUnitTestService.proto;api/services/HelloService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/UserService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/Account.conf;config/defaults/Executor.conf;config/defaults/MarketData.conf;config/defaults/Symbols.conf;config/defaults/User.conf;config/defaults/edge.conf;config/defaults/expiration_display_offset.conf;config/defaults/logging.conf;config/defaults/testkeys.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/Account.proto;config/protos/Executor.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/User.proto;config/protos/environment.proto;config/protos/expiration_display_offset.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/quickbus_cfg.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.proto;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPriceLantencyTester.cpp;md/Diag/ShmDumper.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MDRecoverableConsumer.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/SecurityIDRecorder.cpp;md/SettlementRecorder.cpp;md/Structure/FixedSecurity.cpp;md/Structure/PriceSize.cpp;md/common.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2TestInstrument.cpp;md/test/md2_tests.cpp;os/os.cpp;os/tests/os_tests.cpp;quickbus/core/LocalNode.cpp;quickbus/core/Quickbus.cpp;quickbus/core/SubscriptionID.cpp;quickbus/core/TableID.cpp;quickbus/message_model/Update.cpp;quickbus/message_model/merge_updates.cpp;quickbus/network/QBConnection.cpp;quickbus/network/QBConnectionManager.cpp;quickbus/network/endpoint_description.cpp;quickbus/network/quickbus_msgs.proto;quickbus/pubsub/TablePublisher.cpp;quickbus/pubsub/TableSubscriber.cpp;quickbus/pubsub/tests/qb_pubsub_tests.cpp;quickbus/routing/INode.cpp;quickbus/routing/NodeID.cpp;quickbus/routing/Router.cpp;quickbus/rpc/RPCClient.cpp;quickbus/rpc/RPCServer.cpp;quickbus/rpc/RPCSessionID.cpp;quickbus/rpc/rpc_utils.cpp;quickbus/rpc/tests/qb_rpc_tests.cpp;quickbus/tests/quickbus_tests.cpp;security_model/SecurityHelper.cpp;security_model/old_security.proto;sparkproto/SparkProtos.proto;testing/windows_test_driver.cpp;utils/Dispatcher.cpp;utils/HTTPStream.cpp;utils/PBUtils.cpp;utils/Puid.cpp;utils/SharedMemory.cpp;utils/Sqlite_utils.cpp;utils/Uuid.cpp;utils/datetime.cpp;utils/file_utils.cpp;utils/init_spark_lib.cpp;utils/is_unittest_environment.cpp)
|
||||
@@ -53,7 +53,6 @@ message ICEExchangeData {
|
||||
}
|
||||
|
||||
message FutureContract {
|
||||
string symbol = 10;
|
||||
uint32 expiration_year = 20;
|
||||
uint32 expiration_month = 30;
|
||||
uint32 expiration_day = 40;
|
||||
@@ -85,6 +84,7 @@ message ContractSpecification {
|
||||
|
||||
message Security {
|
||||
uint32 id = 10 [(bts.api.key)=true];
|
||||
string symbol = 11;
|
||||
Venue exchange = 20;
|
||||
ContractSpecification contract_spec = 30;
|
||||
Currency currency = 40;
|
||||
|
||||
@@ -9,7 +9,6 @@ namespace bts {
|
||||
using SecurityKey = utils::ValueWrapper<struct SecurityKeyTag,uint32_t>;
|
||||
using Price = utils::ValueWrapper<struct OrderPriceTag,double>;
|
||||
using Quantity = utils::ValueWrapper<struct QuantityTag,uint32_t>;
|
||||
using AccountName = utils::ValueWrapper<struct AccountNameTag,std::string>;
|
||||
using UserLogin = utils::ValueWrapper<struct UserLoginTag,std::string>;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace md2 {
|
||||
|
||||
/*
|
||||
* Implementation notes:
|
||||
* SlowHeader keeps a security count to know when a list has changed
|
||||
* ColdHeader keeps a security count to know when a list has changed
|
||||
* When a security is made visible increment count (non-atomic)
|
||||
* When user hits walk_security_list just walk all of them
|
||||
* When scanning for new securities we can short circuit the search if the security_count hasn't incremented
|
||||
|
||||
@@ -33,7 +33,8 @@ public:
|
||||
CoconutSecurityStatus::type status() const;
|
||||
uint16_t sequence() const;
|
||||
bool has_depth() const { return _cheader && _cheader->has_depth; }
|
||||
security_key key() const { return _cdata ? _cdata->security.key : invalid_security_key; }
|
||||
// security_key key() const { return _cdata ? _cdata->security.key : invalid_security_key; }
|
||||
security_key key() const { return has_depth() ? hotd()->key : hot()->key; }
|
||||
OldSecurity get_normalized_security() const { bts_assert(is_initialized()); return convert_security(_cdata->security); }
|
||||
|
||||
|
||||
|
||||
@@ -63,10 +63,10 @@ typedef void(*security_cb)(security_key, const char*, size_t, MDConsumerHandle&
|
||||
CAPI size_t md_consumer_walk_security_list(MDConsumer* consumer, security_cb cb) {
|
||||
bts_assert(consumer);
|
||||
std::string buffer;
|
||||
return consumer->walk_security_list([&](const OldSecurity& security, MDConsumerHandle handle) {
|
||||
return consumer->walk_security_list([&](const Security& security, MDConsumerHandle handle) {
|
||||
buffer.clear();
|
||||
security.SerializePartialToString(&buffer);
|
||||
cb(security.security_key(), buffer.c_str(), buffer.size(), handle);
|
||||
cb(security.id(), buffer.c_str(), buffer.size(), handle);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -93,10 +93,10 @@ void safe_call_clr_callback(security_cb cb, security_key key, const char* buffer
|
||||
|
||||
CAPI void md_consumer_set_on_security(MDConsumer* consumer, security_cb cb) {
|
||||
bts_assert(consumer);
|
||||
consumer->on_security([=](const OldSecurity& security, MDConsumerHandle handle) {
|
||||
consumer->on_security([=](const Security& security, MDConsumerHandle handle) {
|
||||
std::string buffer;
|
||||
security.SerializePartialToString(&buffer);
|
||||
safe_call_clr_callback(cb, security.security_key(), buffer.c_str(), buffer.size(), handle);
|
||||
safe_call_clr_callback(cb, security.id(), buffer.c_str(), buffer.size(), handle);
|
||||
});
|
||||
}
|
||||
#endif
|
||||
@@ -104,10 +104,13 @@ CAPI void md_consumer_set_on_security(MDConsumer* consumer, security_cb cb) {
|
||||
typedef void(*just_security_cb)(security_key, const char*, size_t);
|
||||
CAPI void md_consumer_get_single_security(const ColdEntry* entry, just_security_cb cb) {
|
||||
bts_assert(entry);
|
||||
auto security = convert_security(entry->security);
|
||||
bts::api::Security security;
|
||||
// fix
|
||||
auto old = convert_security(entry->security);
|
||||
convert_security(old, security);
|
||||
std::string buffer;
|
||||
security.SerializePartialToString(&buffer);
|
||||
cb(security.security_key(), buffer.c_str(), buffer.size());
|
||||
cb(security.id(), buffer.c_str(), buffer.size());
|
||||
}
|
||||
|
||||
bool is_heart_beat_ok(const ColdHeader &header);
|
||||
|
||||
@@ -48,13 +48,14 @@ unique_ptr<MDRecoverableConsumer::MDConsumerGroup> MDRecoverableConsumer::init(s
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t MDRecoverableConsumer::walk_security_list(OldSecurityCallback callback) {
|
||||
size_t MDRecoverableConsumer::walk_security_list(SecurityCallback callback) {
|
||||
return _current->consumer.walk_security_list(callback);
|
||||
}
|
||||
void MDRecoverableConsumer::on_security(OldSecurityCallback cb) {
|
||||
|
||||
void MDRecoverableConsumer::on_security(SecurityCallback cb) {
|
||||
// Add a filter to the callback to avoid calling the on_security callback with duplicates
|
||||
auto filtered_cb = [this,cb](const OldSecurity& security, MDConsumerHandle handle) {
|
||||
auto key = security.security_key();
|
||||
auto filtered_cb = [this,cb](const Security& security, MDConsumerHandle handle) {
|
||||
auto key = security.id();
|
||||
if (_seen.find(key) == _seen.end()) {
|
||||
_seen.insert(key);
|
||||
cb(security, handle);
|
||||
@@ -153,3 +154,4 @@ set<UserSymbol> get_symbols(Exchange::type exchange) {
|
||||
|
||||
}}//namespace
|
||||
#endif
|
||||
|
||||
@@ -23,8 +23,8 @@ public:
|
||||
|
||||
//
|
||||
// Security functions
|
||||
size_t walk_security_list(md2::OldSecurityCallback callback);
|
||||
void on_security(md2::OldSecurityCallback cb);
|
||||
size_t walk_security_list(md2::SecurityCallback callback);
|
||||
void on_security(md2::SecurityCallback cb);
|
||||
// Scans for added securities - updates managed handles
|
||||
size_t scan_securities();
|
||||
|
||||
@@ -53,7 +53,7 @@ private:
|
||||
std::unique_ptr<MDConsumerGroup> _current;
|
||||
std::vector<std::unique_ptr<MDConsumerGroup>> _old;
|
||||
|
||||
std::vector<md2::OldSecurityCallback> _callbacks;
|
||||
std::vector<md2::SecurityCallback> _callbacks;
|
||||
std::set<security_key> _seen;
|
||||
typedef tbb::mutex Mutex;
|
||||
Mutex _lock;
|
||||
|
||||
@@ -360,9 +360,10 @@ void convert_security(const OldSecurity& source, Security& dest) {
|
||||
dest.mutable_future()->set_expiration_day(source.future().expiration_day());
|
||||
dest.mutable_future()->set_expiration_month(source.future().expiration_month());
|
||||
dest.mutable_future()->set_expiration_year(source.future().expiration_year());
|
||||
dest.mutable_future()->set_symbol(source.future().symbol());
|
||||
dest.set_symbol(source.future().symbol());
|
||||
break;
|
||||
case security_model::SecurityType::SPREAD: {
|
||||
dest.set_symbol(source.spread().symbol());
|
||||
for(const auto& oleg : source.spread().legs()) {
|
||||
auto* nleg = dest.mutable_spread()->add_legs();
|
||||
nleg->set_quantity(oleg.leg_quantity());
|
||||
|
||||
@@ -49,16 +49,15 @@ struct ALIGNED_(32) HotEntry {
|
||||
const uint32_t COCONUT_MAX_DEPTH = 10;
|
||||
struct ALIGNED_(CACHE_LINE) HotDepthEntry {
|
||||
HotDepthEntry() :
|
||||
timestamp(), sequence(0), status(CoconutSecurityStatus::OK), book(), key(invalid_security_key)
|
||||
timestamp(), key(invalid_security_key), status(CoconutSecurityStatus::OK), book(), sequence(0)
|
||||
{ }
|
||||
uint32_t size() const { return sizeof(HotDepthEntry); }
|
||||
TimeStamp timestamp; // 8
|
||||
uint16_t sequence; // 2
|
||||
//md::CoconutSecurityStatus::type status; // 4
|
||||
security_key key; // NOTE: key is at a different offset than it is in HotEntry
|
||||
uint8_t status; // 1
|
||||
// Interleave bid/ask values so the top of book is always on the first line
|
||||
SingleWriterPriceSizeStore book[COCONUT_MAX_DEPTH*2];
|
||||
security_key key; // NOTE: key is at a different offset than it is in HotEntry
|
||||
uint16_t sequence; // 2
|
||||
|
||||
SingleWriterPriceSizeStore& bid(uint32_t depth) { return book[depth*2]; }
|
||||
const SingleWriterPriceSizeStore& bid(uint32_t depth) const { return book[depth*2]; }
|
||||
|
||||
+1498
-1498
File diff suppressed because it is too large.
Load diff
@@ -1,7 +0,0 @@
|
||||
syntax='proto3' ;
|
||||
package bts.orderman ;
|
||||
|
||||
|
||||
message B{}
|
||||
|
||||
message C{}
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
bool operator<(ValueWrapper const&v) const {return _v < v._v;}
|
||||
|
||||
ValueT const& value() const {return _v;}
|
||||
ValueT & value() {return _v;}
|
||||
|
||||
private:
|
||||
ValueT _v;
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "fabric/Domain.h"
|
||||
#include "testing/catch_test_runner.h"
|
||||
|
||||
|
||||
int main( int argc, char*argv [] )
|
||||
{
|
||||
using namespace bts;
|
||||
|
||||
@@ -1,189 +1,20 @@
|
||||
// #include "OrderMan.h"
|
||||
#include "OrderMan.h"
|
||||
#include "server/sparkd/grid/Node.h"
|
||||
#include "events/NewSecurities.h"
|
||||
|
||||
// namespace bts {
|
||||
// namespace orderman {
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
// OrderMan::OrderMan(IOrderManObserver &o,
|
||||
// IFIXGateway &gw,
|
||||
// OrderKeyGenerator const &key_gen) :
|
||||
// state_(State::IN_RECOVERY),
|
||||
// observer_(o),
|
||||
// fix_gw_(gw),
|
||||
// orders_(),
|
||||
// key_gen_(key_gen),
|
||||
// keys_left_(0),
|
||||
// next_key_(),
|
||||
// outgoing_fix_msgs_(),
|
||||
// time_observers_()
|
||||
// {
|
||||
// gen_key();
|
||||
// }
|
||||
|
||||
// OrderMan::~OrderMan() {}
|
||||
|
||||
// void OrderMan::on_end_recovery()
|
||||
// {
|
||||
// bts_assert(state_ == State::IN_RECOVERY);
|
||||
// transition(State::DISCONNECTED);
|
||||
// }
|
||||
|
||||
// void OrderMan::send_pending_messages()
|
||||
// {
|
||||
// if (outgoing_fix_msgs_->first_stream().n_msgs()) {
|
||||
// if (state_ == State::READY) {
|
||||
// outgoing_fix_msgs_->first_stream().close();
|
||||
// fix_gw_.send(outgoing_fix_msgs_);
|
||||
// }
|
||||
// outgoing_fix_msgs_ = fix_gw_.make_outfix_buffer();
|
||||
// }
|
||||
// }
|
||||
|
||||
// void OrderMan::on_venue_ready() {
|
||||
// bts_assert(state_ == State::DISCONNECTED);
|
||||
// transition(State::READY);
|
||||
// }
|
||||
|
||||
// void OrderMan::on_venue_disconnect() {
|
||||
// bts_assert(state_ == State::READY);
|
||||
// transition(State::DISCONNECTED);
|
||||
// }
|
||||
|
||||
// void OrderMan::on_begin_replay()
|
||||
// {
|
||||
// bts_assert(state_ == State::DISCONNECTED);
|
||||
// transition(State::REPLAYING);
|
||||
// }
|
||||
|
||||
// void OrderMan::on_end_replay()
|
||||
// {
|
||||
// bts_assert(state_ == State::REPLAYING);
|
||||
// transition(State::DISCONNECTED);
|
||||
// }
|
||||
|
||||
// void OrderMan::on_exe_report(api::Security const &sec,
|
||||
// OrderKey order_key,
|
||||
// jetfix::fix::ExecutionReportMsg const&exe_report)
|
||||
// {
|
||||
// using namespace jetfix;
|
||||
|
||||
// LOG(OrderMan,Info,
|
||||
// "Received execution report {} for order {} on {}",
|
||||
// exe_report.get<fix::ExecID>(),
|
||||
// order_key.value(),
|
||||
// fix_gw_.name());
|
||||
|
||||
// auto it =orders_.find(order_key);
|
||||
// bool is_new_order = it == orders_.end();
|
||||
|
||||
// // is this an order we know about?
|
||||
// if (is_new_order) {
|
||||
|
||||
// // we have never seen this order so we must have crashed
|
||||
// // before we could persist it. see if we can recover the
|
||||
// // order from the execution report
|
||||
|
||||
// if (exe_report.get<fix::OrdType>() == api::orderman::OT_LIMIT &&
|
||||
// (exe_report.get<fix::ExecType>() == api::orderman::ET_NEW ||
|
||||
// exe_report.get<fix::ExecType>() == api::orderman::ET_REJECTED)) {
|
||||
|
||||
// // recoverable
|
||||
// LOG(OrderMan,Error,
|
||||
// "Received execution report for unknown limit order {} on {}. "
|
||||
// "This should be investigated."
|
||||
// " Will try to recreate the order from the execution report",
|
||||
// order_key.value(),fix_gw_.name());
|
||||
|
||||
// it = orders_.emplace(order_key,
|
||||
// std::unique_ptr<Order>
|
||||
// (new LimitOrder(order_key,*this,exe_report))).first;
|
||||
// }
|
||||
// else {
|
||||
// // unrecoverable
|
||||
// LOG(OrderMan,Error,
|
||||
// "Received execution report for unknown order {} on {}. "
|
||||
// "Will not be able to recover "
|
||||
// "order state. This should never happen. Please investigate",
|
||||
// order_key.value(),fix_gw_.name());
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
// it->second->on_exe_report(exe_report);
|
||||
// observer_.on_order_change(*(it->second));
|
||||
// if (exe_report.get<fix::ExecType> () == api::orderman::ET_FILL ||
|
||||
// exe_report.get<fix::ExecType> () == api::orderman::ET_PARTIAL_FILL) {
|
||||
// OrderFill fill;
|
||||
// extract_fill(sec,exe_report,&fill);
|
||||
// observer_.on_fill(*(it->second),fill);
|
||||
// }
|
||||
// }
|
||||
|
||||
// void OrderMan::on_cancel_reject(api::Security const&,
|
||||
// OrderKey order_key,
|
||||
// jetfix::fix::CancelRejectMsg const&msg)
|
||||
// {
|
||||
// using namespace jetfix;
|
||||
|
||||
// LOG(OrderMan,Error, "Received cancel reject {} for order {} on {}",
|
||||
// msg.get<fix::ExecID>(),
|
||||
// order_key.value(),fix_gw_.name());
|
||||
|
||||
// auto it = orders_.find(order_key);
|
||||
// if (it == orders_.end()) {
|
||||
// LOG(OrderMan,Error,
|
||||
// "Received cancel rejection for unknown order {} on {}. "
|
||||
// " This should never happen. Please investigate",
|
||||
// order_key.value(),fix_gw_.name());
|
||||
// return;
|
||||
// }
|
||||
// else {
|
||||
// it->second->on_cancel_reject(msg);
|
||||
// observer_.on_order_change(*(it->second));
|
||||
// }
|
||||
// }
|
||||
struct OrderMan::PImpl
|
||||
{
|
||||
PImpl(OnOrderState const&s,OnFill const&f) : on_state(s), on_fills(f) {}
|
||||
OnOrderState on_state;
|
||||
OnFill on_fills;
|
||||
|
||||
|
||||
// void OrderMan::on_time( const OrderManTime&t)
|
||||
// {
|
||||
// for (auto &o : time_observers_)
|
||||
// o(t);
|
||||
// }
|
||||
};
|
||||
|
||||
// OrderKey OrderMan::gen_key()
|
||||
// {
|
||||
// const auto KEY_BATCH_SIZE = 1000;
|
||||
OrderMan::OrderMan(OnOrderState const&s,OnFill const&f) : me (new PImpl(s,f)) {}
|
||||
OrderMan::~OrderMan () {}
|
||||
|
||||
|
||||
// if (keys_left_ == 0) {
|
||||
// keys_left_ = KEY_BATCH_SIZE - 1;
|
||||
// next_key_ = key_gen_(KEY_BATCH_SIZE);
|
||||
// }
|
||||
// auto result = next_key_;
|
||||
// keys_left_--;
|
||||
// next_key_ = OrderKey(next_key_.value()+1);
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// const char* OrderMan::state_name(State state)
|
||||
// {
|
||||
// switch (state) {
|
||||
// case State::IN_RECOVERY:
|
||||
// return "IN_RECOVERY";
|
||||
// case State::DISCONNECTED:
|
||||
// return "DISCONNECTED";
|
||||
// case State::REPLAYING:
|
||||
// return "REPLAYING";
|
||||
// case State::READY:
|
||||
// return "READY";
|
||||
// }
|
||||
// }
|
||||
|
||||
// void OrderMan::transition(State new_state) {
|
||||
// LOG(OrderMan,Info, "Order man for {} transitioning from {} to {}",
|
||||
// fix_gw_.name(),state_name(state_),state_name(new_state));
|
||||
|
||||
// state_ = new_state;
|
||||
|
||||
// }
|
||||
|
||||
// }}
|
||||
}}
|
||||
@@ -1,186 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "lib/api/services/OrderService.pb.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
|
||||
#include "server/sparkd/jetfix/codec/MessageDefinitions.h"
|
||||
#include "server/sparkd/jetfix/common/OutFIX.h"
|
||||
|
||||
#include "order_man_common.h"
|
||||
#include "IFIXGateway.h"
|
||||
#include "fix_order_codec.h"
|
||||
|
||||
#include <boost/container/flat_map.hpp>
|
||||
#include "server/sparkd/order_man/order_man_utils.h"
|
||||
|
||||
namespace bts {
|
||||
namespace api {
|
||||
namespace orderman {
|
||||
class OrderState;
|
||||
class Fill;
|
||||
class CreateOrderRequest;
|
||||
class UpdateOrderRequest;
|
||||
class CancelOrderRequest;
|
||||
}}
|
||||
|
||||
class OrderManTime;
|
||||
class IMDSource;
|
||||
class OrderFill {};
|
||||
using TimeObserver = std::function<void(OrderManTime const&)>;
|
||||
|
||||
class Order {
|
||||
public:
|
||||
virtual void on_exe_report(jetfix::fix::ExecutionReportMsg const&) {}
|
||||
virtual void on_cancel_reject(jetfix::fix::CancelRejectMsg const&) {}
|
||||
};
|
||||
|
||||
class IOrderManObserver {
|
||||
public:
|
||||
virtual void on_order_change(Order const &order) = 0;
|
||||
virtual void on_fill(Order const&order, OrderFill const &rf) = 0;
|
||||
};
|
||||
|
||||
|
||||
class IFIXGateway;
|
||||
class CreateOrder;
|
||||
class UpdateOrder;
|
||||
class CancelOrder;
|
||||
|
||||
|
||||
class OrderMan;
|
||||
|
||||
class LimitOrder : public Order{
|
||||
public:
|
||||
LimitOrder(OrderKey, OrderMan &,jetfix::fix::ExecutionReportMsg const&);
|
||||
};
|
||||
|
||||
namespace orderman {
|
||||
|
||||
class OrderMan
|
||||
{
|
||||
public:
|
||||
struct Result {api::orderman::OrderError error;OrderKey key;};
|
||||
|
||||
OrderMan(IOrderManObserver &o,
|
||||
IFIXGateway &gw, OrderKeyGenerator const &key_gen) ;
|
||||
using OnOrderState = std::function<void(api::orderman::OrderState const&)>;
|
||||
using OnFill = std::function<void(api::orderman::Fill const&f)>;
|
||||
|
||||
OrderMan(OnOrderState const&,OnFill const&);
|
||||
~OrderMan();
|
||||
|
||||
template <class OrderType>
|
||||
Result create(typename OrderType::Create const &create_arg)
|
||||
{
|
||||
if (state_!= State::READY) {
|
||||
LOG(OrderMan,Info, "Cannot create order because venue {} is not ready", fix_gw_.name());
|
||||
return Result {api::orderman::OE_VENUE_NOT_READY,OrderKey(0)};
|
||||
}
|
||||
|
||||
auto k = gen_key();
|
||||
auto order_ptr = new OrderType (k,*this,create_arg);
|
||||
auto &order_slot = orders_[k];
|
||||
bts_assert(!order_slot);
|
||||
order_slot = std::unique_ptr<Order>(order_ptr);
|
||||
return {api::orderman::OE_OK,k};
|
||||
}
|
||||
|
||||
template <class OrderType>
|
||||
Result update(OrderKey k, typename OrderType::Update const& update_arg)
|
||||
{
|
||||
if (state_!= State::READY) {
|
||||
LOG(OrderMan,Info, "Cannot update order {} because venue {} is not ready", k.value(),fix_gw_.name());
|
||||
return Result {api::orderman::OE_VENUE_NOT_READY,k};
|
||||
}
|
||||
|
||||
auto it = orders_.find(k);
|
||||
if (it == orders_.end()) {
|
||||
LOG(OrderMan,Error,
|
||||
"Cannot update order: {} on venue {} because no such order exists",
|
||||
k.value(),fix_gw_.name());
|
||||
return Result {api::orderman::OE_UNKNOWN_ORDER,k};
|
||||
}
|
||||
|
||||
auto abstract_order_ptr = it->second.get();
|
||||
auto concrete_order_ptr = dynamic_cast<OrderType*> (abstract_order_ptr);
|
||||
if (!concrete_order_ptr) {
|
||||
LOG(OrderMan,Error,
|
||||
"Cannot update order: {} on venue {} because its type does not match the requested type. "
|
||||
"This is a serious problem. Contact development immediately",
|
||||
k.value(),fix_gw_.name());
|
||||
return Result {api::orderman::OE_ORDER_TYPE_MISMATCH,k};
|
||||
}
|
||||
|
||||
concrete_order_ptr->update(update_arg);
|
||||
return Result {api::orderman::OE_OK,k};
|
||||
}
|
||||
|
||||
template <class OrderType>
|
||||
Result cancel(OrderKey k, typename OrderType::Cancel const& cancel_arg)
|
||||
{
|
||||
if (state_!= State::READY) {
|
||||
LOG(OrderMan,Info, "Cannot cancel order {} because venue {} is not ready", k.value(),fix_gw_.name());
|
||||
return Result {api::orderman::OE_VENUE_NOT_READY,k};
|
||||
}
|
||||
|
||||
auto it = orders_.find(k);
|
||||
if (it == orders_.end()) {
|
||||
LOG(OrderMan,Error,
|
||||
"Cannot cancel order: {} on venue {} because no such order exists",
|
||||
k.value(),fix_gw_.name());
|
||||
return Result {api::orderman::OE_UNKNOWN_ORDER,k};
|
||||
}
|
||||
|
||||
auto abstract_order_ptr = it->second.get();
|
||||
auto concrete_order_ptr = dynamic_cast<OrderType*> (abstract_order_ptr);
|
||||
if (!concrete_order_ptr) {
|
||||
LOG(OrderMan,Error,
|
||||
"Cannot cancel order: {} on venue {} because its type does not match the requested type. "
|
||||
"This is a serious problem. Contact development immediately",
|
||||
k.value(),fix_gw_.name());
|
||||
return Result {api::orderman::OE_ORDER_TYPE_MISMATCH,k};
|
||||
}
|
||||
|
||||
concrete_order_ptr->cancel(cancel_arg);
|
||||
return Result {api::orderman::OE_OK,k};
|
||||
}
|
||||
|
||||
template <class OrderType>
|
||||
Result recover(OrderKey k,typename OrderType::State const&recovered_state)
|
||||
{
|
||||
bts_assert(state_ == State::IN_RECOVERY);
|
||||
auto order_ptr = new OrderType (k,*this,recovered_state);
|
||||
auto &order_slot = orders_[k];
|
||||
bts_assert(!order_slot);
|
||||
order_slot = std::unique_ptr<Order>(order_ptr);
|
||||
return {api::orderman::OE_OK,k};
|
||||
}
|
||||
|
||||
void on_end_recovery();
|
||||
void send_pending_messages();
|
||||
void on_venue_ready();
|
||||
void on_venue_disconnect();
|
||||
void on_begin_replay();
|
||||
void on_end_replay();
|
||||
void on_exe_report(api::Security const &sec, OrderKey order_key,
|
||||
jetfix::fix::ExecutionReportMsg const&exe_report);
|
||||
void on_cancel_reject(api::Security const&, OrderKey order_key,
|
||||
jetfix::fix::CancelRejectMsg const&msg);
|
||||
void on_time( const OrderManTime&t);
|
||||
void start();
|
||||
void create_order(OrderKey key,api::orderman::CreateOrderRequest const&r);
|
||||
void update_order(api::orderman::UpdateOrderRequest const&r);
|
||||
void cancel_order(api::orderman::CancelOrderRequest const&r);
|
||||
|
||||
private:
|
||||
|
||||
enum class State {IN_RECOVERY,DISCONNECTED, REPLAYING, READY };
|
||||
using OrderMap = boost::container::flat_map<OrderKey,std::unique_ptr<Order>> ;
|
||||
|
||||
OrderKey gen_key();
|
||||
const char* state_name(State state);
|
||||
void transition(State new_state) ;
|
||||
|
||||
State state_;
|
||||
// IMDSource &md_src_;
|
||||
IOrderManObserver &observer_;
|
||||
IFIXGateway &fix_gw_;
|
||||
|
||||
OrderMap orders_;
|
||||
OrderKeyGenerator key_gen_;
|
||||
size_t keys_left_;
|
||||
OrderKey next_key_;
|
||||
|
||||
jetfix::OutFIXPtr outgoing_fix_msgs_;
|
||||
std::vector<TimeObserver> time_observers_;
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
class OrderManSetup
|
||||
{
|
||||
public:
|
||||
OrderManSetup();
|
||||
~OrderManSetup();
|
||||
private:
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me;
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -13,8 +13,8 @@ std::string OrderState::to_string () const
|
||||
os.set_order_key(order_key.value());
|
||||
|
||||
auto &proto = *os.mutable_native();
|
||||
proto.set_account_name(account_name.value());
|
||||
proto.set_operator_id(operator_id.value());
|
||||
// proto.set_account_name(account_name.value());
|
||||
// proto.set_operator_id(operator_id.value());
|
||||
proto.set_security_key(security_key.value());
|
||||
proto.set_side(side);
|
||||
proto.set_time_in_force(time_in_force);
|
||||
@@ -22,7 +22,7 @@ std::string OrderState::to_string () const
|
||||
proto.set_customer_or_firm(customer_or_firm);
|
||||
proto.set_cti_code(cti_code);
|
||||
proto.set_user_login(user_login.value());
|
||||
proto.set_exchange_order_id(exchange_order_id.value());
|
||||
// proto.set_exchange_order_id(exchange_order_id.value());
|
||||
proto.set_manual_order_indicator(manual_order_indicator);
|
||||
proto.set_price(price.value());
|
||||
proto.set_quantity(quantity.value());
|
||||
@@ -48,8 +48,8 @@ void OrderState::from_string(std::string const&str)
|
||||
bts_assert(proto.transact_time().size() == ts.size());
|
||||
std::copy(proto.transact_time().begin(),proto.transact_time().end(), &ts[0]);
|
||||
*this = OrderState {
|
||||
AccountName(proto.account_name()),
|
||||
OperatorID(proto.operator_id()),
|
||||
AccountName(),
|
||||
OperatorID(),
|
||||
OrderKey(os.order_key()),
|
||||
SecurityKey(proto.security_key()),
|
||||
proto.side(),
|
||||
@@ -58,7 +58,7 @@ void OrderState::from_string(std::string const&str)
|
||||
proto.customer_or_firm(),
|
||||
proto.cti_code(),
|
||||
UserLogin(proto.user_login()),
|
||||
ExchangeOrderID(proto.exchange_order_id()),
|
||||
ExchangeOrderID(),
|
||||
proto.manual_order_indicator(),
|
||||
Price(proto.price()),
|
||||
Quantity(proto.quantity()),
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <memory>
|
||||
#include "order_man_utils.h"
|
||||
#include "order_man_utils.h"
|
||||
#include "lib/security_model/SecurityHelper.h"
|
||||
|
||||
#include "lib/domain_model/Security.pb.h"
|
||||
|
||||
@@ -133,8 +133,8 @@ WorkingOrder::WorkingOrder(fix::ExecutionReportMsg const&msg)
|
||||
decode_clorid(msg.get<fix::ClOrdID>(),&ok, &sk);
|
||||
|
||||
me->order_data = OrderState {
|
||||
AccountName(msg.get<fix::Account>()),
|
||||
OperatorID(msg.get<fix::TargetSubID>()),
|
||||
to<orderman::AccountName>(msg.get<fix::Account>()),
|
||||
to<orderman::OperatorID>(msg.get<fix::TargetSubID>()),
|
||||
ok,
|
||||
sk,
|
||||
api::BuySell(msg.get<fix::Side>()),
|
||||
@@ -143,7 +143,7 @@ WorkingOrder::WorkingOrder(fix::ExecutionReportMsg const&msg)
|
||||
COF_UNDEFINED,
|
||||
CTI_UNDEFINED,
|
||||
UserLogin(),
|
||||
ExchangeOrderID(msg.get<fix::OrderID>()),
|
||||
to<ExchangeOrderID>(msg.get<fix::OrderID>()),
|
||||
ManualOrderIndicator(msg.get<fix::ManualOrderIndicator>()),
|
||||
Price (msg.get<fix::Price>()),
|
||||
Quantity (msg.get<fix::OrderQty>()),
|
||||
@@ -180,8 +180,8 @@ OrderError WorkingOrder::encode_create(OrderCreate const&create,jetfix::FIXEncod
|
||||
encoding.add<fix::Price> (scale_price(*create.security,create.price).value(), PriceFieldSz);
|
||||
encoding.add<fix::OrderQty> (create.quantity.value(),SizeFieldSz);
|
||||
encoding.add<fix::TransactTimeStr>(&create.transact_time[0],create.transact_time.size());
|
||||
encoding.add<fix::Account> (create.account_name.value());
|
||||
encoding.add<fix::SenderSubID> (create.operator_id.value());
|
||||
encoding.add<fix::Account> (to_str(create.account_name));
|
||||
encoding.add<fix::SenderSubID> (to_str(create.operator_id));
|
||||
|
||||
std::string clordid(clordid_size(),' ');
|
||||
encode_clorid(create.order_key,create.security_key,&clordid);
|
||||
@@ -264,8 +264,8 @@ OrderError WorkingOrder::encode_cancel(OrderCancel const&cancel,jetfix::FIXEncod
|
||||
encoding.add<fix::ClOrdID> (clordid);
|
||||
encoding.add<fix::OrigClOrdID> (clordid);
|
||||
encoding.add<fix::CorrelationClOrdID> (clordid);
|
||||
encoding.add<fix::SenderSubID> (state.operator_id.value());
|
||||
encoding.add<fix::OrderID> (state.exchange_order_id.value());
|
||||
encoding.add<fix::SenderSubID> (to_str(state.operator_id));
|
||||
encoding.add<fix::OrderID> (to_str(state.exchange_order_id));
|
||||
encoding.add<fix::Side> (state.side);
|
||||
encoding.add<fix::TransactTimeStr>(&state.transact_time[0],state.transact_time.size());
|
||||
encoding.add<fix::ManualOrderIndicator> (state.manual_order_indicator);
|
||||
@@ -294,8 +294,8 @@ void WorkingOrder::init_encoding()
|
||||
me->transact_time_bm =
|
||||
encoding.add<fix::TransactTimeStr> (datetime::FIX_timestamp(datetime::now()));
|
||||
|
||||
encoding.add<fix::Account> (state.account_name.value());
|
||||
encoding.add<fix::SenderSubID> (state.operator_id.value());
|
||||
encoding.add<fix::Account> (to_str(state.account_name));
|
||||
encoding.add<fix::SenderSubID> (to_str(state.operator_id));
|
||||
|
||||
std::string clordid(clordid_size(),' ');
|
||||
encode_clorid(state.order_key,state.security_key,&clordid);
|
||||
@@ -308,7 +308,7 @@ void WorkingOrder::init_encoding()
|
||||
encoding.add<fix::OrdType> (state.order_type);
|
||||
encoding.add<fix::CustomerOrFirm> (state.customer_or_firm);
|
||||
encoding.add<fix::CtiCode> (state.cti_code);
|
||||
encoding.add<fix::OrderID> (state.exchange_order_id.value());
|
||||
encoding.add<fix::OrderID> (to_str(state.exchange_order_id));
|
||||
encoding.add<fix::SecurityDesc> (me->security->glbx().security_desc());
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ bool WorkingOrder::on_exe_report (jetfix::fix::ExecutionReportMsg const&msg)
|
||||
auto const &ts_str = msg.get<fix::TransactTimeStr>();
|
||||
std::copy(ts_str.begin(),ts_str.end(),&(me->order_data.transact_time[0]));
|
||||
|
||||
me->order_data.exchange_order_id = ExchangeOrderID(msg.get<fix::OrderID>());
|
||||
me->order_data.exchange_order_id = to<ExchangeOrderID>(msg.get<fix::OrderID>());
|
||||
switch (me->internal_state)
|
||||
{
|
||||
case InternalState::UNACKNOWLEDGED:
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "server/sparkd/jetfix/jetfix.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
class Gateway
|
||||
{
|
||||
public:
|
||||
using On
|
||||
Gateway(config::JetFIX::Connection const&c,
|
||||
|
||||
|
||||
) : _gw(c) {}
|
||||
void on(OutGatewayMsg const&m) {_gw.send(m.msg);}
|
||||
|
||||
|
||||
~Gateway();
|
||||
private:
|
||||
using FIXGw = jetfix::JetFIXGateway<fix::ExecutionReportMsg,
|
||||
fix::BusinessMessageRejectMsg,
|
||||
fix::RejectMsg,
|
||||
fix::CancelRejectMsg>;
|
||||
FIXGw _gw;
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -0,0 +1 @@
|
||||
#include "MDSource.h"
|
||||
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include "server/sparkd/order_man/events/NewSecurities.h"
|
||||
#include "server/sparkd/order_man/events/BookUpdate.h"
|
||||
#include "lib/utils/TimeStamp.h"
|
||||
#include "lib/md/MDConsumerHandle.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
class MDSource
|
||||
{
|
||||
public:
|
||||
using OnBook = std::function<void(event::BookUpdate const&)>;
|
||||
|
||||
MDSource(OnBook const&cb) : _on_book(cb), _handles() {}
|
||||
|
||||
void on(event::NewSecurities const&secs)
|
||||
{
|
||||
for (auto const &s : secs.value)
|
||||
_handles.push_back({utils::TimeStamp(),s.handle});
|
||||
}
|
||||
|
||||
|
||||
void poll_md() {
|
||||
event::BookUpdate book;
|
||||
for (auto &h : _handles)
|
||||
if (h.handle->get_depth(h.last,
|
||||
std::tuple_size<event::BookSide>(),
|
||||
&book.bid()[0],
|
||||
&book.ask()[0]) == md2::HandleReadResult::SUCCESS) {
|
||||
book.security_key = SecurityKey(h.handle->key());
|
||||
_on_book(book);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
OnBook _on_book;
|
||||
struct HandleRecord {
|
||||
utils::TimeStamp last;
|
||||
md2::MDConsumerHandle* handle;
|
||||
};
|
||||
|
||||
std::vector<HandleRecord> _handles;
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,52 @@
|
||||
#include "SecuritySource.h"
|
||||
|
||||
#include "lib/domain_model/common.h"
|
||||
#include "lib/md/MDRecoverableConsumer.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
#include "server/sparkd/order_man/events/NewSecurities.h"
|
||||
#include "server/sparkd/order_man/order_man_utils.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
struct SecuritySource::PImpl
|
||||
{
|
||||
PImpl(OnSecurities const&cb)
|
||||
: on_securities(cb),md_consumer(),known_securities(),pending_event(),
|
||||
keep_alive()
|
||||
{}
|
||||
|
||||
OnSecurities on_securities;
|
||||
md::MDRecoverableConsumer md_consumer;
|
||||
std::map<SecurityKey,std::unique_ptr<api::Security>> known_securities;
|
||||
event::NewSecurities pending_event;
|
||||
std::vector<std::shared_ptr<md2::MDConsumerHandle>> keep_alive;
|
||||
};
|
||||
|
||||
SecuritySource::SecuritySource (OnSecurities const&cb) : me (new PImpl(cb))
|
||||
{
|
||||
me->md_consumer.on_security ([this] (api::Security const &sec, md2::MDConsumerHandle ) {
|
||||
auto &ptr = me->known_securities[SecurityKey(sec.id())];
|
||||
bts_assert(!ptr);
|
||||
ptr = std::make_unique<api::Security>(sec);
|
||||
auto handle = me->md_consumer.get_managed_handle(sec.id());
|
||||
me->keep_alive.push_back(handle);
|
||||
me->pending_event.value.push_back({ptr.get(),handle.get()});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void SecuritySource::discover()
|
||||
{
|
||||
me->md_consumer.scan_securities ();
|
||||
if (me->pending_event.value.size()) {
|
||||
me->on_securities(me->pending_event);
|
||||
me->pending_event.value.clear();
|
||||
}
|
||||
}
|
||||
|
||||
SecuritySource::~SecuritySource () {}
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
namespace event {class NewSecurities;}
|
||||
|
||||
class SecuritySource
|
||||
{
|
||||
public:
|
||||
using OnSecurities = std::function<void(event::NewSecurities const&)>;
|
||||
SecuritySource(OnSecurities const&cb);
|
||||
void discover();
|
||||
|
||||
~SecuritySource();
|
||||
private:
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me;
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "server/sparkd/order_man/events/NewSecurities.h"
|
||||
#include "server/sparkd/order_man/events/BookUpdate.h"
|
||||
#include "lib/utils/TimeStamp.h"
|
||||
#include "lib/md/MDConsumerHandle.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
class TimeSource
|
||||
{
|
||||
public:
|
||||
using OnTime = std::function<void(event::TimeChange const&)>;
|
||||
|
||||
MDSource(OnTime const&cb) : _on_time(cb),_last() {}
|
||||
|
||||
void check_time() {
|
||||
auto now = Timer::now();
|
||||
if (ms_diff(now,_last) > 10) {
|
||||
_last = now;
|
||||
event::TimeChange change;
|
||||
auto ts_str = datetime::FIX_timestamp(datetime::now());
|
||||
bts_assert(ts_str.size() == std::tuple_size<OrderManTime>());
|
||||
std::copy(ts_str.begin(),ts_str.end(),&change.ts_str[0]);
|
||||
_on_time(change);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
OnTime _on_time;
|
||||
TimeStamp _last;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
| remaining_quantity | N | N | N | Y | Y | ~const,null |
|
||||
| reject_msg | N | N | N | Y | Y | ~const,null |
|
||||
|
||||
|
||||
* Order Chain trace
|
||||
** NewOrder
|
||||
=-=-=-=-=-=-==-=-=-=-=-=-==-=-=-=-=-=-=
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "lib/domain_model/common.h"
|
||||
#include "lib/config/protos/MarketData.pb.h"
|
||||
#include "lib/md/Structure/PriceSize.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
namespace event {
|
||||
|
||||
using BookSide = std::array<md2::PriceSize,5> ;
|
||||
|
||||
class BookUpdate {
|
||||
public:
|
||||
SecurityKey security_key;
|
||||
BookSide &bid () {return _book[0];}
|
||||
BookSide &ask () {return _book[1];}
|
||||
|
||||
BookSide& get_side(api::BuySell bs)
|
||||
{
|
||||
bts_assert_d(bs != api::UNDEFINED);
|
||||
return _book[bs - api::BUY];
|
||||
}
|
||||
|
||||
private:
|
||||
std::array<BookSide,2> _book;
|
||||
};
|
||||
|
||||
}}}
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "lib/api/services/OrderService.pb.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
namespace event {
|
||||
|
||||
class ExecutionReport
|
||||
{
|
||||
public:
|
||||
AccountName account_name;
|
||||
OperatorID operator_id;
|
||||
OrderKey order_key;
|
||||
SecurityKey security_key;
|
||||
api::BuySell side;
|
||||
TimeInForce::Type time_in_force;
|
||||
api::orderman::OrderType order_type;
|
||||
api::orderman::ExecType exec_type;
|
||||
api::orderman::OrderStatus order_status;
|
||||
ExchangeOrderID exchange_order_id;
|
||||
OrderPrice price;
|
||||
Quantity order_quantity;
|
||||
Quantity filled_quantity;
|
||||
Quantity last_shares;
|
||||
OrderPrice last_px;
|
||||
std::string reject_msg;
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "server/sparkd/order_man/order_man_utils.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
namespace event {
|
||||
|
||||
class GatewayStatusChange {
|
||||
public:
|
||||
GatewayName name;
|
||||
bool is_connected;
|
||||
};
|
||||
|
||||
}}}
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace bts {
|
||||
|
||||
namespace api {class Security;}
|
||||
namespace md2 {class MDConsumerHandle;}
|
||||
|
||||
namespace orderman {
|
||||
namespace event {
|
||||
|
||||
class NewSecurities
|
||||
{
|
||||
public:
|
||||
struct SecRec {
|
||||
api::Security const* sec;
|
||||
md2::MDConsumerHandle* handle;
|
||||
};
|
||||
std::vector<SecRec> value;
|
||||
};
|
||||
|
||||
}}}
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "OutGatewayMsg.h"
|
||||
#include "server/sparkd/jetfix/common/OutFIXPtr.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
namespace event {
|
||||
|
||||
class OutGatewayMsg {
|
||||
public:
|
||||
jetfix::OutFIXPtr msg;
|
||||
};
|
||||
|
||||
}}}
|
||||
@@ -0,0 +1 @@
|
||||
#include "TimeChange.h"
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "lib/utils/bts_chrono.h"
|
||||
#include "server/sparkd/order_man/order_man_utils.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
namespace event {
|
||||
|
||||
class TimeChange
|
||||
{
|
||||
public:
|
||||
TimeStamp ts;
|
||||
OrderTimeStamp ts_str;
|
||||
};
|
||||
|
||||
}}}
|
||||
@@ -1,52 +1,52 @@
|
||||
#pragma once
|
||||
// #pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <cstring>
|
||||
// #include <memory>
|
||||
// #include <cstring>
|
||||
|
||||
#include "order_man_common.h"
|
||||
#include "server/sparkd/jetfix/codec/i32_toa.h"
|
||||
#include "server/sparkd/jetfix/codec/MessageDefinitions.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
#include "order_man_common.h"
|
||||
// #include "order_man_common.h"
|
||||
// #include "server/sparkd/jetfix/codec/i32_toa.h"
|
||||
// #include "server/sparkd/jetfix/codec/MessageDefinitions.h"
|
||||
// #include "lib/utils/bts_assert.h"
|
||||
// #include "order_man_common.h"
|
||||
|
||||
namespace bts {
|
||||
namespace api {class Security;}
|
||||
// namespace bts {
|
||||
// namespace api {class Security;}
|
||||
|
||||
namespace orderman {
|
||||
// namespace orderman {
|
||||
|
||||
class OrderFill;
|
||||
// class OrderFill;
|
||||
|
||||
void extract_fill(api::Security const &sec,jetfix::fix::ExecutionReportMsg const&, OrderFill *);
|
||||
// void extract_fill(api::Security const &sec,jetfix::fix::ExecutionReportMsg const&, OrderFill *);
|
||||
|
||||
constexpr size_t clordid_size() {return 20;}
|
||||
// constexpr size_t clordid_size() {return 20;}
|
||||
|
||||
inline void encode_clorid(OrderKey ok, SecurityKey sk,std::string *out) {
|
||||
u32_toa(sk.value(),&((*out)[0]),clordid_size()/2);
|
||||
u32_toa(ok.value(),&((*out)[clordid_size()/2]),clordid_size()/2);
|
||||
}
|
||||
// inline void encode_clorid(OrderKey ok, SecurityKey sk,std::string *out) {
|
||||
// u32_toa(sk.value(),&((*out)[0]),clordid_size()/2);
|
||||
// u32_toa(ok.value(),&((*out)[clordid_size()/2]),clordid_size()/2);
|
||||
// }
|
||||
|
||||
inline void decode_clorid(std::string const&in, OrderKey *ok, SecurityKey *sk)
|
||||
{
|
||||
bts_assert(in.size() == clordid_size());
|
||||
char buffer[clordid_size()/2+1];
|
||||
buffer[clordid_size()/2] = 0;
|
||||
// inline void decode_clorid(std::string const&in, OrderKey *ok, SecurityKey *sk)
|
||||
// {
|
||||
// bts_assert(in.size() == clordid_size());
|
||||
// char buffer[clordid_size()/2+1];
|
||||
// buffer[clordid_size()/2] = 0;
|
||||
|
||||
std::memcpy(buffer,&in[0],clordid_size()/2);
|
||||
*sk = SecurityKey(std::atoi(buffer));
|
||||
// std::memcpy(buffer,&in[0],clordid_size()/2);
|
||||
// *sk = SecurityKey(std::atoi(buffer));
|
||||
|
||||
std::memcpy(buffer,&in[clordid_size()/2],clordid_size()/2);
|
||||
*ok = OrderKey(std::atoi(buffer));
|
||||
}
|
||||
// std::memcpy(buffer,&in[clordid_size()/2],clordid_size()/2);
|
||||
// *ok = OrderKey(std::atoi(buffer));
|
||||
// }
|
||||
|
||||
template <class MSG>
|
||||
OrderKey get_order_key(MSG const &msg)
|
||||
{
|
||||
// template <class MSG>
|
||||
// OrderKey get_order_key(MSG const &msg)
|
||||
// {
|
||||
|
||||
bts_assert(msg.template has<jetfix::fix::ClOrdID> ());
|
||||
OrderKey result;
|
||||
SecurityKey dummy;
|
||||
decode_clorid(msg.template get<jetfix::fix::ClOrdID>(),&result,&dummy);
|
||||
return result;
|
||||
}
|
||||
// bts_assert(msg.template has<jetfix::fix::ClOrdID> ());
|
||||
// OrderKey result;
|
||||
// SecurityKey dummy;
|
||||
// decode_clorid(msg.template get<jetfix::fix::ClOrdID>(),&result,&dummy);
|
||||
// return result;
|
||||
// }
|
||||
|
||||
}}
|
||||
// }}
|
||||
@@ -1 +0,0 @@
|
||||
#include "order_man_common.h"
|
||||
@@ -1,23 +0,0 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <functional>
|
||||
|
||||
#include "lib/utils/ValueWrapper.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
#include "lib/domain_model/common.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
using OrderKey = utils::ValueWrapper<struct OrderKeyTag,uint32_t>;
|
||||
using FIXSessionName = utils::ValueWrapper<struct FIXSessionNameTag,std::string>;
|
||||
using OperatorID = utils::ValueWrapper<struct OperatorIDTag,std::string>;
|
||||
using ExchangeOrderID = utils::ValueWrapper<struct ExchangeOrderIDTag,std::string>;
|
||||
using OrderTimeStamp = std::array<char, sizeof("20121204-14:44:02.000")-1> ;
|
||||
using FillID = utils::ValueWrapper<struct FillIDTag,std::string>;
|
||||
using OrderKeyGenerator = std::function<OrderKey (size_t how_many)>;
|
||||
|
||||
}}
|
||||
@@ -3,17 +3,54 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
|
||||
#include "lib/utils/ValueWrapper.h"
|
||||
#include "lib/domain_model/common.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
|
||||
namespace bts {
|
||||
namespace api {class Security;}
|
||||
namespace orderman {
|
||||
using OrderKey = utils::ValueWrapper<struct OrderKeyTag,uint32_t>;
|
||||
using FIXSessionName = utils::ValueWrapper<struct FIXSessionNameTag,std::string>;
|
||||
using OperatorID = utils::ValueWrapper<struct OperatorIDTag,std::string>;
|
||||
using ExchangeOrderID = utils::ValueWrapper<struct ExchangeOrderIDTag,std::string>;
|
||||
using GatewayName = utils::ValueWrapper<struct GatewayNameTag,std::string>;
|
||||
using OperatorID = utils::ValueWrapper<struct OperatorIDTag,std::array<char,18>>;
|
||||
using ExchangeOrderID = utils::ValueWrapper<struct ExchangeOrderIDTag,std::array<char,17>>;
|
||||
using OrderTimeStamp = std::array<char, sizeof("20121204-14:44:02.000")-1> ;
|
||||
using SecurityPtr = const api::Security *;
|
||||
using AccountName = utils::ValueWrapper<struct AccountNameTag,std::array<char,12>>;
|
||||
|
||||
template <size_t N> void to_array(std::string const&str,std::array<char,N>*out )
|
||||
{
|
||||
auto &result = *out;
|
||||
bts_assert(str.size() <= N);
|
||||
memset(&result[0],' ', N);
|
||||
memcpy(&result[0],str.data(),str.size());
|
||||
}
|
||||
|
||||
template <size_t N> void to_str(std::array<char,N> const&in ,std::string *out)
|
||||
{
|
||||
auto &result = *out;
|
||||
result.resize(N);
|
||||
memcpy(&result[0],in.data(),N);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T to(std::string const&str)
|
||||
{
|
||||
T result;
|
||||
to_array(str,&result.value());
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline std::string to_str (T const&t)
|
||||
{
|
||||
std::string result;
|
||||
to_str(t.value(),&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -1,88 +1,88 @@
|
||||
#include "RiskLimitManager.h"
|
||||
|
||||
#include "SharedRiskLimiter.h"
|
||||
#include "RiskLimitState.h"
|
||||
#include "IRiskLimitObserver.h"
|
||||
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/Account.pb.h"
|
||||
#include "lib/config/protos/User.pb.h"
|
||||
#include "lib/domain_model/Security.pb.h"
|
||||
|
||||
#include "lib/utils/bts_assert.h"
|
||||
#include "lib/logging/logging.h"
|
||||
|
||||
#include <boost/container/flat_map.hpp>
|
||||
#include <tuple>
|
||||
|
||||
using namespace bts::orderman;
|
||||
|
||||
namespace bts {
|
||||
namespace risklimits {
|
||||
|
||||
using OperatorMap = boost::container::flat_map<std::string, config::Operator>;
|
||||
|
||||
using SymbolKey = std::tuple<std::string, api::Security::ContractCase>;
|
||||
using KeyType = std::tuple<AccountName, OperatorID, SymbolKey>;
|
||||
using SharedLimiterMap = boost::container::flat_map<KeyType, std::shared_ptr<SharedRiskLimiter>>;
|
||||
|
||||
using StateKeyType = std::tuple<AccountName, OperatorID>;
|
||||
using PBLimitsMap = const google::protobuf::Map<std::__cxx11::string, bts::config::RiskLimit>;
|
||||
|
||||
struct RiskLimitManager::PImpl
|
||||
{
|
||||
RiskLimitManager& this_ptr;
|
||||
OperatorMap operator_map;
|
||||
SharedLimiterMap limiter_map;
|
||||
std::vector<IRiskLimitObserver*> observers;
|
||||
boost::container::flat_map<StateKeyType, RiskLimitState> aggregate_state;
|
||||
|
||||
PImpl(RiskLimitManager& rm) :
|
||||
this_ptr(rm),
|
||||
operator_map(), limiter_map(), observers(), aggregate_state()
|
||||
{
|
||||
auto users = config::get<config::UserCfg>();
|
||||
for(int i = 0; i < users.user_size(); i++)
|
||||
{
|
||||
auto user = users.user(i);
|
||||
for(int j = 0; i < user.operators_size(); j++)
|
||||
operator_map[user.operators(j).operator_id().id()] = user.operators(j);
|
||||
}
|
||||
|
||||
auto accts = config::get<config::AccountCfg>();
|
||||
for(int i = 0; i < accts.accounts_with_limits_size(); i++)
|
||||
{
|
||||
const auto& acct = accts.accounts_with_limits(i).account();
|
||||
const auto& future_limit = accts.accounts_with_limits(i).future_limits();
|
||||
update_limits(future_limit, acct, api::Security::kFuture);
|
||||
const auto& spread_limit = accts.accounts_with_limits(i).spread_limits();
|
||||
update_limits(spread_limit, acct, api::Security::kSpread);
|
||||
}
|
||||
#include "RiskLimitManager.h"
|
||||
|
||||
#include "SharedRiskLimiter.h"
|
||||
#include "RiskLimitState.h"
|
||||
#include "IRiskLimitObserver.h"
|
||||
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/Account.pb.h"
|
||||
#include "lib/config/protos/User.pb.h"
|
||||
#include "lib/domain_model/Security.pb.h"
|
||||
|
||||
#include "lib/utils/bts_assert.h"
|
||||
#include "lib/logging/logging.h"
|
||||
|
||||
#include <boost/container/flat_map.hpp>
|
||||
#include <tuple>
|
||||
|
||||
using namespace bts::orderman;
|
||||
|
||||
namespace bts {
|
||||
namespace risklimits {
|
||||
|
||||
using OperatorMap = boost::container::flat_map<std::string, config::Operator>;
|
||||
|
||||
using SymbolKey = std::tuple<std::string, api::Security::ContractCase>;
|
||||
using KeyType = std::tuple<AccountName, OperatorID, SymbolKey>;
|
||||
using SharedLimiterMap = boost::container::flat_map<KeyType, std::shared_ptr<SharedRiskLimiter>>;
|
||||
|
||||
using StateKeyType = std::tuple<AccountName, OperatorID>;
|
||||
using PBLimitsMap = const google::protobuf::Map<std::__cxx11::string, bts::config::RiskLimit>;
|
||||
|
||||
struct RiskLimitManager::PImpl
|
||||
{
|
||||
RiskLimitManager& this_ptr;
|
||||
OperatorMap operator_map;
|
||||
SharedLimiterMap limiter_map;
|
||||
std::vector<IRiskLimitObserver*> observers;
|
||||
boost::container::flat_map<StateKeyType, RiskLimitState> aggregate_state;
|
||||
|
||||
PImpl(RiskLimitManager& rm) :
|
||||
this_ptr(rm),
|
||||
operator_map(), limiter_map(), observers(), aggregate_state()
|
||||
{
|
||||
auto users = config::get<config::UserCfg>();
|
||||
for(int i = 0; i < users.user_size(); i++)
|
||||
{
|
||||
auto user = users.user(i);
|
||||
for(int j = 0; i < user.operators_size(); j++)
|
||||
operator_map[user.operators(j).operator_id().id()] = user.operators(j);
|
||||
}
|
||||
|
||||
auto accts = config::get<config::AccountCfg>();
|
||||
for(int i = 0; i < accts.accounts_with_limits_size(); i++)
|
||||
{
|
||||
const auto& acct = accts.accounts_with_limits(i).account();
|
||||
const auto& future_limit = accts.accounts_with_limits(i).future_limits();
|
||||
update_limits(future_limit, acct, api::Security::kFuture);
|
||||
const auto& spread_limit = accts.accounts_with_limits(i).spread_limits();
|
||||
update_limits(spread_limit, acct, api::Security::kSpread);
|
||||
}
|
||||
}
|
||||
|
||||
void update_limits(PBLimitsMap & map, const bts::config::Account & acct, api::Security::ContractCase contract_type)
|
||||
{
|
||||
for(auto j = map.begin(); j != map.end(); j++)
|
||||
{
|
||||
for(int k = 0; k < acct.allowed_operators_size(); k++)
|
||||
{
|
||||
auto allowed = operator_map.find(acct.allowed_operators(k).id());
|
||||
if(allowed != operator_map.end())
|
||||
{
|
||||
OperatorID opid(allowed->second.operator_id().id());
|
||||
SharedRiskLimiter& lim = find_limiter(to_accountname(acct), opid, to_symbolkey(j->first, contract_type));
|
||||
lim.on_account_update(acct);
|
||||
lim.on_operator_update(allowed->second);
|
||||
lim.on_risk_limit_update(j->second);
|
||||
}
|
||||
}
|
||||
for(auto j = map.begin(); j != map.end(); j++)
|
||||
{
|
||||
for(int k = 0; k < acct.allowed_operators_size(); k++)
|
||||
{
|
||||
auto allowed = operator_map.find(acct.allowed_operators(k).id());
|
||||
if(allowed != operator_map.end())
|
||||
{
|
||||
OperatorID opid(allowed->second.operator_id().id());
|
||||
SharedRiskLimiter& lim = find_limiter(to_accountname(acct), opid, to_symbolkey(j->first, contract_type));
|
||||
lim.on_account_update(acct);
|
||||
lim.on_operator_update(allowed->second);
|
||||
lim.on_risk_limit_update(j->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SymbolKey to_symbolkey(const api::Security& security)
|
||||
{
|
||||
return std::make_tuple("ES", security.Contract_case());
|
||||
}
|
||||
}
|
||||
|
||||
SymbolKey to_symbolkey(const api::Security& security)
|
||||
{
|
||||
return std::make_tuple("ES", security.Contract_case());
|
||||
}
|
||||
SymbolKey to_symbolkey(const std::string& symbol, api::Security::ContractCase type)
|
||||
{
|
||||
return std::make_tuple(symbol, type);
|
||||
@@ -90,8 +90,8 @@ struct RiskLimitManager::PImpl
|
||||
AccountName to_accountname(const config::Account& key)
|
||||
{
|
||||
return AccountName(key.account_id());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SharedRiskLimiter& find_limiter(AccountName acctname, OperatorID opid, SymbolKey symkey)
|
||||
{
|
||||
KeyType key(acctname, opid, symkey);
|
||||
@@ -105,10 +105,10 @@ struct RiskLimitManager::PImpl
|
||||
limiter_map[key] = ptr;
|
||||
return *ptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
RiskLimitManager::RiskLimitManager() : me(new PImpl(*this)) {}
|
||||
RiskLimitManager::~RiskLimitManager() {}
|
||||
|
||||
|
||||
@@ -94,42 +94,42 @@ struct RiskLimiter::PImpl
|
||||
};
|
||||
|
||||
|
||||
RiskLimiter::RiskLimiter(SharedRiskLimiter& sh, orderman::OrderKey key)
|
||||
: me(new PImpl(sh, key))
|
||||
{
|
||||
}
|
||||
|
||||
RiskLimiter::~RiskLimiter() {}
|
||||
|
||||
RiskLimiter::RiskLimitResult RiskLimiter::check(Quantity qty, api::BuySell side) const
|
||||
{
|
||||
RiskLimiter::RiskLimitResult res;
|
||||
res.success = me->check_can_trade(res.message);
|
||||
if(!res.success)
|
||||
return res;
|
||||
res.success = me->check_clip_size(qty, res.message);
|
||||
if(!res.success)
|
||||
return res;
|
||||
res.success = me->check_position_limit(qty, side, res.message);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void RiskLimiter::on_order_state(const orderman::OrderState& state)
|
||||
{
|
||||
int working_diff = state.remaining_quantity.value() - me->remaining_quantity.value();
|
||||
if(state.side == api::BUY)
|
||||
me->shared.position_info.long_working += working_diff;
|
||||
else
|
||||
me->shared.position_info.short_working += working_diff;
|
||||
|
||||
int filled_diff = state.filled_quantity.value() - me->filled_quantity.value();
|
||||
if(state.side == api::BUY)
|
||||
me->shared.position_info.long_position += filled_diff;
|
||||
else
|
||||
me->shared.position_info.short_position += filled_diff;
|
||||
}
|
||||
|
||||
RiskLimiter::RiskLimiter(SharedRiskLimiter& sh, orderman::OrderKey key)
|
||||
: me(new PImpl(sh, key))
|
||||
{
|
||||
}
|
||||
|
||||
RiskLimiter::~RiskLimiter() {}
|
||||
|
||||
RiskLimiter::RiskLimitResult RiskLimiter::check(Quantity qty, api::BuySell side) const
|
||||
{
|
||||
RiskLimiter::RiskLimitResult res;
|
||||
res.success = me->check_can_trade(res.message);
|
||||
if(!res.success)
|
||||
return res;
|
||||
res.success = me->check_clip_size(qty, res.message);
|
||||
if(!res.success)
|
||||
return res;
|
||||
res.success = me->check_position_limit(qty, side, res.message);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void RiskLimiter::on_order_state(const orderman::OrderState& state)
|
||||
{
|
||||
int working_diff = state.remaining_quantity.value() - me->remaining_quantity.value();
|
||||
if(state.side == api::BUY)
|
||||
me->shared.position_info.long_working += working_diff;
|
||||
else
|
||||
me->shared.position_info.short_working += working_diff;
|
||||
|
||||
int filled_diff = state.filled_quantity.value() - me->filled_quantity.value();
|
||||
if(state.side == api::BUY)
|
||||
me->shared.position_info.long_position += filled_diff;
|
||||
else
|
||||
me->shared.position_info.short_position += filled_diff;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ namespace spreader
|
||||
class SimpleSpreaderCreate : public SpreaderCreate
|
||||
{
|
||||
public:
|
||||
AccountName account_name;
|
||||
orderman::AccountName account_name;
|
||||
orderman::OperatorID operator_id;
|
||||
api::BuySell side;
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
#include <tuple>
|
||||
#include "lib/domain_model/Security.pb.h"
|
||||
#include "server/sparkd/order_man/order_man_common.h"
|
||||
#include "server/sparkd/order_man/order_man_utils.h"
|
||||
|
||||
#include "lib/api/services/OrderService.pb.h"
|
||||
#include "lib/utils/bts_chrono.h"
|
||||
|
||||
@@ -49,7 +50,7 @@ class SpreaderUpdate {};
|
||||
struct SpreaderSubscriptions
|
||||
{
|
||||
std::vector<api::Security const*> securities_for_md;
|
||||
AccountName account_for_limit_check;
|
||||
orderman::AccountName account_for_limit_check;
|
||||
orderman::OperatorID operator_for_limit_check;
|
||||
};
|
||||
|
||||
@@ -115,7 +116,7 @@ protected:
|
||||
|
||||
// use this to accelarate the creation of new orders
|
||||
OrderTemplate const& make_order_template(api::Security const&,
|
||||
AccountName const &,
|
||||
orderman::AccountName const &,
|
||||
orderman::OperatorID const &,
|
||||
api::BuySell ,
|
||||
api::orderman::CustomerOrFirm ,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
@set linuxhome=%homedrive%%homepath%\linux_home
|
||||
@if not exist %linuxhome% (
|
||||
@if not exist %linuxhome%\www\config (
|
||||
mkdir %linuxhome%\www\config
|
||||
mkdir %linuxhome%\.bts\
|
||||
)
|
||||
@if not exist %linuxhome%\.bts\conf (
|
||||
mkdir %linuxhome%\.bts\conf
|
||||
)
|
||||
@@ -7,3 +7,5 @@ cd $ROOT
|
||||
# external includes
|
||||
find externals/linux/include/ -name "*.h" -or -name "*.hpp" | sed s/externals\\/linux\\/include\\///
|
||||
|
||||
# stdlib includes
|
||||
find /usr/include/c++/6 -maxdepth 1 | sed s/\\/usr\\/include\\/c\+\+\\/6\\///
|
||||
@@ -21,7 +21,7 @@ function(update_deps_file deps)
|
||||
list(REMOVE_DUPLICATES deps)
|
||||
list(SORT deps)
|
||||
# Update the deps file
|
||||
set(content "# generated by make process\nset(sources ${deps})\n")
|
||||
set(content "set(sources ${deps})")
|
||||
update_file(${deps_file} "${content}")
|
||||
# Include the file so it's tracked as a generation dependency we don't
|
||||
# need the content.
|
||||
|
||||
Reference in new issue
Block a user