Merge branch 'master' of bitbucket.org:bluetradesys/spark into fix_mics

This commit is contained in:
Kevin Darby committed 2018-11-26 13:42:41 -05:00
commit c7097faba2
45 files changed
+624 -347

No files matched your search

+1 -2
View File
@@ -209,8 +209,7 @@
"type": "cppdbg",
"request": "launch",
"program": "/home/bts/spark/build/ninja_debug/src/server/sparkd/sparkd",
// "args": ["test","Co2RelayTests"],
"args": ["md", "run", "10"],
"args": ["test","Co2Tests"],
"stopAtEntry": false,
"cwd": "/home/bts/spark/build/ninja_debug/src/server/sparkd/",
"environment": [],
+44
View File
@@ -25,3 +25,47 @@
***** FillStore
***** SecuritySrc
* Benchmarks
* OrderMan
** OrderServices
*** callbacks
**** standard
- update
- cancel
- crack
- activate
- book
- settlement
- child order state
- timer
**** low level
- exe reports
- cancel rejects
- gateway status
*** services
**** standard
- secdb
- get time
- schedule actions
- order builder
- activate
- update
- cancel
- crack
**** low level
- governor
- send fix
- get time str
- limiter
** Internalize plan
- change order initiated update/cancel/crack/activate/report_state to
use direct method calls
- need to watch out for reentrancy
- need to also report state externally
- also want to separate active from non active orders in map to speed
up look ups
- want to use direct references in orders to avoid lookups
- want to change how time is captured, the trace is too big to copy
around
+12 -1
View File
@@ -1,5 +1,16 @@
# Release Notes
## 1.4.1
### Tabs
- Tabs now shrink and expand to make better use of horizontal space
### Bug Fixes
- Fixed a bug that could cause excessive CPU usage when a connection broke
- Fixed a layout bug in hedging/requoting performance reports
- Fixed account name mismatching bug for old fills
### Absolute Position limits
- Positions can now be netted or absolute for purposes of limit enforcing
## 1.4.0
### Speed Enhancements
@@ -151,4 +162,4 @@
- PnL report now has PnL columns calculated based on your start of day, current day, and total position
- Start, Day and Total PnL columns are painted with a red or green background color based on if the pnl value is negative or positive respectively
- Corrected cash per point values, used in pnl calculations, for a number of products
- PnL report will now remember any customizations you make to filtering and/or sorting criteria
- PnL report will now remember any customizations you make to filtering and/or sorting criteria
@@ -0,0 +1,50 @@
using bts;
using mbts.spark.filters;
using mbts.ui.controls.adorners;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace mbts.ui.controls {
public class UniformTabGrid : UniformGrid {
public UniformTabGrid () {
this.IsItemsHost = true;
this.Rows = 1;
}
protected override Size MeasureOverride(Size constraint) {
var child_tabs = this.Children.OfType<TabItem>();
var child_tabs_max_width = child_tabs.Sum(t => t.MaxWidth);
// I noticed when debugging that this can sometimes be infinty,
// especially when a TabItem has not been set with a MaxWidth.
if (!double.IsInfinity(child_tabs_max_width)) {
// if the window width is greater than the total tab width, then
// there is more than enough space for all the tabs. If this
// is set to the default of Stretch and the window has only 1
// tab or few tabs, the tab appears in the middle, which is not good.
// i.e. we want tabs to added left to right, so align left
//
// When the window is less than the total tab width, then align
// can be set to stretch b/c the UniformGrid will take care of
// sizing each tab accordingly.
this.HorizontalAlignment = (constraint.Width > child_tabs_max_width)
? HorizontalAlignment.Left
: HorizontalAlignment.Stretch;
// this bit here is necessary because when the window is expanded
// beyond the maxwidth of all the tabs, we switch to Left and the
// headers snap to some smaller than MaxWidth size, which is not
// the behavior we want
foreach (var child in child_tabs) {
child.Width = this.HorizontalAlignment == HorizontalAlignment.Left
? child.MaxWidth
: double.NaN;
}
}
return base.MeasureOverride(constraint);
}
}
}
@@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
xmlns:ui="clr-namespace:mbts.ui"
xmlns:c="clr-namespace:mbts.ui.controls"
mc:Ignorable="d" AllowDrop="True"
Style="{StaticResource BTSFloatingWindow}"
d:DesignHeight="300" d:DesignWidth="300"
@@ -25,18 +26,25 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<WrapPanel x:Name="HeaderPanel" Orientation="Horizontal" Margin="0,0,100,0"
<!-- This stack panel serves as the area between the last tab and the widget control on right side of title bar (below).
It allows the region in between (if such a region exists) to be grabbed to move the window.
-->
<StackPanel Grid.Row="0" Margin="0,0,100,0" Background="Transparent" ui:WindowStyle.IsNonClientArea="True">
<c:UniformTabGrid x:Name="HeaderPanel"
Grid.Row="0"
Panel.ZIndex="1"
IsItemsHost="True"
KeyboardNavigation.TabIndex="1"
Background="Transparent" ui:WindowStyle.IsNonClientArea="True">
</WrapPanel>
Background="Transparent"
ui:WindowStyle.IsNonClientArea="True"
>
</c:UniformTabGrid>
</StackPanel>
<Border Grid.Row="1" BorderThickness="0"
Padding="{Binding Path=Padding, RelativeSource={RelativeSource AncestorType=Window}}" ui:WindowStyle.IsNonClientArea="False" >
<ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" />
</Border>
<Border Grid.Row="0" Width="100" HorizontalAlignment="Right" VerticalAlignment="Stretch" Panel.ZIndex="2" Background="Transparent" ui:WindowStyle.IsNonClientArea="True">
<!-- Window widget control area-->
<Border Grid.Row="0" MinWidth="100" HorizontalAlignment="Right" Panel.ZIndex="2" Background="Transparent" ui:WindowStyle.IsNonClientArea="True">
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Panel.ZIndex="2" Background="Transparent" Margin="5">
<Button Style="{StaticResource RoundMinimizeButton}" HorizontalAlignment="Right" Command="{x:Static SystemCommands.MinimizeWindowCommand}" />
<Button Style="{StaticResource RoundMaximizeButton}" HorizontalAlignment="Right" Command="{x:Static SystemCommands.MaximizeWindowCommand}" />
+2 -1
View File
@@ -45,7 +45,7 @@
</TabItem.RenderTransform>
<TabItem.Template>
<ControlTemplate TargetType="{x:Type TabItem}">
<Border x:Name="bd" BorderBrush="Black" BorderThickness="0,0,0.5,0" Background="#d6d6d6" Width="{DynamicResource TabWidth}" Height="{DynamicResource TabHeight}" MinWidth="40" Margin="0" SnapsToDevicePixels="True" DockPanel.Dock="Left">
<Border x:Name="bd" BorderBrush="Black" BorderThickness="0,0,0.5,0" Background="#d6d6d6" Height="{DynamicResource TabHeight}" MinWidth="40" Margin="0" SnapsToDevicePixels="True" DockPanel.Dock="Left">
<Border.ToolTip>
<TextBlock Text="{Binding Title}" />
</Border.ToolTip>
@@ -90,6 +90,7 @@
</TabItem.Template>
<TabItem.Style>
<Style TargetType="TabItem" BasedOn="{StaticResource {x:Type TabItem}}">
<Setter Property="MaxWidth" Value="{DynamicResource TabWidth}" />
<Setter Property="HeaderTemplate" Value="{StaticResource _template}" />
<Style.Triggers>
<DataTrigger Binding="{Binding EditMode}" Value="True">
+8 -4
View File
@@ -37,13 +37,17 @@ $( document ).ready(function (){
$("#output").html(summary_info);
let whole_result = result.requotes.concat(result.hedges);
let unique_sessions = whole_result.filter(function(value, index, self){
return self.find(function(elm){
return elm.session_name === value.session_name;
});
let unique_sessions = [];
whole_result.filter(function(value) {
if (unique_sessions.find(function(elm) {
return elm.session_name === value.session_name;
}) === undefined) {
unique_sessions.push(value);
}
});
$(unique_sessions).each(function (index, sess_val){
console.log(sess_val.session_name);
let r = result.requotes.find(function(elm){
return elm.session_name === sess_val.session_name;
});
+1 -1
View File
@@ -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;jetfix/codec/FIXArray.cpp;jetfix/common/OutFIX.cpp;jetfix/connection/AsyncReader.cpp;jetfix/connection/IConnection.cpp;jetfix/connection/SocketConnection.cpp;jetfix/gateway/CoreGateway.cpp;jetfix/gateway/JetFIXGateway.cpp;jetfix/gateway/Session.cpp;jetfix/store/FIXFileStore.cpp;jetfix/store/session_name.cpp;jetfix/tests/async_reader_tests.cpp;jetfix/tests/decoding_tests.cpp;jetfix/tests/fix_encoding_stream_tests.cpp;jetfix/tests/fix_fragment_tests.cpp;jetfix/tests/jetfix_performance_tests.cpp;jetfix/tests/sample_fix.cpp;jetfix/tests/store_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;mercury/actors/IPollableActor.cpp;mercury/broker/Broker.cpp;mercury/broker/BrokerProxy.cpp;mercury/broker/ILocalBroker.cpp;mercury/broker/IRemoteBroker.cpp;mercury/common/mercury_common.cpp;mercury/events/TimerEvent.cpp;mercury/executor/Executor.cpp;mercury/topics/Topic.cpp;metrics/metrics.cpp;metrics/system_metrics.cpp;orderman/actors/AsyncFactory.cpp;orderman/actors/ExecutionGateway.cpp;orderman/actors/FillStore.cpp;orderman/actors/MDSupplementarySource.cpp;orderman/actors/OrderStore.cpp;orderman/actors/SODPosition.cpp;orderman/actors/SecuritySrc.cpp;orderman/actors/ServiceBridge.cpp;orderman/actors/order_manager/OrderBuilder.cpp;orderman/actors/order_manager/OrderManager.cpp;orderman/actors/order_manager/OrderServicesData.cpp;orderman/events/CancelRejectEvent.cpp;orderman/events/NewExecutionReportEvent.cpp;orderman/limiter/LimitStore.cpp;orderman/limiter/Limiter.cpp;orderman/limiter/ProductLimitNode.cpp;orderman/limiter/ProductLimitTree.cpp;orderman/limiter/SecurityLimitNode.cpp;orderman/limiter/SecurityLimitTree.cpp;orderman/limiter/tests/limit_tests.cpp;orderman/order_factory/DynamiLine truncated
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)
+6
View File
@@ -147,6 +147,12 @@ message BTSAccount{
AccountSecurityClipLimits security_clip_limits = 90;
AccountExchangeConnections connections = 100;
ExchangeAccountData exchange_account_data = 110;
// extra parameters for risk enforcement
RiskLimitEnforcement risk_limit_enforcement=120;
}
message RiskLimitEnforcement{
bool product_limit_in_net_terms = 10;
}
message AccountProductPositionLimitUnit{
+1
View File
@@ -116,6 +116,7 @@ string dump_security(const FixedSecurity& security) {
auto& leg = psec->legs[x];
if (x > 0) res << ",";
res << "{ 'key': " << leg.key
<< ", 'exkey': " << leg.exchange_key
<< ", 'quantity': " << leg.leg_quantity
<< ", 'leg_price': " << leg.leg_price
<< ", 'delta': " << leg.leg_delta
-12
View File
@@ -61,18 +61,6 @@ void MDProducerHandle::set_key(security_key key) {
}
}
void MDProducerHandle::set_legs(const std::vector<security_key>& legs) {
bts_assert(cdata().security.type == api::SECURITYTYPE_SPREAD);
FixedSpreadSecurityL* fss = (FixedSpreadSecurityL*)&cdata().security;
bts_assert(fss->leg_count() == legs.size());
for (size_t x = 0; x < legs.size(); ++x) {
security_key key = legs[x];
fss->legs[x].key = key;
// attempt to validate that this FixedSpreadLeg is valid
bts_assert_d(fss->legs[x].leg_quantity > 0);
}
}
void MDProducerHandle::update_bbo(TimeStamp time, const PriceSize bid, const PriceSize ask, uint16_t seq) {
if (!has_depth()) {
auto oldtime = hdata().time();
-1
View File
@@ -32,7 +32,6 @@ public:
bts_assert_d(key == cdata().security.key);
return key;
}
void set_legs(const std::vector<security_key>& legs);
void update_bbo(TimeStamp time, const PriceSize bid_price, const PriceSize ask_price, uint16_t seq=0);
void update_direct(TimeStamp time, const std::array<PriceSize,COCONUT_MAX_DEPTH>& bids, const std::array<PriceSize,COCONUT_MAX_DEPTH>& asks, uint32_t seq=0) {
+12 -11
View File
@@ -34,16 +34,17 @@ sqlite3_ptr open_db() {
}
// Create table if it does not exist
auto dbptr = utils::open_db(db_path.c_str());
auto dbptr = sqlite::open_db(db_path.c_str());
bts_assert(dbptr);
auto db = dbptr.get();
sqlite3_busy_timeout(db, 9999);
sqlite3_exec_nofail(db, "PRAGMA journal_mode=OFF");
sqlite3_exec_nofail(db, "PRAGMA syncronous=0");
sqlite::exec_nofail(db, "PRAGMA journal_mode=WAL");
sqlite::exec_nofail(db, "PRAGMA syncronous=0");
sqlite3_exec_nofail(db,
sqlite::exec_nofail(db,
"CREATE TABLE IF NOT EXISTS securities (key INTEGER primary key, symbol TEXT NOT NULL, venue INTEGER NOT NULL, type INTEGER NOT NULL, security_blob BLOB NOT NULL, expiration INTEGER NOT NULL);");
sqlite3_exec_nofail(db,
sqlite::exec_nofail(db,
"CREATE TABLE IF NOT EXISTS metadata (key INTEGER PRIMARY KEY, data BLOB NOT NULL);");
return dbptr;
@@ -67,7 +68,7 @@ size_t load_securities(
// Load all existing securities and call the callback
auto db = dbptr.get();
auto select_stmt = prepare_query(db, "select key,symbol,venue,type,security_blob from securities where expiration > ?");
auto select_stmt = sqlite::prepare_query(db, "select key,symbol,venue,type,security_blob from securities where expiration > ?");
auto select = select_stmt.get();
sqlite3_bind_int(select, 1, sec_expiration_cut_off().to_short());
auto result = sqlite3_step(select);
@@ -112,8 +113,8 @@ size_t load_securities(
void store_if_new(const std::vector<Security*>& securities) {
auto dbptr = open_db();
auto insert = utils::prepare_query(dbptr, "insert or ignore into securities (key, symbol, venue, type, security_blob, expiration) values (?,?,?,?,?,?)");
sqlite3_exec_nofail(dbptr, "BEGIN TRANSACTION");
auto insert = sqlite::prepare_query(dbptr, "insert or ignore into securities (key, symbol, venue, type, security_blob, expiration) values (?,?,?,?,?,?)");
sqlite::exec_nofail(dbptr, "BEGIN TRANSACTION");
std::string buffer;
for (const api::Security* psecurity : securities) {
if (psecurity && psecurity->SerializeToString(&buffer)) {
@@ -127,7 +128,7 @@ void store_if_new(const std::vector<Security*>& securities) {
sqlite3_reset(insert.get());
}
}
sqlite3_exec_nofail(dbptr, "COMMIT TRANSACTION");
sqlite::exec_nofail(dbptr, "COMMIT TRANSACTION");
}
@@ -135,7 +136,7 @@ std::vector<api::synthetic::Metadata> load_metadata() {
std::vector<api::synthetic::Metadata> values;
auto dbptr = open_db();
auto db = dbptr.get();
auto select_stmt = prepare_query(db, "select key,data from metadata");
auto select_stmt = sqlite::prepare_query(db, "select key,data from metadata");
auto select = select_stmt.get();
auto result = sqlite3_step(select);
while(result == SQLITE_ROW) {
@@ -156,7 +157,7 @@ std::vector<api::synthetic::Metadata> load_metadata() {
}
bool store_metadata(const api::synthetic::Metadata& data) {
auto dbptr = open_db();
auto insert = utils::prepare_query(dbptr, "insert or replace into metadata (key, data) values (?,?)");
auto insert = sqlite::prepare_query(dbptr, "insert or replace into metadata (key, data) values (?,?)");
SQLITE_CHK(sqlite3_bind_int(insert.get(), 1, data.security_key()), dbptr);
std::string buffer = data.SerializeAsString();
+98 -27
View File
@@ -7,7 +7,7 @@
#include "lib/logging/logging.h"
#include "lib/md/SecurityDB.h"
#include <boost/filesystem.hpp>
#include <tbb/queuing_mutex.h> // for reservation
#include <tbb/concurrent_queue.h>
#include "lib/config/protos/MarketData.pb.h"
#include "lib/config/protos/system.pb.h"
@@ -22,53 +22,68 @@ using std::size_t;
namespace bts {
namespace md {
uint64_t exchange_id(const api::Security& security);
struct SecurityIDEntry {
api::Security security;
SecurityIDRecorder::Callback callback;
};
struct SecurityIDRecorderState {
SecurityIDRecorderState() :
SecurityIDRecorderState(SecurityIDRecorderParams& p) :
work(),
pending_handle(),
thread_id(),
db(nullptr, sqlite3_close),
timer(),
id((size_t)this)
lookup_key(p.lookup_key),
unresolved_legs()
{}
tbb::concurrent_queue<std::shared_ptr<SecurityIDEntry>> work;
tbb::concurrent_queue<MDProducerHandle> pending_handle;
std::thread::id thread_id;
sqlite3_ptr db;
unique_ptr<DispatcherTimer> timer;
size_t id;
KeyLookupOption lookup_key;
std::map<ExchangeKey, std::vector<FixedSpreadLeg*>> unresolved_legs;
// Oh no, I got methods in my state
void run(utils::Dispatcher& dispatcher) {
timer = std::make_unique<utils::DispatcherTimer>(
dispatcher, 500,
dispatcher, 200,
[=]() { do_work(); });
timer->start();
}
void do_work() {
thread_id = std::this_thread::get_id();
work_spreads();
work_handles();
work_db();
}
void work_spreads();
void work_handles();
void work_db();
void check_access() { bts_assert(thread_id == std::this_thread::get_id()); }
void assign_key(const api::Security& security, const SecurityIDRecorder::Callback& key_assigned);
void add_unresolved_spread(MDProducerHandle& handle);
security_key search(const std::string& descriptor);
security_key insert(const std::string& descriptor, SecurityType);
};
SecurityIDRecorder::SecurityIDRecorder():
_self(new SecurityIDRecorderState())
SecurityIDRecorder::SecurityIDRecorder(SecurityIDRecorderParams params):
_self(new SecurityIDRecorderState(params))
{
if (params.db) {
_self->db = std::move(params.db);
}
init();
}
SecurityIDRecorder::SecurityIDRecorder(utils::Dispatcher& dispatcher):
_self(new SecurityIDRecorderState())
{
init();
_self->run(dispatcher);
if (params.dispatcher) {
_self->run(*params.dispatcher);
}
}
SecurityIDRecorder::~SecurityIDRecorder() { }
@@ -81,13 +96,16 @@ void SecurityIDRecorder::init() {
boost::filesystem::create_directories(db_dir);
}
_self->db = open_db(db_path.c_str());
if (!_self->db) {
_self->db = sqlite::open_db(db_path.c_str());
bts_assert(_self->db);
}
// Set a long busy timeout
sqlite3_busy_timeout(_self->db.get(), 9999);
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);");
sqlite::exec_nofail(_self->db, "PRAGMA journal_mode=WAL");
sqlite::exec_nofail(_self->db, "PRAGMA syncronous=0");
sqlite::exec_nofail(_self->db, "CREATE TABLE IF NOT EXISTS security_keys (descriptor STRING NOT NULL PRIMARY KEY, type int);");
}
void SecurityIDRecorder::ensure_key(MDProducerHandle handle) {
@@ -95,6 +113,15 @@ void SecurityIDRecorder::ensure_key(MDProducerHandle handle) {
}
void SecurityIDRecorder::assign_key(const api::Security& security, const SecurityIDRecorder::Callback& callback) {
if (security.Contract_case() == Security::ContractCase::kSpread) {
for(const auto& leg : security.spread().legs()) {
if (leg.security().id() == invalid_security_key) {
LOG(md,Error, "Security {} has legs which will never be resolved.", security.has_glbx() ? security.glbx().security_desc() : security.symbol());
// No point in trying to add this to the queue
return;
}
}
}
_self->assign_key(security, callback);
}
@@ -111,6 +138,46 @@ void SecurityIDRecorder::do_work() {
_self->do_work();
}
void SecurityIDRecorderState::add_unresolved_spread(MDProducerHandle& handle) {
bts_assert_d(lookup_key);
FixedSpreadSecurityXL* pspread = static_cast<FixedSpreadSecurityXL*>(handle.mutable_security());
if (pspread != nullptr) {
for (size_t x=0; x < pspread->leg_count(); ++x) {
auto& leg = pspread->legs[x];
bts_assert_d(leg.exchange_key.value() != 0);
if (leg.key == invalid_security_key) {
// Because leg is a reference to shared memory we know it will not move
for (const auto* existing : unresolved_legs[leg.exchange_key]) {
if (existing == &leg) goto next;
}
unresolved_legs[leg.exchange_key].push_back(&leg);
}
next:;
}
}
}
void SecurityIDRecorderState::work_spreads() {
check_access();
if (!lookup_key) return;
KeyLookup& lookup = *lookup_key;
int count = 0;
for (auto iter = unresolved_legs.begin(); count < 500 && iter != unresolved_legs.end();) {
const auto& pair = *iter;
++count;
SecurityKey key = lookup(pair.first);
if (key.value() != invalid_security_key) {
for (FixedSpreadLeg* leg : pair.second) {
leg->key = key.value();
}
iter = unresolved_legs.erase(iter);
}
else {
++iter;
}
}
}
bool has_all_leg_keys(const MDProducerHandle& handle) {
if (handle.security().type == SecurityType::SECURITYTYPE_SPREAD) {
const FixedSpreadSecurityXL* pspread = static_cast<const FixedSpreadSecurityXL*>(&handle.security());
@@ -120,11 +187,12 @@ bool has_all_leg_keys(const MDProducerHandle& handle) {
}
}
}
// SyntheticFixedSecurity is guarunteed to have all of its legs
// SyntheticFixedSecurity is guaranteed to have all of its legs
return true;
}
void SecurityIDRecorderState::work_handles() {
check_access();
Security security;
MDProducerHandle handle;
vector<MDProducerHandle> retry;
@@ -133,6 +201,8 @@ void SecurityIDRecorderState::work_handles() {
security.Clear();
// if a spread does not have all of its legs we need to wait
if (!has_all_leg_keys(handle)) {
// add
add_unresolved_spread(handle);
retry.push_back(handle);
}
else {
@@ -150,6 +220,7 @@ void SecurityIDRecorderState::work_handles() {
}
void SecurityIDRecorderState::work_db() {
check_access();
// 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
@@ -184,7 +255,7 @@ void SecurityIDRecorderState::work_db() {
new_descriptors.push_back(descriptor);
++count;
// Limit the amount of time we spend writing to sqlite during startup to avoid blocking the heartbeat
if (count > 500) {
if (count > 200) {
break;
}
}
@@ -196,7 +267,7 @@ void SecurityIDRecorderState::work_db() {
if (!new_entries.empty()) {
sqlite3_exec_nofail(db.get(), "BEGIN TRANSACTION");
sqlite::exec_nofail(db.get(), "BEGIN TRANSACTION");
for (size_t x = 0; x < new_entries.size(); ++x) {
Security& security = new_entries[x]->security;
@@ -205,7 +276,7 @@ void SecurityIDRecorderState::work_db() {
security.set_id(key);
}
sqlite3_exec_nofail(db.get(), "COMMIT TRANSACTION");
sqlite::exec_nofail(db.get(), "COMMIT TRANSACTION");
}
// record the securities
@@ -231,10 +302,10 @@ void SecurityIDRecorderState::work_db() {
void SecurityIDRecorder::bulk_insert(const std::vector<const api::Security*>& data, const char* prefix) {
if (data.size() == 0) return;
sqlite3_exec_nofail(_self->db.get(), "BEGIN TRANSACTION");
sqlite::exec_nofail(_self->db.get(), "BEGIN TRANSACTION");
std::string descriptor;
{
auto insert_stmt = prepare_query(_self->db, "INSERT INTO security_keys (rowid, descriptor, type) values (?, ?, ?)");
auto insert_stmt = sqlite::prepare_query(_self->db, "INSERT INTO security_keys (rowid, descriptor, type) values (?, ?, ?)");
for (const api::Security* sec : data) {
descriptor = prefix + security_descriptor(*sec);
auto type = securitytype_of(*sec);
@@ -246,11 +317,11 @@ void SecurityIDRecorder::bulk_insert(const std::vector<const api::Security*>& da
sqlite3_reset(insert_stmt.get());
}
}
sqlite3_exec_nofail(_self->db.get(), "COMMIT TRANSACTION");
sqlite::exec_nofail(_self->db.get(), "COMMIT TRANSACTION");
}
security_key SecurityIDRecorderState::search(const std::string& descriptor) {
auto select_stmt = prepare_query(db, "SELECT rowid from security_keys where descriptor=? LIMIT 1;");
auto select_stmt = sqlite::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) {
@@ -260,7 +331,7 @@ security_key SecurityIDRecorderState::search(const std::string& descriptor) {
}
security_key SecurityIDRecorderState::insert(const std::string& descriptor, SecurityType type) {
auto insert_stmt = prepare_query(db, "INSERT INTO security_keys (descriptor, type) values (?, ?)");
auto insert_stmt = sqlite::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());
+19 -5
View File
@@ -3,11 +3,14 @@
#include "common.h"
#include "MDProducerHandle.h"
#include "lib/utils/Sqlite_utils.h"
#include <functional>
#include <memory>
#include <atomic>
#include <vector>
#include <tbb/concurrent_queue.h>
#include <optional>
typedef struct sqlite3 sqlite3;
namespace bts {
namespace md {
@@ -17,13 +20,24 @@ namespace md {
* Provides a callback when ids are safely persisted.
*/
typedef const std::function<SecurityKey(ExchangeKey)> KeyLookup;
typedef std::optional<KeyLookup> KeyLookupOption;
struct SecurityIDRecorderParams {
SecurityIDRecorderParams() : dispatcher(), db(sqlite::null_db()), lookup_key() {}
SecurityIDRecorderParams(utils::Dispatcher& d): dispatcher(&d), db(sqlite::null_db()), lookup_key() {}
SecurityIDRecorderParams(utils::Dispatcher& d, KeyLookup& get_key): dispatcher(&d), db(sqlite::null_db()), lookup_key(get_key) {}
SecurityIDRecorderParams(sqlite3_ptr& db): dispatcher(), db(std::move(db)), lookup_key() {}
SecurityIDRecorderParams(sqlite3_ptr& db, KeyLookup& get_key): dispatcher(), db(std::move(db)), lookup_key(get_key) {}
utils::Dispatcher* dispatcher;
sqlite3_ptr db;
KeyLookupOption lookup_key;
};
struct SecurityIDRecorderState;
class SecurityIDRecorder
{
public:
SecurityIDRecorder();
// Automatically call do_work on this dispatcher
SecurityIDRecorder(utils::Dispatcher&);
SecurityIDRecorder(SecurityIDRecorderParams);
~SecurityIDRecorder();
typedef std::function<void(const api::Security&)> Callback;
@@ -32,7 +46,7 @@ public:
// Slow (copies security) - for use by services
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.
// If a dispatcher is not provided you must call work periodically to do lookups and flush the reserved ids to disk.
void do_work();
void bulk_insert(const std::vector<const api::Security*>&, const char* prefix);
+2 -52
View File
@@ -4,7 +4,6 @@
#include "lib/logging/logging.h"
#include "MDProducerHandle.h"
#include "common.h"
#include "SpreadResolver.h"
#include <tbb/concurrent_hash_map.h>
#include <tbb/concurrent_queue.h>
#include <tbb/queuing_rw_mutex.h>
@@ -26,8 +25,7 @@ class SimpleSecurityIndex
{
public:
SimpleSecurityIndex():
_map(),
_spread_resolver()
_map()
{}
~SimpleSecurityIndex() {}
@@ -79,35 +77,11 @@ public:
return add_security(key, std::move(data));
}
//
// Spread resolve logic
void add_spread_legs(ExchangeKey key, const std::vector<ExchangeKey>& legs) {
_spread_resolver.add(key, legs);
}
// Resolves spreads and returns the number spreads resolved
size_t resolve_spreads() {
return _spread_resolver.resolve(
[&](ExchangeKey key) { return get_key(key); },
[&](ExchangeKey& key, std::vector<security_key>& legs) { on_spread_resolved(key, legs); });
}
protected:
void on_spread_resolved(ExchangeKey& key, std::vector<security_key>& legs) {
auto* entry = get_security(key);
bts_assert_d(entry);
if (entry) {
entry->handle.set_legs(legs);
}
}
private:
BTS_NO_COPY(SimpleSecurityIndex);
typedef std::unordered_map<ExchangeKey, std::unique_ptr<SecurityData>> MapType;
MapType _map;
mutable tbb::queuing_rw_mutex _mutex;
SpreadResolver<ExchangeKey> _spread_resolver;
};
@@ -120,8 +94,7 @@ class ConcurrentSecurityIndex
{
public:
ConcurrentSecurityIndex() :
_map(),
_spread_resolver()
_map()
{}
~ConcurrentSecurityIndex() {}
@@ -171,33 +144,10 @@ public:
return add_security(key, std::move(data));
}
//
// Spread resolve logic
void add_spread_legs(ExchangeKey key, const std::vector<ExchangeKey>& legs) {
_spread_resolver.add(key, legs);
}
// Resolves spreads and returns the number spreads resolved
size_t resolve_spreads() {
return _spread_resolver.resolve(
[&](ExchangeKey key) { return get_key(key); },
[&](ExchangeKey& key, std::vector<security_key>& legs) { on_spread_resolved(key, legs); });
}
protected:
void on_spread_resolved(ExchangeKey& key, std::vector<security_key>& legs) {
auto* entry = get_security(key);
bts_assert_d(entry);
if (entry) {
entry->handle.set_legs(legs);
}
}
private:
BTS_NO_COPY(ConcurrentSecurityIndex);
typedef tbb::concurrent_hash_map<ExchangeKey, SecurityData*> MapType;
MapType _map;
SpreadResolver<ExchangeKey> _spread_resolver;
};
}}//namespace
+8 -7
View File
@@ -94,13 +94,14 @@ SettlementRecorder::SettlementRecorder(Platform platform) :
}
// initialize database
_self->db = open_db(db_path.c_str());
_self->db = sqlite::open_db(db_path.c_str());
bts_assert_msg(_self->db, db_path.c_str());
sqlite3* db = _self->db.get();
sqlite3_busy_timeout(db, 9999);
sqlite3_exec_nofail(db, "PRAGMA journal_mode=OFF");
sqlite3_exec_nofail(db, "PRAGMA syncronous=0");
sqlite::exec_nofail(db, "PRAGMA journal_mode=WAL");
sqlite::exec_nofail(db, "PRAGMA syncronous=0");
// key=(security_key+date)
sqlite3_exec_nofail(db,
sqlite::exec_nofail(db,
"CREATE TABLE IF NOT EXISTS settlements2 (key INTEGER NOT NULL, date INTEGER NOT NULL, mantissa INTEGER NOT NULL, exponent INTEGER NOT NULL, PRIMARY KEY (key,date));");
// Delete any records > 10 days old
@@ -108,11 +109,11 @@ SettlementRecorder::SettlementRecorder(Platform platform) :
auto encoded = datetime::ll_to_date(datetime::ptime_to_ll(cutoff)).to_short();
char query[256];
sprintf(query, "delete from settlements2 where date < %i", encoded);
sqlite3_exec_nofail(db, query);
sqlite::exec_nofail(db, query);
// statements
_self->select_stmt = prepare_query(db, "select mantissa,exponent,date from settlements2 where key=? order by date desc limit 2");
_self->insert_stmt = prepare_query(db, "insert or replace into settlements2(key, date, mantissa,exponent) values(?,?,?,?)");
_self->select_stmt = sqlite::prepare_query(db, "select mantissa,exponent,date from settlements2 where key=? order by date desc limit 2");
_self->insert_stmt = sqlite::prepare_query(db, "insert or replace into settlements2(key, date, mantissa,exponent) values(?,?,?,?)");
}
SettlementRecorder::~SettlementRecorder() { }
+18 -1
View File
@@ -251,6 +251,20 @@ size_t num_legs(const Security& sec) {
return 0;
}
uint64_t exchange_id(const Security& security) {
switch(security.ExchangeData_case()) {
case Security::ExchangeDataCase::kCboe: return security.cboe().exchange_id();
case Security::ExchangeDataCase::kGlbx: return security.glbx().exchange_id();
case Security::ExchangeDataCase::kCfe: return security.cfe().exchange_id();
case Security::ExchangeDataCase::kIce: bts_assert(false);
// Debatable whether this should be an error or not.
// If is possible that we might create a spread with no exchange in the future
// and if we did this would be a runtime error.
case Security::ExchangeDataCase::EXCHANGEDATA_NOT_SET: return 0;
}
return -1;
}
void convert_security(const Security& src, FixedSecurity& dest, bool set_security_key) {
dest.key = set_security_key ? src.id() : invalid_security_key;
dest.type = securitytype_of_contractcase(src.Contract_case());
@@ -272,7 +286,9 @@ void convert_security(const Security& src, FixedSecurity& dest, bool set_securit
case Security::ExchangeDataCase::kCfe:
dest.cboe_class_key = src.cfe().class_key();
break;
default:
case Security::ExchangeDataCase::kIce:
bts_assert_d(false);
case Security::ExchangeDataCase::EXCHANGEDATA_NOT_SET:
break;
}
dest.price_break = src.contract_spec().price_break() / src.contract_spec().price_multiplier();
@@ -307,6 +323,7 @@ void convert_security(const Security& src, FixedSecurity& dest, bool set_securit
for (int x = 0; x < src.spread().legs_size(); ++x) {
const auto& src_leg = src.spread().legs(x);
spread.legs[x].key = set_security_key ? src_leg.security().id() : invalid_security_key;
spread.legs[x].exchange_key = ExchangeKey(exchange_id(src_leg.security()));
spread.legs[x].leg_side = src_leg.side();
spread.legs[x].leg_quantity = src_leg.quantity();
spread.legs[x].leg_price = src_leg.price_multiplier();
+7
View File
@@ -6,6 +6,7 @@
#include "lib/utils/bts_array_size.h"
#include "lib/utils/bts_assert.h"
#include "lib/utils/bts_no_copy.h"
#include "lib/utils/ValueWrapper.h"
#include <string>
#include <sstream>
@@ -13,6 +14,9 @@
namespace bts {
namespace md {
using SecurityKey = utils::ValueWrapper<struct SecurityKeyTag,uint32_t>;
using ExchangeKey = utils::ValueWrapper<struct ExchangeKeyTag,uint64_t>;
GCC_DIAG_OFF("-Weffc++") // No Virtual Destructors by design
#define STRING_PROPERTY(NAME) const char* NAME() const { return _##NAME; } \
@@ -95,6 +99,7 @@ struct BTS_EXPORT FixedSpreadLeg
{
FixedSpreadLeg();
security_key key;
ExchangeKey exchange_key;
Side leg_side;
double leg_quantity;
double leg_price;
@@ -180,6 +185,8 @@ void convert_security(const Security& src, FixedSecurity& dest, bool set_securit
SecurityType securitytype_of_contractcase(Security::ContractCase cc);
SecurityType securitytype_of(const Security&);
size_t num_legs(const Security&);
uint64_t exchange_id(const Security& security);
// Stack allocates a security of the given type
template <class C>
-79
View File
@@ -1,79 +0,0 @@
#pragma once
#include "lib/utils/bts_no_copy.h"
#include <vector>
#include <tbb/concurrent_queue.h>
namespace bts {
namespace md {
/*
* SpreadResolved accepts exchange spread definitions and resolves the legs
*/
template <typename ExchangeKey>
class SpreadResolver {
struct ResolverEntry {
ResolverEntry(ExchangeKey key) : exchange_key(key), legs() {}
ResolverEntry() : exchange_key(), legs() {}
ExchangeKey exchange_key;
std::vector<ExchangeKey> legs;
};
public:
SpreadResolver() : _queue() {}
template <class LegContainer>
void add(ExchangeKey key, LegContainer legs) {
ResolverEntry entry(key);
entry.legs.insert(end(entry.legs), begin(legs), end(legs));
_queue.push(entry);
}
// callback should accept const ExchangeKey& key, vector<security_key>& legs)
// When the callback is called the legs will be completely resolved
template <class MapKey, class CallBack>
size_t resolve(MapKey keymap, CallBack on_resolved) {
// Drain the queue and call keymap to resolve each leg
size_t result = 0;
std::vector<ResolverEntry> unresolved;
std::vector<security_key> legs;
while(!_queue.empty()) {
legs.clear();
ResolverEntry entry;
if(_queue.try_pop(entry)) {
// Attempt to look up each spread leg
for(ExchangeKey key : entry.legs) {
security_key result = keymap(key);
if (result == invalid_security_key) {
unresolved.push_back(entry);
break;
}
else {
legs.push_back(result);
}
}
if (legs.size() == entry.legs.size()) {
++result;
on_resolved(entry.exchange_key, legs);
}
}
}
// If any legs remain unresolved push the entry back in the queue for later
for(auto& entry : unresolved) {
_queue.push(entry);
}
return result;
}
size_t count() const { return _queue.unsafe_size(); }
private:
BTS_NO_COPY(SpreadResolver);
tbb::concurrent_queue<ResolverEntry> _queue;
};
}}//namespace
+1 -1
View File
@@ -192,4 +192,4 @@ void SyntheticSecurityService::query_security_metadata(
}}}//namespace
#endif
#endif
+1 -1
View File
@@ -130,7 +130,7 @@ void replay_recording(istream& in, IRelayWriter& writer, int32_t naggle_ms) {
CoconutReplayHeader header;
size_t count = 0;
#ifndef _WIN32
md::SecurityIDRecorder idrec;
md::SecurityIDRecorder idrec {{}};
#endif
if (readbuf(in, &header) && header.magic() == magic && header.version() == 3) {
co2::MDReply message;
+78 -53
View File
@@ -13,6 +13,7 @@
#include "lib/metrics/metrics.h"
#include "lib/config/protos/MarketData.pb.h"
#include "lib/utils/Sqlite_utils.h"
#include <vector>
#include <string>
@@ -27,7 +28,6 @@
#include <thread>
#include <iterator>
using namespace std;
namespace bts {
@@ -151,6 +151,7 @@ void assign_ids(vector<MDProducerHandle>::iterator begin, vector<MDProducerHandl
}
}
class Co2Tests
{
public:
@@ -171,12 +172,20 @@ public:
}
#ifndef WIN32
void test_security_id_recorder() {
void test_security_id_recorder(const std::string& db_name) {
// Verify callbacks happen after work complete
SecurityIDRecorder idsvc, idsvc2;
auto db1 = sqlite::open_db(db_name.c_str());
REQUIRE(db1);
auto db2 = sqlite::open_db(db_name.c_str());
REQUIRE(db2);
SecurityIDRecorder idsvc{{db1}}, idsvc2{{db2}};
security_key result = invalid_security_key;
std::string desc = "FOOX 1";
Security s1 = mkoption("FOOX", invalid_security_key, 2018, 1, 20, 1850);
Security f1 = mkfuture("FOO", invalid_security_key, 2018, 1, 20);
idsvc.assign_key(f1, [](const api::Security& s) {
REQUIRE(s.id() != invalid_security_key);
});
idsvc.assign_key(s1, [&result](const api::Security& s) {
result = s.id();
});
@@ -188,7 +197,66 @@ public:
result2 = s.id();
});
idsvc2.do_work();
REQUIRE(result == result2);
if (db_name == ":memory:") {
// This is a meta-test to make sure we don't accidently generate the same key sequence
// when writing to different databases.
REQUIRE(result != result2);
}
else {
REQUIRE(result == result2);
}
}
void test_security_id_recorder_spreads() {
// Test that security id recorder can resolve spread legs
// Set up "shared memory"
auto cold_header = std::make_shared<ColdHeader>();
auto hot_header = std::make_shared<HotHeader>();
// Create a spread with 2 legs
auto f1 = mkfuture("FO1", invalid_security_key, 2018, 1, 17);
f1.mutable_glbx()->set_exchange_id(100);
REQUIRE(f1.id() == invalid_security_key);
auto f1handle = std::make_unique<Co2TestInstrument> (f1, cold_header, hot_header);
auto f2 = mkfuture("FO2", invalid_security_key, 2018, 1, 20);
f2.mutable_glbx()->set_exchange_id(200);
auto f2handle = std::make_unique<Co2TestInstrument> (f2, cold_header, hot_header);
auto s1 = mkspread("FOO", invalid_security_key, { f1, f2 });
auto s1handle = std::make_unique<Co2TestInstrument> (s1, cold_header, hot_header);
// Add spread to SecurityIDRecorder and work it
auto db = sqlite::open_db(":memory:");
REQUIRE(db);
SecurityIDRecorder idsvc { {db, [&](ExchangeKey k) -> SecurityKey {
for (const auto fut : { f1handle->producer(), f2handle->producer() }) {
if (k.value() == fut.security().numeric_id) return SecurityKey(fut.key());
}
return SecurityKey(invalid_security_key);
} } };
auto workwork = [&]() { idsvc.do_work(); idsvc.do_work(); };
idsvc.ensure_key(s1handle->producer());
workwork();
// Expect no key
REQUIRE(s1handle->consumer().key() == invalid_security_key);
// Add leg spreads
idsvc.ensure_key(f1handle->producer());
idsvc.ensure_key(f2handle->producer());
workwork();
// Expect legs to have keys
REQUIRE(f1handle->consumer().key() != invalid_security_key);
REQUIRE(f2handle->consumer().key() != invalid_security_key);
// Expect spread to have keys
REQUIRE(s1handle->consumer().key() != invalid_security_key);
}
#endif
@@ -518,50 +586,6 @@ public:
REQUIRE(bbo_count > 0);
}
void test_spread_resolver() {
SpreadResolver<string> resolver;
vector<string> legs;
legs.push_back("1");
legs.push_back("2");
legs.push_back("3");
legs.push_back("4");
resolver.add("1234", legs);
legs.clear();
legs.push_back("4");
legs.push_back("5");
resolver.add("45", legs);
auto key_map = [](string& key) -> security_key {
if (key == "1") return 1;
if (key == "2") return 2;
if (key == "3") return 3;
if (key == "4") return 4;
if (key == "5") return invalid_security_key;
REQUIRE(false);
return 0;
};
auto key_map2 = [](string& key) -> security_key {
if (key == "4") return 4;
if (key == "5") return 5;
REQUIRE(false);
return 0;
};
// 2 unresolved spreads
REQUIRE(resolver.count() == 2);
resolver.resolve(key_map, [&](const string& key, const vector<security_key>& legs) {
REQUIRE(key == "1234");
REQUIRE(legs.size() == 4);
});
// 1 spread remains
REQUIRE(resolver.count() == 1);
resolver.resolve(key_map2, [&](const string& key, const vector<security_key>& legs) {
REQUIRE(key == "45");
REQUIRE(legs.size() == 2);
});
REQUIRE(resolver.count() == 0);
}
void test_no_double_security_callback() {
MDProducer producer(TEST_PLATFORM);
vector<MDProducerHandle> producers = create_test_securities(producer);
@@ -1002,7 +1026,11 @@ TEST_CASE("CO2Tests","[md]") {
#ifndef WIN32
SECTION("test_security_id_recorder") {
co2_tests->test_security_id_recorder();
co2_tests->test_security_id_recorder(":memory:");
co2_tests->test_security_id_recorder("file::memory:?cache=shared");
}
SECTION("test_security_id_recorder_spreads") {
co2_tests->test_security_id_recorder_spreads();
}
#endif
SECTION("test_price_size") {
@@ -1026,9 +1054,6 @@ TEST_CASE("CO2Tests","[md]") {
SECTION("test_consumer_defer_handle2") {
co2_tests->test_consumer_defer_handle2();
}
SECTION("test_spread_resolver") {
co2_tests->test_spread_resolver();
}
SECTION("test_no_double_security_callback") {
co2_tests->test_no_double_security_callback();
}
@@ -15,6 +15,7 @@
#include <algorithm>
#include <unordered_map>
#include <boost/algorithm/string/trim.hpp>
namespace bts {
namespace orderman {
@@ -123,10 +124,11 @@ void OrderManager::on_fill_recovery(
update.events->size());
me->state = State::WAIT_ORDERS;
for (auto const &ev : *(update.events))
me->services_data.limiter.add(*ev.security, ev.fill.account(),
ev.fill.side(),
for (auto const &ev : *(update.events)) {
auto trimmed_account_name = boost::algorithm::trim_copy(ev.fill.account());
me->services_data.limiter.add(*ev.security, trimmed_account_name,ev.fill.side(),
Quantity(ev.fill.last_shares()));
}
me->stored_order_sub = subscribe<StoredOrderEvent>(
[this](auto const &orders) { this->on_order_recovery(orders); });
+70 -11
View File
@@ -9,10 +9,13 @@ namespace orderman{
class LimiterUtils{
public:
static void can_send_new_order(api::Side side, Quantity quantity, bool is_security_level,
int long_pos_limit, int short_pos_limit,
int net_pos,
Limiter::LimiterQueryResult& out_res){
static void can_send_new_order_net(api::Side side,
Quantity quantity,
bool is_security_level,
int long_pos_limit,
int short_pos_limit,
int net_pos,
Limiter::LimiterQueryResult& out_res){
out_res.ok = true;
bts_assert(long_pos_limit >= 0);
bts_assert(short_pos_limit <= 0);
@@ -35,13 +38,15 @@ public:
else
out_res.error_msg = fmt::format("Product Short Position (Max {} Current {})", short_pos_limit, net_pos);
}
}
static void can_update_order (api::Side side,
Quantity from, Quantity to,
bool is_security_level,
int long_pos_limit, int short_pos_limit,
int net_pos,
Limiter::LimiterQueryResult& out_res){
}
static void can_update_order_net (api::Side side,
Quantity from,
Quantity to,
bool is_security_level,
int long_pos_limit,
int short_pos_limit,
int net_pos,
Limiter::LimiterQueryResult& out_res){
out_res.ok = true;
if (to.value() > from.value()){
int net_pos_new = 0;
@@ -65,6 +70,60 @@ public:
out_res.error_msg = fmt::format("Product Short Position (Max {} Current {})", short_pos_limit, net_pos);
}
}
}
static void can_send_new_order_abs(api::Side side,
Quantity quantity,
uint32_t long_pos_limit,
uint32_t short_pos_limit,
uint32_t long_pos,
uint32_t short_pos,
Limiter::LimiterQueryResult& out_res){
out_res.ok = true;
if(side == api::Side::SIDE_BUY){
if(long_pos + quantity.value() > long_pos_limit){
out_res.error_msg = fmt::format("Long Position (Abs) "
"(Max {} Current {})",
long_pos_limit,long_pos);
out_res.ok = false;
}
}
else{
if(short_pos + quantity.value() > short_pos_limit){
out_res.error_msg = fmt::format("Short Position (Abs) "
"(Max {} Current {})",
short_pos_limit,short_pos);
out_res.ok = false;
}
}
}
static void can_update_order_abs (api::Side side,
Quantity from,
Quantity to,
uint32_t long_pos_limit,
uint32_t short_pos_limit,
uint32_t long_pos,
uint32_t short_pos,
Limiter::LimiterQueryResult& out_res){
out_res.ok = true;
if (to.value() > from.value()){
uint32_t diff = to.value() - from.value();
if(side == api::Side::SIDE_BUY){
if(long_pos + diff > long_pos_limit){
out_res.error_msg = fmt::format("Long Position (Abs) "
"(Max {} Current {})",
long_pos_limit,long_pos);
out_res.ok = false;
}
}
else{
if(short_pos + diff > short_pos_limit){
out_res.error_msg = fmt::format("Short Position (Abs) "
"(Max {} Current {})",
short_pos_limit,short_pos);
out_res.ok = false;
}
}
}
}
static api::Side invert_side(api::Side side){
return side == api::SIDE_BUY ? api::SIDE_SELL : api::SIDE_BUY;
@@ -5,14 +5,17 @@ namespace orderman{
ProductLimitNode::ProductLimitNode(uint32_t account_id,
uint32_t, // parent_account_id,
const bts::api::admin::AccountProductPositionLimitUnit& limit)
const bts::api::admin::AccountProductPositionLimitUnit& limit,
bool enforce_net)
:
_account_id(account_id),
//_parent_account_id(parent_account_id),
_limit(limit),
_enforce_net(enforce_net),
_long_pos_limit (limit.long_position_limit()),
_short_pos_limit (-1 * limit.short_position_limit()),
_net_pos(0)
_short_pos_limit (limit.short_position_limit()),
_long_pos(0),
_short_pos(0)
{}
}}
+58 -15
View File
@@ -20,49 +20,92 @@ class ProductLimitNode{
private:
const uint32_t _account_id; // , _parent_account_id;
const bts::api::admin::AccountProductPositionLimitUnit& _limit;
const int _long_pos_limit, _short_pos_limit;
int _net_pos;
const bool _enforce_net;
const uint32_t _long_pos_limit, _short_pos_limit;
// this is the only state here
uint32_t _long_pos, _short_pos;
public:
ProductLimitNode(uint32_t account_id,
uint32_t parent_account_id,
const bts::api::admin::AccountProductPositionLimitUnit& limit);
const bts::api::admin::AccountProductPositionLimitUnit& limit,
bool enforce_net);
// accessors
////////////
uint32_t account_id() const {return _account_id;}
int net_pos() const {return _net_pos;}
int net_pos() const {
return static_cast<int>(_long_pos)-static_cast<int>(_short_pos);
}
// position updates
///////////////////
void copy_positions_from(const ProductLimitNode& source){
_net_pos = source.net_pos();
_long_pos=source._long_pos;
_short_pos=source._short_pos;
}
void add_position(api::Side side, uint32_t qty){
if (side==api::Side::SIDE_BUY)
_net_pos += qty;
_long_pos += qty;
else
_net_pos -= qty;
_short_pos += qty;
}
void remove_position(api::Side side, uint32_t qty){
if (side==api::Side::SIDE_BUY)
_net_pos -= qty;
_long_pos = _subtract_unsigned(_long_pos, qty);
else
_net_pos += qty;
_short_pos = _subtract_unsigned(_short_pos, qty);
}
// risk limit checks
////////////////////
Limiter::LimiterQueryResult can_send_new_order(api::Side side, Quantity quantity) const{
Limiter::LimiterQueryResult result;
LimiterUtils::can_send_new_order (side, quantity, false,
_long_pos_limit, _short_pos_limit,
_net_pos, result);
if (_enforce_net)
LimiterUtils::can_send_new_order_net (side,
quantity,
false,
static_cast<int>(_long_pos_limit),
-1 * static_cast<int>(_short_pos_limit),
net_pos(),
result);
else
LimiterUtils::can_send_new_order_abs (side,
quantity,
_long_pos_limit,
_short_pos_limit,
_long_pos,
_short_pos,
result);
return result;
}
Limiter::LimiterQueryResult can_update_order(api::Side side, Quantity from, Quantity to) const{
Limiter::LimiterQueryResult result;
LimiterUtils::can_update_order (side, from, to, false,
_long_pos_limit, _short_pos_limit,
_net_pos, result);
if(_enforce_net)
LimiterUtils::can_update_order_net (side,
from,
to,
false,
static_cast<int>(_long_pos_limit),
-1 * static_cast<int>(_short_pos_limit),
net_pos(),
result);
else
LimiterUtils::can_update_order_abs (side,
from,
to,
_long_pos_limit,
_short_pos_limit,
_long_pos,
_short_pos,
result);
return result;
}
uint32_t _subtract_unsigned(uint32_t n1, uint32_t n2){
if(n1 >= n2)
return n1-n2;
else{
LOG(OrderMan, Error, "ProductLimitNode._subtract_unsigned {0}-{1} ",
n1, n2);
return 0;
}
}
// test only functions
//////////////////////
const bts::api::admin::AccountProductPositionLimitUnit& test_only_func_limit() const {return _limit;}
@@ -10,8 +10,14 @@ ProductLimitTree::ProductLimitTree(const api::Product& product,
_product (product)
{
for(const auto& account : admin_data.accounts()){
bool enforce_net=true; // default is net
if(account.has_risk_limit_enforcement())
enforce_net=account.risk_limit_enforcement().product_limit_in_net_terms();
const bts::api::admin::AccountProductPositionLimitUnit* limit = bts::admin::AdminServiceUtils::find_account_product_position_limit(account, _product);
_tree.emplace_back(account.id(), bts::admin::AdminServiceUtils::has_id(account.parent_account_id()) ? account.parent_account_id() : 0, limit != nullptr ? *limit : zero_limit);
_tree.emplace_back(account.id(),
bts::admin::AdminServiceUtils::has_id(account.parent_account_id()) ? account.parent_account_id() : 0,
limit != nullptr ? *limit : zero_limit,
enforce_net);
}
}
}}
+6 -6
View File
@@ -71,9 +71,9 @@ public:
return result;
}
if (_apply_sec_position_limits)
LimiterUtils::can_send_new_order (side, quantity, true,
_long_pos_limit, _short_pos_limit,
_net_pos, result);
LimiterUtils::can_send_new_order_net (side, quantity, true,
_long_pos_limit, _short_pos_limit,
_net_pos, result);
if (result.ok)
result = _product_node.can_send_new_order(side, quantity);
return result;
@@ -86,9 +86,9 @@ public:
return result;
}
if (_apply_sec_position_limits)
LimiterUtils::can_update_order (side, from, to, true,
_long_pos_limit, _short_pos_limit,
_net_pos, result);
LimiterUtils::can_update_order_net (side, from, to, true,
_long_pos_limit, _short_pos_limit,
_net_pos, result);
if (result.ok)
result = _product_node.can_update_order(side, from, to);
return result;
+14 -13
View File
@@ -57,42 +57,43 @@ void SqliteStore::init_db() {
LOG(persist, Warn, "{} database does not exist yet. Creating it at {}",
me->db, path.string());
me->conn = utils::open_db(path.c_str());
me->conn = sqlite::open_db(path.c_str());
bts_assert_msg(me->conn, path.c_str());
const char *create_schema_sql =
"create table store ( ns text, key text, value text)";
utils::sqlite3_exec_nofail(me->conn, create_schema_sql);
sqlite::exec_nofail(me->conn, create_schema_sql);
const char *key_index_sql =
"create unique index key_index on store(ns,key)";
utils::sqlite3_exec_nofail(me->conn, key_index_sql);
sqlite::exec_nofail(me->conn, key_index_sql);
const char *ns_index_sql = "create index ns_index on store(ns)";
utils::sqlite3_exec_nofail(me->conn, ns_index_sql);
sqlite::exec_nofail(me->conn, ns_index_sql);
} else {
me->conn = utils::open_db(path.c_str());
me->conn = sqlite::open_db(path.c_str());
}
// Asynchronous for speed
utils::sqlite3_exec_nofail(me->conn, "PRAGMA synchronous = 0;");
utils::sqlite3_exec_nofail(me->conn, "PRAGMA journal_mode=WAL");
sqlite::exec_nofail(me->conn, "PRAGMA synchronous = 0;");
sqlite::exec_nofail(me->conn, "PRAGMA journal_mode=WAL");
// prepare insert statement
const char *insert_sql = "insert into store (ns, key, value) values(?,?,?)";
me->insert = utils::prepare_query(me->conn, insert_sql);
me->insert = sqlite::prepare_query(me->conn, insert_sql);
// prepare update statement
const char *update_sql =
"update store set value = ? where ns = ? and key = ?";
me->update = utils::prepare_query(me->conn, update_sql);
me->update = sqlite::prepare_query(me->conn, update_sql);
// prepare remove statement
const char *remove_all_sql = "delete from store where ns = ?";
me->remove_all = utils::prepare_query(me->conn, remove_all_sql);
me->remove_all = sqlite::prepare_query(me->conn, remove_all_sql);
// prepare remove statement
const char *remove_sql = "delete from store where ns = ? and key = ?";
me->remove = utils::prepare_query(me->conn, remove_sql);
me->remove = sqlite::prepare_query(me->conn, remove_sql);
}
SqliteStore::~SqliteStore() {}
@@ -100,7 +101,7 @@ SqliteStore::~SqliteStore() {}
SqliteStore::Data SqliteStore::retrieve_all() {
SqliteStore::Data result;
sqlite3_stmt_ptr query =
utils::prepare_query(me->conn, "select ns,key,value from store");
sqlite::prepare_query(me->conn, "select ns,key,value from store");
int sqlite_result;
do {
@@ -125,7 +126,7 @@ std::pair<bool, std::string> SqliteStore::retrieve_one(std::string const &ns,
std::string const &k) {
auto query_str = fmt::format(
"select ns,key,value from store where ns='{}' and key='{}'", ns, k);
sqlite3_stmt_ptr query = utils::prepare_query(me->conn, query_str.c_str());
sqlite3_stmt_ptr query = sqlite::prepare_query(me->conn, query_str.c_str());
std::pair<bool, std::string> result{false, ""};
+1 -1
View File
@@ -167,7 +167,7 @@ void QBConnection::recv_msg_body()
handle_msg(&m);
}
else
recv_msg_body();
close_connection(error.message());
});
}
+11 -6
View File
@@ -3,22 +3,27 @@
#include "bts_assert.h"
#include <cstring>
namespace bts {
namespace utils {
namespace sqlite {
void sqlite3_exec_nofail(sqlite3* db, const char* sql) {
void exec_nofail(sqlite3* db, const char* sql) {
char* error_message = nullptr;
int result = sqlite3_exec(db, sql, nullptr, nullptr, &error_message);
bts_assert_msg(result == SQLITE_OK, error_message);
}
void sqlite3_exec_nofail(sqlite3_ptr & db, const char * sql) {
return sqlite3_exec_nofail(db.get(), sql);
void exec_nofail(sqlite3_ptr & db, const char * sql) {
return exec_nofail(db.get(), sql);
}
sqlite3_ptr open_db(const char* path) {
sqlite3* temp;
bts_assert(sqlite3_open(path, &temp) == SQLITE_OK);
return sqlite3_ptr(temp, sqlite3_close);
if (sqlite3_open(path, &temp) == SQLITE_OK) {
return sqlite3_ptr(temp, sqlite3_close);
}
else {
LOG(Gen, Error, "Failed to open database {}", std::string(path));
return null_db();
}
}
sqlite3_stmt_ptr prepare_query(sqlite3 * db, const char * query) {
+7 -8
View File
@@ -1,12 +1,9 @@
#pragma once
#ifndef WIN32
#include <sqlite/sqlite3.h>
#include <memory>
#include "lib/utils/bts_export.h"
#include <sqlite/sqlite3.h>
#include "lib/utils/bts_assert.h"
typedef struct sqlite3 sqlite3;
typedef struct sqlite3_stmt sqlite3_stmt;
typedef std::unique_ptr<sqlite3, int(*)(sqlite3*)> sqlite3_ptr;
typedef std::unique_ptr<sqlite3_stmt, int(*)(sqlite3_stmt*)> sqlite3_stmt_ptr;
@@ -18,13 +15,15 @@ typedef std::unique_ptr<sqlite3_stmt, int(*)(sqlite3_stmt*)> sqlite3_stmt_ptr;
} \
} while(0)
namespace bts {
namespace utils {
void sqlite3_exec_nofail(sqlite3* db, const char* sql);
void sqlite3_exec_nofail(sqlite3_ptr& db, const char* sql);
namespace bts {
namespace sqlite {
void exec_nofail(sqlite3* db, const char* sql);
void exec_nofail(sqlite3_ptr& db, const char* sql);
sqlite3_ptr open_db(const char* path);
inline sqlite3_ptr null_db() { return sqlite3_ptr(nullptr, sqlite3_close); }
sqlite3_stmt_ptr prepare_query(sqlite3* db, const char* query);
sqlite3_stmt_ptr prepare_query(sqlite3_ptr& db, const char* query);
}}//namespace
+2
View File
@@ -3,6 +3,7 @@
g++ -isystem ../externals/include \
-I ../include \
-I ../include/spark \
-std=c++1z \
-o md_publisher_example \
md_publisher_example.cpp \
-Wl,-rpath,../lib \
@@ -14,6 +15,7 @@ g++ -isystem ../externals/include \
g++ -isystem ../externals/include \
-I ../include \
-I ../include/spark \
-std=c++1z \
-fPIC \
-g \
-shared \
@@ -43,7 +43,7 @@ void run_cx_server(UserSymbol* psyms, size_t symcount)
CXMain::CXMain() :
_producer(co2::PLATFORM_CELOXICA),
_security_recorder(),
_security_recorder({}),
_settlement_recorder(co2::PLATFORM_CELOXICA),
_listeners()
{
@@ -312,8 +312,6 @@ void MDP3Listener::onSpread(onixs::Handler&, const onixs::Security&, const Instr
FixedSpreadSecurityL fsec;
set_security_common(sec, fsec);
std::vector<uint32_t> leg_exchange_ids;
leg_exchange_ids.reserve(sec.legs().size());
onixs::Decimal min_tick = tick_rule(sec);
@@ -341,10 +339,10 @@ void MDP3Listener::onSpread(onixs::Handler&, const onixs::Security&, const Instr
}
fsec.legs[x].leg_quantity = leg.legRatioQty();
fsec.legs[x].leg_side = leg.legSide() == onixs::LegSide::BuySide ? api::SIDE_BUY : api::SIDE_SELL;
leg_exchange_ids.push_back(leg.legSecurityId());
fsec.legs[x].exchange_key = ExchangeKey(leg.legSecurityId());
fsec.legs[x].key = invalid_security_key;
}
add_security(fsec);
_index.add_spread_legs(fsec.numeric_id, leg_exchange_ids);
}
template <size_t MAX_DEPTH,class TBook>
@@ -26,7 +26,9 @@ namespace bts {
namespace md {
MDP3Main::MDP3Main() :
_producer(PLATFORM_MDP3ONIXS, { utils::Dispatcher::current() }),
_index(),
_recorder ({ utils::Dispatcher::current(), [=](ExchangeKey k) { return SecurityKey(_index.get_key(k.value())); } }),
_producer(PLATFORM_MDP3ONIXS, _recorder ),
// _settlement_recorder(PLATFORM_MDP3ONIXS),
_engines(),
_handlers(),
@@ -152,10 +154,6 @@ void MDP3Main::run(std::vector<UserSymbol>& symbols) {
// Timers
auto& disp = utils::Dispatcher::current();
utils::DispatcherTimer spread_resolve_timer(disp, 1000, [&]() {
_index.resolve_spreads();
});
spread_resolve_timer.start();
// utils::DispatcherTimer settlement_timer(disp, 100, [&]() {
// _settlement_recorder.do_work();
@@ -38,6 +38,7 @@ private:
BTS_NO_COPY(MDP3Main);
CMESecurityIndex _index;
SecurityIDRecorder _recorder;
MDProducer _producer;
// co2::SettlementRecorder _settlement_recorder;
std::map<std::string, std::unique_ptr<onixs::FeedEngine>> _engines;
@@ -46,7 +46,7 @@ AdminServiceServer::AdminServiceServer(bts::api::ServiceContext& context)
if (_state.ParseFromString(ser_data))
{
data_found = true;
AdminServiceUtils::fill_connections_from_config(_state);
_check_data_on_start();
_update_and_publish(false);
}
}
@@ -343,4 +343,10 @@ void AdminServiceServer::_publish_md_entitlements(){
// _md_perm_publisher.add_or_update(p);
// _md_perm_publisher.flush();
// }
void AdminServiceServer::_check_data_on_start (){
AdminServiceUtils::fill_connections_from_config(_state);
for(int i=0; i<_state.accounts().size(); i++)
if(!_state.mutable_accounts(i)->has_risk_limit_enforcement())
_state.mutable_accounts(i)->mutable_risk_limit_enforcement()->set_product_limit_in_net_terms(true);
}
}}
+6 -1
View File
@@ -71,12 +71,17 @@ public:
const api::Response<bts::api::VoidMessage>& reply) override;
private:
// this is mainly does 2 things :
// 1. some data is in partially in config, this copies
// that to here
// 2. for new data fields, it initializes them here
void _check_data_on_start();
void _update_and_publish (bool is_insert);
void _publish_md_entitlements();
void _publish_md_permissions();
void _add_live_order(map<string,map<string,OrdersSummaryUnit>>& agg,
const OrderRecord& order);
void _cancel_orders(const std::vector<string>& accounts,
const std::vector<string>& users);
const std::vector<string>& users);
};
}}
+3
View File
@@ -103,6 +103,9 @@ module Accounts =
clearingAccount = ""
}
}
riskLimitEnforcement =
{ productLimitInNetTerms = true
}
}
+2
View File
@@ -284,6 +284,8 @@ let update msg (model:Model) : Model * Cmd<Msg> =
| DeleteProductLimit i ->
let limits = erase model.scratch.productPositionLimits i
{ model with scratch = { model.scratch with productPositionLimits = limits } }, Cmd.Empty
| EnforceProductLimitInNetTerms value ->
{model with scratch = {model.scratch with riskLimitEnforcement = {productLimitInNetTerms = value}}}, Cmd.none
| SecurityLimits limits ->
{ model with scratch = { model.scratch with securityPositionLimits = limits } }, Cmd.Empty
| DeleteSecurityLimit i ->
+1
View File
@@ -71,6 +71,7 @@ type Msg =
| ProductLimits of AccountProductPositionLimitUnit * AccountProductPositionLimitUnit
| AddProductLimit of AccountProductPositionLimitUnit
| DeleteProductLimit of int
| EnforceProductLimitInNetTerms of bool
| SecurityLimits of AccountSecurityPositionLimitUnit[]
| DeleteSecurityLimit of int
+8 -4
View File
@@ -360,8 +360,8 @@ let productLimits model dispatch =
TableControl.Cell (str "Exchange")
TableControl.Cell (str "Security Type")
TableControl.Cell (str "Symbol")
TableControl.Cell (str "Max Net Long Position")
TableControl.Cell (str "Max Net Short Position")
TableControl.Cell (str "Max Long Position")
TableControl.Cell (str "Max Short Position")
]
className = ""
header = None
@@ -526,6 +526,10 @@ let productLimits model dispatch =
div [ ClassName "column is-size-7 has-text-grey-mid is-help-text" ]
[str "This limits the net position for a product (i.e. accumulated position over all securities belonging to a product). This can be set for one product, or for all products within a security type by selecting \"All\" for symbol. (Note that \"All\" applies the same limits to each symbol, not the combiled position of all symbols)"]
]
div [][
Fields.radioButton "Use Net Contracts" "" model.scratch.riskLimitEnforcement.productLimitInNetTerms [] (EnforceProductLimitInNetTerms >> dispatch)
Fields.radioButton "Use Absolute Contracts" "" (not model.scratch.riskLimitEnforcement.productLimitInNetTerms) [] (not >> EnforceProductLimitInNetTerms >> dispatch)
]
TableControl.createDataTable (Some headerRow) rws (Button.button "Add" "" "plus-circle" Button.Enabled addRow)
br []
]
@@ -541,8 +545,8 @@ let securityLimitsView model dispatch =
TableControl.Cell (str "Security Type")
TableControl.Cell (str "Symbol")
TableControl.Cell (str "Security")
TableControl.Cell (str "Max Net Long Position")
TableControl.Cell (str "Max Net Short Position")
TableControl.Cell (str "Max Long Position")
TableControl.Cell (str "Max Short Position")
]
className = ""
header = None
+21
View File
@@ -173,10 +173,31 @@ let checkbox (lbl:string) (description:string) (dv:bool) (attrs:IHTMLProp list)
]
]
let radioButton (lbl:string) (description:string) (dv:bool) (attrs:IHTMLProp list) (onchange:bool->unit) =
div [ ClassName "field" ]
[
div [ ClassName "control" ]
[
label [ ] [
input ([
ClassName "checkbox"
Type "radio"
Checked dv
OnChange (fun ev -> !!ev.target?``checked`` |> onchange)
] @ attrs)
str (" " + lbl)
]
nbsp.element
span [ClassName "is-size-7 has-text-grey-mid"][ str description]
]
]
let mapSelectEx (lbl:string) (options:Map<string,string>) (defaultText:string option) (defaultValue:string option) (onchange:'a->unit) (is_disabled:bool option) =
let dis = match is_disabled with
| None -> false
| Some a -> a
let optList:ReactElement list =
match defaultText with
| None -> ([ for opt in options do yield option [ Value opt.Key ] [ str (opt.Value) ] ])