Merge branch 'master' of https://bitbucket.org/bluetradesys/spark into fix_mics
This commit is contained in:
commit
7e0d79ac68
38 files changed
+761
-218
No files matched your search
Vendored
+2
-1
@@ -209,7 +209,8 @@
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "/home/bts/spark/build/ninja_debug/src/server/sparkd/sparkd",
|
||||
"args": ["test","Co2RelayTests"],
|
||||
// "args": ["test","Co2RelayTests"],
|
||||
"args": ["md", "run", "10"],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "/home/bts/spark/build/ninja_debug/src/server/sparkd/",
|
||||
"environment": [],
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
UIntTemplate="{StaticResource SimpleValueTextTemplate}"
|
||||
MarketDataTypeTemplate="{StaticResource SimpleValueTextTemplate}"
|
||||
MarketDataCalculationTemplate="{StaticResource SimpleValueTextTemplate}"
|
||||
ConditionalPriceTypeTemplate="{StaticResource SimpleValueTextTemplate}"
|
||||
>
|
||||
<usp:DataGridParameterCellTemplateConverter.BooleanTemplate>
|
||||
<DataTemplate>
|
||||
@@ -122,6 +123,11 @@
|
||||
<ComboBox SelectedItem="{Binding value}" ItemsSource="{u:EnumBindingSource {u:Nested sp:LegSpreaderParams.Types.LegMarketDataCalculation}}" ItemTemplate="{StaticResource EnumDescriptionTemplate}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.MarketDataCalculationTemplate>
|
||||
<usp:DataGridParameterCellTemplateConverter.ConditionalPriceTypeTemplate>
|
||||
<DataTemplate>
|
||||
<ComboBox SelectedItem="{Binding value}" ItemsSource="{u:EnumBindingSource {u:Nested sp:ConditionalQuoting.Types.PriceType}}" ItemTemplate="{StaticResource EnumDescriptionTemplate}"/>
|
||||
</DataTemplate>
|
||||
</usp:DataGridParameterCellTemplateConverter.ConditionalPriceTypeTemplate>
|
||||
<usp:DataGridParameterCellTemplateConverter.QuantityMeasureTemplate>
|
||||
<DataTemplate>
|
||||
<Grid IsEnabled="{Binding enabled}">
|
||||
|
||||
@@ -304,6 +304,7 @@ namespace mbts.ui.spark {
|
||||
public DataTemplate QuantityMeasureTemplate { get; set; }
|
||||
public DataTemplate MarketDataTypeTemplate { get; set; }
|
||||
public DataTemplate MarketDataCalculationTemplate { get; set; }
|
||||
public DataTemplate ConditionalPriceTypeTemplate { get; set; }
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
Type t = (Type)value;
|
||||
@@ -314,6 +315,7 @@ namespace mbts.ui.spark {
|
||||
else if (t == typeof(QuantityMeasure)) return QuantityMeasureTemplate;
|
||||
else if (t == typeof(LegSpreaderParams.Types.MarketDataType)) return MarketDataTypeTemplate;
|
||||
else if (t == typeof(LegSpreaderParams.Types.LegMarketDataCalculation)) return MarketDataCalculationTemplate;
|
||||
else if (t == typeof(ConditionalQuoting.Types.PriceType)) return ConditionalPriceTypeTemplate;
|
||||
else return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -103,6 +103,11 @@ namespace bts.shell {
|
||||
OutsideTicks = 3,
|
||||
Priority = RulePriority
|
||||
};
|
||||
public static ConditionalQuoting ConditionalQuoting => new ConditionalQuoting
|
||||
{
|
||||
NTicks = 2,
|
||||
PriceType = ConditionalQuoting.Types.PriceType.Leg
|
||||
};
|
||||
public static QuoteInsideMarketDistanceWithTravel QuoteInsideMarketDistanceWithTravel => new QuoteInsideMarketDistanceWithTravel { Priority = RulePriority };
|
||||
public static QuoteInsideMarketDistance QuoteInsideMarketDistance => new QuoteInsideMarketDistance { Priority = RulePriority };
|
||||
#endregion
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using mbts.ui.spark;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace mbts.spark {
|
||||
partial class SyntheticEditorVM {
|
||||
class EnableHedgeModel : RowModelBase<bool> {
|
||||
public override string display_name { get; } = "Enable Hedging";
|
||||
public override string help_text { get; } = "Send a hedge for this leg?";
|
||||
public override string man_page { get; } = string.Empty;
|
||||
|
||||
public override bool get_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
leg_tup.leg_params.EnableHedging;
|
||||
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, bool value) =>
|
||||
leg_tup.leg_params.EnableHedging = value;
|
||||
|
||||
public override bool has_errors(IReadOnlyCollection<LegSpreaderParamsTuple> leg_tups) =>
|
||||
!leg_tups.Any(lt => lt.leg_params.EnableHedging);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using mbts.ui.spark;
|
||||
using System;
|
||||
|
||||
namespace mbts.spark {
|
||||
partial class SyntheticEditorVM {
|
||||
class MinLeanQtyModel : RowModelBase<System.UInt32> {
|
||||
public override string display_name { get; } = "Min Lean Qty";
|
||||
public override string help_text { get; } = "Minimum Quantity required at this leg to quote";
|
||||
public override string man_page { get; } = string.Empty;
|
||||
|
||||
public override System.UInt32 get_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
leg_tup.leg_params.QuoteParams.MinLeanQty;
|
||||
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, System.UInt32 value) =>
|
||||
leg_tup.leg_params.QuoteParams.MinLeanQty = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
using bts.shell;
|
||||
using mbts.ui.spark;
|
||||
|
||||
namespace mbts.spark {
|
||||
partial class SyntheticEditorVM {
|
||||
class ConditionalQuoteEnabledModel : RowModelBase<bool> {
|
||||
readonly ConditionalQuotingTicksModel _ticks;
|
||||
readonly ConditionalQuotingPriceTypeModel _price_type;
|
||||
|
||||
public ConditionalQuoteEnabledModel(ConditionalQuotingTicksModel ticks, ConditionalQuotingPriceTypeModel price_type)
|
||||
{
|
||||
_ticks = ticks;
|
||||
_price_type = price_type;
|
||||
}
|
||||
|
||||
public override string display_name { get; } = string.Empty;
|
||||
public override string help_text { get; } = string.Empty;
|
||||
public override string man_page { get; } = string.Empty;
|
||||
public override ParameterSection[] section_path { get; } = new[] { Sections.Quote, Subsections.Conditional };
|
||||
|
||||
public override bool get_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
leg_tup.leg_params.QuoteParams.ConditionalQuoting != null;
|
||||
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, bool value) {
|
||||
if (value) {
|
||||
if (leg_tup.leg_params.QuoteParams.ConditionalQuoting == null) {
|
||||
leg_tup.leg_params.QuoteParams.ConditionalQuoting = SyntheticDataHelper.Defaults.ConditionalQuoting;
|
||||
_ticks.apply_value(leg_tup);
|
||||
_price_type.apply_value(leg_tup);
|
||||
}
|
||||
} else {
|
||||
leg_tup.leg_params.QuoteParams.ConditionalQuoting = null;
|
||||
}
|
||||
_ticks.set_enabled(leg_tup, value);
|
||||
_price_type.set_enabled(leg_tup, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
using mbts.ui.spark;
|
||||
using bts.spark;
|
||||
using PriceType = bts.spark.ConditionalQuoting.Types.PriceType;
|
||||
using mbts.collections.extensions;
|
||||
using System.Collections.Generic;
|
||||
using bts.shell;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
partial class SyntheticEditorVM
|
||||
{
|
||||
class ConditionalQuotingPriceTypeModel : RowModelBase<PriceType>
|
||||
{
|
||||
IDictionary<uint, PriceType> _value_store = new Dictionary<uint, PriceType>();
|
||||
|
||||
public override string display_name { get; } = "Price Type";
|
||||
public override string help_text { get; } = string.Empty;
|
||||
public override string man_page { get; } = string.Empty;
|
||||
public override ParameterSection[] section_path { get; } = new[] { Sections.Quote, Subsections.Conditional };
|
||||
|
||||
public void apply_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
_get_value(leg_tup).PriceType = _value_from_store(leg_tup);
|
||||
|
||||
public override PriceType get_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
_get_value(leg_tup) is ConditionalQuoting cond ?
|
||||
cond.PriceType :
|
||||
_value_from_store(leg_tup);
|
||||
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, PriceType value)
|
||||
{
|
||||
_value_store[leg_tup.SecurityKey] = value;
|
||||
if (_get_value(leg_tup) is ConditionalQuoting cond)
|
||||
cond.PriceType = value;
|
||||
}
|
||||
|
||||
protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) => _get_value(leg_tup) != null; //TAHA_SPREADER
|
||||
|
||||
ConditionalQuoting _get_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
leg_tup.leg_params.QuoteParams.ConditionalQuoting;
|
||||
|
||||
PriceType _value_from_store(LegSpreaderParamsTuple leg_tup) =>
|
||||
_value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.ConditionalQuoting.PriceType);
|
||||
}
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
using bts.shell;
|
||||
using bts.spark;
|
||||
using mbts.collections.extensions;
|
||||
using mbts.ui.spark;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace mbts.spark {
|
||||
partial class SyntheticEditorVM {
|
||||
class ConditionalQuotingTicksModel : RowModelBase<int> {
|
||||
IDictionary<uint, int> _value_store = new Dictionary<uint, int>();
|
||||
|
||||
public override string display_name { get; } = "Ticks";
|
||||
public override string help_text { get; } = string.Empty;
|
||||
public override string man_page { get; } = string.Empty;
|
||||
public override ParameterSection[] section_path { get; } = new[] { Sections.Quote, Subsections.Conditional };
|
||||
|
||||
public void apply_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
_get_value(leg_tup).NTicks = _value_from_store(leg_tup);
|
||||
|
||||
public override int get_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
_get_value(leg_tup) is ConditionalQuoting cond ?
|
||||
cond.NTicks :
|
||||
_value_from_store(leg_tup);
|
||||
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, int value) {
|
||||
_value_store[leg_tup.SecurityKey] = value;
|
||||
if (_get_value(leg_tup) is ConditionalQuoting cond)
|
||||
cond.NTicks = value;
|
||||
}
|
||||
|
||||
protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) =>
|
||||
_get_value(leg_tup) != null;
|
||||
|
||||
ConditionalQuoting _get_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
leg_tup.leg_params.QuoteParams.ConditionalQuoting;
|
||||
|
||||
int _value_from_store(LegSpreaderParamsTuple leg_tup) =>
|
||||
_value_store.GetValueOrDefault(leg_tup.SecurityKey, _ => SyntheticDataHelper.Defaults.ConditionalQuoting.NTicks);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,6 +103,13 @@ namespace mbts.spark {
|
||||
"Reduces re-quoting updates by defining a region on either side " +
|
||||
"of the working quoting order, inside which quote updates will not be sent.");
|
||||
|
||||
public static ParameterSection Conditional =>
|
||||
new ParameterSection("Conditional", true,
|
||||
"Reduces re-quoting updates by only quoting if N ticks away from the opposite " +
|
||||
"inside market. Quotes are cancelled when it gets further away. 'Price Type' " +
|
||||
"dictates if this logic applies to the quoting market or to the synthetic spread " +
|
||||
"market");
|
||||
|
||||
public static ParameterSection InsideMarketThrottleThresholds =>
|
||||
new ParameterSection("Inside Market Throttle Thresholds", true,
|
||||
"Reduces re-quoting for quotes that are moving toward the inside market. " +
|
||||
|
||||
@@ -178,6 +178,9 @@ namespace mbts.spark {
|
||||
var quote_throttle_outside_ticks = new QuoteThrottleOutsideTicksModel();
|
||||
var quote_throttle_inside_ticks = new QuoteThrottleInsideTicksModel();
|
||||
|
||||
var conditional_quoting_ticks = new ConditionalQuotingTicksModel();
|
||||
var conditional_quoting_price_type = new ConditionalQuotingPriceTypeModel();
|
||||
|
||||
var quote_inside_market_throttle_ticks = new QuoteInsideMarketThrottleTicksModel();
|
||||
var quote_inside_market_throttle_min_move = new QuoteInsideMarketThrottleMinMoveModel();
|
||||
|
||||
@@ -199,13 +202,18 @@ namespace mbts.spark {
|
||||
_quantity_model,
|
||||
_price_mult_model,
|
||||
new IsQuoteModel(),
|
||||
//new EnableHedgeModel(), //TAHA_SPREADER
|
||||
new HedgeRatioModel(),
|
||||
//new MinLeanQtyModel(), //TAHA_SPREADER
|
||||
new QuoteHiddenModel(),
|
||||
new MarketDataTypeModel(),
|
||||
new MarketDataCalculationModel(),
|
||||
new QuoteThrottleEnabledModel(quote_throttle_inside_ticks, quote_throttle_outside_ticks),
|
||||
quote_throttle_inside_ticks,
|
||||
quote_throttle_outside_ticks,
|
||||
new ConditionalQuoteEnabledModel(conditional_quoting_ticks, conditional_quoting_price_type),
|
||||
conditional_quoting_ticks,
|
||||
conditional_quoting_price_type,
|
||||
//new QuoteInsideMarketThrottleEnabledModel(quote_inside_market_throttle_ticks, quote_inside_market_throttle_min_move),
|
||||
//quote_inside_market_throttle_ticks,
|
||||
//quote_inside_market_throttle_min_move,
|
||||
|
||||
@@ -1 +1 @@
|
||||
set(sources api/apicore.proto;api/apigateway.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/service_helpers/AdminServiceUtils.cpp;api/services/AdminService.proto;api/services/ApiUnitTestService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.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/Executor.conf;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/quickbus_cfg.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.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.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/tests/domain_tests.cpp;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/PriceSize.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/md2_tests.cpp;md/test/synthetic_book_merge_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;sparkproto/SparkProtos.proto;testing/catch_test_runner.cpp;utils/AuthToken.cpp;utils/Dispatcher.cpp;utils/GrowableSPSCQueue.cpp;utils/HTTPStream.cpp;utils/PBUtils.cpp;utils/Puid.cpp;utils/SecureLogon.cpp;utils/SharedMemory.cpp;utils/Sqlite_utils.cpp;utils/Uuid.cpp;utils/datetime.cpp;utils/download.cpp;utils/file_utils.cpp;utils/init_spark_lib.cpp;utils/is_unittest_environment.cpp;utils/stats.cpp;utils/thread_manager.cpp)
|
||||
set(sources api/apicore.proto;api/apigateway.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/service_helpers/AdminServiceUtils.cpp;api/services/AdminService.proto;api/services/ApiUnitTestService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.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/Executor.conf;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/quickbus_cfg.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.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.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/tests/domain_tests.cpp;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/MDPeriodicDumper.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/PriceSize.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/md2_tests.cpp;md/test/synthetic_book_merge_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;sparkproto/SparkProtos.proto;testing/catch_test_runner.cpp;utils/AuthToken.cpp;utils/Dispatcher.cpp;utils/GrowableSPSCQueue.cpp;utils/HTTPStream.cpp;utils/PBUtils.cpp;utils/Puid.cpp;utils/SecureLogon.cpp;utils/SharedMemory.cpp;utils/Sqlite_utils.cpp;utils/Uuid.cpp;utils/datetime.cpp;utils/download.cpp;utils/file_utils.cpp;utils/init_spark_lib.cpp;utils/is_unittest_environment.cpp;utils/stats.cpp;utils/thread_manager.cpp)
|
||||
@@ -0,0 +1,188 @@
|
||||
#include "MDPeriodicDumper.h"
|
||||
#include "lib/md/MDConsumer.h"
|
||||
#include "lib/utils/TimeStamp.h"
|
||||
#include "lib/utils/Dispatcher.h"
|
||||
#include "lib/utils/datetime.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
/*
|
||||
* Design considerations
|
||||
*
|
||||
* - We want this test to be 'fair'
|
||||
* - We want a manageable amount of data
|
||||
* -
|
||||
*/
|
||||
|
||||
struct Entry {
|
||||
uint32_t seq;
|
||||
MDConsumerHandle handle;
|
||||
std::unique_ptr<api::Security> security;
|
||||
};
|
||||
|
||||
std::string print_book(
|
||||
PrintFormat format,
|
||||
const Entry& e,
|
||||
utils::TimeStamp twrite,
|
||||
utils::TimeStamp tread,
|
||||
uint32_t seq,
|
||||
bool ambiguous,
|
||||
const std::array<PriceSize,COCONUT_MAX_DEPTH>& bid,
|
||||
const std::array<PriceSize,COCONUT_MAX_DEPTH>& ask) {
|
||||
|
||||
std::stringstream ss;
|
||||
if(format == PrintFormat::Human) {
|
||||
ss << std::endl;
|
||||
ss << e.security->glbx().security_desc() << " (" << e.handle.key() << ")" << std::endl;
|
||||
ss << "Sequence: " << seq;
|
||||
if (ambiguous) ss << "*";
|
||||
ss << std::endl;
|
||||
ss << "TWrit: " << twrite.to_uint64() << " ns" << std::endl;
|
||||
ss << "TRead: " << tread.to_uint64() << " ns" << std::endl;
|
||||
char buffer[512];
|
||||
|
||||
snprintf(buffer, 512, "%-5s %-14s | %-14s %-5s\n", "sz", "bid", "ask", "sz");
|
||||
ss << buffer;
|
||||
ss << "-------------------- - -------------------- \n";
|
||||
for (auto x = COCONUT_MAX_DEPTH; x != 0; --x) {
|
||||
auto a = ask[x-1];
|
||||
if (!os::is_nan(a.price())) {
|
||||
snprintf(buffer, 512, "%5s %14s | %14.7f %5d\n", "", "", a.price(), a.size());
|
||||
ss << buffer;
|
||||
}
|
||||
}
|
||||
ss << "-------------------- - -------------------- \n";
|
||||
for (uint32_t x = 0; x < COCONUT_MAX_DEPTH; ++x) {
|
||||
auto b = bid[x];
|
||||
if (!os::is_nan(b.price())) {
|
||||
snprintf(buffer, 512, "%5d %14.7f | \n", b.size(), b.price());
|
||||
ss << buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (format == PrintFormat::CSV) {
|
||||
// Symbol, Id, Sequence, Ambiguous, TWrite, TRead, BidBook, AskBook
|
||||
ss << e.security->glbx().security_desc() << ","
|
||||
<< e.security->id() << ","
|
||||
<< seq << ","
|
||||
<< (ambiguous ? "true," : "false,")
|
||||
<< twrite.to_uint64() << ","
|
||||
<< tread.to_uint64() << ",";
|
||||
for (size_t x = 0; x < COCONUT_MAX_DEPTH; ++x) {
|
||||
if (!bid[x].is_nan()) {
|
||||
ss << " " << std::setprecision(11) << bid[x].price() << "-";
|
||||
if (bid[x].implied_size() > 0) { ss << "*"; }
|
||||
ss << bid[x].size();
|
||||
}
|
||||
}
|
||||
ss << ",";
|
||||
for (size_t x = 0; x < COCONUT_MAX_DEPTH; ++x) {
|
||||
if (!ask[x].is_nan()) {
|
||||
ss << " " << std::setprecision(11) << ask[x].price() << "-";
|
||||
if (ask[x].implied_size() > 0) { ss << "*"; }
|
||||
ss << ask[x].size();
|
||||
}
|
||||
}
|
||||
ss << std::endl;
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
datetime::Date expiration(const api::Security& sec) {
|
||||
auto f = sec.future();
|
||||
return { (uint16_t)f.expiration_year(), (uint8_t)f.expiration_month(), (uint8_t)f.expiration_day() };
|
||||
}
|
||||
|
||||
std::vector<Entry> filter_entries(std::vector<Entry>& entries) {
|
||||
// Choose the front month for all symbols
|
||||
auto today = datetime::today();
|
||||
std::map<UserSymbol, Entry*> map;
|
||||
for (auto& e : entries) {
|
||||
auto type = securitytype_of(*e.security);
|
||||
// Only futures because front month is complicated
|
||||
if (type != api::SECURITYTYPE_FUTURE) continue;
|
||||
UserSymbol key { e.security->symbol(), e.security->exchange(), type };
|
||||
auto& current_entry = map[key];
|
||||
if (current_entry == nullptr) {
|
||||
current_entry = &e;
|
||||
}
|
||||
else {
|
||||
auto cur = expiration(*current_entry->security);
|
||||
auto next = expiration(*e.security);
|
||||
if (next > today && next < cur) {
|
||||
current_entry = &e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Entry> result;
|
||||
for (const auto& pair : map) {
|
||||
result.push_back(std::move(*pair.second));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void write_header(PrintFormat format, long seq_mod, const std::vector<Entry>& entries) {
|
||||
if (format == PrintFormat::Human) {
|
||||
std::cout << "Dumping every sequence % " << seq_mod << " == 0 for\n";
|
||||
std::cout << "Selected securities: " << std::endl;
|
||||
for (const auto& e : entries) {
|
||||
std::cout << e.security->glbx().security_desc() << std::endl;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// CSV header
|
||||
std::cout << "Symbol,Id,Sequence,Ambiguous,TWrite,TRead,BidBook,AskBook";
|
||||
// for (size_t x = 0; x < COCONUT_MAX_DEPTH; ++x) {
|
||||
// std::cout << "," << "Bid" << x << ", DirectBidSize" << x << ", ImpliedBidSize" << x;
|
||||
// }
|
||||
// for (size_t x = 0; x < COCONUT_MAX_DEPTH; ++x) {
|
||||
// std::cout << "," << "Ask" << x << ", AskSize" << x << ", ImpliedAskSize" << x;
|
||||
// }
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void run_periodic_dumper(const std::set<UserSymbol>& symbols, uint32_t seq_mod, PrintFormat format) {
|
||||
|
||||
MDConsumer consumer(symbols, nullptr);
|
||||
|
||||
// read all securities into a vector
|
||||
std::vector<Entry> entries;
|
||||
consumer.walk_security_list([&](const api::Security& sec, MDConsumerHandle handle) {
|
||||
entries.push_back({ 0, handle, std::make_unique<api::Security>(sec) });
|
||||
});
|
||||
|
||||
entries = filter_entries(entries);
|
||||
|
||||
write_header(format, seq_mod, entries);
|
||||
|
||||
auto& disp = utils::Dispatcher::background();
|
||||
|
||||
// spin around on the vector detecting changes
|
||||
std::array<PriceSize,COCONUT_MAX_DEPTH> bid,ask;
|
||||
while(true) {
|
||||
for(auto& e : entries) {
|
||||
auto sequence = e.handle.sequence();
|
||||
if (sequence != e.seq && sequence % seq_mod == 0) {
|
||||
e.seq = sequence;
|
||||
auto tread = TimeStamp::now();
|
||||
utils::TimeStamp twrite;
|
||||
e.handle.get_book(twrite, COCONUT_MAX_DEPTH, bid.data(), ask.data());
|
||||
auto seq2 = e.handle.sequence();
|
||||
// print book to stdout (async?)
|
||||
disp.post([=,&e]() {
|
||||
std::cout << print_book(format, e, twrite, tread, sequence, (sequence != seq2), bid, ask);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}}//ns
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "lib/md/UserSymbol.h"
|
||||
#include <set>
|
||||
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
enum class PrintFormat {
|
||||
Human,
|
||||
CSV
|
||||
};
|
||||
|
||||
void run_periodic_dumper(const std::set<UserSymbol>&, uint32_t seq_mod, PrintFormat format);
|
||||
|
||||
|
||||
}}//ns
|
||||
@@ -1,69 +0,0 @@
|
||||
#ifndef NO_CPP0X
|
||||
#include "MDPriceLantencyTester.h"
|
||||
#include "../MDConsumer.h"
|
||||
#include "lib/utils/Dispatcher.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
struct HandleData {
|
||||
MDConsumerHandle handle;
|
||||
utils::TimeStamp time;
|
||||
utils::TimeStamp last_price_change;
|
||||
float bid, ask;
|
||||
};
|
||||
|
||||
void run_md_price_latency_test(UserSymbol symbol) {
|
||||
set<UserSymbol> symbols;
|
||||
symbols.insert(symbol);
|
||||
std::shared_ptr<api::ISyntheticSecurityService> null;
|
||||
MDConsumer consumer(symbols, null);
|
||||
|
||||
vector<HandleData> handles;
|
||||
|
||||
consumer.walk_security_list([&](const Security&, MDConsumerHandle handle) {
|
||||
HandleData entry = { handle, TimeStamp(), TimeStamp(), 0, 0 };
|
||||
if (!entry.handle.is_initialized()) {
|
||||
cout << "Please start the md publisher before running this command." << endl;
|
||||
return;
|
||||
}
|
||||
handles.push_back(entry);
|
||||
});
|
||||
|
||||
cout << "key, sequence, handover, delta, bid price, ask price" << endl;
|
||||
while (true) {
|
||||
for(auto& entry : handles) {
|
||||
PriceSize bid, ask;
|
||||
if (entry.handle.get_direct_book(entry.time, 1, &bid, &ask) == HandleReadResult::SUCCESS) {
|
||||
auto bid_price = bid.price();
|
||||
auto ask_price = ask.price();
|
||||
if (bid_price != entry.bid || ask_price != entry.ask) {
|
||||
auto now = TimeStamp::now();
|
||||
auto handover = (now - entry.time);
|
||||
auto delta = (now - entry.last_price_change);
|
||||
entry.last_price_change = entry.time;
|
||||
entry.bid = bid_price;
|
||||
entry.ask = ask_price;
|
||||
utils::Dispatcher::background().post([=]() {
|
||||
cout <<
|
||||
entry.handle.key() << ','
|
||||
<< entry.handle.sequence() << ','
|
||||
<< handover.microseconds() << ','
|
||||
<< delta.microseconds() << ','
|
||||
<< bid_price << ',' << ask_price
|
||||
<< endl;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}}//namespace
|
||||
#endif
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/utils/bts_export.h"
|
||||
#include "../common.h"
|
||||
#include "../UserSymbol.h"
|
||||
#include <string>
|
||||
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
BTS_EXPORT void run_md_price_latency_test(UserSymbol);
|
||||
|
||||
|
||||
}}//namespace
|
||||
|
||||
@@ -305,17 +305,6 @@ CoconutSecurityStatus MDConsumerHandle::status() const {
|
||||
}
|
||||
never;
|
||||
}
|
||||
uint16_t MDConsumerHandle::sequence() const {
|
||||
switch(_type) {
|
||||
case HANDLETYPE_VOID: return 0;
|
||||
case HANDLETYPE_DEPTH: return book.hot->sequence;
|
||||
case HANDLETYPE_BBO: return bbo.hot->sequence;
|
||||
case HANDLETYPE_SYNTHETIC:
|
||||
bts_assert(!synthetic.def->legs.empty());
|
||||
return sane::min_by<MDConsumerHandle, TimeStamp>(synthetic.def->legs, [](const MDConsumerHandle& h) { return h.last_market_update(); })->sequence();
|
||||
}
|
||||
never;
|
||||
}
|
||||
|
||||
}}//namespace
|
||||
|
||||
|
||||
@@ -159,7 +159,17 @@ public:
|
||||
bool is_heart_beating() const;
|
||||
TimeStamp heartbeat() const;
|
||||
CoconutSecurityStatus status() const;
|
||||
uint16_t sequence() const;
|
||||
uint32_t sequence() const {
|
||||
switch(_type) {
|
||||
case HANDLETYPE_VOID: return 0;
|
||||
case HANDLETYPE_DEPTH: return book.hot->sequence;
|
||||
case HANDLETYPE_BBO: return bbo.hot->sequence;
|
||||
case HANDLETYPE_SYNTHETIC:
|
||||
bts_assert(!synthetic.def->legs.empty());
|
||||
return sane::min_by<MDConsumerHandle, TimeStamp>(synthetic.def->legs, [](const MDConsumerHandle& h) { return h.last_market_update(); })->sequence();
|
||||
}
|
||||
bts_assert(false);
|
||||
}
|
||||
security_key key() const {
|
||||
switch(_type) {
|
||||
case HANDLETYPE_VOID: return invalid_security_key;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "lib/utils/WaitFreeQueue.h"
|
||||
#include "Shm/MDStructure.h"
|
||||
#include "MemorySegmentUtils.h"
|
||||
#include "SecurityIDRecorder.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -102,12 +103,21 @@ private:
|
||||
//
|
||||
|
||||
MDProducer::MDProducer(Platform platform, bool shared) :
|
||||
_mutex(new Mutex()),
|
||||
_mutex(new std::mutex()),
|
||||
_producers(),
|
||||
_id_recorder(),
|
||||
_platform(platform),
|
||||
_shared(shared)
|
||||
{
|
||||
}
|
||||
{ }
|
||||
#ifndef WIN32
|
||||
MDProducer::MDProducer(Platform platform, SecurityIDRecorder recorder, bool shared) :
|
||||
_mutex(new std::mutex()),
|
||||
_producers(),
|
||||
_id_recorder(std::make_unique<SecurityIDRecorder>(recorder)),
|
||||
_platform(platform),
|
||||
_shared(shared)
|
||||
{ }
|
||||
#endif
|
||||
MDProducer::MDProducer(MDProducer&& other) :
|
||||
_mutex(std::move(other._mutex)),
|
||||
_producers(std::move(other._producers)),
|
||||
@@ -143,15 +153,18 @@ MDProducerImpl& MDProducer::get_producer(const char* symbol, SecurityType type,
|
||||
MDProducerHandle MDProducer::add_security(const FixedSecurity& security) {
|
||||
bts_assert_d(strlen(security.symbol()) > 0);
|
||||
bts_assert(security.size >= sizeof(FixedSecurity));
|
||||
Mutex::scoped_lock lock(*_mutex);
|
||||
std::lock_guard<std::mutex> lock(*_mutex);
|
||||
auto& impl = get_producer(security.symbol(), security.type, security.exchange);
|
||||
auto result = impl.add_security(security);
|
||||
if (security.key != invalid_security_key) { result.set_key(security.key); }
|
||||
else if(_id_recorder) {
|
||||
_id_recorder->ensure_key(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
MDProducerChannel MDProducer::get_channel(const char* symbol, SecurityType type, Venue exchange) {
|
||||
Mutex::scoped_lock lock(*_mutex);
|
||||
std::lock_guard<std::mutex> lock(*_mutex);
|
||||
return MDProducerChannel(get_producer(symbol, type, exchange));
|
||||
}
|
||||
|
||||
|
||||
@@ -7,19 +7,21 @@
|
||||
#include "MDProducerHandle.h"
|
||||
#include "MDProducerChannel.h"
|
||||
#include "Shm/FixedSecurity.h"
|
||||
#include "tbb/queuing_mutex.h"
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
class MDProducerImpl;
|
||||
class SecurityIDRecorder;
|
||||
|
||||
class BTS_EXPORT MDProducer
|
||||
{
|
||||
public:
|
||||
MDProducer(Platform platform, bool shared=true);
|
||||
MDProducer(Platform platform, SecurityIDRecorder recorder, bool shared=true);
|
||||
MDProducer(MDProducer&& other);
|
||||
~MDProducer();
|
||||
|
||||
@@ -39,9 +41,9 @@ private:
|
||||
|
||||
MDProducerImpl& get_producer(const char* symbol, SecurityType type, Venue exchange);
|
||||
|
||||
typedef tbb::queuing_mutex Mutex;
|
||||
std::unique_ptr<Mutex> _mutex;
|
||||
std::unique_ptr<std::mutex> _mutex;
|
||||
std::vector<std::unique_ptr<MDProducerImpl>> _producers;
|
||||
std::unique_ptr<SecurityIDRecorder> _id_recorder;
|
||||
Platform _platform;
|
||||
bool _shared;
|
||||
};
|
||||
|
||||
@@ -118,7 +118,7 @@ private:
|
||||
// Private default constructor allows friend classes to store this class in a concurrent_queue
|
||||
MDProducerHandle();
|
||||
friend class tbb::concurrent_queue < MDProducerHandle > ;
|
||||
friend class SecurityIDRecorder;
|
||||
friend class SecurityIDRecorderState;
|
||||
friend struct bts::co2::Work;
|
||||
|
||||
HotEntry& hdata() const {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef WIN32
|
||||
#include "SecurityIDRecorder.h"
|
||||
|
||||
#include "lib/utils/defer.h"
|
||||
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/utils/Sqlite_utils.h"
|
||||
@@ -33,14 +32,30 @@ struct SecurityIDRecorderState {
|
||||
work(),
|
||||
pending_handle(),
|
||||
db(nullptr, sqlite3_close),
|
||||
select_stmt(nullptr, sqlite3_finalize),
|
||||
insert_stmt(nullptr, sqlite3_finalize)
|
||||
timer(),
|
||||
id((size_t)this)
|
||||
{}
|
||||
tbb::concurrent_queue<std::shared_ptr<SecurityIDEntry>> work;
|
||||
tbb::concurrent_queue<MDProducerHandle> pending_handle;
|
||||
sqlite3_ptr db;
|
||||
sqlite3_stmt_ptr select_stmt;
|
||||
sqlite3_stmt_ptr insert_stmt;
|
||||
unique_ptr<DispatcherTimer> timer;
|
||||
size_t id;
|
||||
|
||||
void run(utils::Dispatcher& dispatcher) {
|
||||
timer = std::make_unique<utils::DispatcherTimer>(
|
||||
dispatcher, 500,
|
||||
[=]() { do_work(); });
|
||||
timer->start();
|
||||
}
|
||||
void do_work() {
|
||||
work_handles();
|
||||
work_db();
|
||||
}
|
||||
void work_handles();
|
||||
void work_db();
|
||||
void assign_key(const api::Security& security, const SecurityIDRecorder::Callback& key_assigned);
|
||||
security_key search(const std::string& descriptor);
|
||||
security_key insert(const std::string& descriptor, SecurityType);
|
||||
};
|
||||
|
||||
SecurityIDRecorder::SecurityIDRecorder():
|
||||
@@ -49,6 +64,13 @@ SecurityIDRecorder::SecurityIDRecorder():
|
||||
init();
|
||||
}
|
||||
|
||||
SecurityIDRecorder::SecurityIDRecorder(utils::Dispatcher& dispatcher):
|
||||
_self(new SecurityIDRecorderState())
|
||||
{
|
||||
init();
|
||||
_self->run(dispatcher);
|
||||
}
|
||||
|
||||
SecurityIDRecorder::~SecurityIDRecorder() { }
|
||||
|
||||
void SecurityIDRecorder::init() {
|
||||
@@ -66,27 +88,27 @@ void SecurityIDRecorder::init() {
|
||||
sqlite3_exec_nofail(_self->db, "PRAGMA journal_mode=WAL");
|
||||
sqlite3_exec_nofail(_self->db, "PRAGMA syncronous=0");
|
||||
sqlite3_exec_nofail(_self->db, "CREATE TABLE IF NOT EXISTS security_keys (descriptor STRING NOT NULL PRIMARY KEY, type int);");
|
||||
|
||||
// Prepare statements
|
||||
_self->insert_stmt = prepare_query(_self->db, "INSERT INTO security_keys (descriptor, type) values (?, ?)");
|
||||
_self->select_stmt = prepare_query(_self->db, "SELECT rowid from security_keys where descriptor=? LIMIT 1;");
|
||||
}
|
||||
|
||||
void SecurityIDRecorder::ensure_key(MDProducerHandle handle) {
|
||||
_self->pending_handle.push(handle);
|
||||
}
|
||||
|
||||
void SecurityIDRecorder::assign_key(const api::Security& security, const SecurityIDRecorder::Callback& callback) {
|
||||
_self->assign_key(security, callback);
|
||||
}
|
||||
|
||||
void SecurityIDRecorderState::assign_key(const api::Security& security, const SecurityIDRecorder::Callback& callback) {
|
||||
if (security.id() == invalid_security_key) {
|
||||
auto work = std::make_shared<SecurityIDEntry>();
|
||||
work->security = security;
|
||||
work->callback = callback;
|
||||
_self->work.push(work);
|
||||
this->work.push(work);
|
||||
}
|
||||
}
|
||||
|
||||
void SecurityIDRecorder::do_work() {
|
||||
work_handles();
|
||||
work_db();
|
||||
_self->do_work();
|
||||
}
|
||||
|
||||
bool has_all_leg_keys(const MDProducerHandle& handle) {
|
||||
@@ -102,11 +124,12 @@ bool has_all_leg_keys(const MDProducerHandle& handle) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void SecurityIDRecorder::work_handles() {
|
||||
void SecurityIDRecorderState::work_handles() {
|
||||
Security security;
|
||||
MDProducerHandle handle;
|
||||
vector<MDProducerHandle> retry;
|
||||
while (_self->pending_handle.try_pop(handle)) {
|
||||
int count = 0;
|
||||
while (pending_handle.try_pop(handle)) {
|
||||
security.Clear();
|
||||
// if a spread does not have all of its legs we need to wait
|
||||
if (!has_all_leg_keys(handle)) {
|
||||
@@ -114,6 +137,7 @@ void SecurityIDRecorder::work_handles() {
|
||||
}
|
||||
else {
|
||||
convert_security(handle.security(), &security);
|
||||
++count;
|
||||
assign_key(security, [handle](const api::Security& security) mutable {
|
||||
handle.set_key(security.id());
|
||||
});
|
||||
@@ -121,11 +145,11 @@ void SecurityIDRecorder::work_handles() {
|
||||
}
|
||||
|
||||
for(const auto& h : retry) {
|
||||
_self->pending_handle.push(h);
|
||||
pending_handle.push(h);
|
||||
}
|
||||
}
|
||||
|
||||
void SecurityIDRecorder::work_db() {
|
||||
void SecurityIDRecorderState::work_db() {
|
||||
// Drain the work queue
|
||||
// Query the database for each security. If it has an ID set it
|
||||
// If it does not have an ID add it to a list
|
||||
@@ -139,7 +163,7 @@ void SecurityIDRecorder::work_db() {
|
||||
vector<string> new_descriptors;
|
||||
size_t count = 0;
|
||||
string descriptor;
|
||||
while (_self->work.try_pop(temp)) {
|
||||
while (work.try_pop(temp)) {
|
||||
descriptor = security_descriptor(temp->security);
|
||||
|
||||
// If we're unable to create a descriptor try again later
|
||||
@@ -167,12 +191,12 @@ void SecurityIDRecorder::work_db() {
|
||||
}
|
||||
|
||||
for (auto& d : defer) {
|
||||
_self->work.push(move(d));
|
||||
work.push(move(d));
|
||||
}
|
||||
|
||||
|
||||
if (!new_entries.empty()) {
|
||||
sqlite3_exec_nofail(_self->db.get(), "BEGIN TRANSACTION");
|
||||
sqlite3_exec_nofail(db.get(), "BEGIN TRANSACTION");
|
||||
|
||||
for (size_t x = 0; x < new_entries.size(); ++x) {
|
||||
Security& security = new_entries[x]->security;
|
||||
@@ -181,7 +205,7 @@ void SecurityIDRecorder::work_db() {
|
||||
security.set_id(key);
|
||||
}
|
||||
|
||||
sqlite3_exec_nofail(_self->db.get(), "COMMIT TRANSACTION");
|
||||
sqlite3_exec_nofail(db.get(), "COMMIT TRANSACTION");
|
||||
}
|
||||
|
||||
// record the securities
|
||||
@@ -225,23 +249,23 @@ void SecurityIDRecorder::bulk_insert(const std::vector<const api::Security*>& da
|
||||
sqlite3_exec_nofail(_self->db.get(), "COMMIT TRANSACTION");
|
||||
}
|
||||
|
||||
security_key SecurityIDRecorder::search(const std::string& descriptor) {
|
||||
sqlite3_bind_text(_self->select_stmt.get(), 1, descriptor.c_str(), descriptor.size(), SQLITE_STATIC);
|
||||
DEFER(sqlite3_reset(_self->select_stmt.get()));
|
||||
int result = sqlite3_step(_self->select_stmt.get());
|
||||
security_key SecurityIDRecorderState::search(const std::string& descriptor) {
|
||||
auto select_stmt = prepare_query(db, "SELECT rowid from security_keys where descriptor=? LIMIT 1;");
|
||||
sqlite3_bind_text(select_stmt.get(), 1, descriptor.c_str(), descriptor.size(), SQLITE_STATIC);
|
||||
int result = sqlite3_step(select_stmt.get());
|
||||
if (result == SQLITE_DONE || result == SQLITE_ROW) {
|
||||
return sqlite3_column_int(_self->select_stmt.get(), 0);
|
||||
return sqlite3_column_int(select_stmt.get(), 0);
|
||||
}
|
||||
return invalid_security_key;
|
||||
}
|
||||
|
||||
security_key SecurityIDRecorder::insert(const std::string& descriptor, SecurityType type) {
|
||||
sqlite3_bind_text(_self->insert_stmt.get(), 1, descriptor.c_str(), descriptor.size(), SQLITE_STATIC);
|
||||
sqlite3_bind_int(_self->insert_stmt.get(), 2, (int)type);
|
||||
DEFER(sqlite3_reset(_self->insert_stmt.get()));
|
||||
int result = sqlite3_step(_self->insert_stmt.get());
|
||||
security_key SecurityIDRecorderState::insert(const std::string& descriptor, SecurityType type) {
|
||||
auto insert_stmt = prepare_query(db, "INSERT INTO security_keys (descriptor, type) values (?, ?)");
|
||||
sqlite3_bind_text(insert_stmt.get(), 1, descriptor.c_str(), descriptor.size(), SQLITE_STATIC);
|
||||
sqlite3_bind_int(insert_stmt.get(), 2, (int)type);
|
||||
int result = sqlite3_step(insert_stmt.get());
|
||||
if (result == SQLITE_DONE || result == SQLITE_ROW) {
|
||||
return sqlite3_last_insert_rowid(_self->db.get());
|
||||
return sqlite3_last_insert_rowid(db.get());
|
||||
}
|
||||
// Just in case our insert failed due to duplicate row
|
||||
auto key = search(descriptor);
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
#include <tbb/concurrent_queue.h>
|
||||
#include <tbb/queuing_mutex.h>
|
||||
|
||||
namespace bts {
|
||||
namespace md {
|
||||
@@ -23,6 +22,8 @@ class SecurityIDRecorder
|
||||
{
|
||||
public:
|
||||
SecurityIDRecorder();
|
||||
// Automatically call do_work on this dispatcher
|
||||
SecurityIDRecorder(utils::Dispatcher&);
|
||||
~SecurityIDRecorder();
|
||||
typedef std::function<void(const api::Security&)> Callback;
|
||||
|
||||
@@ -32,23 +33,24 @@ public:
|
||||
void assign_key(const api::Security& security, const Callback& key_assigned);
|
||||
|
||||
// Someone must call work periodically to do lookups and flush the reserved ids to disk.
|
||||
// returne true if there is more work to be done
|
||||
void do_work();
|
||||
|
||||
void bulk_insert(const std::vector<const api::Security*>&, const char* prefix);
|
||||
|
||||
private:
|
||||
std::unique_ptr<SecurityIDRecorderState> _self;
|
||||
std::shared_ptr<SecurityIDRecorderState> _self;
|
||||
|
||||
void init();
|
||||
security_key search(const std::string& descriptor);
|
||||
security_key insert(const std::string& descriptor, SecurityType);
|
||||
|
||||
void work_handles();
|
||||
void work_db();
|
||||
|
||||
BTS_NO_COPY(SecurityIDRecorder);
|
||||
};
|
||||
|
||||
}}//namespace
|
||||
#else
|
||||
#include "MDProducerHandle.h"
|
||||
namespace bts {
|
||||
namespace md {
|
||||
class SecurityIDRecorder {
|
||||
public:
|
||||
void ensure_key(MDProducerHandle){};
|
||||
};
|
||||
}}
|
||||
#endif
|
||||
@@ -25,15 +25,12 @@ typedef SyntheticSecurityServiceBase::MetadataStatefulPublisher MetadataPublishe
|
||||
|
||||
struct SyntheticSecurityService::Pimpl {
|
||||
Pimpl(const MetadataStatefulPublisher& fn) :
|
||||
recorder(),
|
||||
timer(utils::Dispatcher::background(), 200, [&]() { recorder.do_work(); }),
|
||||
recorder(utils::Dispatcher::background()),
|
||||
synthetics(), on_security(),
|
||||
meta(), on_metadata(), metadata_publisher(fn)
|
||||
{
|
||||
timer.start();
|
||||
}
|
||||
md::SecurityIDRecorder recorder;
|
||||
utils::DispatcherTimer timer;
|
||||
std::unordered_map<SecurityKey, Security> synthetics;
|
||||
utils::Event<Security> on_security;
|
||||
std::unordered_map<SecurityKey, Metadata> meta;
|
||||
|
||||
@@ -52,6 +52,7 @@ private:
|
||||
Quantity quantity) {
|
||||
_child_order_state.place_order(price,
|
||||
quantity,
|
||||
_spreader.current_time(),
|
||||
_fill_trace);
|
||||
}
|
||||
void _modify_order (Price new_price){
|
||||
|
||||
@@ -171,6 +171,22 @@ void SingleLegQuoter::_compute_price_quantity(Price& price,
|
||||
_drivers_temp_usage,
|
||||
price,
|
||||
quantity);
|
||||
if(!_apply_quote_entry_params(price, quantity))
|
||||
quantity=Quantity(0);
|
||||
}
|
||||
bool SingleLegQuoter::_apply_quote_entry_params(
|
||||
Price new_price,
|
||||
Quantity new_quantity){
|
||||
bool working_and_new = is_active_order() &&
|
||||
ms_diff(
|
||||
_spreader.current_time(),
|
||||
_price_quantity_state.order_state().order_place_time())
|
||||
<= 5000;
|
||||
return working_and_new ? true : SpreaderUtils::conditional_quoting(
|
||||
new_price,
|
||||
new_quantity,
|
||||
_this_leg_data.leg_index(),
|
||||
_spreader);
|
||||
}
|
||||
void SingleLegQuoter::_adjust_for_hidden_order(Price& price,
|
||||
Quantity& quantity){
|
||||
|
||||
@@ -169,8 +169,13 @@ private:
|
||||
bool _target_reached(){
|
||||
return _price_quantity_state.target_reached();
|
||||
}
|
||||
void _place_order (Price price, Quantity quantity, const PerfTrace &trace = PerfTrace()) {
|
||||
_child_order_state.place_order(price, quantity,trace);
|
||||
void _place_order (Price price,
|
||||
Quantity quantity,
|
||||
const PerfTrace &trace) {
|
||||
_child_order_state.place_order(price,
|
||||
quantity,
|
||||
_spreader.current_time(),
|
||||
trace);
|
||||
}
|
||||
void _modify_order (Price price, Quantity quantity, PerfTrace &trace) {
|
||||
_child_order_state.modify_order(price, quantity, trace);
|
||||
@@ -181,6 +186,17 @@ private:
|
||||
// this is the function that computes the quoting price and the
|
||||
// quantity for this leg.
|
||||
void _compute_price_quantity(Price& price, Quantity& quantity);
|
||||
// applies the applicable throttling params that are
|
||||
// parts of the quoting params
|
||||
void _apply_quote_throttling_params (
|
||||
Price new_price, Quantity new_quantity,
|
||||
Price& out_price, Quantity& out_quantity);
|
||||
// applies the applicable quoting params that control
|
||||
// whether there should be a quote out there or not.
|
||||
// returns false is the quote shoudl not be out
|
||||
// there
|
||||
bool _apply_quote_entry_params (
|
||||
Price new_price, Quantity new_quantity);
|
||||
// this takes in a price and qty that already has
|
||||
// computed values and applies the hidden order logic
|
||||
// to them (ie if the price results in a cross, and adjusts
|
||||
|
||||
@@ -20,7 +20,10 @@ _filled_price(src._filled_price),
|
||||
_filled_quantity(src._filled_quantity),
|
||||
_last_filled_price(src._last_filled_price),
|
||||
_last_reported_order_price(src._last_reported_order_price),
|
||||
_last_filled_quantity(src._last_filled_quantity)
|
||||
_last_filled_quantity(src._last_filled_quantity),
|
||||
_out_price(src._out_price),
|
||||
_out_quantity(src._out_quantity),
|
||||
_order_place_time(src._order_place_time)
|
||||
{ }
|
||||
SpreaderChildOrderState::SpreaderChildOrderState (bts::orderman::ChildOrder& child_order,
|
||||
SecurityKey sec_key,
|
||||
@@ -50,6 +53,7 @@ void SpreaderChildOrderState::_init_running_values(){
|
||||
_last_filled_quantity = Quantity(0);
|
||||
_out_price = Price(0);
|
||||
_out_quantity = Quantity(0);
|
||||
_order_place_time=bts::TimeStamp();
|
||||
}
|
||||
void SpreaderChildOrderState::re_init(){
|
||||
SpreaderUtils::compute_average_price(_base_price, _base_quantity,
|
||||
|
||||
@@ -33,6 +33,7 @@ private:
|
||||
Quantity _last_filled_quantity;
|
||||
Price _out_price;
|
||||
Quantity _out_quantity;
|
||||
bts::TimeStamp _order_place_time;
|
||||
public:
|
||||
// constructors ///////////////////
|
||||
///////////////////////////////////
|
||||
@@ -93,6 +94,9 @@ public:
|
||||
Quantity out_quantity () const {
|
||||
return _out_quantity;
|
||||
}
|
||||
bts::TimeStamp order_place_time() const{
|
||||
return _order_place_time;
|
||||
}
|
||||
// init ///////////////////
|
||||
///////////////////////////
|
||||
// zero's out base values
|
||||
@@ -125,9 +129,11 @@ public:
|
||||
/////////////////////////////////////
|
||||
void place_order(Price price,
|
||||
Quantity quantity,
|
||||
const PerfTrace & trace = PerfTrace()){
|
||||
bts::TimeStamp curr_time,
|
||||
const PerfTrace& trace){
|
||||
_out_price = price;
|
||||
_out_quantity = quantity;
|
||||
_order_place_time=curr_time;
|
||||
bts_assert(_n_place_orders == 0);
|
||||
_n_place_orders++;
|
||||
LOG(OrderMan, Info, "SpreaderChildOrderState::place_order "
|
||||
|
||||
@@ -238,6 +238,12 @@ public:
|
||||
price_qty = Quantity(0); cumm_qty = Quantity(0);
|
||||
return false;
|
||||
}
|
||||
// find the top of the synthetic book
|
||||
static Price top_of_book_price (const ISpreaderManager&,
|
||||
api::Side){
|
||||
Price rv(os::nan());
|
||||
return rv;
|
||||
}
|
||||
////////////////////////////////////////////////////
|
||||
// quoting params //////////////////////////////////
|
||||
////////////////////////////////////////////////////
|
||||
@@ -270,6 +276,60 @@ public:
|
||||
else
|
||||
return false;
|
||||
}
|
||||
static bool conditional_quoting(Price quoting_price,
|
||||
Quantity quoting_qty,
|
||||
size_t leg_idx,
|
||||
const ISpreaderManager& spreader){
|
||||
const auto& leg_data=spreader.get_leg_data(leg_idx);
|
||||
const auto& leg_params=leg_data.leg_params();
|
||||
if(leg_params.has_quote_params() &&
|
||||
leg_params.quote_params().has_conditional_quoting()){
|
||||
const auto& cond_quoting_params=
|
||||
leg_params.quote_params().conditional_quoting();
|
||||
// if(cond_quoting_params.price_type()==spark::ConditionalQuoting::LEG)
|
||||
// TODO: for synthetic condition
|
||||
return conditional_quoting_leg(quoting_price,
|
||||
quoting_qty,
|
||||
leg_data.trading_side(),
|
||||
leg_data.tick_size(),
|
||||
spreader.get_book(leg_idx),
|
||||
cond_quoting_params.n_ticks());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// applies the conditional quoting logic, when the
|
||||
// setting applies to the quoting leg.
|
||||
// if the calculated quoting price (first arg)
|
||||
// is not n ticks within (or through, depending
|
||||
// on the value of n_ticks) it returns false
|
||||
static bool conditional_quoting_leg (Price quoting_price,
|
||||
Quantity,
|
||||
api::Side quote_side,
|
||||
double tick_size,
|
||||
const Book& book,
|
||||
int n_ticks){
|
||||
if(quote_side==api::SIDE_BUY){
|
||||
const md::PriceSize& top_ask=book.ask()[0];
|
||||
if(top_ask.size()==0)
|
||||
return false;
|
||||
int t_diff=securities::price_diff_to_ticks(
|
||||
quoting_price.value(),
|
||||
top_ask.price(),
|
||||
tick_size);
|
||||
return t_diff<=n_ticks;
|
||||
}
|
||||
else{
|
||||
const md::PriceSize& top_bid=book.bid()[0];
|
||||
if(top_bid.size()==0)
|
||||
return false;
|
||||
int t_diff=securities::price_diff_to_ticks(
|
||||
top_bid.price(),
|
||||
quoting_price.value(),
|
||||
tick_size);
|
||||
return t_diff<=n_ticks;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// pre-hedge params ////////////////////////////////
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
@@ -47,7 +47,9 @@ TEST_CASE ("quoter price quantity state", "[spreader]")
|
||||
REQUIRE (s.out_price() == Price (0.0));
|
||||
REQUIRE (s.out_quantity() == Quantity (0));
|
||||
// set out price and quantity
|
||||
order.place_order(Price (-0.35), Quantity (123));
|
||||
PerfTrace dont_care;
|
||||
bts::TimeStamp ts;
|
||||
order.place_order(Price (-0.35), Quantity (123),ts,dont_care);
|
||||
REQUIRE (s.target_spread_price() == Price (-1.0));
|
||||
REQUIRE (s.target_leg_quantity() == Quantity (200));
|
||||
REQUIRE (s.aggregated_filled_quantity() == Quantity (25));
|
||||
@@ -100,7 +102,9 @@ TEST_CASE ("quoter price quantity state", "[spreader]")
|
||||
s.add_hedged_reduction (Quantity(5));
|
||||
s.add_hedged_reduction (Quantity(15));
|
||||
// set out values
|
||||
order_2.place_order (Price(1), Quantity (50));
|
||||
PerfTrace dont_care;
|
||||
bts::TimeStamp ts;
|
||||
order_2.place_order (Price(1), Quantity (50),ts,dont_care);
|
||||
REQUIRE (s.target_spread_price() == Price (-1.0));
|
||||
REQUIRE (s.target_leg_quantity() == Quantity (200));
|
||||
REQUIRE (s.aggregated_filled_quantity() == Quantity (40));
|
||||
@@ -121,7 +125,7 @@ TEST_CASE ("quoter price quantity state", "[spreader]")
|
||||
on_order_update (order_2, api::orderman::OrderStatus::ORDER_STATUS_WORKING, Quantity (10), Price (2000));
|
||||
s.add_hedged_reduction (Quantity(3));
|
||||
s.add_hedged_reduction (Quantity(7));
|
||||
order_2.place_order (Price(0.75), Quantity (50));
|
||||
order_2.place_order (Price(0.75), Quantity (50),ts,dont_care);
|
||||
REQUIRE (s.target_spread_price() == Price (-1.0));
|
||||
REQUIRE (s.target_leg_quantity() == Quantity (200));
|
||||
REQUIRE (s.aggregated_filled_quantity() == Quantity (10));
|
||||
|
||||
@@ -60,6 +60,7 @@ message QuoteParams
|
||||
// e.g. If you are working N lots of 2 (leg_1) by 3 spread, you will work leg_1 at a price determined by
|
||||
// the price level at which you can sell N*3*lean_quantity_ratio.
|
||||
double lean_quantity_ratio = 20;
|
||||
uint32 min_lean_qty = 30;
|
||||
|
||||
QuoteMuteZone quote_mute_zone = 1000;
|
||||
QuoteRepriceThrottle quote_reprice_throttle = 1010;
|
||||
@@ -67,6 +68,7 @@ message QuoteParams
|
||||
QuoteInsideMarketDistanceWithTravel quote_inside_market_distance_with_travel = 1030;
|
||||
QuoteMaxOrderMove quote_max_order_move = 1040;
|
||||
QuoteHidden quote_hidden = 1050;
|
||||
ConditionalQuoting conditional_quoting=1060;
|
||||
}
|
||||
|
||||
/*************************************Quote MuteZone***********************************
|
||||
@@ -100,6 +102,27 @@ message QuoteMuteZone
|
||||
uint32 inside_ticks = 20;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Conditional Quoting //////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////
|
||||
message ConditionalQuoting{
|
||||
// for a leg to be quoted, the quote (or spreader) price has
|
||||
// to be within N ticks from the opposite inside market.
|
||||
// If there is an active quote and the condition ceases
|
||||
// to exist, its pulled.
|
||||
// negative values mean it has to penetrate that
|
||||
// many ticks into the opposite inside market
|
||||
int32 n_ticks = 1;
|
||||
// this tells if the logic applies wrt to the
|
||||
// quoting order (and its market), or the synthetic itself
|
||||
enum PriceType
|
||||
{
|
||||
LEG = 0;
|
||||
SYNTHETIC = 1;
|
||||
}
|
||||
PriceType price_type=10;
|
||||
}
|
||||
|
||||
/*************************************Quote RepriceThrottled (unused)*******************************
|
||||
(Stellar's sensitivity)
|
||||
This parameter defines regions (wrt their distance from the inside market)
|
||||
|
||||
@@ -11,6 +11,7 @@ using namespace bts::md;
|
||||
|
||||
void produce()
|
||||
{
|
||||
// For Production use you should use provide a SecurityIDRecorder so security keys are generated
|
||||
md::MDProducer producer(co2::PLATFORM_SIM);
|
||||
|
||||
// Create temporary security (on the stack)
|
||||
@@ -20,7 +21,6 @@ void produce()
|
||||
fsec.exchange = api::VENUE_GLBX;
|
||||
fsec.low_tick = 0.0078125;
|
||||
fsec.high_tick = 0.0078125;
|
||||
fsec.cash_per_point = 0.0128;
|
||||
// display price is price * pow10(display_factor)
|
||||
fsec.display_factor = 0;
|
||||
fsec.expiration_year = 2018;
|
||||
@@ -34,11 +34,36 @@ void produce()
|
||||
fsec.cme_price_display_format = 3;
|
||||
fsec.cme_market_segment_id = 84;
|
||||
|
||||
md::FixedSpreadSecurityL fspread;
|
||||
fspread.numeric_id = 1200;
|
||||
fspread.symbol("ZF");
|
||||
fsec.security_desc("ZFU8-ZFU9");
|
||||
fsec.cfi_code("FMDXSX");
|
||||
fspread.exchange = api::VENUE_GLBX;
|
||||
fspread.low_tick = 0.001;
|
||||
fspread.high_tick = 0.001;
|
||||
fspread.display_factor = 0;
|
||||
fspread.set_leg_count(2);
|
||||
for (size_t x = 0; x < 2; ++x) {
|
||||
auto& leg = fspread.legs[x];
|
||||
leg.leg_price = 0.25;//optional LegPrice id=566
|
||||
leg.leg_delta = 0.1;//optional LegOptionDelta id=1017
|
||||
leg.leg_quantity = 1; // LegRatioQty id=623
|
||||
leg.leg_side = api::SIDE_BUY; // LegSide id=624
|
||||
}
|
||||
|
||||
|
||||
std::vector<md::MDProducerHandle> producer_handles;
|
||||
// Add the security to the producer (this copies fsec) and get a handle to update it
|
||||
// This call is thread safe and may take a symbol specific lock internally
|
||||
producer_handles.push_back(producer.add_security(fsec));
|
||||
MDProducerHandle future_handle = producer.add_security(fsec);
|
||||
// future_handle is small and safe to copy
|
||||
producer_handles.push_back(future_handle);
|
||||
producer_handles.push_back(producer.add_security(fspread));
|
||||
|
||||
// The securities added though producer.add_security will not be visible to the rest of the system
|
||||
// until a security key has been generated. If you supplied SecurityIDRecorder to the MDProducer constructor
|
||||
// then this will happen automatically.
|
||||
|
||||
// initialized bid side book data
|
||||
std::array<md::PriceSize, md::COCONUT_MAX_DEPTH> bids {{
|
||||
|
||||
@@ -15,14 +15,12 @@ namespace md {
|
||||
MDP3Listener::MDP3Listener(
|
||||
CMESecurityIndex& index,
|
||||
MDProducer& producer,
|
||||
SecurityIDRecorder& recorder,
|
||||
// co2::SettlementRecorder& ,
|
||||
const std::vector<MDProducerChannel> channels) :
|
||||
_index(index),
|
||||
_producer(producer),
|
||||
_packet_arrived(),
|
||||
_latest_sequence(0),
|
||||
_security_recorder(recorder),
|
||||
// _settlement_recorder(settles),
|
||||
_symbol_filter_storage(),
|
||||
_symbol_filter(),
|
||||
@@ -227,12 +225,7 @@ void MDP3Listener::add_security(const FixedSecurity& security) {
|
||||
auto handle = _producer.add_security(security);
|
||||
bts_assert(security.numeric_id != 0);
|
||||
// Add it to the index so it can receive messages
|
||||
SecurityData* data = _index.add_security(security.numeric_id, handle);
|
||||
|
||||
// Assign a security key
|
||||
if (data->handle.key() == invalid_security_key) {
|
||||
_security_recorder.ensure_key(data->handle);
|
||||
}
|
||||
_index.add_security(security.numeric_id, handle);
|
||||
}
|
||||
|
||||
void MDP3Listener::flush_books() {
|
||||
|
||||
@@ -31,7 +31,6 @@ class MDP3Listener :
|
||||
public:
|
||||
MDP3Listener(CMESecurityIndex& index,
|
||||
MDProducer&,
|
||||
SecurityIDRecorder&,
|
||||
// co2::SettlementRecorder&,
|
||||
const std::vector<MDProducerChannel>);
|
||||
virtual ~MDP3Listener();
|
||||
@@ -185,7 +184,6 @@ private:
|
||||
MDProducer& _producer;
|
||||
utils::TimeStamp _packet_arrived;
|
||||
uint32_t _latest_sequence;
|
||||
SecurityIDRecorder& _security_recorder;
|
||||
// co2::SettlementRecorder& _settlement_recorder;
|
||||
std::vector<std::string> _symbol_filter_storage;
|
||||
std::set<onixs::StrRef> _symbol_filter;
|
||||
|
||||
@@ -26,8 +26,7 @@ namespace bts {
|
||||
namespace md {
|
||||
|
||||
MDP3Main::MDP3Main() :
|
||||
_producer(PLATFORM_MDP3ONIXS),
|
||||
_security_recorder(),
|
||||
_producer(PLATFORM_MDP3ONIXS, { utils::Dispatcher::current() }),
|
||||
// _settlement_recorder(PLATFORM_MDP3ONIXS),
|
||||
_engines(),
|
||||
_handlers(),
|
||||
@@ -153,11 +152,6 @@ void MDP3Main::run(std::vector<UserSymbol>& symbols) {
|
||||
// Timers
|
||||
|
||||
auto& disp = utils::Dispatcher::current();
|
||||
utils::DispatcherTimer security_timer(disp, 500, [&]() {
|
||||
_security_recorder.do_work();
|
||||
});
|
||||
security_timer.start();
|
||||
|
||||
utils::DispatcherTimer spread_resolve_timer(disp, 1000, [&]() {
|
||||
_index.resolve_spreads();
|
||||
});
|
||||
@@ -346,7 +340,7 @@ unique_ptr<MDP3Listener> MDP3Main::prepare_listener(onixs::Handler& handler, con
|
||||
|
||||
const auto& options = channel_settings_for(channel.id);
|
||||
|
||||
unique_ptr<MDP3Listener> listener(new MDP3Listener(_index, _producer, _security_recorder, /*_settlement_recorder,*/ producer_channels));
|
||||
unique_ptr<MDP3Listener> listener(new MDP3Listener(_index, _producer, /*_settlement_recorder,*/ producer_channels));
|
||||
for (auto& symbol : channel.symbols) {
|
||||
listener->add_filter_symbol(symbol.symbol());
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ private:
|
||||
|
||||
CMESecurityIndex _index;
|
||||
MDProducer _producer;
|
||||
SecurityIDRecorder _security_recorder;
|
||||
// co2::SettlementRecorder _settlement_recorder;
|
||||
std::map<std::string, std::unique_ptr<onixs::FeedEngine>> _engines;
|
||||
std::map<std::string, std::unique_ptr<onixs::Handler>> _handlers;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "lib/md/get_symbols.h"
|
||||
#include "lib/md/UserSymbol.h"
|
||||
#include "lib/md/Diag/ShmDumper.h"
|
||||
#include "lib/md/Diag/MDPeriodicDumper.h"
|
||||
#include "platforms/mdp3_onixs/MDP3Main.h"
|
||||
#include "lib/md/SecurityDB.h"
|
||||
#include "server/sparkd/exchange_sim/ExchangeSim.h"
|
||||
@@ -111,51 +112,89 @@ string& uppercase(string& s) {
|
||||
return s;
|
||||
}
|
||||
template <class T, class T2>
|
||||
T parse_enum(const string& value, const string& prefix, T2 parse, T default_value) {
|
||||
bool parse_enum(const string& value, const string& prefix, T2 parse, T default_value, T* presult) {
|
||||
string temp = value;
|
||||
if (temp.find(prefix) == string::npos) {
|
||||
temp = prefix + "_" + temp;
|
||||
}
|
||||
T result;
|
||||
if (parse(temp, &result)) {
|
||||
return result;
|
||||
}
|
||||
return default_value;
|
||||
}
|
||||
void run_dump(const vector<string>& args) {
|
||||
// either
|
||||
// name, [hot|cold]
|
||||
// symbol type exchange [venue|hot] [hot|cold]
|
||||
|
||||
string name_or_symbol = default_arg(args, 0, "");
|
||||
string hotcold_or_type = default_arg(args, 1, "cold");
|
||||
string venue = default_arg(args, 2, "glbx");
|
||||
string platform = default_arg(args, 3, "");
|
||||
bool hot = std::find(args.begin(), args.end(), "hot") != args.end();
|
||||
if (name_or_symbol.empty()) return;
|
||||
if (name_or_symbol.find("PLATFORM") == string::npos /*heuristic*/) {
|
||||
Platform p = parse_enum<Platform>(uppercase(platform), "PLATFORM", co2::Platform_Parse, co2::PLATFORM_UNSET);
|
||||
if (p == co2::PLATFORM_UNSET) {
|
||||
api::Venue v = parse_enum<api::Venue>(uppercase(venue), "VENUE", api::Venue_Parse, api::VENUE_UNSET);
|
||||
p = platform_for_exchange(v);
|
||||
}
|
||||
stringstream ss;
|
||||
ss << uppercase(name_or_symbol)
|
||||
<< "_SECURITYTYPE_" << uppercase(hotcold_or_type)
|
||||
<< "_VENUE_" << uppercase(venue) << "_"
|
||||
<< co2::Platform_Name(p);
|
||||
name_or_symbol = ss.str();
|
||||
}
|
||||
if (name_or_symbol.find("bts_edge_") == string::npos) {
|
||||
name_or_symbol = "bts_edge_" + config::get<PublisherNamespace>().shared_memory_namespace() + "_" + name_or_symbol;
|
||||
}
|
||||
ShmDumper dumper(name_or_symbol);
|
||||
if (!hot || hotcold_or_type == "cold" || hotcold_or_type == "c") {
|
||||
dumper.dump_cold();
|
||||
if(parse(temp, presult)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
*presult = default_value;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool int_of_string(const std::string& str, long* result) {
|
||||
try {
|
||||
size_t pos = 0;
|
||||
int i = std::stol(str, &pos);
|
||||
if (pos == str.size()) {
|
||||
*result = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch(const std::exception&) { }
|
||||
return false;
|
||||
}
|
||||
|
||||
typedef std::string Symbol;
|
||||
struct MDArgs {
|
||||
api::Venue venue;
|
||||
co2::Platform platform;
|
||||
api::SecurityType type;
|
||||
Symbol symbol;
|
||||
bool hot;
|
||||
long number;
|
||||
};
|
||||
MDArgs parse_md_args(const vector<string>& args) {
|
||||
using namespace api;
|
||||
using namespace co2;
|
||||
auto venue = VENUE_UNSET; // Default to glbx. If you change this change below (used) also
|
||||
auto platform = PLATFORM_UNSET;
|
||||
auto type = SECURITYTYPE_UNSET;
|
||||
bool hot = false;
|
||||
long number = 0;
|
||||
std::string symbol;
|
||||
for (auto str : args) {
|
||||
uppercase(str);
|
||||
bool used =
|
||||
(venue == VENUE_UNSET && parse_enum(str, "VENUE", Venue_Parse, venue, &venue)) ||
|
||||
(platform == PLATFORM_UNSET && parse_enum(str, "PLATFORM", Platform_Parse, platform, &platform)) ||
|
||||
parse_enum(str, "SECURITYTYPE", SecurityType_Parse, type, &type);
|
||||
if (str == "HOT") { hot = true; used = true; }
|
||||
else if (str == "COLD") { hot = false; used = true; }
|
||||
else {
|
||||
used |= int_of_string(str, &number);
|
||||
}
|
||||
if (!used) {
|
||||
symbol = str;
|
||||
}
|
||||
}
|
||||
if (venue == VENUE_UNSET) venue = VENUE_GLBX;
|
||||
if (platform == PLATFORM_UNSET) platform = platform_for_exchange(venue);
|
||||
return { venue, platform, type, symbol, hot, number };
|
||||
}
|
||||
|
||||
void run_dump(const vector<string>& args) {
|
||||
using std::get;
|
||||
|
||||
auto p = parse_md_args(args);
|
||||
stringstream ss;
|
||||
ss << "bts_edge_" << config::get<PublisherNamespace>().shared_memory_namespace() << "_"
|
||||
<< uppercase(p.symbol) << "_"
|
||||
<< SecurityType_Name(p.type) << "_"
|
||||
<< Venue_Name(p.venue) << "_"
|
||||
<< Platform_Name(p.platform);
|
||||
|
||||
ShmDumper dumper(ss.str());
|
||||
if (p.hot) {
|
||||
dumper.dump_hot();
|
||||
}
|
||||
else {
|
||||
dumper.dump_cold();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -178,7 +217,7 @@ void run_rectool(const vector<string> args) {
|
||||
}
|
||||
}
|
||||
|
||||
void dump_db(const vector<string> args) {
|
||||
void dump_db(const vector<string>& args) {
|
||||
set<security_key> keys;
|
||||
bool all = false;
|
||||
for (const auto& arg : args) {
|
||||
@@ -208,6 +247,19 @@ void dump_db(const vector<string> args) {
|
||||
});
|
||||
}
|
||||
|
||||
void run_tail(const vector<string>& args) {
|
||||
std::set<UserSymbol> products;
|
||||
auto conf = parse_md_args(args);
|
||||
PlatformConfig config;
|
||||
config.set_type(api::SecurityType_Name(api::SECURITYTYPE_FUTURE));
|
||||
config.set_platform(co2::Platform_Name(conf.platform));
|
||||
get_system_md_symbols(config, products);
|
||||
auto mod = conf.number > 0 ? conf.number : 1000;
|
||||
PrintFormat fmt = PrintFormat::CSV;
|
||||
for (const auto& a : args) { if (a == "longform") fmt = PrintFormat::Human; }
|
||||
md::run_periodic_dumper(products, mod, fmt);
|
||||
}
|
||||
|
||||
|
||||
|
||||
string help() {
|
||||
@@ -229,6 +281,7 @@ void md_tool(std::vector<std::string> const &args) {
|
||||
else if (cmd == "relay") relay_everything();
|
||||
else if (cmd == "test_relay") relay_everything();
|
||||
else if (cmd == "dumpsecurity" || cmd == "dumpsecurities") dump_db(vector<string>(args.begin()+1, args.end()));
|
||||
else if (cmd == "tail") run_tail(args);
|
||||
else printhelp();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user