Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
661ccf80fc | ||
|
|
36212a8cf7 | ||
|
|
d8683151fe |
No files matched your search
@@ -37,4 +37,3 @@ trace_data/
|
||||
*.rej
|
||||
/build
|
||||
.clangd/
|
||||
/.cache/
|
||||
Vendored
+5
-9
@@ -8,15 +8,13 @@
|
||||
"program": "${workspaceRoot}/build/ninja_debug/server/sparkd",
|
||||
"args": [
|
||||
"run",
|
||||
"test",
|
||||
"-a",
|
||||
"OutrightVanillaOrder"
|
||||
// "test",
|
||||
// "-a",
|
||||
// "[ilink3]"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceRoot}/build/ninja_debug/server/",
|
||||
"environment": [
|
||||
{ "name": "TZ", "value": "America/Chicago" }
|
||||
],
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"setupCommands": [
|
||||
@@ -33,9 +31,7 @@
|
||||
"request": "launch",
|
||||
"program": "/home/bts/spark/build/ninja_debug/server/sparkd",
|
||||
"args": [
|
||||
"test",
|
||||
"-a",
|
||||
"[ilink3]"
|
||||
"run"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "/home/bts/spark/build/ninja_debug/server/",
|
||||
|
||||
@@ -41,7 +41,6 @@ else ()
|
||||
-Wno-missing-braces -Wno-ignored-qualifiers \
|
||||
--std=c++17 -fdiagnostics-color")
|
||||
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -DNDEBUG -O3")
|
||||
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
|
||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wno-undef")
|
||||
add_subdirectory(src/server/sparkd)
|
||||
add_subdirectory(src/lib)
|
||||
|
||||
+1
-1
Submodule docker/linux updated: 7258a028d7...6f0dd9324b.
@@ -1,40 +1,40 @@
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.api.orderman;
|
||||
using bts.utils;
|
||||
using mbts.spark.utilities;
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.api.orderman;
|
||||
using bts.utils;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
namespace mbts.spark {
|
||||
interface IAlgoProvider {
|
||||
AlgoTypeSetImmutable get_permitted_algos(SecurityImmutable security);
|
||||
AlgoTypeSetImmutable get_permitted_algos(SecurityCriteriaClause clause);
|
||||
IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_algos();
|
||||
IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_algos(SecurityImmutable security);
|
||||
IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_algos(SecurityCriteriaClause clause);
|
||||
}
|
||||
|
||||
// This interface is used to distinguish the attachable algo provider
|
||||
// from the standard one wrt MEF export/import.
|
||||
interface IAttachableAlgoProvider : IAlgoProvider { }
|
||||
|
||||
class AlgoProvider : IAlgoProvider {
|
||||
readonly IEnumerable<SecurityAlgoTypeSetImmutable> _security_algo_types;
|
||||
readonly IAlgoStudioModel _studio_model;
|
||||
readonly ISecurityAuxiliaryDataModel _security_auxiliary_model;
|
||||
readonly IObservable<TableUpdate<AlgoData, AlgoKey>> _studio_algos_source;
|
||||
readonly DynamicOrderHelper _dynamic_helper;
|
||||
readonly AlgoTypeSetImmutable _full_set;
|
||||
|
||||
public AlgoProvider(IEnumerable<SecurityAlgoTypeSetImmutable> algo_sets, IAlgoStudioModel studio_model, DynamicOrderHelper dynamic_helper, ISecurityAuxiliaryDataModel security_auxiliary_model) {
|
||||
_security_algo_types = algo_sets;
|
||||
_studio_model = studio_model;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
namespace mbts.spark {
|
||||
interface IAlgoProvider {
|
||||
AlgoTypeSetImmutable get_permitted_algos(SecurityImmutable security);
|
||||
AlgoTypeSetImmutable get_permitted_algos(SecurityCriteriaClause clause);
|
||||
IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_algos();
|
||||
IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_algos(SecurityImmutable security);
|
||||
IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_algos(SecurityCriteriaClause clause);
|
||||
}
|
||||
|
||||
// This interface is used to distinguish the attachable algo provider
|
||||
// from the standard one wrt MEF export/import.
|
||||
interface IAttachableAlgoProvider : IAlgoProvider { }
|
||||
|
||||
class AlgoProvider : IAlgoProvider {
|
||||
readonly IEnumerable<SecurityAlgoTypeSetImmutable> _security_algo_types;
|
||||
readonly IAlgoStudioModel _studio_model;
|
||||
readonly ISecurityAuxiliaryDataModel _security_auxiliary_model;
|
||||
readonly IObservable<TableUpdate<AlgoData, AlgoKey>> _studio_algos_source;
|
||||
readonly DynamicOrderHelper _dynamic_helper;
|
||||
readonly AlgoTypeSetImmutable _full_set;
|
||||
|
||||
public AlgoProvider(IEnumerable<SecurityAlgoTypeSetImmutable> algo_sets, IAlgoStudioModel studio_model, DynamicOrderHelper dynamic_helper, ISecurityAuxiliaryDataModel security_auxiliary_model) {
|
||||
_security_algo_types = algo_sets;
|
||||
_studio_model = studio_model;
|
||||
_dynamic_helper = dynamic_helper;
|
||||
_full_set = new AlgoTypeSetImmutable(
|
||||
ImmutableHashSet.CreateRange(
|
||||
@@ -51,42 +51,42 @@ namespace mbts.spark {
|
||||
_studio_algos_source = studio_model.definitions
|
||||
.StartWith(TableUpdate<AlgoData, AlgoKey>.mk_empty(AlgoData.key_fn))
|
||||
.Cache();
|
||||
}
|
||||
|
||||
public AlgoTypeSetImmutable get_permitted_algos(SecurityImmutable security) =>
|
||||
_security_algo_types.Where(p => p.security_criteria.includes(security))
|
||||
.Select(sec_algos => sec_algos.algo_type_set)
|
||||
.Aggregate(_full_set, (result, algos) => result.intersect_with(algos));
|
||||
|
||||
public AlgoTypeSetImmutable get_permitted_algos(SecurityCriteriaClause clause) =>
|
||||
_security_algo_types.Where(p => p.security_criteria.is_subset_of(clause))
|
||||
.Select(sec_algos => sec_algos.algo_type_set)
|
||||
.Aggregate(_full_set, (result, algos) => result.intersect_with(algos));
|
||||
|
||||
public IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_algos() =>
|
||||
_studio_algos_source
|
||||
.AppendTable(_security_algo_types
|
||||
.Select(s => s.algo_type_set)
|
||||
.Aggregate(AlgoTypeSetImmutable.empty, (a, b) => a.union_with(b))
|
||||
.define_algos(_dynamic_helper));
|
||||
|
||||
public IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_algos(SecurityCriteriaClause security_clause) {
|
||||
var system_algos = _security_algo_types.match_algos(
|
||||
security_clause,
|
||||
_dynamic_helper,
|
||||
def => _fit_to_type(def, security_clause, _security_algo_types));
|
||||
|
||||
return _studio_algos_source.Select(
|
||||
a => (algo: a, fitted_def: _fit_to_type(a.value, security_clause, _security_algo_types)),
|
||||
tup => tup.algo.key)
|
||||
.Select(tup => AlgoData.create(tup.fitted_def, tup.algo.name, tup.algo.key), a => a.key)
|
||||
.AppendTable(system_algos.Values);
|
||||
}
|
||||
|
||||
public IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_algos(SecurityImmutable security) {
|
||||
var clause = new SecurityCriteriaClause(
|
||||
exchanges: new[] { security.Exchange },
|
||||
security_types: new[] { security.security_type() });
|
||||
}
|
||||
|
||||
public AlgoTypeSetImmutable get_permitted_algos(SecurityImmutable security) =>
|
||||
_security_algo_types.Where(p => p.security_criteria.includes(security))
|
||||
.Select(sec_algos => sec_algos.algo_type_set)
|
||||
.Aggregate(_full_set, (result, algos) => result.intersect_with(algos));
|
||||
|
||||
public AlgoTypeSetImmutable get_permitted_algos(SecurityCriteriaClause clause) =>
|
||||
_security_algo_types.Where(p => p.security_criteria.is_subset_of(clause))
|
||||
.Select(sec_algos => sec_algos.algo_type_set)
|
||||
.Aggregate(_full_set, (result, algos) => result.intersect_with(algos));
|
||||
|
||||
public IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_algos() =>
|
||||
_studio_algos_source
|
||||
.AppendTable(_security_algo_types
|
||||
.Select(s => s.algo_type_set)
|
||||
.Aggregate(AlgoTypeSetImmutable.empty, (a, b) => a.union_with(b))
|
||||
.define_algos(_dynamic_helper));
|
||||
|
||||
public IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_algos(SecurityCriteriaClause security_clause) {
|
||||
var system_algos = _security_algo_types.match_algos(
|
||||
security_clause,
|
||||
_dynamic_helper,
|
||||
def => _fit_to_type(def, security_clause, _security_algo_types));
|
||||
|
||||
return _studio_algos_source.Select(
|
||||
a => (algo: a, fitted_def: _fit_to_type(a.value, security_clause, _security_algo_types)),
|
||||
tup => tup.algo.key)
|
||||
.Select(tup => AlgoData.create(tup.fitted_def, tup.algo.name, tup.algo.key), a => a.key)
|
||||
.AppendTable(system_algos.Values);
|
||||
}
|
||||
|
||||
public IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_algos(SecurityImmutable security) {
|
||||
var clause = new SecurityCriteriaClause(
|
||||
exchanges: new[] { security.Exchange },
|
||||
security_types: new[] { security.security_type() });
|
||||
// i.e., non-studio algos
|
||||
var system_algos = _security_algo_types.match_algos(
|
||||
clause,
|
||||
@@ -94,141 +94,135 @@ namespace mbts.spark {
|
||||
def => _fit_to_type(def, security, _security_algo_types),
|
||||
_security_auxiliary_model.get_display_quantity_divisor(security));
|
||||
|
||||
return _studio_algos_source.Select(
|
||||
a => (algo: a, fitted_def: _fit_to_type(a.value, security, _security_algo_types)),
|
||||
tup => tup.algo.key)
|
||||
// filter out algos that use an unsupported root, because this would have the effect of duplicating the default algo
|
||||
// (e.g., GlbxIceberg orders would be converted to Limit/Spreader orders for non-Glbx securities).
|
||||
.Filter(tup => tup.fitted_def.actual().CustomCase == tup.algo.value.actual().CustomCase, tup => tup.algo.key)
|
||||
.Select(tup => AlgoData.create(tup.fitted_def, tup.algo.name, tup.algo.key), AlgoData.key_fn)
|
||||
return _studio_algos_source.Select(
|
||||
a => (algo: a, fitted_def: _fit_to_type(a.value, security, _security_algo_types)),
|
||||
tup => tup.algo.key)
|
||||
// filter out algos that use an unsupported root, because this would have the effect of duplicating the default algo
|
||||
// (e.g., GlbxIceberg orders would be converted to Limit/Spreader orders for non-Glbx securities).
|
||||
.Filter(tup => tup.fitted_def.actual().CustomCase == tup.algo.value.actual().CustomCase, tup => tup.algo.key)
|
||||
.Select(tup => AlgoData.create(tup.fitted_def, tup.algo.name, tup.algo.key), AlgoData.key_fn)
|
||||
.AppendTable(system_algos.Values);
|
||||
}
|
||||
|
||||
protected virtual void assign_fallback_algo(CustomOrderDefinition mdef, SecurityCriteriaClause security_clause) {
|
||||
if (security_clause.security_types.empty_if_null().Contains(Security.ContractOneofCase.Synthetic.security_type())) {
|
||||
mdef.Spreader = new SpreaderOrderDefinition();
|
||||
} else {
|
||||
mdef.Limit = new LimitOrderDefinition();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void assign_fallback_algo(CustomOrderDefinition mdef, SecurityImmutable security) {
|
||||
if (security.ContractCase == Security.ContractOneofCase.Synthetic) {
|
||||
mdef.Spreader = new SpreaderOrderDefinition {
|
||||
Security = security.CloneToMutable()
|
||||
};
|
||||
} else {
|
||||
mdef.Limit = new LimitOrderDefinition();
|
||||
}
|
||||
}
|
||||
|
||||
CustomOrderDefinitionImmutable _fit_to_type(CustomOrderDefinitionImmutable defi, SecurityCriteriaClause security_clause, IEnumerable<SecurityAlgoTypeSetImmutable> algo_sets) {
|
||||
var mroot = defi.CloneToMutable();
|
||||
if (_fit_to_type(mroot, security_clause, algo_sets)) {
|
||||
defi = new CustomOrderDefinitionImmutable(mroot);
|
||||
}
|
||||
return defi;
|
||||
}
|
||||
|
||||
CustomOrderDefinitionImmutable _fit_to_type(CustomOrderDefinitionImmutable defi, SecurityImmutable security, IEnumerable<SecurityAlgoTypeSetImmutable> algo_sets) {
|
||||
var mroot = defi.CloneToMutable();
|
||||
if (_fit_to_type(mroot, security, algo_sets)) {
|
||||
defi = new CustomOrderDefinitionImmutable(mroot);
|
||||
}
|
||||
return defi;
|
||||
}
|
||||
|
||||
bool _fit_to_type(CustomOrderDefinition mdef, SecurityCriteriaClause security_clause, IEnumerable<SecurityAlgoTypeSetImmutable> algo_sets) {
|
||||
while (mdef.CustomCase == CustomOrderDefinition.CustomOneofCase.Composite)
|
||||
mdef = mdef.Composite.Definition;
|
||||
var sec_sets = algo_sets.Where(s => security_clause.is_subset_of(s.security_criteria));
|
||||
if (mdef.CustomCase == CustomOrderDefinition.CustomOneofCase.Dynamic) {
|
||||
if (!algo_sets.All(s => s.algo_type_set.dynamic_types.Contains(mdef.Dynamic.DynamicOrderType))) {
|
||||
assign_fallback_algo(mdef, security_clause);
|
||||
return true;
|
||||
}
|
||||
} else if (!sec_sets.All(s => s.algo_type_set.factory_types.Contains(mdef.CustomCase))) {
|
||||
assign_fallback_algo(mdef, security_clause);
|
||||
return true;
|
||||
}
|
||||
return OrderDataHelper.get_child_algo_data(mdef).Count(cad => _fit_to_type(cad.get_child(mdef), security_clause, algo_sets)) > 0;
|
||||
}
|
||||
|
||||
bool _fit_to_type(CustomOrderDefinition mdef, SecurityImmutable security, IEnumerable<SecurityAlgoTypeSetImmutable> algo_sets) {
|
||||
while (mdef.CustomCase == CustomOrderDefinition.CustomOneofCase.Composite)
|
||||
mdef = mdef.Composite.Definition;
|
||||
var sec_sets = algo_sets.Where(s => s.security_criteria.includes(security));
|
||||
if (mdef.CustomCase == CustomOrderDefinition.CustomOneofCase.Dynamic) {
|
||||
if (!sec_sets.All(s => s.algo_type_set.dynamic_types.Contains(mdef.Dynamic.DynamicOrderType))) {
|
||||
assign_fallback_algo(mdef, security);
|
||||
return true;
|
||||
}
|
||||
} else if (!sec_sets.All(s => s.algo_type_set.factory_types.Contains(mdef.CustomCase))) {
|
||||
assign_fallback_algo(mdef, security);
|
||||
return true;
|
||||
}
|
||||
return OrderDataHelper.get_child_algo_data(mdef).Count(cad => _fit_to_type(cad.get_child(mdef), security, algo_sets)) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
class AttachableAlgoProvider : AlgoProvider, IAttachableAlgoProvider {
|
||||
public AttachableAlgoProvider(IEnumerable<SecurityAlgoTypeSetImmutable> algo_sets, IAlgoStudioModel studio_model, DynamicOrderHelper dynamic_helper, ISecurityAuxiliaryDataModel security_auxiliary_model)
|
||||
: base(algo_sets, studio_model, dynamic_helper, security_auxiliary_model) { }
|
||||
|
||||
// arbitrarily assign LimitOrderDefinition (this is just a placeholder; the real child is the attach target algo).
|
||||
// Note: although 'None' might seem approrpriate, the server requires a valid definition (perhaps this will change in the future).
|
||||
protected override void assign_fallback_algo(CustomOrderDefinition mdef, SecurityCriteriaClause security_clause) =>
|
||||
mdef.Limit = new LimitOrderDefinition();
|
||||
|
||||
// arbitrarily assign LimitOrderDefinition (this is just a placeholder; the real child is the attach target algo).
|
||||
// Note: although 'None' might seem approrpriate, the server requires a valid definition (perhaps this will change in the future).
|
||||
protected override void assign_fallback_algo(CustomOrderDefinition mdef, SecurityImmutable security) =>
|
||||
mdef.Limit = new LimitOrderDefinition();
|
||||
}
|
||||
|
||||
static class AlgoProviderExtensions {
|
||||
// This stream filters out composite algos that are not subsets of the non-composite algo types in the table
|
||||
// (normally, such composites are 'auto-fit,' meaning the algo nodes that are not part of the set are replaced with ones that are).
|
||||
// For example, consider a composite algo the following structure: Offset -> GlbxIceberg.
|
||||
// If an update arrives with these noncomposite types: "Iceberg, Limit, Market," that composite algo is not a subset of the non-composite algo types,
|
||||
// because GlbxIceberg is not in the table, so it would only be added to the table if/when GlbxIceberg arrives.
|
||||
public static IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_complete_algos(this IAlgoProvider algo_provider, bool allow_undefined_child = false) =>
|
||||
subscribe_complete_algos(algo_provider.subscribe_algos(), allow_undefined_child);
|
||||
|
||||
public static IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_complete_algos(IObservable<TableUpdate<AlgoData, AlgoKey>> source, bool allow_undefined_child = false) =>
|
||||
Observable.Create<TableUpdate<AlgoData, AlgoKey>>(o => {
|
||||
var last_out = TableUpdate<AlgoData, AlgoKey>.mk_empty(AlgoData.key_fn);
|
||||
var incomplete_composites = ImmutableHashSet<AlgoData>.Empty;
|
||||
return source.Subscribe(table => {
|
||||
var bd = last_out.to_builder();
|
||||
foreach (var algo in incomplete_composites.Where(a => _validate_algo_structure(a.value, table.state, allow_undefined_child))) {
|
||||
incomplete_composites = incomplete_composites.Remove(algo);
|
||||
bd.add_or_update(algo);
|
||||
}
|
||||
foreach (var a in table.removed.Concat(table.changes.Old()))
|
||||
bd.remove(a.key);
|
||||
foreach (var a in table.added.Concat(table.changed)) {
|
||||
if (_validate_algo_structure(a.value, table.state, allow_undefined_child)) {
|
||||
bd.add_or_update(a);
|
||||
} else {
|
||||
incomplete_composites = incomplete_composites.Add(a);
|
||||
}
|
||||
}
|
||||
o.OnNext(last_out = bd.to_table());
|
||||
});
|
||||
});
|
||||
|
||||
static bool _validate_algo_structure(CustomOrderDefinitionImmutable custom_def, IReadOnlyDictionary<AlgoKey, AlgoData> allowed_algo_parts, bool allow_undefined_child) =>
|
||||
OrderDataHelper.enumerate_algo_structure(custom_def)
|
||||
.Select((algo_node, index) =>
|
||||
// None is an acceptable algo type as long as it's not the root algo (i.e., index > 0)
|
||||
(index > 0 && allow_undefined_child && algo_node.type == CustomOrderDefinition.CustomOneofCase.None) || _is_part_contained(algo_node, allowed_algo_parts))
|
||||
.All();
|
||||
|
||||
static bool _is_part_contained((CustomOrderDefinition.CustomOneofCase type, string dyn, uint studio_id, uint spreader_sec) structure, IReadOnlyDictionary<AlgoKey, AlgoData> state) =>
|
||||
structure.type == CustomOrderDefinition.CustomOneofCase.Composite ||
|
||||
structure.type == CustomOrderDefinition.CustomOneofCase.Dynamic ?
|
||||
state.ContainsKey(AlgoKey.from_dynamic_type(structure.dyn)) :
|
||||
state.ContainsKey(AlgoKey.from_known_type(structure.type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void assign_fallback_algo(CustomOrderDefinition mdef, SecurityCriteriaClause security_clause) {
|
||||
if (security_clause.security_types.empty_if_null().Contains(Security.ContractOneofCase.Synthetic.security_type())) {
|
||||
mdef.Spreader = new SpreaderOrderDefinition();
|
||||
} else {
|
||||
mdef.Limit = new LimitOrderDefinition();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void assign_fallback_algo(CustomOrderDefinition mdef, SecurityImmutable security) {
|
||||
if (security.ContractCase == Security.ContractOneofCase.Synthetic) {
|
||||
mdef.Spreader = new SpreaderOrderDefinition {
|
||||
Security = security.CloneToMutable()
|
||||
};
|
||||
} else {
|
||||
mdef.Limit = new LimitOrderDefinition();
|
||||
}
|
||||
}
|
||||
|
||||
CustomOrderDefinitionImmutable _fit_to_type(CustomOrderDefinitionImmutable defi, SecurityCriteriaClause security_clause, IEnumerable<SecurityAlgoTypeSetImmutable> algo_sets) {
|
||||
var mroot = defi.CloneToMutable();
|
||||
if (_fit_to_type(mroot, security_clause, algo_sets)) {
|
||||
defi = new CustomOrderDefinitionImmutable(mroot);
|
||||
}
|
||||
return defi;
|
||||
}
|
||||
|
||||
CustomOrderDefinitionImmutable _fit_to_type(CustomOrderDefinitionImmutable defi, SecurityImmutable security, IEnumerable<SecurityAlgoTypeSetImmutable> algo_sets) {
|
||||
var mroot = defi.CloneToMutable();
|
||||
if (_fit_to_type(mroot, security, algo_sets)) {
|
||||
defi = new CustomOrderDefinitionImmutable(mroot);
|
||||
}
|
||||
return defi;
|
||||
}
|
||||
|
||||
bool _fit_to_type(CustomOrderDefinition mdef, SecurityCriteriaClause security_clause, IEnumerable<SecurityAlgoTypeSetImmutable> algo_sets) {
|
||||
while (mdef.CustomCase == CustomOrderDefinition.CustomOneofCase.Composite)
|
||||
mdef = mdef.Composite.Definition;
|
||||
var sec_sets = algo_sets.Where(s => security_clause.is_subset_of(s.security_criteria));
|
||||
if (mdef.CustomCase == CustomOrderDefinition.CustomOneofCase.Dynamic) {
|
||||
if (!algo_sets.All(s => s.algo_type_set.dynamic_types.Contains(mdef.Dynamic.DynamicOrderType))) {
|
||||
assign_fallback_algo(mdef, security_clause);
|
||||
return true;
|
||||
}
|
||||
} else if (!sec_sets.All(s => s.algo_type_set.factory_types.Contains(mdef.CustomCase))) {
|
||||
assign_fallback_algo(mdef, security_clause);
|
||||
return true;
|
||||
}
|
||||
return OrderDataHelper.get_child_algo_data(mdef).Count(cad => _fit_to_type(cad.get_child(mdef), security_clause, algo_sets)) > 0;
|
||||
}
|
||||
|
||||
bool _fit_to_type(CustomOrderDefinition mdef, SecurityImmutable security, IEnumerable<SecurityAlgoTypeSetImmutable> algo_sets) {
|
||||
while (mdef.CustomCase == CustomOrderDefinition.CustomOneofCase.Composite)
|
||||
mdef = mdef.Composite.Definition;
|
||||
var sec_sets = algo_sets.Where(s => s.security_criteria.includes(security));
|
||||
if (mdef.CustomCase == CustomOrderDefinition.CustomOneofCase.Dynamic) {
|
||||
if (!sec_sets.All(s => s.algo_type_set.dynamic_types.Contains(mdef.Dynamic.DynamicOrderType))) {
|
||||
assign_fallback_algo(mdef, security);
|
||||
return true;
|
||||
}
|
||||
} else if (!sec_sets.All(s => s.algo_type_set.factory_types.Contains(mdef.CustomCase))) {
|
||||
assign_fallback_algo(mdef, security);
|
||||
return true;
|
||||
}
|
||||
return OrderDataHelper.get_child_algo_data(mdef).Count(cad => _fit_to_type(cad.get_child(mdef), security, algo_sets)) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
class AttachableAlgoProvider : AlgoProvider, IAttachableAlgoProvider {
|
||||
public AttachableAlgoProvider(IEnumerable<SecurityAlgoTypeSetImmutable> algo_sets, IAlgoStudioModel studio_model, DynamicOrderHelper dynamic_helper, ISecurityAuxiliaryDataModel security_auxiliary_model)
|
||||
: base(algo_sets, studio_model, dynamic_helper, security_auxiliary_model) { }
|
||||
|
||||
// arbitrarily assign LimitOrderDefinition (this is just a placeholder; the real child is the attach target algo).
|
||||
// Note: although 'None' might seem approrpriate, the server requires a valid definition (perhaps this will change in the future).
|
||||
protected override void assign_fallback_algo(CustomOrderDefinition mdef, SecurityCriteriaClause security_clause) =>
|
||||
mdef.Limit = new LimitOrderDefinition();
|
||||
|
||||
// arbitrarily assign LimitOrderDefinition (this is just a placeholder; the real child is the attach target algo).
|
||||
// Note: although 'None' might seem approrpriate, the server requires a valid definition (perhaps this will change in the future).
|
||||
protected override void assign_fallback_algo(CustomOrderDefinition mdef, SecurityImmutable security) =>
|
||||
mdef.Limit = new LimitOrderDefinition();
|
||||
}
|
||||
|
||||
static class AlgoProviderExtensions {
|
||||
// This stream filters out composite algos that are not subsets of the non-composite algo types in the table
|
||||
// (normally, such composites are 'auto-fit,' meaning the algo nodes that are not part of the set are replaced with ones that are).
|
||||
// For example, consider a composite algo the following structure: Offset -> GlbxIceberg.
|
||||
// If an update arrives with these noncomposite types: "Iceberg, Limit, Market," that composite algo is not a subset of the non-composite algo types,
|
||||
// because GlbxIceberg is not in the table, so it would only be added to the table if/when GlbxIceberg arrives.
|
||||
public static IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_complete_algos(this IAlgoProvider algo_provider) =>
|
||||
subscribe_complete_algos(algo_provider.subscribe_algos());
|
||||
|
||||
public static IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_complete_algos(IObservable<TableUpdate<AlgoData, AlgoKey>> source) =>
|
||||
Observable.Create<TableUpdate<AlgoData, AlgoKey>>(o => {
|
||||
var last_out = TableUpdate<AlgoData, AlgoKey>.mk_empty(AlgoData.key_fn);
|
||||
var incomplete_composites = ImmutableHashSet<AlgoData>.Empty;
|
||||
return source.Subscribe(table => {
|
||||
var bd = last_out.to_builder();
|
||||
foreach (var algo in incomplete_composites.Where(a => OrderDataHelper.enumerate_algo_structure(a.value).All(tup => _is_part_contained(tup, table.state)))) {
|
||||
incomplete_composites = incomplete_composites.Remove(algo);
|
||||
bd.add_or_update(algo);
|
||||
}
|
||||
foreach (var a in table.removed.Concat(table.changes.Old()))
|
||||
bd.remove(a.key);
|
||||
foreach (var a in table.added.Concat(table.changed)) {
|
||||
var structure = OrderDataHelper.enumerate_algo_structure(a.value);
|
||||
if (structure.All(t => _is_part_contained(t, table.state))) {
|
||||
bd.add_or_update(a);
|
||||
} else {
|
||||
incomplete_composites = incomplete_composites.Add(a);
|
||||
}
|
||||
}
|
||||
o.OnNext(last_out = bd.to_table());
|
||||
});
|
||||
});
|
||||
|
||||
static bool _is_part_contained((CustomOrderDefinition.CustomOneofCase type, string dyn, uint studio_id, uint spreader_sec) structure, IReadOnlyDictionary<AlgoKey, AlgoData> state) =>
|
||||
structure.type == CustomOrderDefinition.CustomOneofCase.Composite ||
|
||||
structure.type == CustomOrderDefinition.CustomOneofCase.Dynamic ?
|
||||
state.ContainsKey(AlgoKey.from_dynamic_type(structure.dyn)) :
|
||||
state.ContainsKey(AlgoKey.from_known_type(structure.type));
|
||||
}
|
||||
}
|
||||
@@ -162,7 +162,7 @@ namespace mbts.spark {
|
||||
strip_name_filter.load_state(filters.strip_name);
|
||||
mic_code_filter.load_state(filters.mic_code);
|
||||
}
|
||||
rows_view.set_sort_descriptions(s.sorting_criterion, columns);
|
||||
rows_view.set_sort_descriptions(s.sorting_criteria, columns);
|
||||
}
|
||||
}), DataGridFilterHelper.hook_filters(rows_view, _filters),
|
||||
settings_manager.subscribe_current().OnDispatcher().Subscribe(grid_settings_manager),
|
||||
|
||||
@@ -91,9 +91,9 @@ namespace bts.shell {
|
||||
}
|
||||
|
||||
|
||||
public static GridSettings DefaultGridSettings => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criterion, enable_background_color: true);
|
||||
public static GridSettings DefaultGridSettings => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criteria, enable_background_color: true);
|
||||
|
||||
public IReadOnlyList<SortingCriteria> sorting_criterion => _sorting_criteria ?? (_sorting_criteria = DefaultColumns.default_sorting_criterion.ToList());
|
||||
public IReadOnlyList<SortingCriteria> sorting_criteria => _sorting_criteria ?? (_sorting_criteria = DefaultColumns.default_sorting_criteria.ToList());
|
||||
|
||||
public static StartupData Default(SecurityCriteria security_criteria) =>
|
||||
new StartupData(security_criteria, new FilterStates(), null);
|
||||
@@ -131,7 +131,7 @@ namespace bts.shell {
|
||||
|
||||
|
||||
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criterion {
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criteria {
|
||||
get {
|
||||
yield return new SortingCriteria(security.id, true);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace bts.shell.time_and_sales {
|
||||
[ProtoMember(1)]
|
||||
public readonly SecurityCriteria security_criteria;
|
||||
[ProtoMember(2)]
|
||||
List<SortingCriteria> _sorting_criterion;
|
||||
List<SortingCriteria> _sorting_criteria;
|
||||
[ProtoMember(3)]
|
||||
public FilterStates filters;
|
||||
[ProtoMember(4)]
|
||||
@@ -28,19 +28,19 @@ namespace bts.shell.time_and_sales {
|
||||
public TimeAndSalesSettings(SecurityCriteria security_criteria) :
|
||||
this(security_criteria, new FilterStates(), null, null) { }
|
||||
|
||||
public TimeAndSalesSettings(SecurityCriteria security_criteria, FilterStates filters, GridSettings grid = default, List<SortingCriteria> sorting_criterion = null) {
|
||||
public TimeAndSalesSettings(SecurityCriteria security_criteria, FilterStates filters, GridSettings grid = default, List<SortingCriteria> sorting_criteria = null) {
|
||||
this.security_criteria = security_criteria;
|
||||
this.filters = filters;
|
||||
this.grid = grid;
|
||||
_sorting_criterion = sorting_criterion;
|
||||
_sorting_criteria = sorting_criteria;
|
||||
}
|
||||
|
||||
public static GridSettings DefaultGridSettings => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criterion);
|
||||
public static GridSettings DefaultGridSettings => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criteria);
|
||||
|
||||
public List<SortingCriteria> sorting_criterion => _sorting_criterion ?? (_sorting_criterion = DefaultColumns.default_sorting_criterion.ToList());
|
||||
public List<SortingCriteria> sorting_criteria => _sorting_criteria ?? (_sorting_criteria = DefaultColumns.default_sorting_criteria.ToList());
|
||||
|
||||
public static TimeAndSalesSettings Default(SecurityCriteria security_criteria) =>
|
||||
new TimeAndSalesSettings(security_criteria, new FilterStates(), null, DefaultColumns.default_sorting_criterion.ToList());
|
||||
new TimeAndSalesSettings(security_criteria, new FilterStates(), null, DefaultColumns.default_sorting_criteria.ToList());
|
||||
|
||||
public TimeAndSalesSettings with(SecurityCriteria security_criteria) =>
|
||||
new TimeAndSalesSettings(security_criteria, filters, grid);
|
||||
@@ -53,7 +53,7 @@ namespace bts.shell.time_and_sales {
|
||||
public static GridColumnSettings aggressor => new GridColumnSettings(Columns.Aggressor.col_id(), DefaultColumnHeaders.Aggressor, width: DefaultColumnWidths.Aggressor);
|
||||
public static GridColumnSettings security_key => new GridColumnSettings(Columns.SecurityKey.col_id(), DefaultColumnHeaders.SecurityKey, is_visible: false, width: DefaultColumnWidths.SecurityKey);
|
||||
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criterion {
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criteria {
|
||||
get {
|
||||
yield return new SortingCriteria(time.id, false);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using bts.api;
|
||||
using bts.co2;
|
||||
using bts.utils;
|
||||
using bts.utils.csv;
|
||||
using mbts;
|
||||
using mbts.spark;
|
||||
using mbts.ui.controls;
|
||||
@@ -50,18 +49,6 @@ namespace bts.shell.time_and_sales {
|
||||
public void raise_invalidated() =>
|
||||
invalidated?.Invoke();
|
||||
|
||||
public static System.Collections.Specialized.OrderedDictionary csv_ordered_properties =>
|
||||
CsvHelper.create_ordering_maintainer(
|
||||
typeof(TimeAndSalesRowVM),
|
||||
new string[] {
|
||||
nameof(security),
|
||||
nameof(time),
|
||||
nameof(price),
|
||||
nameof(size),
|
||||
nameof(aggressor_side),
|
||||
nameof(security_key),
|
||||
});
|
||||
|
||||
public bool Equals(TimeAndSalesRowVM other) =>
|
||||
other != null &&
|
||||
row_key == other.row_key;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using bts.shell.fills;
|
||||
using bts.spark;
|
||||
using bts.view;
|
||||
using bts.utils.csv;
|
||||
using mbts;
|
||||
using mbts.co2;
|
||||
using mbts.persist;
|
||||
@@ -125,8 +124,6 @@ namespace bts.shell.time_and_sales {
|
||||
show_in_context_menu = _can_pause_updates
|
||||
};
|
||||
_commands = new SparkCommand[] {
|
||||
// csv export
|
||||
new SparkCommandCommand("Export to csv", Icons.Export, FileDialogCommand.export_csv(() => _vm.rows.ToCsv(TimeAndSalesRowVM.csv_ordered_properties), "TaS")),
|
||||
// ladder
|
||||
SparkCommands.ShowLadderAutoLookup(SparkCommands.KeyGestures.ShowLadder)
|
||||
.complete(current_sec_key_src, sec_keys => sec_keys.Count > 0),
|
||||
@@ -162,7 +159,7 @@ namespace bts.shell.time_and_sales {
|
||||
})),
|
||||
_menu_display_vm.spark_cmd
|
||||
};
|
||||
_vm.load(_state.filters, _state.sorting_criterion, _state.grid);
|
||||
_vm.load(_state.filters, _state.sorting_criteria, _state.grid);
|
||||
_vm.request_show_ladder += show_ladder;
|
||||
var security_criteria_src = _bus.subscribe(update_securities_cmd.tag);
|
||||
var subs = new List<IDisposable> {
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace bts.shell {
|
||||
grid ?? this.grid,
|
||||
menu_display ?? this.menu_display);
|
||||
|
||||
public static GridSettings DefaultGridSettings => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criterion);
|
||||
public static GridSettings DefaultGridSettings => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criteria);
|
||||
|
||||
static class DefaultColumns {
|
||||
public static GridColumnSettings name => new GridColumnSettings(col_id(Columns.Name), DefaultColumnHeaders.Name, width: DefaultColumnWidths.Security);
|
||||
@@ -80,7 +80,7 @@ namespace bts.shell {
|
||||
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, is_visible: false, width: DefaultColumnWidths.SecurityKey);
|
||||
public static GridColumnSettings user => new GridColumnSettings(col_id(Columns.User), DefaultColumnHeaders.User, is_visible: false, width: DefaultColumnWidths.User);
|
||||
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criterion {
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criteria {
|
||||
get {
|
||||
yield return new SortingCriteria(name.id, true);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace mbts.spark {
|
||||
_revert_cmd_tooltip = backing(nameof(revert_cmd_tooltip), get_revert_tooltip);
|
||||
//
|
||||
_dispose = new CompositeDisposable(
|
||||
_model.subscribe_complete_algos(allow_undefined_child: true).OnDispatcher().Subscribe(_definitions_update_buffer),
|
||||
_model.subscribe_complete_algos().OnDispatcher().Subscribe(_definitions_update_buffer),
|
||||
_definitions_update_buffer.OnDispatcher()
|
||||
.SubscribeEach(u => {
|
||||
u.FilterIncremental(a => a.key.is_composite, out var added, out var changes, out var removed);
|
||||
|
||||
@@ -5,7 +5,6 @@ using bts.collections;
|
||||
using bts.shell.fills;
|
||||
using bts.spark;
|
||||
using bts.utils;
|
||||
using bts.utils.csv;
|
||||
using mbts.collections;
|
||||
using mbts.persist;
|
||||
using mbts.spark.filters;
|
||||
@@ -155,7 +154,7 @@ namespace mbts.spark {
|
||||
TimeTextTuple.FromDateTime(DateTime.Today),
|
||||
TimeTextTuple.FromDateTime(DateTime.Today.AddDays(1)))
|
||||
},
|
||||
settings.sorting_criterion);
|
||||
settings.sorting_criteria);
|
||||
// resources/subscriptions
|
||||
_dispose = new CompositeDisposable(
|
||||
ObservableAutoWrapper.connect(col_tups, columns, ct => ct.col),
|
||||
@@ -210,8 +209,8 @@ namespace mbts.spark {
|
||||
public FillsFilterStates get_filters() =>
|
||||
_rows_manager.get_filters();
|
||||
|
||||
public IEnumerable<SortingCriteria> get_sorting_criterion() =>
|
||||
_rows_manager.get_sorting_criterion();
|
||||
public IEnumerable<SortingCriteria> get_sorting_criteria() =>
|
||||
_rows_manager.get_sorting_criteria();
|
||||
|
||||
public void on_sorting(object sender, DIYGridSortingEventArgs e) =>
|
||||
_rows_manager.on_sorting(e);
|
||||
@@ -334,27 +333,6 @@ namespace mbts.spark {
|
||||
public override bool Equals(object obj) => Equals(obj as Row);
|
||||
public override int GetHashCode() => _fill.FillKey.GetHashCode() ^ _order.Key.GetHashCode();
|
||||
|
||||
public static System.Collections.Specialized.OrderedDictionary csv_ordered_properties =>
|
||||
CsvHelper.create_ordering_maintainer(typeof(Row),
|
||||
new string[] {
|
||||
nameof(security),
|
||||
nameof(order_type),
|
||||
nameof(root_algo_display_name),
|
||||
nameof(side),
|
||||
nameof(fill_time),
|
||||
nameof(user),
|
||||
nameof(account),
|
||||
nameof(exchange),
|
||||
nameof(time_in_force),
|
||||
nameof(size),
|
||||
nameof(price),
|
||||
nameof(fill_kind),
|
||||
nameof(fill_status),
|
||||
nameof(fill_key),
|
||||
nameof(order_key),
|
||||
nameof(security_key)
|
||||
});
|
||||
|
||||
public event Action invalidated;
|
||||
void IRowVM.raise_invalidated() => invalidated?.Invoke();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ using bts.shell;
|
||||
using bts.shell.fills;
|
||||
using bts.spark;
|
||||
using bts.view;
|
||||
using bts.utils.csv;
|
||||
using mbts.persist;
|
||||
using mbts.ui;
|
||||
using mbts.ui.settings;
|
||||
@@ -41,7 +40,7 @@ namespace mbts.spark {
|
||||
public override UIElement Content => _view;
|
||||
public override IEnumerable<SparkCommand> Commands => _commands;
|
||||
|
||||
public override FillsSettings SaveState => _state = new FillsSettings(_state.orders, _vm.get_sorting_criterion().ToList(), _vm.get_filters(), _vm.get_grid_save_state()) {
|
||||
public override FillsSettings SaveState => _state = new FillsSettings(_state.orders, _vm.get_sorting_criteria().ToList(), _vm.get_filters(), _vm.get_grid_save_state()) {
|
||||
menu_display = _menu_display_vm.safe_create()
|
||||
};
|
||||
|
||||
@@ -62,7 +61,6 @@ namespace mbts.spark {
|
||||
_view = new FillsView { DataContext = _vm };
|
||||
|
||||
_commands = new List<SparkCommand> {
|
||||
new SparkCommandCommand("Export to csv", Icons.Export, FileDialogCommand.export_csv(() => _vm.rows.ToCsv(FillsVM.Row.csv_ordered_properties), "Fills")),
|
||||
// wrap the grid settings view factory in a dialogCommand here since the vm is destroyed/recreated when the security criteria changes
|
||||
SparkCommands.window_settings_command(new DialogCommand(() => {
|
||||
var vm = new ShellSettingsDialogVM<GridSettings, SimpleGridSettingsVM>(
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace bts.shell {
|
||||
readonly IBus _bus;
|
||||
readonly OrdersModel _orders_model;
|
||||
readonly UserSettingsHub _settings_hub;
|
||||
/// Fills 'sorting-criterion' settings were compromised a while back (mid-late 2018).
|
||||
/// Fills 'sorting-criteria' settings were compromised a while back (mid-late 2018).
|
||||
/// The issue was that, when a column was sorted, its 'sort member path' was assigned to the SortingCriteria.col_name,
|
||||
/// rather than the <see cref="Columns"/> enum/id string.
|
||||
/// This dictionary serves as a reverse-lookup so the sort member path can be converted to the enum/id string.
|
||||
@@ -58,7 +58,7 @@ namespace bts.shell {
|
||||
_bus.post(SparkTags.ShowWindow, await load(state));
|
||||
|
||||
IShellWindow _create(FillsSettings state) {
|
||||
GridSettingsHelper.normalize_sorting_criterion(state.sorting_criterion, _sort_member_to_id);
|
||||
GridSettingsHelper.normalize_sorting_criteria(state.sorting_criteria, _sort_member_to_id);
|
||||
var settings_manager = new WindowSettingsManager<GridSettings>(_settings_hub,
|
||||
state.grid,
|
||||
get: us => us.fills_grid,
|
||||
|
||||
@@ -34,9 +34,9 @@ namespace bts.shell.fills {
|
||||
this.grid = grid;
|
||||
}
|
||||
|
||||
public static GridSettings DefaultGridSettings => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criterion);
|
||||
public static GridSettings MiniGridSettings => GridSettings.Default.with(DefaultColumns.Mini.all, DefaultColumns.Mini.sorting_criterion);
|
||||
public IReadOnlyList<SortingCriteria> sorting_criterion => _sorting_criteria ?? (_sorting_criteria = DefaultColumns.default_sorting_criterion.ToList());
|
||||
public static GridSettings DefaultGridSettings => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criteria);
|
||||
public static GridSettings MiniGridSettings => GridSettings.Default.with(DefaultColumns.Mini.all, DefaultColumns.Mini.sorting_criteria);
|
||||
public IReadOnlyList<SortingCriteria> sorting_criteria => _sorting_criteria ?? (_sorting_criteria = DefaultColumns.default_sorting_criteria.ToList());
|
||||
public static FillsSettings Default() =>
|
||||
new FillsSettings(null, null, new FillsFilterStates(), null);
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace bts.shell.fills {
|
||||
public static GridColumnSettings fill_key => new GridColumnSettings(col_id(Columns.FillKey), DefaultColumnHeaders.FillKey, width: DefaultColumnWidths.FillKey);
|
||||
public static GridColumnSettings order_key => new GridColumnSettings(col_id(Columns.OrderKey), DefaultColumnHeaders.OrderKey, width: DefaultColumnWidths.OrderKey);
|
||||
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, is_visible: false, width: DefaultColumnWidths.SecurityKey);
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criterion {
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criteria {
|
||||
get {
|
||||
yield return new SortingCriteria(fill_time.id, false);
|
||||
}
|
||||
@@ -96,7 +96,7 @@ namespace bts.shell.fills {
|
||||
};
|
||||
|
||||
public static IEnumerable<GridColumnSettings> all => DefaultColumns.all.Select(_convert);
|
||||
public static IEnumerable<SortingCriteria> sorting_criterion => default_sorting_criterion.Where(c => _try_get_data(c.col_name, out (bool is_visible, double? _) d) && d.is_visible);
|
||||
public static IEnumerable<SortingCriteria> sorting_criteria => default_sorting_criteria.Where(c => _try_get_data(c.col_name, out (bool is_visible, double? _) d) && d.is_visible);
|
||||
|
||||
static bool _try_get_data(string id_str, out (bool is_visible, double? width_override) data) {
|
||||
if (Enum.TryParse(id_str, out Columns k) && _mini_cols_data.TryGetValue(k, out data))
|
||||
|
||||
@@ -635,8 +635,8 @@ namespace mbts.spark {
|
||||
if (s.mini_ob.value == null)
|
||||
s.mini_ob = new LadderMiniOrderBookSettings(bts.shell.orderbook.OrderBookStartupData.default_mini_grid.general);
|
||||
#pragma warning disable CS0612 // Type or member is obsolete
|
||||
if (s.mini_ob.value.sorting_criterion.Count == 0)
|
||||
s.mini_ob = new LadderMiniOrderBookSettings(s.mini_ob.value.with(sorting_criterion: bts.shell.orderbook.OrderBookStartupData.default_mini_grid.general.sorting_criterion));
|
||||
if (s.mini_ob.value.sorting_criteria.Count == 0)
|
||||
s.mini_ob = new LadderMiniOrderBookSettings(s.mini_ob.value.with(sorting_criteria: bts.shell.orderbook.OrderBookStartupData.default_mini_grid.general.sorting_criteria));
|
||||
#pragma warning restore CS0612 // Type or member is obsolete
|
||||
s.row_height = LadderRender.measure_row_height(s);
|
||||
return s;
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace mbts.spark {
|
||||
string candidate = string.Empty;
|
||||
if (a.HasValue) {
|
||||
var algo_name = a.Value.name;
|
||||
var words = algo_name.Split(delim, StringSplitOptions.RemoveEmptyEntries);
|
||||
var words = algo_name.Split(delim);
|
||||
if (words.Length == 1) {
|
||||
var single_word = words[0];
|
||||
if (single_word.Length > 1) {
|
||||
@@ -153,7 +153,7 @@ namespace mbts.spark {
|
||||
candidate = single_word;
|
||||
}
|
||||
} else {
|
||||
candidate = string.Join(string.Empty, words.Take(2).Select(w => w.Substring(0, 1)));
|
||||
candidate = words.Take(2).Select(w => w.Substring(0, 1)).list_string(string.Empty);
|
||||
}
|
||||
}
|
||||
return candidate.ToUpper();
|
||||
|
||||
@@ -401,7 +401,7 @@ namespace mbts.spark {
|
||||
clone = SparkUtils.clone_proto(_current);
|
||||
#pragma warning disable CS0612 // Type or member is obsolete
|
||||
clone.mini_ob = new LadderMiniOrderBookSettings(_current.mini_ob.value != null ?
|
||||
mini_ob.create().with(sorting_criterion: _current.mini_ob.value.sorting_criterion) :
|
||||
mini_ob.create().with(sorting_criteria: _current.mini_ob.value.sorting_criteria) :
|
||||
mini_ob.create());
|
||||
#pragma warning restore CS0612 // Type or member is obsolete
|
||||
}
|
||||
|
||||
@@ -8,16 +8,16 @@ namespace bts.shell.manual_fills {
|
||||
[ProtoContract]
|
||||
class ManualFillsSettings {
|
||||
[ProtoMember(1)]
|
||||
readonly SortingCriteria[] _sorting_criterion;
|
||||
readonly SortingCriteria[] _sorting_criteria;
|
||||
|
||||
public static ManualFillsSettings Default =>
|
||||
new ManualFillsSettings(new[] { new SortingCriteria(nameof(mbts.ui.spark.ManualFillsView.Columns.Security), true) });
|
||||
|
||||
public ManualFillsSettings() { }
|
||||
|
||||
public ManualFillsSettings(IEnumerable<SortingCriteria> sorting_criterion) =>
|
||||
_sorting_criterion = sorting_criterion.ToArray();
|
||||
public ManualFillsSettings(IEnumerable<SortingCriteria> sorting_criteria) =>
|
||||
_sorting_criteria = sorting_criteria.ToArray();
|
||||
|
||||
public IReadOnlyList<SortingCriteria> sorting_criterion => _sorting_criterion ?? Array.Empty<SortingCriteria>();
|
||||
public IReadOnlyList<SortingCriteria> sorting_criteria => _sorting_criteria ?? Array.Empty<SortingCriteria>();
|
||||
}
|
||||
}
|
||||
@@ -44,10 +44,10 @@ namespace bts.shell {
|
||||
var vm = ManualFillsVM.create(_bus, _orders_model);
|
||||
var view = new ManualFillsView { DataContext = vm };
|
||||
view.data_grid.Sorting += on_sorting;
|
||||
IReadOnlyList<SortingCriteria> last_sorting_criterion = Array.Empty<SortingCriteria>();
|
||||
IReadOnlyList<SortingCriteria> last_sorting_criteria = Array.Empty<SortingCriteria>();
|
||||
using (apply_sort()) {
|
||||
var col_sort_tuples =
|
||||
from sc in settings.sorting_criterion
|
||||
from sc in settings.sorting_criteria
|
||||
join col in view.data_grid.Columns on sc.col_name equals _col_id(col)
|
||||
select (col, sc);
|
||||
foreach (var (col, sc) in col_sort_tuples) {
|
||||
@@ -65,8 +65,8 @@ namespace bts.shell {
|
||||
new SparkCommandCommand("Delete Selected", Icons.Trash, vm.remove_selected_fills_cmd)
|
||||
};
|
||||
return (view, cmds, get_settings, Disposable.Create(
|
||||
vm.rows_view.subscribe_sorting_criterion(sm => view.data_grid.Columns.TryGetFirst(dc => dc.SortMemberPath == sm, out DataGridColumn match) ? _col_id(match) : null)
|
||||
.Subscribe(sc => last_sorting_criterion = sc),
|
||||
vm.rows_view.subscribe_sorting_criteria(sm => view.data_grid.Columns.TryGetFirst(dc => dc.SortMemberPath == sm, out DataGridColumn match) ? _col_id(match) : null)
|
||||
.Subscribe(sc => last_sorting_criteria = sc),
|
||||
vm));
|
||||
//
|
||||
void on_sorting(object sender, DataGridSortingEventArgs e) {
|
||||
@@ -102,7 +102,7 @@ namespace bts.shell {
|
||||
});
|
||||
|
||||
ManualFillsSettings get_settings() =>
|
||||
new ManualFillsSettings(last_sorting_criterion);
|
||||
new ManualFillsSettings(last_sorting_criteria);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
class OrderBookSortingData : IEquatable<OrderBookSortingData> {
|
||||
public readonly IReadOnlyList<SortingCriteria> sorting_criterion;
|
||||
public readonly IReadOnlyList<SortingCriteria> sorting_criteria;
|
||||
public readonly IComparer<OrderBookRowVM> comparer;
|
||||
public readonly string desc;
|
||||
|
||||
@@ -52,13 +52,13 @@ namespace mbts.spark {
|
||||
comp_builder.add(Comparer<OrderBookRowVM>.Create((l, r) => l.order_key.CompareTo(r.order_key)));
|
||||
}
|
||||
comparer = comp_builder.to_comparer();
|
||||
sorting_criterion = column_sorting_hierarchy.Select(col => new SortingCriteria(col.id, col.SortDirection.GetValueOrDefault() == ListSortDirection.Ascending)).ToArray();
|
||||
desc = string.Join(", ", sorting_criterion);
|
||||
sorting_criteria = column_sorting_hierarchy.Select(col => new SortingCriteria(col.id, col.SortDirection.GetValueOrDefault() == ListSortDirection.Ascending)).ToArray();
|
||||
desc = string.Join(", ", sorting_criteria);
|
||||
}
|
||||
|
||||
public bool Equals(OrderBookSortingData other) => other != null && EqualityComparer.safe_sequence_equals(sorting_criterion, other.sorting_criterion);
|
||||
public bool Equals(OrderBookSortingData other) => other != null && EqualityComparer.safe_sequence_equals(sorting_criteria, other.sorting_criteria);
|
||||
public override bool Equals(object obj) => base.Equals(obj);
|
||||
public override int GetHashCode() => EqualityComparer.aggregate_hash(sorting_criterion);
|
||||
public override int GetHashCode() => EqualityComparer.aggregate_hash(sorting_criteria);
|
||||
public override string ToString() => desc;
|
||||
}
|
||||
|
||||
@@ -393,7 +393,7 @@ namespace mbts.spark {
|
||||
};
|
||||
|
||||
public (FilterStates filters, IReadOnlyList<SortingCriteria> sorting) create() =>
|
||||
(create_filter_states(), get_sorting_data().sorting_criterion);
|
||||
(create_filter_states(), get_sorting_data().sorting_criteria);
|
||||
|
||||
public void load_from((FilterStates filters, IReadOnlyList<SortingCriteria> sorting) state) {
|
||||
if (state.filters is FilterStates fs) {
|
||||
|
||||
@@ -4,7 +4,6 @@ using bts.api.orderman;
|
||||
using bts.collections;
|
||||
using bts.spark;
|
||||
using bts.utils;
|
||||
using bts.utils.csv;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using System;
|
||||
@@ -12,7 +11,6 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Reactive.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Linq;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using Columns = mbts.spark.OrderBookGridView.ColumnKeys;
|
||||
@@ -62,35 +60,6 @@ namespace mbts.spark {
|
||||
public event Action<(OrderSecurityRootPair oldval, OrderSecurityRootPair newval)> updated;
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public static System.Collections.Specialized.OrderedDictionary csv_ordered_properties =>
|
||||
CsvHelper.create_ordering_maintainer(
|
||||
typeof(OrderBookRowVM),
|
||||
new string[] {
|
||||
nameof(security_text),
|
||||
nameof(symbol),
|
||||
nameof(time_created),
|
||||
nameof(last_change),
|
||||
nameof(user),
|
||||
nameof(account),
|
||||
nameof(exchange),
|
||||
nameof(time_in_force),
|
||||
nameof(order_type),
|
||||
nameof(root_algo_display_name),
|
||||
nameof(order_sub_type),
|
||||
nameof(side),
|
||||
nameof(quantity),
|
||||
nameof(filled_quantity),
|
||||
nameof(price),
|
||||
nameof(avg_price),
|
||||
nameof(last_price),
|
||||
nameof(piq),
|
||||
nameof(status),
|
||||
// last message (could contains commas, so skipping)
|
||||
nameof(security_key),
|
||||
nameof(order_key),
|
||||
nameof(parent_order_key),
|
||||
});
|
||||
|
||||
// Core
|
||||
public OrderSecurityRootPair order_tuple { get; private set; }
|
||||
public OrderRecordImmutable order => order_tuple.order.order;
|
||||
|
||||
@@ -606,7 +606,7 @@ namespace mbts.spark {
|
||||
_columns.filter_changed -= _on_filter_changed;
|
||||
grid_settings_manager.algo_tree_display_mode_changed -= _on_filter_changed;
|
||||
#pragma warning disable CS0612 // Type or member is obsolete
|
||||
_columns.load_from((state.filters, (state.orderbook_grid?.general ?? OrderBookStartupData.DefaultGrid.general).sorting_criterion));
|
||||
_columns.load_from((state.filters, (state.orderbook_grid?.general ?? OrderBookStartupData.DefaultGrid.general).sorting_criteria));
|
||||
#pragma warning restore CS0612 // Type or member is obsolete
|
||||
// resume column filter updates
|
||||
_columns.filter_changed += _on_filter_changed;
|
||||
@@ -739,7 +739,7 @@ namespace mbts.spark {
|
||||
static OrderBookFillsGridSettings _get_fills_settings(FillsVM fills_vm) =>
|
||||
fills_vm == null ? OrderBookStartupData.DefaultFillsGrid :
|
||||
new OrderBookFillsGridSettings {
|
||||
sorting_criterion = fills_vm.get_sorting_criterion().ToList(),
|
||||
sorting_criteria = fills_vm.get_sorting_criteria().ToList(),
|
||||
filters = fills_vm.get_filters(),
|
||||
general = fills_vm.grid_settings_manager.create()
|
||||
};
|
||||
|
||||
@@ -6,7 +6,6 @@ using bts.shell.fills;
|
||||
using bts.shell.orderbook;
|
||||
using bts.spark;
|
||||
using bts.view;
|
||||
using bts.utils.csv;
|
||||
using mbts.persist;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui;
|
||||
@@ -232,7 +231,6 @@ namespace mbts.spark {
|
||||
toggle_collapse_all_command,
|
||||
toggle_expand_all_command,
|
||||
show_grid_settings_command,
|
||||
new SparkCommandCommand("Export to csv", Icons.Export, FileDialogCommand.export_csv(() => _vm.rows.ToCsv(OrderBookRowVM.csv_ordered_properties), "OrderBook")),
|
||||
// hidden cmds (i.e., keyboard shortcuts at window level)
|
||||
hidden_cmd(new SparkCommandCommand(OrderBookView.CommandDescriptions.ModifyOrders, null, _vm.modify_selected_orders_cmd, OrderBookView.KeyboardShortcuts.ModifyOrders)),
|
||||
hidden_cmd(new SparkCommandCommand(OrderBookView.CommandDescriptions.RevertOrders, null, _vm.revert_selected_orders_cmd, OrderBookView.KeyboardShortcuts.RevertOrders)),
|
||||
|
||||
@@ -12,9 +12,9 @@ namespace bts.shell.orderbook {
|
||||
[ProtoMember(2)]
|
||||
public FillsFilterStates filters { get; set; }
|
||||
[ProtoMember(3)]
|
||||
public List<SortingCriteria> sorting_criterion { get; set; }
|
||||
public List<SortingCriteria> sorting_criteria { get; set; }
|
||||
|
||||
public FillsSettings to_startup_data() =>
|
||||
new FillsSettings(null, sorting_criterion, filters, general);
|
||||
new FillsSettings(null, sorting_criteria, filters, general);
|
||||
}
|
||||
}
|
||||
@@ -82,9 +82,9 @@ namespace bts.shell.orderbook {
|
||||
algo_tree_display_mode = gs.algo_tree_display_mode;
|
||||
}
|
||||
|
||||
public OrderBookGridSettings create(IEnumerable<SortingCriteria> sorting_criterion) {
|
||||
public OrderBookGridSettings create(IEnumerable<SortingCriteria> sorting_criteria) {
|
||||
var gs = core_manager.create();
|
||||
gs.general = gs.general.with(sorting_criterion: sorting_criterion);
|
||||
gs.general = gs.general.with(sorting_criteria: sorting_criteria);
|
||||
gs.algo_tree_display_mode = _algo_tree_display_mode;
|
||||
return gs;
|
||||
}
|
||||
|
||||
@@ -133,15 +133,15 @@ namespace bts.shell.orderbook {
|
||||
get {
|
||||
var default_fills = FillsSettings.Default();
|
||||
var rv = new OrderBookFillsGridSettings {
|
||||
sorting_criterion = default_fills.sorting_criterion.ToList(),
|
||||
sorting_criteria = default_fills.sorting_criteria.ToList(),
|
||||
filters = default_fills.filters,
|
||||
general = FillsSettings.MiniGridSettings
|
||||
};
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
static GridSettings _default_general_grid => GridSettings.Default.with(DefaultColumns.standard, DefaultColumns.sorting_criterion);
|
||||
public static OrderBookGridSettings default_mini_grid => new OrderBookGridSettings(GridSettings.Default.with(DefaultColumns.mini, DefaultColumns.sorting_criterion)) {
|
||||
static GridSettings _default_general_grid => GridSettings.Default.with(DefaultColumns.standard, DefaultColumns.sorting_criteria);
|
||||
public static OrderBookGridSettings default_mini_grid => new OrderBookGridSettings(GridSettings.Default.with(DefaultColumns.mini, DefaultColumns.sorting_criteria)) {
|
||||
algo_tree_display_mode = AlgoTreeDisplayMode.RootAndLeafNodes
|
||||
};
|
||||
|
||||
@@ -179,7 +179,7 @@ namespace bts.shell.orderbook {
|
||||
public static GridColumnSettings edit_price => new GridColumnSettings(Columns.EditablePrice.ToString(), DIYGrid.DefaultColumnHeaders.Price, width: DIYGrid.DefaultColumnWidths.MiniOrderBook.EditablePrice);
|
||||
public static GridColumnSettings commit => new GridColumnSettings(Columns.Commit.ToString(), width: DIYGrid.DefaultColumnWidths.MiniOrderBook.Commit);
|
||||
|
||||
public static IEnumerable<SortingCriteria> sorting_criterion {
|
||||
public static IEnumerable<SortingCriteria> sorting_criteria {
|
||||
get {
|
||||
yield return new SortingCriteria(time_created.id, false);
|
||||
}
|
||||
|
||||
@@ -64,9 +64,9 @@ namespace bts.shell {
|
||||
this.grid = grid;
|
||||
}
|
||||
|
||||
public static GridSettings DefaultGridSettings => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criterion);
|
||||
public static GridSettings DefaultGridSettings => GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criteria);
|
||||
|
||||
public IReadOnlyList<SortingCriteria> sorting_criterion => _sort_criteria ?? (_sort_criteria = DefaultColumns.default_sorting_criterion.ToList());
|
||||
public IReadOnlyList<SortingCriteria> sorting_criteria => _sort_criteria ?? (_sort_criteria = DefaultColumns.default_sorting_criteria.ToList());
|
||||
public static PAndLStartupData Default() =>
|
||||
new PAndLStartupData(null, new FilterStates(), pnl_calc_type.midpoint);
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace bts.shell {
|
||||
public static GridColumnSettings pnl_price => new GridColumnSettings(col_id(Columns.PNLPrice), DefaultColumnHeaders.PnLPrice, width: DefaultColumnWidths.PnL_Generic, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
|
||||
public static GridColumnSettings has_day_trades => new GridColumnSettings(col_id(Columns.TradedToday), "Traded Today", width: 100, horizontal_alignment: System.Windows.HorizontalAlignment.Center);
|
||||
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criterion {
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criteria {
|
||||
get {
|
||||
yield return new SortingCriteria(account.id, true);
|
||||
yield return new SortingCriteria(exchange.id, true);
|
||||
|
||||
@@ -622,7 +622,9 @@ namespace bts.shell.pnl {
|
||||
|
||||
static class PNLDataExtensions {
|
||||
public static string pnl_symbol(this SecurityImmutable security) {
|
||||
return bts.api.ExchangeSpecificUitlities.get_pnl_symbol(security);
|
||||
if(security.HasIce)
|
||||
return PNLICEHelper.get_symbol(security);
|
||||
return security.Symbol;
|
||||
}
|
||||
|
||||
// while override_cpp could use double.NaN to indicate the lack of an override,
|
||||
@@ -634,7 +636,7 @@ namespace bts.shell.pnl {
|
||||
|
||||
public static (double default_cpp, double? override_cpp) pnl_cpp_tuple(this PNLUnitImmutable pnl_unit, SecurityImmutable security) {
|
||||
// TODO: actual impl
|
||||
double calced_pnl = bts.api.ExchangeSpecificUitlities.get_cpp(pnl_unit,security);
|
||||
double calced_pnl = PNLICEHelper.get_cpp(pnl_unit,security);
|
||||
return (calced_pnl, pnl_unit.HasCppOverride ? pnl_unit.CppOverride.Value : (double?)null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using bts.api.position;
|
||||
using bts.utils;
|
||||
using mbts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
|
||||
namespace bts.shell.pnl {
|
||||
|
||||
static class PNLICEHelper{
|
||||
|
||||
public static bool is_spread(SecurityImmutable sec){
|
||||
return sec.HasSpread && sec.Ice.StripName.Contains("/");
|
||||
}
|
||||
|
||||
public static bool is_strip(SecurityImmutable sec){
|
||||
return sec.HasSpread && !is_spread(sec);
|
||||
}
|
||||
|
||||
public static bool is_ice_lots(SecurityImmutable sec){
|
||||
return sec.Ice.MarketDescription.Contains("ICE Lots");
|
||||
}
|
||||
|
||||
public static double get_future_cpp (SecurityImmutable sec){
|
||||
if(sec.Symbol == "HHD")
|
||||
return 1;
|
||||
if(is_ice_lots(sec))
|
||||
return 2500;
|
||||
else{
|
||||
var days_in_month = DateTime.DaysInMonth(Convert.ToInt32(sec.Future.ExpirationYear),
|
||||
Convert.ToInt32(sec.Future.ExpirationMonth));
|
||||
return days_in_month; // because the size is multiplied by 2500 already
|
||||
}
|
||||
}
|
||||
|
||||
public static double get_spread_cpp(SecurityImmutable sec){
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static double get_strip_cpp(PNLUnitImmutable pnl,
|
||||
SecurityImmutable sec){
|
||||
double rv = 0;
|
||||
foreach (var l in sec.Spread.Legs)
|
||||
if(l.Security.HasFuture)
|
||||
rv += get_cpp(pnl,l.Security);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static string get_symbol (SecurityImmutable sec){
|
||||
var rv = String.Format("{0}{1}{2}",
|
||||
sec.Symbol,
|
||||
is_ice_lots(sec)? " ICE LOTS" : String.Empty,
|
||||
is_spread(sec)? " Spread" : String.Empty);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static double get_cpp (PNLUnitImmutable pnl,
|
||||
SecurityImmutable sec){
|
||||
if (sec.HasGlbx)
|
||||
return pnl.CashValue;
|
||||
else if (sec.HasIce){
|
||||
if(sec.HasFuture)
|
||||
return get_future_cpp(sec);
|
||||
else if(is_spread(sec))
|
||||
return get_spread_cpp(sec);
|
||||
else if(is_strip(sec))
|
||||
return get_strip_cpp(pnl,sec);
|
||||
}
|
||||
return Double.NaN;
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -85,14 +85,14 @@ namespace bts.shell {
|
||||
Func<PNLSaveState> get_save_state = () => {
|
||||
var cols = cached_columns.ToArray(c => c.create());
|
||||
var filters = vm.get_filters_states();
|
||||
var sorting_criterion = vm.sorting_hierarchy.Select(tup => new SortingCriteria(tup.key.ToString(), tup.direction == ListSortDirection.Ascending)).ToArray();
|
||||
var sorting_criteria = vm.sorting_hierarchy.Select(tup => new SortingCriteria(tup.key.ToString(), tup.direction == ListSortDirection.Ascending)).ToArray();
|
||||
var calc_type = vm.calculation_type;
|
||||
var state = settings_manager.instance_settings;
|
||||
if (state == null) {
|
||||
// don't use defaults if the user manipulated the window state outside of the settings dialog (e.g., resized column(s) via drag, or changed sort/filter)
|
||||
var defaults = settings_manager.default_settings;
|
||||
if (calc_type == defaults.calculation_type &&
|
||||
defaults.sorting_criterion.SequenceEqual(sorting_criterion) &&
|
||||
defaults.sorting_criteria.SequenceEqual(sorting_criteria) &&
|
||||
defaults.grid.columns.SequenceEqual(cols) && defaults.filters.safe_equals(filters)) {
|
||||
// the user's current state still matches the defaults (i.e., no outside manipulation was performed); return null so this window will use the latest default settings when restored
|
||||
return new PNLSaveState { use_defaults = true, settings = null };
|
||||
@@ -101,7 +101,7 @@ namespace bts.shell {
|
||||
}
|
||||
// assign latest values, as they may have be modified outside of the settings dialog (in which case the settings manager would be out of date)
|
||||
state = state.with(
|
||||
sorting_criterion,
|
||||
sorting_criteria,
|
||||
vm.anchors,
|
||||
filters,
|
||||
state.grid.with(columns: cols, background: vm.grid_background_color.rgb_color()),
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace bts.shell.pnl {
|
||||
};
|
||||
|
||||
[ProtoMember(1)]
|
||||
SortingCriteria[] _sorting_criterion;
|
||||
SortingCriteria[] _sorting_criteria;
|
||||
[ProtoMember(5)]
|
||||
Columns[] _anchors;
|
||||
[ProtoMember(7)]
|
||||
@@ -106,7 +106,7 @@ namespace bts.shell.pnl {
|
||||
|
||||
public static PNLSettings Default =>
|
||||
new PNLSettings {
|
||||
_sorting_criterion = new[] {
|
||||
_sorting_criteria = new[] {
|
||||
new SortingCriteria(nameof(Columns.Account), true),
|
||||
new SortingCriteria(nameof(Columns.Security), true)
|
||||
},
|
||||
@@ -154,7 +154,7 @@ namespace bts.shell.pnl {
|
||||
public static GridSettings DefaultGridSettings =>
|
||||
GridSettings.Default.with(
|
||||
DefaultColumns.all,
|
||||
DefaultColumns.default_sorting_criterion,
|
||||
DefaultColumns.default_sorting_criteria,
|
||||
enable_background_color: true);
|
||||
|
||||
public static fills.FillsSettings DefaultAuxiliaryFills {
|
||||
@@ -289,8 +289,8 @@ namespace bts.shell.pnl {
|
||||
public PNLCellAppearance header_defaults => header_cell_appearance.to_appearance().merge(grid_defaults);
|
||||
public IReadOnlyList<PNLAnimationTriggerData> header_row_animations => _header_row_animations ?? (_header_row_animations = default_header_row_animations.ToArray());
|
||||
//
|
||||
public IReadOnlyList<SortingCriteria> sorting_criterion =>
|
||||
_sorting_criterion ?? (_sorting_criterion = DefaultColumns.default_sorting_criterion.ToArray());
|
||||
public IReadOnlyList<SortingCriteria> sorting_criteria =>
|
||||
_sorting_criteria ?? (_sorting_criteria = DefaultColumns.default_sorting_criteria.ToArray());
|
||||
|
||||
PNLCellAppearanceProto _grid_cell_appearance => _grid_cell_appearance_backing ?? (
|
||||
_grid_cell_appearance_backing = new PNLCellAppearanceProto {
|
||||
@@ -305,7 +305,7 @@ namespace bts.shell.pnl {
|
||||
});
|
||||
|
||||
public PNLSettings with(
|
||||
IEnumerable<SortingCriteria> sorting_criterion = null,
|
||||
IEnumerable<SortingCriteria> sorting_criteria = null,
|
||||
IEnumerable<Columns> anchors = null,
|
||||
FilterStates filters = null,
|
||||
GridSettings grid = null,
|
||||
@@ -323,7 +323,7 @@ namespace bts.shell.pnl {
|
||||
header_row_display = header_row_display ?? this.header_row_display,
|
||||
// row operators (anchors, sorting, filters)
|
||||
_anchors = (anchors ?? _anchors.empty_if_null()).ToArray(),
|
||||
_sorting_criterion = (sorting_criterion ?? _sorting_criterion.empty_if_null()).ToArray(),
|
||||
_sorting_criteria = (sorting_criteria ?? _sorting_criteria.empty_if_null()).ToArray(),
|
||||
filters = filters ?? this.filters,
|
||||
// cell appearance (group/header)
|
||||
_group_background_colors = _group_background_colors?.ToList(),
|
||||
@@ -349,7 +349,7 @@ namespace bts.shell.pnl {
|
||||
data_formatting.safe_equals(other.data_formatting) &&
|
||||
// row operators (anchors, sorting, filters)
|
||||
anchors.SequenceEqual(other.anchors) &&
|
||||
sorting_criterion.SequenceEqual(other.sorting_criterion) &&
|
||||
sorting_criteria.SequenceEqual(other.sorting_criteria) &&
|
||||
filters.safe_equals(other.filters) &&
|
||||
// cell appearance (group/header)
|
||||
group_background_colors.SequenceEqual(other.group_background_colors) &&
|
||||
@@ -431,7 +431,7 @@ namespace bts.shell.pnl {
|
||||
public static GridColumnSettings settlement_price => new GridColumnSettings(nameof(Columns.SettlementPrice), DefaultColumnHeaders.Settlement, false, width: DefaultColumnWidths.Settlement, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings pnl_price => new GridColumnSettings(nameof(Columns.PNLPrice), DefaultColumnHeaders.PnLPrice, width: DefaultColumnWidths.Price, horizontal_alignment: HorizontalAlignment.Right);
|
||||
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criterion {
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criteria {
|
||||
get {
|
||||
yield return new SortingCriteria(account.id, true);
|
||||
yield return new SortingCriteria(security.id, true);
|
||||
|
||||
@@ -118,7 +118,15 @@ namespace bts.shell.pnl {
|
||||
).FilterWithRaw(filter_src, PNLRowData.key_fn, null)
|
||||
.OnDispatcher()
|
||||
.Subscribe(_update),
|
||||
_symbols_source(pnl_source).OnDispatcher().Subscribe(symbol_filter_items_observer),
|
||||
// Note: the symbol filter items don't really need to be an IObservable
|
||||
// (the symbol items used to be extracted from the IObservable pnl_source).
|
||||
// It is only an IObservable now due to legacy; the filter was designed to observe incremental updates.
|
||||
// This is can be easily changed if need be.
|
||||
Observable.Return(
|
||||
TableUpdate<string, string>.mk_empty(sym => sym).with_added(
|
||||
SecurityHelper.get_all_display_symbols()))
|
||||
.OnDispatcher()
|
||||
.Subscribe(symbol_filter_items_observer),
|
||||
Disposable.Create(() => {
|
||||
foreach (var f in _all_filters)
|
||||
f.filter_changed -= _refresh_filter.execute;
|
||||
@@ -369,7 +377,7 @@ namespace bts.shell.pnl {
|
||||
}
|
||||
anchors.sync_with(settings.anchors);
|
||||
header_row_display = settings.header_row_display;
|
||||
sorting_hierarchy = DIYGridSortHelper.convert_sorting_criterion<ColumnKeys>(settings.sorting_criterion).ToList();
|
||||
sorting_hierarchy = DIYGridSortHelper.convert_sorting_criteria<ColumnKeys>(settings.sorting_criteria).ToList();
|
||||
// group background colors
|
||||
_group_background_converter = new AlternationConverter();
|
||||
_group_background_converter.Values.AddRange(settings.group_background_colors.Select(c => c.argb_color()));
|
||||
|
||||
@@ -337,8 +337,8 @@ namespace mbts.spark {
|
||||
public IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_algos(SecurityImmutable security, bool attachable_only = false) =>
|
||||
(attachable_only ? _attachable_algo_provider : _algo_provider).subscribe_algos(security);
|
||||
|
||||
public IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_complete_algos(bool attachable_only = false, bool allow_undefined_child = false) =>
|
||||
(attachable_only ? _attachable_algo_provider : _algo_provider).subscribe_complete_algos(allow_undefined_child);
|
||||
public IObservable<TableUpdate<AlgoData, AlgoKey>> subscribe_complete_algos(bool attachable_only = false) =>
|
||||
(attachable_only ? _attachable_algo_provider : _algo_provider).subscribe_complete_algos();
|
||||
#endregion
|
||||
|
||||
#region Input
|
||||
|
||||
@@ -44,17 +44,17 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
static class TradesSource {
|
||||
public static IEnumerable<Product> aggregate_security_criteria(IEnumerable<SecurityImmutable> securities, IEnumerable<SecurityCriteria> security_criterion) =>
|
||||
securities.Where(s => security_criterion.Any(sc => ContractPickerModel.security_in_criteria(sc, s)))
|
||||
public static IEnumerable<Product> aggregate_security_criteria(IEnumerable<SecurityImmutable> securities, IEnumerable<SecurityCriteria> security_criteria) =>
|
||||
securities.Where(s => security_criteria.Any(sc => ContractPickerModel.security_in_criteria(sc, s)))
|
||||
.Select(Product.from_security)
|
||||
.Distinct();
|
||||
|
||||
public static IObservable<IReadOnlyList<TradeInfo>> create(MDConsumer consumer, IObservable<IReadOnlyDictionary<uint, SecurityImmutable>> security_map, IObservable<IEnumerable<SecurityCriteria>> security_criterion, TimeSpan poll_interval) =>
|
||||
security_criterion.CombineLatest(security_map, (criterion, map) => (criterion, map))
|
||||
public static IObservable<IReadOnlyList<TradeInfo>> create(MDConsumer consumer, IObservable<IReadOnlyDictionary<uint, SecurityImmutable>> security_map, IObservable<IEnumerable<SecurityCriteria>> security_criteria, TimeSpan poll_interval) =>
|
||||
security_criteria.CombineLatest(security_map, (criterion, map) => (criterion, map))
|
||||
.Scan((channels: ImmutableDictionary<Product, ChannelConsumer>.Empty, active: new List<ChannelConsumer>(0)), (channel_data, data) => {
|
||||
var (criterion, map) = data;
|
||||
var (criteria, map) = data;
|
||||
var (channels, active) = channel_data;
|
||||
var products = aggregate_security_criteria(map.Values, criterion);
|
||||
var products = aggregate_security_criteria(map.Values, criteria);
|
||||
active = new List<ChannelConsumer>();
|
||||
foreach (var p in products) {
|
||||
if (!channels.TryGetValue(p, out var c)) {
|
||||
|
||||
@@ -68,8 +68,8 @@ namespace mbts.ui.controls {
|
||||
.to_comparer();
|
||||
}
|
||||
|
||||
public static IEnumerable<(TKey key, ListSortDirection direction)> convert_sorting_criterion<TKey>(IEnumerable<SortingCriteria> sorting_criterion) where TKey : struct {
|
||||
foreach (var sc in sorting_criterion) {
|
||||
public static IEnumerable<(TKey key, ListSortDirection direction)> convert_sorting_criteria<TKey>(IEnumerable<SortingCriteria> sorting_criteria) where TKey : struct {
|
||||
foreach (var sc in sorting_criteria) {
|
||||
if (Enum.TryParse(sc.col_name, false, out TKey key))
|
||||
yield return (key, sc.direction());
|
||||
}
|
||||
|
||||
@@ -76,9 +76,9 @@ namespace mbts.ui.settings {
|
||||
// columns
|
||||
[ProtoMember(6)]
|
||||
List<GridColumnSettings> _columns;
|
||||
// sorting criterion
|
||||
// sorting criteria
|
||||
[ProtoMember(7)]
|
||||
List<SortingCriteria> _sorting_criterion;
|
||||
List<SortingCriteria> _sorting_criteria;
|
||||
// background
|
||||
[ProtoMember(8)]
|
||||
[DefaultValue(_default_background)]
|
||||
@@ -103,7 +103,7 @@ namespace mbts.ui.settings {
|
||||
uint font_color = _default_font_color,
|
||||
ColorOpacityProto? selection_highlight = null,
|
||||
IEnumerable<GridColumnSettings> columns = null,
|
||||
IEnumerable<SortingCriteria> sorting_criterion = null,
|
||||
IEnumerable<SortingCriteria> sorting_criteria = null,
|
||||
uint background = _default_background,
|
||||
bool enable_background_color = _default_enable_background_color) {
|
||||
//
|
||||
@@ -113,7 +113,7 @@ namespace mbts.ui.settings {
|
||||
_font_weight = (ushort)font_weight.ToOpenTypeWeight();
|
||||
_selection_highlight = selection_highlight ?? new ColorOpacityProto(0, 1);
|
||||
_columns = new List<GridColumnSettings>(columns.empty_if_null());
|
||||
_sorting_criterion = new List<SortingCriteria>(sorting_criterion.empty_if_null());
|
||||
_sorting_criteria = new List<SortingCriteria>(sorting_criteria.empty_if_null());
|
||||
_background = background;
|
||||
_enable_background_color = enable_background_color;
|
||||
}
|
||||
@@ -127,15 +127,15 @@ namespace mbts.ui.settings {
|
||||
public uint background_color => _background;
|
||||
public bool enable_background_color => _enable_background_color;
|
||||
public IReadOnlyList<GridColumnSettings> columns => _columns ?? (_columns = new List<GridColumnSettings>(0));
|
||||
[Obsolete] // TODO: remove sorting_criterion from GridSettings entirely. This should be part of IShellWindow's StartupData, since it is an instance-specific setting, and prob not part of the shared defaults
|
||||
public IReadOnlyList<SortingCriteria> sorting_criterion => _sorting_criterion ?? (_sorting_criterion = new List<SortingCriteria>(0));
|
||||
[Obsolete] // TODO: remove sorting_criteria from GridSettings entirely. This should be part of IShellWindow's StartupData, since it is an instance-specific setting, and prob not part of the shared defaults
|
||||
public IReadOnlyList<SortingCriteria> sorting_criteria => _sorting_criteria ?? (_sorting_criteria = new List<SortingCriteria>(0));
|
||||
|
||||
public static GridSettings get_default() =>
|
||||
new GridSettings(_default_font_family, _default_font_size, FontWeights.Normal, _default_font_color, new ColorOpacityProto(Colors.MediumSlateBlue, 0.4));
|
||||
|
||||
public GridSettings with(
|
||||
IEnumerable<GridColumnSettings> columns = null,
|
||||
IEnumerable<SortingCriteria> sorting_criterion = null,
|
||||
IEnumerable<SortingCriteria> sorting_criteria = null,
|
||||
string font_family = null,
|
||||
double font_size = double.NaN,
|
||||
uint? background = null,
|
||||
@@ -147,7 +147,7 @@ namespace mbts.ui.settings {
|
||||
_font_color,
|
||||
_selection_highlight,
|
||||
columns ?? _columns,
|
||||
sorting_criterion ?? _sorting_criterion,
|
||||
sorting_criteria ?? _sorting_criteria,
|
||||
background ?? _background,
|
||||
enable_background_color ?? _enable_background_color);
|
||||
|
||||
@@ -164,7 +164,7 @@ namespace mbts.ui.settings {
|
||||
_enable_background_color == other._enable_background_color &&
|
||||
EqualityComparer.safe_sequence_equals(columns, other.columns) &&
|
||||
#pragma warning disable CS0612 // Type or member is obsolete
|
||||
EqualityComparer.safe_sequence_equals(sorting_criterion, other.sorting_criterion);
|
||||
EqualityComparer.safe_sequence_equals(sorting_criteria, other.sorting_criteria);
|
||||
#pragma warning restore CS0612 // Type or member is obsolete
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
@@ -181,7 +181,7 @@ namespace mbts.ui.settings {
|
||||
_enable_background_color.GetHashCode(),
|
||||
EqualityComparer.safe_aggregate_hash(columns),
|
||||
#pragma warning disable CS0612 // Type or member is obsolete
|
||||
EqualityComparer.safe_aggregate_hash(sorting_criterion));
|
||||
EqualityComparer.safe_aggregate_hash(sorting_criteria));
|
||||
#pragma warning restore CS0612 // Type or member is obsolete
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,14 +54,14 @@ namespace mbts.ui.settings {
|
||||
public static string fmt_col_id<TColKey>(TColKey key) where TColKey : struct =>
|
||||
key.ToString();
|
||||
|
||||
public static void normalize_sorting_criterion<TColKey>(IEnumerable<SortingCriteria> sorting_criterion, IReadOnlyDictionary<string, TColKey> sort_member_to_id) where TColKey : struct =>
|
||||
normalize_sorting_criterion(sorting_criterion, new Func<string, TColKey?>[] {
|
||||
public static void normalize_sorting_criteria<TColKey>(IEnumerable<SortingCriteria> sorting_criteria, IReadOnlyDictionary<string, TColKey> sort_member_to_id) where TColKey : struct =>
|
||||
normalize_sorting_criteria(sorting_criteria, new Func<string, TColKey?>[] {
|
||||
parse_col_id<TColKey>,
|
||||
col_name => sort_member_to_id.TryGetValue(col_name, out var k) ? k : (TColKey?)null
|
||||
});
|
||||
|
||||
public static void normalize_sorting_criterion<TColKey>(IEnumerable<SortingCriteria> sorting_criterion, IEnumerable<Func<string, TColKey?>> conversion_dels) where TColKey : struct {
|
||||
foreach (var sc in sorting_criterion) {
|
||||
public static void normalize_sorting_criteria<TColKey>(IEnumerable<SortingCriteria> sorting_criteria, IEnumerable<Func<string, TColKey?>> conversion_dels) where TColKey : struct {
|
||||
foreach (var sc in sorting_criteria) {
|
||||
sc.col_name = conversion_dels
|
||||
.Select(del => del(sc.col_name))
|
||||
.FirstOrDefault(k => k.HasValue)?.ToString() ?? sc.col_name;
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace mbts.ui.controls {
|
||||
public Func<T, bool> filter { get; private set; }
|
||||
|
||||
public TFiltersState get_filters() => _filters.create();
|
||||
public IEnumerable<SortingCriteria> get_sorting_criterion() => _sorting.create();
|
||||
public IEnumerable<SortingCriteria> get_sorting_criteria() => _sorting.create();
|
||||
|
||||
public void on_sorting(DIYGridSortingEventArgs e) => _sorting.on_sorting(e);
|
||||
public void on_settings(TFiltersState filters, IEnumerable<SortingCriteria> sorting) {
|
||||
|
||||
@@ -54,13 +54,13 @@ namespace mbts.ui.controls {
|
||||
).to_comparer();
|
||||
}
|
||||
|
||||
public void load_from(IEnumerable<SortingCriteria> sorting_criterion) {
|
||||
public void load_from(IEnumerable<SortingCriteria> sorting_criteria) {
|
||||
var sort_member_to_id = _map
|
||||
.Where(kv => !string.IsNullOrEmpty(kv.Value.col.sort_member_path))
|
||||
.Distinct()
|
||||
.ToDictionary(kv => kv.Value.col.sort_member_path, kv => kv.Key);
|
||||
GridSettingsHelper.normalize_sorting_criterion(sorting_criterion, sort_member_to_id);
|
||||
_on_settings(sorting_criterion
|
||||
GridSettingsHelper.normalize_sorting_criteria(sorting_criteria, sort_member_to_id);
|
||||
_on_settings(sorting_criteria
|
||||
.Select(sc => (GridSettingsHelper.parse_col_id<TColKey>(sc.col_name), sc.is_ascending ? ListSortDirection.Ascending : ListSortDirection.Descending))
|
||||
.Where(t => t.Item1.HasValue)
|
||||
.Select(t => (t.Item1.Value, t.Item2)));
|
||||
|
||||
@@ -64,25 +64,6 @@ namespace mbts.ui {
|
||||
}
|
||||
}, can_execute == null ? null : new Func<object, bool>(_ => can_execute()));
|
||||
|
||||
public static IDialogCommand export_csv(
|
||||
Func<string> get_file_content,
|
||||
string source_window_name) =>
|
||||
new AnonymousFileDialogCommand<object>(_ =>
|
||||
_create_save_file_dialog(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
|
||||
$"BTS_Spark_{source_window_name}_{DateTime.Now.ToString("yyyyMMdd_HHmm")}.csv",
|
||||
new[] { ("CSV (comma delimited)", new string[] { "csv" }) }
|
||||
),
|
||||
(_, file) => {
|
||||
try {
|
||||
File.WriteAllText(file, get_file_content.Invoke());
|
||||
} catch (Exception ex) {
|
||||
BTSMessageBox.Show($"Error exporting data to csv: {ex}.", "CSV Export Error", BTSMessageBoxButtons.OK, System.Windows.MessageBoxImage.Error, true, false, true);
|
||||
}
|
||||
},
|
||||
// we are always able to perform an export, even when no rows (it will just be a header)
|
||||
(_) => true);
|
||||
|
||||
static TDialog _create_file_dialog<TDialog>(string initial_dir = null, IReadOnlyList<(string name, string[] extensions)> filter_items = null) where TDialog : FileDialog, new() {
|
||||
var rv = new TDialog();
|
||||
if (!string.IsNullOrEmpty(initial_dir))
|
||||
|
||||
@@ -372,11 +372,11 @@ namespace mbts.ui {
|
||||
on sd.PropertyName equals col.path
|
||||
select new SortingCriteria(col.id, sd.Direction == ListSortDirection.Ascending);
|
||||
|
||||
public static IEnumerable<SortDescription> get_sort_descriptions(this IEnumerable<SortingCriteria> sorting_criterion, IEnumerable<DataGridColumn> columns) =>
|
||||
get_sort_descriptions(sorting_criterion, columns.Select(c => (controls.DataGridEx.GetCellKey(c)?.ToString(), c.SortMemberPath)));
|
||||
public static IEnumerable<SortDescription> get_sort_descriptions(this IEnumerable<SortingCriteria> sorting_criteria, IEnumerable<DataGridColumn> columns) =>
|
||||
get_sort_descriptions(sorting_criteria, columns.Select(c => (controls.DataGridEx.GetCellKey(c)?.ToString(), c.SortMemberPath)));
|
||||
|
||||
public static IEnumerable<SortDescription> get_sort_descriptions(this IEnumerable<SortingCriteria> sorting_criterion, IEnumerable<(string id, string path)> columns) =>
|
||||
from sc in sorting_criterion
|
||||
public static IEnumerable<SortDescription> get_sort_descriptions(this IEnumerable<SortingCriteria> sorting_criteria, IEnumerable<(string id, string path)> columns) =>
|
||||
from sc in sorting_criteria
|
||||
join col in columns
|
||||
on sc.col_name equals col.id
|
||||
select new SortDescription(col.path, sc.direction());
|
||||
@@ -384,9 +384,9 @@ namespace mbts.ui {
|
||||
/// <summary>
|
||||
/// Converts each <see cref="SortingCriteria"/> into a <see cref="SortDescription"/> and assigns the result to <paramref name="collection_view"/>.SortDescriptions.
|
||||
/// </summary>
|
||||
public static void set_sort_descriptions(this ICollectionView collection_view, IEnumerable<SortingCriteria> sorting_criterion, ObservableCollection<controls.DIYGrid.ColumnBase> columns) {
|
||||
public static void set_sort_descriptions(this ICollectionView collection_view, IEnumerable<SortingCriteria> sorting_criteria, ObservableCollection<controls.DIYGrid.ColumnBase> columns) {
|
||||
using (collection_view.DeferRefresh()) {
|
||||
collection_view.SortDescriptions.SetItems(sorting_criterion.empty_if_null()
|
||||
collection_view.SortDescriptions.SetItems(sorting_criteria.empty_if_null()
|
||||
.Select(sc => new SortDescription(
|
||||
columns.FirstOrDefault(c => string.Equals(c.id, sc.col_name, StringComparison.CurrentCultureIgnoreCase))?.sort_member_path,
|
||||
sc.is_ascending ? ListSortDirection.Ascending : ListSortDirection.Descending))
|
||||
@@ -394,18 +394,18 @@ namespace mbts.ui {
|
||||
}
|
||||
}
|
||||
|
||||
public static IObservable<IReadOnlyList<SortingCriteria>> subscribe_sorting_criterion(this ICollectionView collection_view, Func<string, string> sort_member_to_id) =>
|
||||
public static IObservable<IReadOnlyList<SortingCriteria>> subscribe_sorting_criteria(this ICollectionView collection_view, Func<string, string> sort_member_to_id) =>
|
||||
Observable.Create<IReadOnlyList<SortingCriteria>>(o => {
|
||||
INotifyCollectionChanged notification_src = collection_view.SortDescriptions;
|
||||
IList<SortDescription> sort_descriptions = collection_view.SortDescriptions;
|
||||
var sorting_criterion = sort_descriptions.Select(to_criteria).ToList();
|
||||
var sorting_criteria = sort_descriptions.Select(to_criteria).ToList();
|
||||
notification_src.CollectionChanged += on_sort_descriptions_changed;
|
||||
o.OnNext(sorting_criterion);
|
||||
o.OnNext(sorting_criteria);
|
||||
return Disposable.Create(dispose);
|
||||
// local methods
|
||||
void on_sort_descriptions_changed(object sender, NotifyCollectionChangedEventArgs e) {
|
||||
CollectionHelper.reflect_change(sorting_criterion, collection_view.SortDescriptions, to_criteria, null, e);
|
||||
o.OnNext(sorting_criterion);
|
||||
CollectionHelper.reflect_change(sorting_criteria, collection_view.SortDescriptions, to_criteria, null, e);
|
||||
o.OnNext(sorting_criteria);
|
||||
}
|
||||
SortingCriteria to_criteria(SortDescription sd) => new SortingCriteria(sort_member_to_id(sd.PropertyName), sd.Direction == ListSortDirection.Ascending);
|
||||
void dispose() => notification_src.CollectionChanged -= on_sort_descriptions_changed;
|
||||
|
||||
@@ -169,7 +169,7 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
// restore sort state or supply default value
|
||||
pnl_view.set_sort_descriptions(startup_data.sorting_criterion, columns);
|
||||
pnl_view.set_sort_descriptions(startup_data.sorting_criteria, columns);
|
||||
|
||||
var col_settings_flags = new Dictionary<string, GridColumnSettingsFeatureFlags> {
|
||||
{ Columns.StartPNL.ToString(), GridColumnSettingsFeatureFlags.ImmutableFontColor },
|
||||
|
||||
@@ -259,7 +259,6 @@ namespace mbts.co2 {
|
||||
}
|
||||
}
|
||||
|
||||
// If Size is wrong remember to update from
|
||||
[StructLayout(LayoutKind.Sequential, Size = 704)]
|
||||
internal struct ColdEntry {
|
||||
public int exchange_status;
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using bts.api.position;
|
||||
using bts.utils;
|
||||
using mbts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
|
||||
namespace bts.api {
|
||||
|
||||
static class ExchangeSpecificUitlities{
|
||||
private static string _default_hub = "Henry";
|
||||
static class ICE{
|
||||
|
||||
#region Contract Type
|
||||
public static bool is_spread(SecurityImmutable sec){
|
||||
return sec.HasSpread && sec.Ice.StripName.Contains("/");
|
||||
}
|
||||
|
||||
public static bool is_strip(SecurityImmutable sec){
|
||||
return sec.HasSpread && !is_spread(sec);
|
||||
}
|
||||
|
||||
public static bool is_ice_lots(SecurityImmutable sec){
|
||||
return sec.Ice.MarketDescription.Contains("ICE Lots");
|
||||
}
|
||||
|
||||
public static bool is_tas(SecurityImmutable sec){
|
||||
return sec.Ice.MarketDescription.Contains("TAS");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CPP
|
||||
public static double get_future_cpp (SecurityImmutable sec){
|
||||
if(sec.Symbol == "HHD")
|
||||
// only futures in HHD are the dailies, everything
|
||||
// else is a strip or spread
|
||||
return 1;
|
||||
if(is_ice_lots(sec))
|
||||
return 2500;
|
||||
else{
|
||||
var days_in_month = DateTime.DaysInMonth(Convert.ToInt32(sec.Future.ExpirationYear),
|
||||
Convert.ToInt32(sec.Future.ExpirationMonth));
|
||||
return days_in_month; // because the size is multiplied by 2500 already
|
||||
}
|
||||
}
|
||||
|
||||
public static double get_spread_cpp(SecurityImmutable sec){
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static double get_strip_cpp(PNLUnitImmutable pnl,
|
||||
SecurityImmutable sec){
|
||||
// add up all the legs
|
||||
double rv = 0;
|
||||
foreach (var l in sec.Spread.Legs)
|
||||
if(l.Security.HasFuture)
|
||||
rv += get_cpp(pnl,l.Security);
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static double get_cpp (PNLUnitImmutable pnl,
|
||||
SecurityImmutable sec){
|
||||
if(sec.HasFuture)
|
||||
return get_future_cpp(sec);
|
||||
else if(is_spread(sec))
|
||||
return get_spread_cpp(sec);
|
||||
else if(is_strip(sec))
|
||||
return get_strip_cpp(pnl,sec);
|
||||
return Double.NaN;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Symbol
|
||||
public static string get_pnl_symbol (SecurityImmutable sec){
|
||||
// for pnl purposes, for a symbol, the division is :
|
||||
// Futures and Strips
|
||||
// ICE Lots
|
||||
// Spreads
|
||||
var rv = String.Format("{0}{1}{2}",
|
||||
sec.Symbol,
|
||||
is_ice_lots(sec)? " ICE LOTS" : String.Empty,
|
||||
is_spread(sec)? " Spread" : String.Empty);
|
||||
return rv;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Formatting
|
||||
public static string format_security (SecurityImmutable? security){
|
||||
if(security.HasValue && security.Value.HasIce){
|
||||
bool ice_lots = is_ice_lots(security.Value),
|
||||
tas = is_tas(security.Value);
|
||||
return String.Format("{0}{1}{2}{3}{4}",
|
||||
security?.Symbol,
|
||||
ice_lots? " ICE Lots" : String.Empty,
|
||||
tas ? " TAS" : String.Empty,
|
||||
String.Compare(security.Value.Ice.HubAlias, _default_hub,true)==0 ? String.Empty :
|
||||
" " + security.Value.Ice.HubAlias,
|
||||
" " + security?.Ice.StripName);
|
||||
}
|
||||
return String.Empty;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
public static double get_cpp (PNLUnitImmutable pnl,
|
||||
SecurityImmutable sec){
|
||||
if(sec.HasIce)
|
||||
return ICE.get_cpp(pnl,sec);
|
||||
return pnl.CashValue;
|
||||
}
|
||||
|
||||
public static string get_pnl_symbol (SecurityImmutable sec){
|
||||
if(sec.HasIce)
|
||||
return ICE.get_pnl_symbol(sec);
|
||||
return sec.Symbol;
|
||||
}
|
||||
|
||||
public static string format_security(SecurityImmutable? security){
|
||||
if(security?.HasIce == true)
|
||||
return ICE.format_security(security);
|
||||
return security?.ToString();
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -11,5 +11,8 @@ namespace bts.api {
|
||||
default: return SecurityType.Unset;
|
||||
}
|
||||
}
|
||||
|
||||
public static string display_symbol(this SecurityImmutable security) =>
|
||||
SecurityHelper.get_display_symbol(security);
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ namespace bts.api {
|
||||
switch (security?.ContractCase) {
|
||||
case ContractOneofCase.Future:
|
||||
if(security?.HasIce == true)
|
||||
return bts.api.ExchangeSpecificUitlities.format_security(security);
|
||||
return _format_ICE(security);
|
||||
return format_future(security?.Symbol, security?.security_desc(), security.Value.Future);
|
||||
case ContractOneofCase.Spread:
|
||||
if (security?.HasGlbx == true) {
|
||||
@@ -50,7 +50,7 @@ namespace bts.api {
|
||||
return security?.Glbx.SecurityDesc;
|
||||
}
|
||||
else if(security?.HasIce == true)
|
||||
return bts.api.ExchangeSpecificUitlities.format_security(security);
|
||||
return _format_ICE(security);
|
||||
return string.Join("", _format_future_legs(SecurityHelper.get_flat_future_legs(security?.Spread.Legs)));
|
||||
case ContractOneofCase.Synthetic: return security?.Synthetic.Name;
|
||||
default: return "Unknown-security";
|
||||
@@ -84,5 +84,28 @@ namespace bts.api {
|
||||
default: return $"{fl.quantity:+0;-0}{sym_exp_name}";
|
||||
}
|
||||
}
|
||||
|
||||
static string _format_ICE (SecurityImmutable? security){
|
||||
string symbol = security?.Symbol,
|
||||
strip = security?.Ice.StripName,
|
||||
md_desc = security?.Ice.MarketDescription,
|
||||
type_append = "";
|
||||
|
||||
if(md_desc.Contains("25k ICE Lots")){
|
||||
if(md_desc.Contains("TAS"))
|
||||
type_append = "TAS";
|
||||
}
|
||||
else if(md_desc.Contains("ICE Lots")){
|
||||
if(md_desc.Contains("TAS"))
|
||||
type_append = "ICE Lots TAS";
|
||||
else
|
||||
type_append = "ICE Lots";
|
||||
}
|
||||
else if(md_desc.Contains("TAS"))
|
||||
type_append = "TAS";
|
||||
type_append = string.IsNullOrEmpty(type_append) ?
|
||||
" " : $" {type_append} ";
|
||||
return $"{symbol}{type_append}{strip}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,24 @@
|
||||
using System;
|
||||
using mbts.co2;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using static bts.api.Security;
|
||||
|
||||
namespace bts.api {
|
||||
internal static class SecurityHelper {
|
||||
public static IEnumerable<string> get_all_display_symbols() =>
|
||||
get_all_display_symbols(UserSymbol.get_all().Select(usym => usym.symbol));
|
||||
|
||||
public static IEnumerable<string> get_all_display_symbols(IEnumerable<string> system_symbols) {
|
||||
// todo: actual impl
|
||||
return system_symbols;
|
||||
}
|
||||
|
||||
public static string get_display_symbol(SecurityImmutable security) {
|
||||
// todo: actual impl
|
||||
return security.Symbol;
|
||||
}
|
||||
|
||||
public static IEnumerable<FutureLeg> get_flat_future_legs(SecurityImmutable sec) {
|
||||
switch (sec.ContractCase) {
|
||||
case ContractOneofCase.Spread: return _get_flat_future_legs(sec.Spread.Legs, 1);
|
||||
@@ -83,37 +97,26 @@ namespace bts.api {
|
||||
}
|
||||
|
||||
public static int Compare(SecurityImmutable x, SecurityImmutable y) {
|
||||
int c = non_deterministic_impl();
|
||||
if (c == 0) {
|
||||
c = x.ToString().CompareTo(y.ToString());
|
||||
if (c == 0)
|
||||
c = x.Id.CompareTo(y.Id);
|
||||
if (x.ContractCase == ContractOneofCase.Future) {
|
||||
return y.ContractCase == ContractOneofCase.Future ? Compare(x.Symbol, x.Future, y.Symbol, y.Future) : -1;
|
||||
} else if (y.ContractCase == ContractOneofCase.Future) {
|
||||
return 1;
|
||||
}
|
||||
return c;
|
||||
// this has been observed to be non-determinisitc with certain ICE securities
|
||||
// (it is determenistic with other exchanges..as far as we know).
|
||||
int non_deterministic_impl() {
|
||||
if (x.ContractCase == ContractOneofCase.Future) {
|
||||
return y.ContractCase == ContractOneofCase.Future ? Compare(x.Symbol, x.Future, y.Symbol, y.Future) : -1;
|
||||
} else if (y.ContractCase == ContractOneofCase.Future) {
|
||||
return 1;
|
||||
}
|
||||
var xlegs = get_flat_future_legs(x).ToList();
|
||||
var ylegs = get_flat_future_legs(y).ToList();
|
||||
int max = Math.Min(xlegs.Count, ylegs.Count);
|
||||
for (int i = 0; i < max; i++) {
|
||||
int rv = Compare(xlegs[i].symbol, xlegs[i].future, ylegs[i].symbol, ylegs[i].future);
|
||||
if (rv != 0)
|
||||
return rv;
|
||||
rv = xlegs[i].quantity.CompareTo(ylegs[i].quantity);
|
||||
if (rv != 0)
|
||||
return rv;
|
||||
rv = xlegs[i].exchange.CompareTo(ylegs[i].exchange);
|
||||
if (rv != 0)
|
||||
return rv;
|
||||
}
|
||||
return xlegs.Count.CompareTo(ylegs.Count);
|
||||
var xlegs = get_flat_future_legs(x).ToList();
|
||||
var ylegs = get_flat_future_legs(y).ToList();
|
||||
int max = Math.Min(xlegs.Count, ylegs.Count);
|
||||
for (int i = 0; i < max; i++) {
|
||||
int rv = Compare(xlegs[i].symbol, xlegs[i].future, ylegs[i].symbol, ylegs[i].future);
|
||||
if (rv != 0)
|
||||
return rv;
|
||||
rv = xlegs[i].quantity.CompareTo(ylegs[i].quantity);
|
||||
if (rv != 0)
|
||||
return rv;
|
||||
rv = xlegs[i].exchange.CompareTo(ylegs[i].exchange);
|
||||
if (rv != 0)
|
||||
return rv;
|
||||
}
|
||||
return xlegs.Count.CompareTo(ylegs.Count);
|
||||
}
|
||||
|
||||
public static int Compare(string x_sym, FutureContract x, string y_sym, FutureContract y) {
|
||||
@@ -127,4 +130,4 @@ namespace bts.api {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,6 @@ namespace bts {
|
||||
Plugin,
|
||||
Sdk,
|
||||
Http,
|
||||
iLink3
|
||||
// Please keep this list in sync with logging.h/logging.cpp
|
||||
}
|
||||
|
||||
|
||||
@@ -7,22 +7,6 @@ using System.Reactive.Linq;
|
||||
|
||||
namespace System.Collections.Generic {
|
||||
public static class EnumerableExtensions {
|
||||
/// <summary>
|
||||
/// Determines whether all elements of a sequence are true.
|
||||
/// </summary>
|
||||
/// <param name="source">An <see cref="IEnumerable{bool}"/> that contains the elements to which to apply the predicate.</param>
|
||||
/// <returns>True if every element of the source sequence is true, or if the sequence is empty; otherwise false.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null</exception>
|
||||
public static bool All(this IEnumerable<bool> source) {
|
||||
if (source is null)
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
foreach (var v in source) {
|
||||
if (!v)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Similar to <see cref="Enumerable.All{TSource}(IEnumerable{TSource}, Func{TSource, bool})"/>, but returns false if the <paramref name="source"/> is empty.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace bts.utils.csv {
|
||||
public static class CsvHelper {
|
||||
|
||||
public static string ToCsv<T>(this IEnumerable<T> items, OrderedDictionary properties = null) where T : class {
|
||||
var output = "";
|
||||
var delimiter = ",";
|
||||
if (properties == null) {
|
||||
properties = new OrderedDictionary();
|
||||
foreach (var pi in typeof(T).GetProperties()) {
|
||||
properties.Add(pi.Name, pi);
|
||||
}
|
||||
}
|
||||
|
||||
using (var sw = new StringWriter()) {
|
||||
var dict_values = properties.Values.OfType<PropertyInfo>();
|
||||
var header = dict_values.Select(n => n.Name).Aggregate((first, second) => first + delimiter + second);
|
||||
sw.WriteLine(header);
|
||||
foreach (var i in items) {
|
||||
var row = dict_values.Select(x => x.GetValue(i, null))
|
||||
.Select(x => x == null ? "null" : x.ToString())
|
||||
.Aggregate((first, second) => first + delimiter + second);
|
||||
sw.WriteLine(row);
|
||||
}
|
||||
output = sw.ToString();
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public static OrderedDictionary create_ordering_maintainer(Type t, string[] property_names_in_order) {
|
||||
OrderedDictionary od = new OrderedDictionary();
|
||||
var props = t.GetProperties();
|
||||
foreach (var n in property_names_in_order) {
|
||||
var query = props.Where(pi => pi.Name == n);
|
||||
if (query.Any()) {
|
||||
var property_info = query.First();
|
||||
if (!od.Contains(property_info)) {
|
||||
od.Add(n, property_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
return od;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -1,5 +1,4 @@
|
||||
using bts.api;
|
||||
using bts.collections;
|
||||
using bts.resources;
|
||||
using bts.test;
|
||||
using bts.utils.proto;
|
||||
@@ -11,6 +10,7 @@ namespace bts.mcore {
|
||||
class SecurityTests {
|
||||
[Test]
|
||||
public void test_security_equal() {
|
||||
|
||||
SecurityImmutable a = new SecurityImmutable(new Security() { Id = 42 });
|
||||
SecurityImmutable b = new SecurityImmutable(new Security() { Id = 42 });
|
||||
SecurityImmutable c = new SecurityImmutable(new Security() { Id = 4 });
|
||||
@@ -29,31 +29,20 @@ namespace bts.mcore {
|
||||
|
||||
[Test]
|
||||
public void test_security_compare() {
|
||||
foreach (var file_path in SecurityFiles.all())
|
||||
_test_security_compare(_read_securities(file_path));
|
||||
}
|
||||
const string securities_resource = "KrandallOrderBookCrash.security_proto";
|
||||
// verify that the sample size doesn't shrink for some reason.
|
||||
// if it grows a bit that's fine; the generic comparison test
|
||||
// asserts against collections that are too large.
|
||||
const int min_sample_size = 91;
|
||||
|
||||
void _test_security_compare(IEnumerable<SecurityImmutable> securities) {
|
||||
const int max_count = 2048;
|
||||
var sec_list = securities as IList<SecurityImmutable> ?? securities.ToList();
|
||||
if (sec_list.Count > max_count)
|
||||
sec_list = sec_list.WrapSubRange(0, max_count);
|
||||
ComparisonTests.transitive_comparison(sec_list, SecurityHelper.Comparer.InstanceImmutable);
|
||||
ComparisonTests.identity_comparison(sec_list, SecurityHelper.Comparer.InstanceImmutable);
|
||||
}
|
||||
var securities = StreamHelper.ReadProtos<Security>(
|
||||
ResourceHelper.LoadResource(securities_resource))
|
||||
.Select(s => new SecurityImmutable(s))
|
||||
.ToList();
|
||||
Assert.IsTrue(securities.Count >= min_sample_size);
|
||||
|
||||
IEnumerable<SecurityImmutable> _read_securities(string file_path) =>
|
||||
StreamHelper.ReadProtos<Security>(ResourceHelper.LoadResource(file_path)).Select(s => new SecurityImmutable(s));
|
||||
|
||||
static class SecurityFiles {
|
||||
public const string
|
||||
KrandallOrderBookCrash = "KrandallOrderBookCrash.security_proto",
|
||||
NonDeterministicICEFutures = "NonDeterministicICEFutures.security_proto";
|
||||
|
||||
public static IEnumerable<string> all() {
|
||||
yield return KrandallOrderBookCrash;
|
||||
yield return NonDeterministicICEFutures;
|
||||
}
|
||||
ComparisonTests.transitive_comparison(securities, SecurityHelper.Comparer.InstanceImmutable);
|
||||
ComparisonTests.identity_comparison(securities, SecurityHelper.Comparer.InstanceImmutable);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,14 @@ using System.Linq;
|
||||
|
||||
namespace bts.mcore {
|
||||
static class ComparisonTests {
|
||||
/// <summary>
|
||||
/// Compares every permutation of pairs in the specified items.
|
||||
/// Be wary of use with large collections, as performance is O(n^2).
|
||||
/// </summary>
|
||||
public static void transitive_comparison<T>(IEnumerable<T> items, IComparer<T> comparer, int min_item_count = 2, int max_item_count = 5000) {
|
||||
public static void transitive_comparison<T>(IEnumerable<T> items, IComparer<T> comparer) {
|
||||
// Verify that the sample size isn't too big.
|
||||
// This test compares each item to every other item
|
||||
// (technically twice; lhs/rhs is flipped the second time),
|
||||
// so performance is O(n^2).
|
||||
const int max_sample_size = 4092;
|
||||
var sorted_items = items.ToList();
|
||||
Assert.That(sorted_items.Count >= min_item_count);
|
||||
Assert.That(sorted_items.Count <= max_item_count);
|
||||
Assert.That(sorted_items.Count <= max_sample_size);
|
||||
sorted_items.Sort(comparer);
|
||||
for (int i = 0; i < sorted_items.Count - 1; i++) {
|
||||
for (int j = i + 1; j < sorted_items.Count; j++) {
|
||||
|
||||
@@ -16,6 +16,5 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources\KrandallOrderBookCrash.security_proto" />
|
||||
<EmbeddedResource Include="Resources\NonDeterministicICEFutures.security_proto" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1 +1 @@
|
||||
set(sources files/audit_ilink3.py;files/audit_upload.sh;files/audit_uploader.py;files/cert_secure_logon.txt;files/example.conf;files/futures.coconut.xz;files/onixs_ice/ConnectivityConfiguration.APITest.xml;files/onixs_ice/ConnectivityConfiguration.APITest.xml.orig;files/onixs_ice/ConnectivityConfiguration.PerfTest.xml;files/onixs_ice/ConnectivityConfiguration.Production.xml;files/perf_trace/compiled.css;files/perf_trace/index.html;files/perf_trace/jquery-3.3.1.min.js;files/perf_trace/main.js;files/perf_trace/perf_log.sql;files/perf_trace/perf_trace_analysis.sql;files/perf_trace/plotly-latest.min.js)
|
||||
set(sources files/cert_secure_logon.txt;files/futures.coconut.xz;files/onixs_ice/ConnectivityConfiguration.APITest.xml;files/onixs_ice/ConnectivityConfiguration.PerfTest.xml;files/onixs_ice/ConnectivityConfiguration.Production.xml;files/perf_trace/compiled.css;files/perf_trace/index.html;files/perf_trace/jquery-3.3.1.min.js;files/perf_trace/main.js;files/perf_trace/perf_log.sql;files/perf_trace/perf_trace_analysis.sql;files/perf_trace/plotly-latest.min.js)
|
||||
@@ -1,405 +0,0 @@
|
||||
import json
|
||||
import csv
|
||||
import datetime, time
|
||||
import argparse, os
|
||||
|
||||
|
||||
def valid_file(f):
|
||||
if not os.path.exists(f):
|
||||
# Argparse uses the ArgumentTypeError to give a rejection message like:
|
||||
# error: argument input: x does not exist
|
||||
raise argparse.ArgumentTypeError("{0} does not exist".format(f))
|
||||
return f
|
||||
|
||||
def valid_date(s):
|
||||
try:
|
||||
return datetime.datetime.strptime(s, "%Y%m%d")
|
||||
except ValueError:
|
||||
raise argparse.ArgumentTypeError("Not a valid date: '{0}'.".format(s))
|
||||
|
||||
def print_headers():
|
||||
# From https://www.cmegroup.com/confluence/display/EPICSANDBOX/iLink+3+-+Minimum+Acceptable+Audit+Trail+Elements+-+Data+Definitions+and+Validation+Rules
|
||||
line_to_write = "Sending Timestamps,Message Direction,Operator ID,Session ID,Manual Order Indicator,Message Type,Instrument,Order Flow ID,\
|
||||
CME Globex Order ID,Client Order ID,Order Request ID,Buy/Sell Indicator,Quantity,Limit Price,Stop Price,Order Type,Order Qualifier,IFM Flag,\
|
||||
Display Quantity,Minimum Quantity,Country of Origin,Fill Price,Fill Quantity,Cumulative Quantity,Remaining Quantity,Aggressor Flag,Source of Cancellation,\
|
||||
Reject Reason,CME Globex Message ID,Cross ID,Quote Request ID,Message Quote ID,Quote Set ID,Quote Entry ID,Bid Price,Bid Size,Offer Price,Offer Size,\
|
||||
Processed Entries,Party Details List Request ID,ListUpdateAction,Self-Matching Prevention ID,Self-Match Prevention Instr,Customer Type Indicator,\
|
||||
AvgPxGroupID,Average Px Ind,CmtaGiveUpCD,Origin,Clearing Trade Price Type,Customer Handling Instr,Executing Firm ID,Account Number,Take Up Firm,Take up Account"
|
||||
|
||||
with open (args.output_file, 'w') as the_file:
|
||||
the_file.write(line_to_write)
|
||||
the_file.write("\n")
|
||||
|
||||
def set_blanks():
|
||||
return ""
|
||||
|
||||
def get_value(json_key):
|
||||
prices = ["Price", "LastPx", "StopPx"]
|
||||
if json_key in json_data:
|
||||
if json_key in prices:
|
||||
x = json_data[json_key]
|
||||
return x['mantissa']/100000000000
|
||||
else:
|
||||
return json_data[json_key]
|
||||
else:
|
||||
return ""
|
||||
|
||||
|
||||
# Column 1 - Sending Timestamps
|
||||
def SendingTimeEpoch(epochtime): #1
|
||||
#TIME = time.strftime('%Y%m%d-%H:%M:%S.{}'.format(epochtime/1000000000), time.gmtime(epochtime/1000000000))
|
||||
TIME = datetime.datetime.fromtimestamp(int(epochtime) / 1e9).strftime('%Y%m%d-%H:%M:%S.%f')
|
||||
return TIME
|
||||
|
||||
# Column 2 - Message Direction
|
||||
def direction(whichway):
|
||||
if whichway == '<':
|
||||
DIRECTION = "FROM CME"
|
||||
else:
|
||||
DIRECTION = "TO CME"
|
||||
return DIRECTION
|
||||
|
||||
# Column 3 - Operator ID
|
||||
def SenderID(sender):
|
||||
if "SenderID" in json_data:
|
||||
SENDER = json_data["SenderID"]
|
||||
return SENDER
|
||||
else:
|
||||
return SESSIONID
|
||||
|
||||
|
||||
# Column 4 - Session ID
|
||||
|
||||
# Column 5 - Manual Order Indicator
|
||||
def ManualOrderIndicator(manual):
|
||||
if "ManualOrderIndicator" in json_data:
|
||||
if manual == "Manual":
|
||||
return "1"
|
||||
else:
|
||||
return "0"
|
||||
|
||||
# Column 6 - Message Type
|
||||
def MessageType(msg_type,orderstatus):
|
||||
if msg_type == "NewOrderSingle514":
|
||||
return "D"
|
||||
elif msg_type == "ExecutionReportNew522":
|
||||
return "8--0"
|
||||
if "ExecutionReportTrade" in msg_type:
|
||||
if orderstatus == "PartiallyFilled":
|
||||
return "8--1"
|
||||
else:
|
||||
return "8--2"
|
||||
elif msg_type == "ExecutionReportCancel534":
|
||||
return "8--4"
|
||||
elif msg_type == "ExecutionReportModify531":
|
||||
return "8--5"
|
||||
elif msg_type == "ExecutionReportCancel534":
|
||||
return "8--H"
|
||||
elif msg_type == "ExecutionReportReject523":
|
||||
return "8--8"
|
||||
elif msg_type == "OrderCancelReplaceReject536":
|
||||
return "9--2"
|
||||
elif msg_type == "OrderCancelReject535":
|
||||
return "9--1"
|
||||
elif msg_type == "PartyDetailsDefinitionRequest518":
|
||||
return "CX"
|
||||
elif msg_type == "PartyDetailsDefinitionRequestAck519":
|
||||
return "CY"
|
||||
elif msg_type == "OrderCancelRequest516":
|
||||
return "F"
|
||||
elif msg_type == "OrderCancelReplaceRequest515":
|
||||
return "G"
|
||||
|
||||
|
||||
|
||||
# Column 12 - Buy-Sell Indicator/Side
|
||||
def Side(indicator):
|
||||
if "Side" in json_data:
|
||||
if indicator == "Buy":
|
||||
return "1"
|
||||
else:
|
||||
return "2"
|
||||
|
||||
# Column 16 - Order Type/OrdType
|
||||
def OrdType(ordertype):
|
||||
if "OrdType" in json_data:
|
||||
if ordertype == "MarketWithProtection" or ordertype == "MarketwithProtection":
|
||||
return "1"
|
||||
elif ordertype == "Limit":
|
||||
return "2"
|
||||
elif ordertype == "StopWithProtection" or ordertype == "StopwithProtection":
|
||||
return "3"
|
||||
elif ordertype == "StopLimit":
|
||||
return "4"
|
||||
elif ordertype == "MarketLimit":
|
||||
return "K"
|
||||
else:
|
||||
return ""
|
||||
|
||||
# Column 17 - Order Qualifier/TimeInForce
|
||||
def TimeInForce(orderqual):
|
||||
if "TimeInForce" in json_data:
|
||||
if orderqual == "Day":
|
||||
return "0"
|
||||
elif orderqual == "GTC":
|
||||
return "1"
|
||||
elif orderqual == "FAK":
|
||||
return "3"
|
||||
elif orderqual == "GTD":
|
||||
return "6"
|
||||
else:
|
||||
return ""
|
||||
|
||||
# Column 18 IFM Flag/OFMOverride
|
||||
def OFMOverride(imfflag):
|
||||
if "OFMOverride" in json_data:
|
||||
if imfflag == "Enabled":
|
||||
return "1"
|
||||
else:
|
||||
return "0"
|
||||
|
||||
# Column 19 Display Quantity/DisplayQty
|
||||
def DisplayQty(qty):
|
||||
if "DisplayQty" in json_data:
|
||||
if str(qty) == "0":
|
||||
return ""
|
||||
elif str(qty) == "4294967295":
|
||||
return ""
|
||||
else:
|
||||
return qty
|
||||
|
||||
|
||||
# Column 26 - Aggressor Flag/AggressorIndicator
|
||||
def AggressorIndicator(aggressor):
|
||||
if "AggressorIndicator" in json_data:
|
||||
if aggressor == "True":
|
||||
return "1"
|
||||
else:
|
||||
return "0"
|
||||
|
||||
# Column 27 - Source of Cancellation/ExecRestatementReason
|
||||
def ExecRestatementReason(sourcecancel):
|
||||
if "ExecRestatementReason" in json_data:
|
||||
if sourcecancel == "Exchange":
|
||||
return "8"
|
||||
elif sourcecancel == "CancelledNotBest":
|
||||
return "9"
|
||||
elif sourcecancel == "CancelOnDisconnect":
|
||||
return "100"
|
||||
elif sourcecancel == "CancelRestingDueToSelfMatchPrevention":
|
||||
return "103"
|
||||
elif sourcecancel == "CancelFromCMEGlobexCreditControlsViolation":
|
||||
return "104"
|
||||
elif sourcecancel == "CancelFromCMEOne":
|
||||
return "105"
|
||||
elif sourcecancel == "CancelFromRiskManagementAPI":
|
||||
return "106"
|
||||
elif sourcecancel == "CancelAggressingDueToSelfMatchPrevention":
|
||||
return "107"
|
||||
elif sourcecancel == "CancelDueToVolatilityQuoteOptionLessThanMinOrderSize":
|
||||
return "108"
|
||||
else:
|
||||
return ""
|
||||
|
||||
# Column 43 - Self-Match Prevention Instr/SelfMatchPreventionInstruction
|
||||
def SelfMatchPreventionInstruction(instr):
|
||||
if "SelfMatchPreventionInstruction" in json_data:
|
||||
if instr == "CancelOldest":
|
||||
return "O"
|
||||
elif instr == "CancelNewest":
|
||||
return "N"
|
||||
else:
|
||||
return ""
|
||||
|
||||
# Column 44 - Customer Type Indicator/CustOrderCapacity
|
||||
def CustOrderCapacity(custord):
|
||||
if "CustOrderCapacity" in json_data:
|
||||
if custord == "NULL_VALUE":
|
||||
return ""
|
||||
elif custord == "Membertradingfortheirownaccount":
|
||||
return "1"
|
||||
elif custord == "ClearingFirmtradingforitsproprietaryaccount":
|
||||
return "2"
|
||||
elif custord == "Membertradingforanothermember":
|
||||
return "3"
|
||||
else:
|
||||
return "4"
|
||||
|
||||
# Column 46 - Average Px Ind/AvgPxInd
|
||||
def AvgPxInd(avgpxindicator):
|
||||
if "AvgPxInd" in json_data:
|
||||
if avgpxindicator == "NULL_VALUE":
|
||||
return ""
|
||||
else:
|
||||
return avgpxindicator
|
||||
|
||||
# Column 48 - Origin/ClearingAccountType
|
||||
def ClearingAccountType(accounttype):
|
||||
if "ClearingAccountType" in json_data:
|
||||
if accounttype == "Customer":
|
||||
return "0"
|
||||
elif accounttype == "Firm":
|
||||
return "1"
|
||||
else:
|
||||
return ""
|
||||
|
||||
# Column 49 - Clearing Trade Price Type/ClearingTradePriceType
|
||||
def ClearingTradePriceType(clrtrdprice):
|
||||
if "ClearingTradePriceType" in json_data:
|
||||
if clrtrdprice == "NULL_VALUE":
|
||||
return "0"
|
||||
else:
|
||||
return "3"
|
||||
|
||||
# Column 50 - Customer Handling Instr/CustOrderHandlingInst
|
||||
def CustOrderHandlingInst(custorderinst):
|
||||
if "CustOrderHandlingInst" in json_data:
|
||||
if custorderinst == "ClientElectronic":
|
||||
return "C"
|
||||
elif custorderinst == "TEST":
|
||||
return "D"
|
||||
else:
|
||||
return ""
|
||||
|
||||
# Column 51 and 52 - Getting the Firm and Account Number
|
||||
def partyid(partydetailid,column):
|
||||
for x in partydetailid:
|
||||
role = x['PartyDetailRole']
|
||||
id = x['PartyDetailID']
|
||||
if column == "51" and role == "ExecutingFirm":
|
||||
return id
|
||||
if column == "52" and role == "CustomerAccount":
|
||||
return id
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("json_log", help="the json log[.gz] you wish to process", type=valid_file)
|
||||
parser.add_argument("output_file", help="the destination csv file you wish to write")
|
||||
parser.add_argument("-d", "--date", help="the date you wish to parse from the log, specified as YYYYmmdd",
|
||||
default=datetime.datetime.today().strftime("%Y%m%d"), type=valid_date)
|
||||
args = parser.parse_args()
|
||||
|
||||
print_headers()
|
||||
|
||||
list_types = ['NewOrderSingle514', 'OrderCancelReplaceRequest515', 'OrderCancelRequest516', 'PartyDetailsDefinitionRequest518', 'PartyDetailsDefinitionRequestAck519', \
|
||||
'ExecutionReportNew522', 'ExecutionReportReject523', 'ExecutionReportTradeOutright525', 'ExecutionReportTradeSpread526', 'ExecutionReportTradeSpreadLeg527', \
|
||||
'ExecutionReportModify531', 'ExecutionReportCancel534', 'OrderCancelReject535', 'OrderCancelReplaceReject536', ]
|
||||
|
||||
# Note that the timedeltas specificed in trade_day_start and trade_day_end
|
||||
# are based on Chicago times; as such, this script should run on a machine
|
||||
# set to a Chicago timezone. A future impromovement would be to determine
|
||||
# the current machine's timezone and determine the appropriate offset
|
||||
# versus Chicago time, but for now we assume this will run on a Chicago
|
||||
# tz machine.
|
||||
input_as_datetime = args.date
|
||||
trade_day_start = input_as_datetime - datetime.timedelta(days=1) + datetime.timedelta(hours=16, minutes=30)
|
||||
trade_day_utc_start = time.gmtime((time.mktime(trade_day_start.timetuple())))
|
||||
trade_day_end = input_as_datetime + datetime.timedelta(hours=16)
|
||||
trade_day_utc_end = time.gmtime((time.mktime(trade_day_end.timetuple())))
|
||||
|
||||
file_opener = None
|
||||
if args.json_log.endswith(".gz"):
|
||||
import gzip
|
||||
file_opener = gzip.open
|
||||
else:
|
||||
file_opener = open
|
||||
|
||||
|
||||
#inputFile = open(fileInput) #open json file
|
||||
#outputFile = open(fileOutput, 'w') #load csv file
|
||||
# Get Session
|
||||
with file_opener(args.json_log) as json_file:
|
||||
for line in json_file:
|
||||
data = json.loads(line)
|
||||
json_data = data['msg_json']
|
||||
if "Session" in json_data:
|
||||
SESSIONID = json_data["Session"]
|
||||
|
||||
#inputFile = open(fileInput) #open json file
|
||||
#outputFile = open(fileOutput, 'w') #load csv file
|
||||
with file_opener(args.json_log) as json_file:
|
||||
for line in json_file:
|
||||
data = json.loads(line)
|
||||
line_timestamp = time.strptime(data['time'], "%Y%m%d-%H:%M:%S.%f")
|
||||
if trade_day_utc_start <= line_timestamp <= trade_day_utc_end:
|
||||
json_data = data['msg_json']
|
||||
NAME = json_data["Name"]
|
||||
if NAME in list_types:
|
||||
EXECUTING_FIRM_ID = ""
|
||||
ACCOUNT_NUMBER = ""
|
||||
DIRECTION = direction(data['direction'])
|
||||
# Set Blanks
|
||||
blank_json = {'QuoteReqID': '', 'QuoteID': '', 'QuoteSetID': '', 'QuoteEntryID': '', 'BidPx': '', 'BidSize': '', 'OfferPx': '', \
|
||||
'OfferSize': '', 'NoProcessedEntries': '', 'ListUpdateAction': '', 'MinQty': '', 'AvgPxGroupID': '', \
|
||||
'CmtaGiveUpCD': '', 'TAKE_UP_FIRM': '', 'TAKE_UP_ACCOUNT': '',}
|
||||
|
||||
# No Data Processing
|
||||
straight_json = {'SecurityID': '', 'ClOrdID': '', 'OrderID': '', 'OrderRequestID': '', 'OrderQty': '', \
|
||||
'Location': '', 'LastQty': '', 'CumQty': '', 'LeavesQty': '', 'Text': '', 'SideTradeID': '', 'CrossID': '', 'SelfMatchPreventionID': '', \
|
||||
'Price': '', 'StopPx': '', 'LastPx': '', 'PartyDetailsListReqID': '', 'OrdStatus': ''}
|
||||
|
||||
# Processing Data
|
||||
process_json = {'SendingTimeEpoch': '', 'ManualOrderIndicator': '', 'SenderID': '', 'Side': '', 'OrdType': '', 'TimeInForce': '', \
|
||||
'OFMOverride': '', 'AggressorIndicator': '', 'ExecRestatementReason': '', 'SelfMatchPreventionInstruction': '', 'CustOrderCapacity': '', \
|
||||
'AvgPxInd': '', 'ClearingAccountType': '', 'ClearingTradePriceType': '', 'CustOrderHandlingInst': '', 'DisplayQty': ''}
|
||||
|
||||
for d in straight_json:
|
||||
test = get_value(d)
|
||||
if test != "None" or test != "":
|
||||
if "," in str(test):
|
||||
test = test.replace(",",";")
|
||||
if "4294967295" in str(test):
|
||||
test = ""
|
||||
if "us;" in str(test):
|
||||
test = test.upper()
|
||||
if d == "SelfMatchPreventionID" and len(str(test)) > 8:
|
||||
test = ""
|
||||
straight_json[d] = test
|
||||
else:
|
||||
straight_json[d] = ''
|
||||
|
||||
for d in process_json:
|
||||
if d in json_data:
|
||||
function = locals()[d]
|
||||
test = function(json_data[d])
|
||||
if test != "None":
|
||||
process_json[d] = test
|
||||
else:
|
||||
process_json[d] = ''
|
||||
elif d == "SenderID":
|
||||
function = locals()[d]
|
||||
test = function(SenderID)
|
||||
if test != "None":
|
||||
process_json[d] = test
|
||||
|
||||
# Party Message Fields
|
||||
# Column 51 - Executing Firm ID
|
||||
if "NoPartyDetails" in json_data:
|
||||
EXECUTING_FIRM_ID = partyid(json_data['NoPartyDetails'], "51")
|
||||
# Column 52 - Party Account Number
|
||||
ACCOUNT_NUMBER = partyid(json_data['NoPartyDetails'], "52")
|
||||
|
||||
line_to_write = process_json['SendingTimeEpoch'] + "," + DIRECTION + "," + process_json['SenderID'] + "," + SESSIONID + "," + process_json['ManualOrderIndicator'] + "," + \
|
||||
MessageType(NAME,straight_json['OrdStatus']) + "," + str(straight_json['SecurityID']) + "," + str(straight_json['ClOrdID']) + "," + str(straight_json['OrderID']) + "," + str(straight_json['ClOrdID']) + "," + \
|
||||
str(straight_json['OrderRequestID']) + "," + process_json['Side'] + "," + str(straight_json['OrderQty']) + "," + str(straight_json['Price']) + "," + \
|
||||
str(straight_json['StopPx']) + "," + process_json['OrdType'] + "," + process_json['TimeInForce'] + "," + process_json['OFMOverride'] + "," + str(process_json['DisplayQty']) + "," + \
|
||||
blank_json['MinQty'] + "," + straight_json['Location'] + "," + str(straight_json['LastPx']) + "," + str(straight_json['LastQty']) + "," + str(straight_json['CumQty']) + "," + \
|
||||
str(straight_json['LeavesQty']) + "," + process_json['AggressorIndicator'] + "," + process_json['ExecRestatementReason'] + "," + str(straight_json['Text']) + "," + \
|
||||
str(straight_json['SideTradeID']) + "," + str(straight_json['CrossID']) + "," + blank_json['QuoteReqID'] + "," + blank_json['QuoteID'] + "," + blank_json['QuoteSetID'] + "," + \
|
||||
blank_json['QuoteEntryID'] + "," + blank_json['BidPx'] + "," + blank_json['BidSize'] + "," + blank_json['OfferPx'] + "," + blank_json['OfferSize'] + "," + \
|
||||
blank_json['NoProcessedEntries'] + "," + str(straight_json['PartyDetailsListReqID']) + "," + blank_json['ListUpdateAction'] + "," + str(straight_json['SelfMatchPreventionID']) + "," + \
|
||||
process_json['SelfMatchPreventionInstruction'] + "," + process_json['CustOrderCapacity'] + "," + blank_json['AvgPxGroupID'] + "," + process_json['AvgPxInd'] + "," + \
|
||||
blank_json['CmtaGiveUpCD'] + "," + str(process_json['ClearingAccountType']) + "," + process_json['ClearingTradePriceType'] + "," + process_json['CustOrderHandlingInst'] + "," + \
|
||||
EXECUTING_FIRM_ID + "," + str(ACCOUNT_NUMBER) + "," + blank_json['TAKE_UP_FIRM'] + "," + blank_json['TAKE_UP_ACCOUNT']
|
||||
|
||||
|
||||
#print(line_to_write)
|
||||
|
||||
with open (args.output_file, 'a') as the_file:
|
||||
the_file.write(line_to_write)
|
||||
the_file.write("\n")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
#/bin/bash
|
||||
|
||||
function help_and_exit()
|
||||
{
|
||||
echo
|
||||
echo Usage: $0 [option]... config_file
|
||||
echo
|
||||
echo Can also be used in cron like the following
|
||||
echo 40 16 * * 1-5 /usr/bin/docker exec spark_10000 bash /sparkbin/data_files/audit_upload.sh /sparkdata/data/audit_uploads/example.conf
|
||||
echo example.conf included. The location of the conf file should be relative to the docker container, not the host
|
||||
echo
|
||||
echo Options are as follows:
|
||||
echo " -d|--date YYYYMMDD Example is 20180731"
|
||||
echo " Help: "
|
||||
echo " -h|--help Display this message."
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
DATE=$(date +%Y%m%d)
|
||||
ORIG_DIR=$(pwd)
|
||||
ERROR_LEVEL="0"
|
||||
|
||||
while getopts "d:h" option; do
|
||||
case $option in
|
||||
d) DATE=$OPTARG ;;
|
||||
h) help_and_exit;;
|
||||
\?) echo "Invalid option: -$OPTARG" >&2;
|
||||
exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1))
|
||||
|
||||
CONFIG_FILE=$1
|
||||
|
||||
declare -A conf_vars; while read line; do conf_vars[${line%=*}]=${line#*=}; done <$CONFIG_FILE
|
||||
|
||||
SESSION_ID=${conf_vars[session_id]}
|
||||
FCM=${conf_vars[fcm]}
|
||||
CLIENT=${conf_vars[client]}
|
||||
|
||||
cd /sparkbin/data_files
|
||||
|
||||
for SESSION in $(ls /sparkdata/data/ilink3/); do
|
||||
if [[ $SESSION == *$SESSION_ID* ]]; then
|
||||
echo "Session is $SESSION"
|
||||
SESSION_DAY=$(date +%Y-%m-%d)
|
||||
if [[ $SESSION == "cme_"* ]]; then
|
||||
SESSION_DAY=$(date -d "$DATE -$(date -d $DATE +%u) days" +"%Y-%m-%d")
|
||||
AUDIT_SCRIPT="audit_ilink3.py"
|
||||
fi
|
||||
echo $SESSION_DAY
|
||||
if [[ ! -d /sparkdata/data/ilink3/$SESSION/audit_logs ]]; then
|
||||
mkdir -p /sparkdata/data/ilink3/$SESSION/audit_logs
|
||||
fi
|
||||
if [[ -d /sparkdata/data/ilink3/$SESSION/$SESSION_DAY ]]; then
|
||||
echo "Starting the creation of the audit log"
|
||||
python $AUDIT_SCRIPT -d $DATE /sparkdata/data/ilink3/$SESSION/$SESSION_DAY/log /sparkdata/data/ilink3/$SESSION/audit_logs/"$FCM"_audit_"$SESSION"_"$DATE".csv
|
||||
fi
|
||||
if [[ ! -d /sparkdata/data/md_audit ]]; then
|
||||
mkdir /sparkdata/data/md_audit
|
||||
fi
|
||||
if [[ -d /sparkdata/data/md_audit ]]; then
|
||||
# Running the MD Audit csv generation
|
||||
cd /sparkbin
|
||||
./sparkd adminreport md > /sparkdata/data/md_audit/"$FCM"_md_"$CLIENT"_"$DATE".csv
|
||||
cd /sparkbin/data_files
|
||||
fi
|
||||
echo "Uploading to the (s)FTP Server"
|
||||
python audit_uploader.py --config_file="$CONFIG_FILE" --datestamp $DATE --session="$SESSION" --client="$CLIENT" --fcm="$FCM"
|
||||
fi
|
||||
done
|
||||
@@ -1,150 +0,0 @@
|
||||
import getopt, sys, datetime
|
||||
import paramiko, ftplib
|
||||
|
||||
#########################################################
|
||||
# Commandline Args #
|
||||
#########################################################
|
||||
|
||||
def usage():
|
||||
print "-------------------------------------------------------"
|
||||
print "-Usage: -"
|
||||
print "-------------------------------------------------------"
|
||||
print "- --config_file= : Path to upload config file -"
|
||||
print "- -if no path is specified look -"
|
||||
print "- in the working directory. -"
|
||||
print "- -"
|
||||
print "- --help : Print this message -"
|
||||
print "- -"
|
||||
print "- --datestamp= : Optional, defaults to today -"
|
||||
print "- -replaces *datestamp in the -"
|
||||
print "- the upload config file -"
|
||||
print "- -"
|
||||
print "- --fcm : Optional, spark input -"
|
||||
print "- -"
|
||||
print "- --session : Optional, spark jf session -"
|
||||
print "-------------------------------------------------------"
|
||||
|
||||
fcm = ''
|
||||
session = ''
|
||||
|
||||
try:
|
||||
options, arguments = getopt.getopt(sys.argv[1:],"h",['config_file=', 'datestamp=', 'help', 'fcm=', 'client=', 'session='])
|
||||
except getopt.GetoptError, err:
|
||||
print str(err)
|
||||
usage()
|
||||
sys.exit(2)
|
||||
|
||||
for option, value in options:
|
||||
if option in ("-h","--h","-help","--help"):
|
||||
usage()
|
||||
sys.exit()
|
||||
elif option in ("-config_file","--config_file"):
|
||||
config_file = value
|
||||
elif option in ("-datestamp","--datestamp"):
|
||||
datestamp = value
|
||||
elif option in ("-fcm","--fcm"):
|
||||
fcm = value
|
||||
elif option in ("-client","--client"):
|
||||
client = value
|
||||
elif option in ("-session","--session"):
|
||||
session = value
|
||||
|
||||
for argument in arguments:
|
||||
if argument in ("h", "help"):
|
||||
usage()
|
||||
sys.exit()
|
||||
else:
|
||||
print "Unrecognized commandline argument. Type help for usage."
|
||||
sys.exit()
|
||||
|
||||
if len(options) <= 0:
|
||||
print "Requires a config file to run."
|
||||
usage()
|
||||
sys.exit()
|
||||
|
||||
|
||||
#########################################################
|
||||
# Read Config Function #
|
||||
#########################################################
|
||||
|
||||
def read_config_file(config_file, datestamp=datetime.datetime.today().strftime('%Y%m%d'), fcm=fcm, session=session):
|
||||
'''
|
||||
Parse our config file that gets passed in as a commandline parameter.
|
||||
All config keys must be of the form key=value. White space is ignored.
|
||||
All config keys must be seperated by a newline character.
|
||||
Called during initialization.
|
||||
'''
|
||||
upload_config = {}
|
||||
config_file = open(config_file, 'r')
|
||||
config_file = config_file.read()
|
||||
for config in config_file.split("\n"):
|
||||
if '=' in config:
|
||||
cleaned_key = config.split('=')[0].strip().upper()
|
||||
cleaned_value = config.split('=')[1].strip()
|
||||
if '*datestamp*' in cleaned_value:
|
||||
cleaned_value = cleaned_value.replace('*datestamp*',datestamp)
|
||||
if '*fcm*' in cleaned_value:
|
||||
cleaned_value = cleaned_value.replace('*fcm*',fcm)
|
||||
if '*client*' in cleaned_value:
|
||||
cleaned_value = cleaned_value.replace('*client*',client)
|
||||
if '*session*' in cleaned_value:
|
||||
cleaned_value = cleaned_value.replace('*session*',session)
|
||||
upload_config[cleaned_key] = cleaned_value
|
||||
else:
|
||||
pass
|
||||
return upload_config
|
||||
|
||||
#########################################################
|
||||
# FTP File Transfer Function #
|
||||
#########################################################
|
||||
def putfile_ftp(file, put_path, site, user, password, port=21, verbose=True):
|
||||
if verbose: print 'Uploading', file
|
||||
local = open(file, 'rb')
|
||||
remote = ftplib.FTP(site)
|
||||
remote.login(user, password)
|
||||
remote.storbinary(put_path, local, 1024)
|
||||
remote.quit()
|
||||
local.close()
|
||||
if verbose: print 'Upload done.'
|
||||
|
||||
#########################################################
|
||||
# SFTP File Transfer Function #
|
||||
#########################################################
|
||||
def putfile_sftp(file, put_path, site, username, password, port=22, verbose=True):
|
||||
transport = paramiko.Transport((site, port))
|
||||
transport.connect(username = username, password = password)
|
||||
sftp = paramiko.SFTPClient.from_transport(transport)
|
||||
sftp.put(file, put_path)
|
||||
sftp.close()
|
||||
transport.close()
|
||||
|
||||
|
||||
#########################################################
|
||||
# Main #
|
||||
#########################################################
|
||||
#if datestamp != None:
|
||||
# upload_config = read_config_file(config_file, datestamp)
|
||||
#else:
|
||||
# upload_config = read_config_file(config_file)
|
||||
|
||||
try:
|
||||
datestamp
|
||||
except NameError:
|
||||
upload_config = read_config_file(config_file)
|
||||
else:
|
||||
upload_config = read_config_file(config_file, datestamp)
|
||||
|
||||
|
||||
|
||||
print upload_config
|
||||
|
||||
if upload_config["PROTOCOL_PUT"] in ['FTP','ftp']:
|
||||
print "Protocol = FTP"
|
||||
putfile_ftp(upload_config["GET_ILINK3_FILE_PATH"] + upload_config["GET_ILINK3_FILE_NAME"], upload_config["PUT_ILINK3_FILE_PATH"] + upload_config["PUT_ILINK3_FILE_NAME"], upload_config["PUT_HOST"], upload_config["USERNAME_PUT"], upload_config["PASSWORD_PUT"], upload_config["PORT_PUT"] )
|
||||
putfile_ftp(upload_config["GET_MD_FILE_PATH"] + upload_config["GET_MD_FILE_NAME"], upload_config["PUT_MD_FILE_PATH"] + upload_config["PUT_MD_FILE_NAME"], upload_config["PUT_HOST"], upload_config["USERNAME_PUT"], upload_config["PASSWORD_PUT"], upload_config["PORT_PUT"] )
|
||||
elif upload_config["PROTOCOL_PUT"] in ['SFTP','sftp']:
|
||||
print "Protocol = SFTP"
|
||||
putfile_sftp(upload_config["GET_ILINK3_FILE_PATH"] + upload_config["GET_ILINK3_FILE_NAME"], upload_config["PUT_ILINK3_FILE_PATH"] + upload_config["PUT_ILINK3_FILE_NAME"], upload_config["PUT_HOST"], upload_config["USERNAME_PUT"], upload_config["PASSWORD_PUT"], int(upload_config["PORT_PUT"]) )
|
||||
putfile_sftp(upload_config["GET_MD_FILE_PATH"] + upload_config["GET_MD_FILE_NAME"], upload_config["PUT_MD_FILE_PATH"] + upload_config["PUT_MD_FILE_NAME"], upload_config["PUT_HOST"], upload_config["USERNAME_PUT"], upload_config["PASSWORD_PUT"], int(upload_config["PORT_PUT"]) )
|
||||
|
||||
|
||||
@@ -1,19 +1,12 @@
|
||||
Session ID Access ID Secret Key Creation Date Expiration Date Environment
|
||||
|
||||
M4D lLtjH74y1Kh5XUJTLyH2 f1K_tROQp2lTIplVp34WxKa7xDUgfFnIteolfik061o 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC1 VEMlkDuLz74OVHSuacQB IuHyYT3b-9KUo3WsuXykt-fXsjzp7L-JOrdCSQZLNl0 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC5 77lzSUwPLlM9obaXh2mK z6aA9qfASDKfZkYTVKFqJd-78i0HZ2Q9ec3CKCYIqHg 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC7 RphzI3rn71oGUEiYnX9e y6OvvPPyoyj2S8YAnE1gFduXT8v29HIMjO5EngYxSNg 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC8 PYBIm2TI9gFPIxmHbuYl 6o-ZolGH2DdeQOlGtJ5Zqoh_kg7VdbxkmjeOHmigKwU 2019-09-03 2020-09-03 CERT
|
||||
|
||||
NGG RYcigz3bSLIIBBF2A2Hq qB1dm9VkTKeXcdQpFzla8B3_jwTgya_-Fk5iyEJvr2E 2020-06-15 2021-06-15 NEWRELEASE
|
||||
|
||||
NGF o4OTmmTLQ7Lv4g6bCm26 HbD3FneMyb9Fu-FkCDLscCczHqFcFE2PyWv978RXGyA 2019-12-20 2020-12-20 NEWRELEASE
|
||||
|
||||
UZE EeFdZ1FPepk6U4k3xBZA 2LjEtdLvBLLB1QuDJ4KiJW6M4dF6IHWd_UKmo7p3_Us 2020-06-24 2021-06-24 NEWRELEASE
|
||||
|
||||
VAE Y8iqatTewuoHX16gghw8 FNcCB3Ks1qleS56quYzH4V7zAu78YY2bCdLRi9tmU9E 2020-06-24 2021-06-24 NEWRELEASE
|
||||
Session ID Access ID Secret Key Creation Date Expiration Date Environment
|
||||
|
||||
M4D lLtjH74y1Kh5XUJTLyH2 f1K_tROQp2lTIplVp34WxKa7xDUgfFnIteolfik061o 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC1 VEMlkDuLz74OVHSuacQB IuHyYT3b-9KUo3WsuXykt-fXsjzp7L-JOrdCSQZLNl0 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC5 77lzSUwPLlM9obaXh2mK z6aA9qfASDKfZkYTVKFqJd-78i0HZ2Q9ec3CKCYIqHg 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC7 RphzI3rn71oGUEiYnX9e y6OvvPPyoyj2S8YAnE1gFduXT8v29HIMjO5EngYxSNg 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC8 PYBIm2TI9gFPIxmHbuYl 6o-ZolGH2DdeQOlGtJ5Zqoh_kg7VdbxkmjeOHmigKwU 2019-09-03 2020-09-03 CERT
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
fcm=FCM
|
||||
client=NAME
|
||||
session_id=ses
|
||||
put_host=ftpc.example.com
|
||||
port_put=2222
|
||||
username_put=user
|
||||
password_put=password
|
||||
protocol_put=sftp
|
||||
get_ilink3_file_path=/sparkdata/data/ilink3/*session*/audit_logs/
|
||||
put_ilink3_file_path=/
|
||||
get_ilink3_file_name=*fcm*_audit_*session*_*datestamp*.csv
|
||||
put_ilink3_file_name=*fcm*_audit_*session*_*datestamp*.csv
|
||||
get_md_file_path=/sparkdata/data/md_audit/
|
||||
put_md_file_path=/
|
||||
get_md_file_name=*fcm*_md_*client*_*datestamp*.csv
|
||||
put_md_file_name=*fcm*_md_*client*_*datestamp*.csv
|
||||
@@ -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/service_helpers/AlgoServiceUtils.cpp;api/service_helpers/PositionUtilities.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/BasePositionService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MBOService.proto;api/services/MarginService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/MarketDataService.proto;api/services/MoneyFileService.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/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/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/keycode.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/position_cfg.conf;config/defaults/span.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/AlgoTypes.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/keycode.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/position_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/span.proto;config/protos/spreader.proto;config/protos/subprocess.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/sod.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/MBOProcessor.cpp;md/MBOServiceServer.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/Product.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityMapper.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/ice/ICEUtils.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/service/MarketDataServiceServer.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/mbo_tests.cpp;md/test/md2_tests.cpp;md/test/md_test_utils.cpp;md/test/synthetic_book_merge_tests.cpp;md/vendor/OnixsUtils.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.cLine 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/service_helpers/AlgoServiceUtils.cpp;api/service_helpers/PositionUtilities.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/BasePositionService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MBOService.proto;api/services/MarginService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/MarketDataService.proto;api/services/MoneyFileService.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/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/AlgoTypes.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/keycode.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/position_cfg.conf;config/defaults/span.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/keycode.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/position_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/span.proto;config/protos/spreader.proto;config/protos/subprocess.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/sod.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/MBOProcessor.cpp;md/MBOServiceServer.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/Product.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityMapper.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/ice/ICEUtils.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/service/MarketDataServiceServer.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/mbo_tests.cpp;md/test/md2_tests.cpp;md/test/md_test_utils.cpp;md/test/synthetic_book_merge_tests.cpp;md/vendor/OnixsUtils.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.Line truncated
|
||||
@@ -580,9 +580,7 @@ bts::api::orderman::RoutingRecord AdminServiceUtils::get_routing_record(const bt
|
||||
rv.set_session(conn_ptr->name());
|
||||
rv.set_operator_id(cme_user_data->operator_id());
|
||||
rv.set_location(cme_user_data->location());
|
||||
|
||||
rv.set_smp_id(cme_user_data->smp_id());
|
||||
|
||||
if (cme_user_data->smp_instruction()== "O")
|
||||
rv.set_smp_instruction(api::orderman::SelfMatchPreventionInstruction::SELF_MATCH_PREVENTION_INSTRUCTION_CANCEL_RESTING);
|
||||
else if (cme_user_data->smp_instruction()== "N")
|
||||
|
||||
@@ -386,9 +386,7 @@ message NativeOrderState {
|
||||
RoutingRecord routing_record = 5;
|
||||
NativeOrderType native_type = 6;
|
||||
string last_transact_time = 7;
|
||||
uint64 last_transact_time_unix_ns = 9;
|
||||
double stop_px = 8;
|
||||
uint64 exchange_order_id_u64 = 10;
|
||||
}
|
||||
|
||||
// Custom order states
|
||||
@@ -457,8 +455,7 @@ enum TimeInForce {
|
||||
TIME_IN_FORCE_UNDEFINED = 0;
|
||||
TIME_IN_FORCE_DAY = 48;
|
||||
TIME_IN_FORCE_GTC = 49;
|
||||
TIME_IN_FORCE_IOC = 51; // FAK
|
||||
TIME_IN_FORCE_DATE = 52;
|
||||
TIME_IN_FORCE_IOC = 51;
|
||||
}
|
||||
|
||||
enum ManualOrderIndicator {
|
||||
|
||||
@@ -45,12 +45,6 @@ CMEOptions {
|
||||
}
|
||||
}
|
||||
|
||||
ICEPublisherOptions {
|
||||
value {
|
||||
network_interface: "eth1"
|
||||
}
|
||||
}
|
||||
|
||||
#to make this work in dev clone the operations repo
|
||||
#go here: c:\\code\\bts\\operations\\ice\\ICE_iMpactMulticastFeed_GettingStarted-1_1_36\\bin\\easyTunnel>
|
||||
#modify the easyTunnelProxy.properties file to replace
|
||||
|
||||
+13
-1091
File diff suppressed because it is too large.
Load diff
@@ -1,10 +1,10 @@
|
||||
#nusers: 100
|
||||
#nusers: 1
|
||||
#allow concurrent : true
|
||||
#expires: 2022-Jun-01 00:00:00 637896384000000000
|
||||
#generation_time: 2021-Mar-25 15:21:51.824504 5249208843545632944
|
||||
#expires: 2021-Jan-01 00:00:00 637450560000000000
|
||||
#generation_time: 2020-Apr-03 18:39:31.010863 5248901378137496534
|
||||
EncryptedKeyCode {
|
||||
value {
|
||||
keycode: "HdVz7cDRyofLl3vA8TPulaIHkquYzq24QTXThZccEpZkvk5mDF5dKkQa9fWG5JOWnswNZVfVct0bpHG99X3XHDTdhHyZy0xb+eEI4PS50vaHQGw3fHmFh/ku9EwLxMZZYCEnhelsg2LADjIG8ebqsgmVi6asHZo70nZCaIXzwu8KCjak/sD7K2EP5odhnRpPL4JdsSkgUAwmrr0V17pFxH1RmTS6pXYUvko3DTOIM8yudWabVlSrdmcsnCEzHN5WbZiMdPNEykhEdEtKM58TR9tVnk+JuDIU8uczEQsLK2tT1VVoleGLc5TM/p8jhWokkvr8WdbToIGaalhp72VG6g=="
|
||||
keycode: "BJBQWsbdTXWa/iLmOf3ekE8vP/NYkf0Q/nUsp/rJ78Ze3W9pNXICCMabmmsr1xOM7aqRIclPgZd955uSSfvFkdNWFTxwPQ5IfnDGopj3QdhUVxhzgVLaXHN+vC0H/MWrDQ5K4WY5J/6VXgUn1LSN/2HNb5iR2sKXeh3Alamg87YtCWEi+scelffE7HK5ERT/3A3Y/e0pqUFhP6xouIjHRhC2FRBb6OoJQVvFwVDADSuKZNo9B6GhC3H0YdHqjFhGDoky5ecgzeKIX8uWJEQNnQXQJ0iTgQ95+YR5IMU+XWdlVfSrc0fuTmj3YWcBQ8Kl2ItEcobyZzJYega3tu6Ftw=="
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,6 @@ message CMEOptions
|
||||
// Defines amount of time Feed Engine keeps cycling before going to sleep when no useful activity can be done
|
||||
optional uint32 spin_time = 4 [default = 1];
|
||||
optional uint32 channels_per_thread = 5 [default = 3];
|
||||
// rmem_max
|
||||
optional uint32 udp_socket_buffer_size = 11 [default = 268435456]; //256mb
|
||||
}
|
||||
message CMEChannel {
|
||||
@@ -111,13 +110,9 @@ message CMEOptions
|
||||
optional string feed_engine = 3 [default = "default"];
|
||||
|
||||
|
||||
// for re-orders
|
||||
optional uint32 max_gap_recovery_cache_size = 11 [default = 6];
|
||||
// for re-orders
|
||||
optional uint32 lost_packet_wait_timeout_ms = 12 [default = 10];
|
||||
|
||||
optional OnixSLogMode onixs_log_mode = 13 [default = Important];
|
||||
// If using both feeds prefer the B feed for snapshots
|
||||
optional bool prefer_backup_feeds = 15 [default = false];
|
||||
|
||||
optional bool use_tcp_replay = 20 [default = true];
|
||||
|
||||
@@ -9,9 +9,9 @@ message JetFIX {
|
||||
enum JetFIXPlatform {
|
||||
GLBX = 1;
|
||||
CBOE = 6;
|
||||
SIM = 2;
|
||||
ICE = 3;
|
||||
SIMICE = 4;
|
||||
SIM = 2;
|
||||
ICE = 3;
|
||||
SIMICE = 4;
|
||||
}
|
||||
optional JetFIXPlatform platform = 15 [default = GLBX];
|
||||
|
||||
@@ -87,8 +87,6 @@ message JetFIX {
|
||||
|
||||
optional uint32 max_connection_attempts = 346 [default=10];
|
||||
optional bool auto_fix_seq_num = 347 [default=false];
|
||||
optional bool use_ilink3 = 348 [default=false] ;
|
||||
optional uint32 uuid_offset = 349 [default=0];
|
||||
}
|
||||
|
||||
repeated Connection connection = 10;
|
||||
@@ -118,4 +116,4 @@ message CMECannedSecureLogon {
|
||||
"MC8 AbEEtBn63WIAuItPDz1c n3ndjYb03Hx6wBO3me35HoONyDgO5TZKWk0tDSaX9KA 2018-04-05 2019-04-05 CERT \n"
|
||||
"T39 UWggBgHWAe07aqW3ps2I tbb3it0rUQSSTa0TC9QcRwkrHEMDLWhaJH4VQ0FqGB4 2018-04-05 2019-04-05 NEWRELEASE \n"
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -73,5 +73,4 @@ message DynamicAlgos{
|
||||
optional bool enable_tas = 3 [default = false];
|
||||
optional bool enable_tascounter = 4 [default = false];
|
||||
optional bool enable_limit_cover = 5 [default = false];
|
||||
optional bool enable_onsignal = 6 [default = false];
|
||||
}
|
||||
@@ -212,20 +212,31 @@ inline bool gr_than(double p1, double p2, double tick_size) {
|
||||
return gr_than_eq(p1, p2, tick_size) &&
|
||||
!test_price_equality(p1, p2, tick_size);
|
||||
}
|
||||
inline bool test_price_equality(double price_1, double price_2) {
|
||||
return std::fabs(price_2 - price_1) < market_epsilon();
|
||||
}
|
||||
|
||||
// ice specialization /////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Works only if ICEExchangeData is part of the a spread security
|
||||
// inline bool is_ice_strip(const bts::api::ICEExchangeData& ice_data){
|
||||
// return ice_data.is_strip();
|
||||
// }
|
||||
|
||||
inline bool is_ice_spread(const bts::api::ICEExchangeData& ice_data){
|
||||
inline bool is_ice_strip(const bts::api::ICEExchangeData& ice_data){
|
||||
// TODO, put this in the security
|
||||
const auto& strip = ice_data.strip_name();
|
||||
return strip.find("/") != std::string::npos;
|
||||
auto find = [&](const std::string& sub) -> bool {
|
||||
return strip.find(sub) != std::string::npos;
|
||||
};
|
||||
if(!find("/"))
|
||||
return find("-") ||
|
||||
find("Q1") || find("Q2") || find("Q3") || find("Q4") ||
|
||||
find("Cal");
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool is_strip(const bts::api::Security& sec){
|
||||
return sec.has_ice() && sec.has_spread() && !is_ice_spread(sec.ice());
|
||||
if(sec.has_spread())
|
||||
if (sec.has_ice())
|
||||
return is_ice_strip(sec.ice());
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool is_spread_of_strips(const bts::api::Security& sec){
|
||||
|
||||
@@ -52,7 +52,7 @@ class FIXEncodingStream {
|
||||
auto msg_offset = _buffer.size();
|
||||
|
||||
_current_msg = FIXFragment(_buffer);
|
||||
_begin_string_bm = _current_msg.add<fix::BeginString>(std::string_view {"FIX.4.2"});
|
||||
_begin_string_bm = _current_msg.add<fix::BeginString>("FIX.4.2");
|
||||
_body_length_bm = _current_msg.add<fix::BodyLength>(0, 6);
|
||||
|
||||
char mt_encoding[4];
|
||||
|
||||
@@ -85,7 +85,6 @@ typedef StringField<307> UnderlyingSecurityDesc;
|
||||
typedef StringField<336> TradingSessionID;
|
||||
typedef StringField<35> MsgType;
|
||||
typedef StringField<37> OrderID;
|
||||
typedef BigIntField<37> OrderIDu64;
|
||||
typedef StringField<41> OrigClOrdID;
|
||||
typedef StringField<440> ClearingAccount;
|
||||
typedef StringField<48> SecurityID;
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
#include <memory>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <string_view>
|
||||
|
||||
#include "lib/jetfix/codec/ReaderCursor.h"
|
||||
#include "lib/utils/meta_programming.h"
|
||||
#include "lib/utils/datetime.h"
|
||||
@@ -205,13 +203,6 @@ public:
|
||||
static std::pair<uint32_t,uint32_t> write (char*buffer,std::string const &str)
|
||||
{return write (buffer,str.data (),str.size ());}
|
||||
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
static uint32_t max_value_size (std::string_view const&str) {return str.size ();}
|
||||
static std::pair<uint32_t,uint32_t> write (char*buffer,std::string_view const &str)
|
||||
{return write (buffer,str.data (),str.size ());}
|
||||
#endif
|
||||
|
||||
static std::pair<uint32_t,uint32_t> write (char*buffer,const char*str,uint32_t sz)
|
||||
{
|
||||
memcpy (buffer,str,sz);
|
||||
|
||||
@@ -23,9 +23,9 @@ SocketConnection::SocketConnection(bts::config::JetFIX::Connection const &cfg,
|
||||
: _fd(-1), _cfg(cfg), _log(cfg.log_fix_stream()), _in_log(), _out_log(),
|
||||
_perf_log(perf_log) {
|
||||
if (_log) {
|
||||
_in_log.open(std::string("/tmp/fix_raw_read_log_") + session_name(cfg).as_string,
|
||||
_in_log.open(std::string("/tmp/fix_raw_read_log_") + session_name(cfg),
|
||||
std::ios_base::app);
|
||||
_out_log.open(std::string("/tmp/fix_raw_write_log_") + session_name(cfg).as_string,
|
||||
_out_log.open(std::string("/tmp/fix_raw_write_log_") + session_name(cfg),
|
||||
std::ios_base::app);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -786,10 +786,9 @@ OutFIXPtr make_logon(uint32_t seq_num, uint32_t last_seq_num_processed,
|
||||
if(session_cfg.platform() == bts::config::JetFIX_Connection_JetFIXPlatform_ICE ||
|
||||
session_cfg.platform() == bts::config::JetFIX_Connection_JetFIXPlatform_SIMICE)
|
||||
{
|
||||
std::string sender_comp_id = session_cfg.sender_subid();
|
||||
buffer.add<ICEApplicationSystemName>(sender_comp_id);
|
||||
buffer.add<ICEApplicationSystemVersion>(std::string_view{"1.0"});
|
||||
buffer.add<ICEApplicationSystemVendor>(sender_comp_id);
|
||||
buffer.add<ICEApplicationSystemName>("Katallage");
|
||||
buffer.add<ICEApplicationSystemVersion>("1.0");
|
||||
buffer.add<ICEApplicationSystemVendor>("Katallage");
|
||||
|
||||
buffer.add<UserName>(session_cfg.user_name());
|
||||
buffer.add<RawDataLength>(session_cfg.raw_data().size());
|
||||
@@ -797,18 +796,19 @@ OutFIXPtr make_logon(uint32_t seq_num, uint32_t last_seq_num_processed,
|
||||
buffer.add<EncryptMethod>(0);
|
||||
buffer.add<ICEStrategyPreference>(1);
|
||||
buffer.add<ICETimeStampPreference>(1);
|
||||
} else {
|
||||
buffer.add<ApplicationSystemName>(std::string_view{application});
|
||||
buffer.add<ApplicationSystemVersion>(std::string_view{"1.0"});
|
||||
buffer.add<ApplicationSystemVendor>(std::string_view{"BTS"});
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.add<ApplicationSystemName>(application);
|
||||
buffer.add<ApplicationSystemVersion>("1.0");
|
||||
buffer.add<ApplicationSystemVendor>("BTS");
|
||||
|
||||
if (session_cfg.has_trading_session_id()) {
|
||||
buffer.add<fix::NoTradingSessions>(1);
|
||||
buffer.add<fix::TradingSessionID>(session_cfg.trading_session_id());
|
||||
}
|
||||
if (session_cfg.has_udf_support_indicator())
|
||||
buffer.add<fix::UDFSupportIndicator>(
|
||||
session_cfg.udf_support_indicator());
|
||||
buffer.add<fix::UDFSupportIndicator>(session_cfg.udf_support_indicator());
|
||||
|
||||
if (session_cfg.use_cme_secure_logon()) {
|
||||
bts_assert(session_cfg.sender_compid().size() >= 3);
|
||||
@@ -819,24 +819,25 @@ OutFIXPtr make_logon(uint32_t seq_num, uint32_t last_seq_num_processed,
|
||||
std::string last_seq_num_str(9, ' ');
|
||||
i32_toa(last_seq_num_processed, &last_seq_num_str[0], 9);
|
||||
auto ld = glbx::calculate_hmac(
|
||||
session_id, seq_num_str, session_cfg.sender_compid(),
|
||||
session_cfg.sender_subid(), time_str, session_cfg.target_subid(),
|
||||
std::to_string(session_cfg.seconds_between_hbs()),
|
||||
session_cfg.sender_locationid(), last_seq_num_str, application,
|
||||
"1.0", "BTS");
|
||||
#ifndef BTS_EDGE
|
||||
LOG(Jetfix, Info, "Canonical string for secure logon: {}",
|
||||
ld.canonical);
|
||||
#endif
|
||||
session_id, seq_num_str, session_cfg.sender_compid(),
|
||||
session_cfg.sender_subid(), time_str, session_cfg.target_subid(),
|
||||
std::to_string(session_cfg.seconds_between_hbs()),
|
||||
session_cfg.sender_locationid(), last_seq_num_str, application, "1.0",
|
||||
"BTS");
|
||||
#ifndef BTS_EDGE
|
||||
LOG(Jetfix, Info, "Canonical string for secure logon: {}", ld.canonical);
|
||||
#endif
|
||||
buffer.add<EncodedTextLen>(ld.access_key.size());
|
||||
buffer.add<EncodedText>(ld.access_key);
|
||||
buffer.add<EncryptedPasswordMethod>(std::string_view{"CME-1-SHA-256"});
|
||||
buffer.add<EncryptedPasswordMethod>("CME-1-SHA-256");
|
||||
buffer.add<EncryptedPasswordLen>(ld.signature.size());
|
||||
buffer.add<EncryptedPassword>(ld.signature);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.add<RawDataLength>(session_cfg.raw_data().size());
|
||||
buffer.add<RawData>(session_cfg.raw_data());
|
||||
if (session_cfg.user_name() != "")
|
||||
if(session_cfg.user_name() != "")
|
||||
buffer.add<UserName>(session_cfg.user_name());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ void load_seq_nums(std::string const &path, uint32_t *last_seq_num,
|
||||
FIXFileStore::FIXFileStore(config::JetFIX::Connection const &cfg,
|
||||
std::string base_path)
|
||||
: me(new PImpl(cfg)) {
|
||||
auto sn = session_name(cfg).as_string;
|
||||
auto sn = session_name(cfg);
|
||||
me->active = sn.size() > 0;
|
||||
if (me->active) {
|
||||
|
||||
|
||||
@@ -75,74 +75,66 @@ bool in_session (datetime::PTime const &ref_date,
|
||||
return closest_earlier_end<closest_earlier_start;
|
||||
}
|
||||
|
||||
SessionName session_name_from_ptime (datetime::PTime t,
|
||||
std::string session_name_from_ptime (datetime::PTime t,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end)
|
||||
{
|
||||
SessionName result;
|
||||
result.as_string = std::string(10,' ');
|
||||
std::string result (10,' ');
|
||||
auto start_of_session = t;
|
||||
|
||||
if (time_of_day_start > time_of_day_end &&
|
||||
start_of_session.time_of_day () <= time_of_day_end)
|
||||
start_of_session -= boost::gregorian::date_duration (1);
|
||||
|
||||
using namespace boost::posix_time;
|
||||
ptime epoch(boost::gregorian::date(1970,1,1));
|
||||
ptime session_start_date(start_of_session.date());
|
||||
result.as_uint64_t = (session_start_date - epoch).total_milliseconds();
|
||||
|
||||
sprintf (&(result.as_string[0]), "%04d-%02d-%02d",
|
||||
|
||||
sprintf (&result[0], "%04d-%02d-%02d",
|
||||
(unsigned short) start_of_session.date ().year (),
|
||||
start_of_session.date ().month ().as_number (),
|
||||
start_of_session.date ().day ().as_number ());
|
||||
return result;
|
||||
}
|
||||
|
||||
SessionName session_name (datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday_start,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::gregorian::greg_weekday weekday_end,
|
||||
boost::posix_time::time_duration time_of_day_end)
|
||||
std::string session_name (datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday_start,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::gregorian::greg_weekday weekday_end,
|
||||
boost::posix_time::time_duration time_of_day_end)
|
||||
{
|
||||
if (in_session (ref_date,weekday_start,time_of_day_start,weekday_end,time_of_day_end))
|
||||
return session_name_from_ptime (closest_before (ref_date,weekday_start,time_of_day_start),
|
||||
boost::posix_time::time_duration(0, 0, 0),
|
||||
boost::posix_time::time_duration(0, 0, 1));
|
||||
else
|
||||
return {};
|
||||
return std::string ();
|
||||
}
|
||||
|
||||
SessionName session_name (datetime::PTime const &ref_date,
|
||||
std::string session_name (datetime::PTime const &ref_date,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end)
|
||||
{
|
||||
if (in_session (ref_date,time_of_day_start,time_of_day_end))
|
||||
return session_name_from_ptime (ref_date, time_of_day_start, time_of_day_end);
|
||||
else
|
||||
return {};
|
||||
return "";
|
||||
}
|
||||
|
||||
SessionName session_name (config::JetFIX::Connection const &session_cfg)
|
||||
std::string session_name (config::JetFIX::Connection const &session_cfg)
|
||||
{
|
||||
auto now = datetime::local_now ();
|
||||
|
||||
if (session_cfg.has_start_day ()) {
|
||||
bts_assert (session_cfg.has_end_day ());
|
||||
auto sn =
|
||||
session_name (now,
|
||||
parse_weekday (session_cfg.start_day ()),
|
||||
parse_time (session_cfg.start_time ()),
|
||||
parse_weekday (session_cfg.end_day ()),
|
||||
parse_time (session_cfg.end_time ()));
|
||||
sn.as_uint64_t += session_cfg.uuid_offset();
|
||||
return sn;
|
||||
return session_name (now,
|
||||
parse_weekday (session_cfg.start_day ()),
|
||||
parse_time (session_cfg.start_time ()),
|
||||
parse_weekday (session_cfg.end_day ()),
|
||||
parse_time (session_cfg.end_time ()));
|
||||
} else
|
||||
return session_name (now,
|
||||
parse_time (session_cfg.start_time ()),
|
||||
parse_time (session_cfg.end_time ()));
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/config/protos/jetfix.pb.h"
|
||||
#include "lib/utils/datetime.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "lib/utils/datetime.h"
|
||||
#include "lib/config/protos/jetfix.pb.h"
|
||||
|
||||
namespace boost {
|
||||
namespace gregorian {
|
||||
@@ -11,45 +11,39 @@ class greg_weekday;
|
||||
}
|
||||
namespace posix_time {
|
||||
class time_duration;
|
||||
}
|
||||
} // namespace boost
|
||||
}}
|
||||
|
||||
|
||||
namespace bts {
|
||||
namespace jetfix {
|
||||
|
||||
boost::gregorian::greg_weekday parse_weekday(std::string weekday_str);
|
||||
bool parse_time(std::string const &time_str,
|
||||
boost::posix_time::time_duration *out);
|
||||
boost::gregorian::greg_weekday parse_weekday (std::string weekday_str);
|
||||
bool parse_time (std::string const &time_str,boost::posix_time::time_duration *out);
|
||||
|
||||
datetime::PTime closest_before(datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday,
|
||||
boost::posix_time::time_duration time_of_day);
|
||||
datetime::PTime closest_before (datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday,
|
||||
boost::posix_time::time_duration time_of_day);
|
||||
|
||||
bool in_session(datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday_start,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::gregorian::greg_weekday weekday_end,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
bool in_session (datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday_start,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::gregorian::greg_weekday weekday_end,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
|
||||
bool in_session(datetime::PTime const &ref_date,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
bool in_session (datetime::PTime const &ref_date,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
|
||||
struct SessionName {
|
||||
std::string as_string;
|
||||
uint64_t as_uint64_t;
|
||||
bool empty() const {return as_string.empty();};
|
||||
};
|
||||
std::string session_name (datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday_start,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::gregorian::greg_weekday weekday_end,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
|
||||
SessionName session_name(datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday_start,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::gregorian::greg_weekday weekday_end,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
SessionName session_name(datetime::PTime const &ref_date,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
SessionName session_name(config::JetFIX::Connection const &session_cfg);
|
||||
std::string session_name (datetime::PTime const &ref_date,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
|
||||
} // namespace jetfix
|
||||
} // namespace bts
|
||||
std::string session_name (config::JetFIX::Connection const &session_cfg);
|
||||
|
||||
}}
|
||||
@@ -81,9 +81,9 @@ TEST_CASE ("JetFIX Field2Tests", "[jetfix]")
|
||||
std::string out (20, ' ');
|
||||
typedef StringField<123> Field;
|
||||
|
||||
REQUIRE(Field::max_value_size (std::string_view{"hello"})==5);
|
||||
REQUIRE(Field::max_value_size ("hello")==5);
|
||||
|
||||
auto result = Field::write (&out[0],std::string_view{"hello"});
|
||||
auto result = Field::write (&out[0],"hello");
|
||||
REQUIRE (result.first==5);
|
||||
REQUIRE (result.second=='h'+'e'+'l'+'l'+'o');
|
||||
REQUIRE (out.compare (0,5,"hello") == 0);
|
||||
@@ -112,7 +112,7 @@ TEST_CASE ("JetFIX FIXFragmentTests" , "[jetfix]")
|
||||
FIXFragment g (0);
|
||||
g.add<CharField<1>> ('a');
|
||||
g.add<FloatField<2>> (1.2,-1,6);
|
||||
g.add<StringField<3>> (std::string_view{"hello"});
|
||||
g.add<StringField<3>> ("hello");
|
||||
g.add<IntField<4>> (123,3);
|
||||
const char*t_s = "20150427-19:05:18.922";
|
||||
g.add<TimeField<5>> (datetime::parse_FIX_timestamp (t_s));
|
||||
@@ -141,14 +141,14 @@ TEST_CASE ("JetFIX FIXFragmentTests" , "[jetfix]")
|
||||
FIXFragment g;
|
||||
auto c_bm = g.add<CharField<1>> ('a');
|
||||
auto f_bm = g.add<FloatField<2>> (1.2,-1,6);
|
||||
auto s_bm = g.add<StringField<3>> (std::string_view{"hello"});
|
||||
auto s_bm = g.add<StringField<3>> ("hello");
|
||||
auto i_bm = g.add<IntField<4>> (123,3);
|
||||
auto t_bm = g.add<TimeField<5>> (datetime::parse_FIX_timestamp (t_s1));
|
||||
auto b_bm = g.add<BoolField<6>> (true);
|
||||
|
||||
g.overwrite (c_bm,'b');
|
||||
g.overwrite (f_bm,1.3,-1,6);
|
||||
g.overwrite (s_bm,std::string_view {"olleh"});
|
||||
g.overwrite (s_bm,"olleh");
|
||||
g.overwrite (i_bm,321,3);
|
||||
g.overwrite (t_bm,(datetime::parse_FIX_timestamp (t_s2)));
|
||||
g.overwrite (b_bm,false);
|
||||
@@ -172,11 +172,11 @@ TEST_CASE ("JetFIX FIXFragmentTests" , "[jetfix]")
|
||||
FIXFragment g1;;
|
||||
g1.add<CharField<1>> ('a');
|
||||
g1.add<FloatField<2>> (1.2,-1,6);
|
||||
g1.add<StringField<3>> (std::string_view{"hello"});
|
||||
g1.add<StringField<3>> ("hello");
|
||||
auto chk1 = g1.checksum ();
|
||||
|
||||
FIXFragment g2;
|
||||
g2.add<StringField<4>> (std::string_view{"goodbye"});
|
||||
g2.add<StringField<4>> ("goodbye");
|
||||
g2.add<IntField<5>> (321,3);
|
||||
auto chk2 = g2.checksum ();
|
||||
|
||||
|
||||
@@ -6,270 +6,279 @@
|
||||
#include "lib/jetfix/common/OutFIXPtr.h"
|
||||
#include "lib/jetfix/store/FIXFileStore.h"
|
||||
#include "lib/jetfix/store/session_name.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/utils/TempDir.h"
|
||||
#include "lib/utils/TimeStamp.h"
|
||||
#include "lib/utils/datetime.h"
|
||||
#include "lib/logging/logging.h"
|
||||
|
||||
#include <boost/date_time.hpp>
|
||||
#include <boost/date_time/gregorian/gregorian.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/date_time.hpp>
|
||||
|
||||
namespace bts {
|
||||
namespace jetfix {
|
||||
|
||||
TEST_CASE("JetFIX SessionNameTests", "[jetfix]") {
|
||||
SECTION("greg_weekday_works") {
|
||||
const char *days[] = {"sun", "Monday", "tuesday", "Wedn",
|
||||
"Thursday", "Friday", "sat"};
|
||||
TEST_CASE ("JetFIX SessionNameTests", "[jetfix]")
|
||||
{
|
||||
SECTION("greg_weekday_works")
|
||||
{
|
||||
const char*days [] = {"sun","Monday","tuesday","Wedn","Thursday","Friday","sat"};
|
||||
|
||||
int i = 0;
|
||||
int i =0;
|
||||
for (auto d : days)
|
||||
REQUIRE(parse_weekday(d) == boost::gregorian::greg_weekday(i++));
|
||||
REQUIRE (parse_weekday (d)==boost::gregorian::greg_weekday (i++));
|
||||
}
|
||||
|
||||
SECTION("closest_before_works")
|
||||
{
|
||||
auto same_day_before = closest_before (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(16, 59, 59));
|
||||
REQUIRE (datetime::FIX_date_time_string (same_day_before)=="20150717-16:59:59");
|
||||
|
||||
auto same_day_after = closest_before (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(17,0,1));
|
||||
REQUIRE (datetime::FIX_date_time_string (same_day_after)=="20150710-17:00:01");
|
||||
|
||||
auto another_day_same_week = closest_before (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::gregorian::Thursday,
|
||||
boost::posix_time::time_duration(16, 59, 59));
|
||||
REQUIRE (datetime::FIX_date_time_string (another_day_same_week)=="20150716-16:59:59");
|
||||
|
||||
auto another_day_previous_week = closest_before (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::gregorian::Saturday,
|
||||
boost::posix_time::time_duration(16, 59, 59));
|
||||
REQUIRE (datetime::FIX_date_time_string (another_day_previous_week)=="20150711-16:59:59");
|
||||
|
||||
}
|
||||
|
||||
SECTION("closest_before_works") {
|
||||
auto same_day_before =
|
||||
closest_before(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(16, 59, 59));
|
||||
REQUIRE(datetime::FIX_date_time_string(same_day_before) ==
|
||||
"20150717-16:59:59");
|
||||
SECTION("in_session_works")
|
||||
{
|
||||
REQUIRE (in_session (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::gregorian::Sunday,
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(17, 0, 1)));
|
||||
|
||||
auto same_day_after = closest_before(
|
||||
datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::gregorian::Friday, boost::posix_time::time_duration(17, 0, 1));
|
||||
REQUIRE(datetime::FIX_date_time_string(same_day_after) ==
|
||||
"20150710-17:00:01");
|
||||
REQUIRE (!in_session (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::gregorian::Sunday,
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(16, 59, 59)));
|
||||
|
||||
auto another_day_same_week =
|
||||
closest_before(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::gregorian::Thursday,
|
||||
boost::posix_time::time_duration(16, 59, 59));
|
||||
REQUIRE(datetime::FIX_date_time_string(another_day_same_week) ==
|
||||
"20150716-16:59:59");
|
||||
REQUIRE (in_session (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
boost::posix_time::time_duration(17, 59, 59)));
|
||||
|
||||
auto another_day_previous_week =
|
||||
closest_before(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::gregorian::Saturday,
|
||||
boost::posix_time::time_duration(16, 59, 59));
|
||||
REQUIRE(datetime::FIX_date_time_string(another_day_previous_week) ==
|
||||
"20150711-16:59:59");
|
||||
REQUIRE (!in_session (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::posix_time::time_duration(0,0,0),
|
||||
boost::posix_time::time_duration(16, 0,0)));
|
||||
|
||||
REQUIRE (in_session (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)));
|
||||
|
||||
REQUIRE (!in_session (datetime::make_ptime (2015,7,17,17,47,0,0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)));
|
||||
}
|
||||
|
||||
SECTION("in_session_works") {
|
||||
REQUIRE(in_session(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::gregorian::Sunday,
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
SECTION("session_name_works")
|
||||
{
|
||||
REQUIRE (session_name (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::gregorian::Sunday,
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(17, 0, 1)) ==
|
||||
"2015-07-12");
|
||||
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(17, 0, 1)));
|
||||
|
||||
REQUIRE(!in_session(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::gregorian::Sunday,
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
REQUIRE (session_name (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::gregorian::Sunday,
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(16, 59, 59)) == "");
|
||||
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(16, 59, 59)));
|
||||
REQUIRE (session_name (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
boost::posix_time::time_duration(17, 59, 59)) ==
|
||||
"2015-07-17");
|
||||
|
||||
REQUIRE(in_session(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
boost::posix_time::time_duration(17, 59, 59)));
|
||||
REQUIRE (session_name (datetime::make_ptime (2015,7,17,18,0,0,0),
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
boost::posix_time::time_duration(17, 59, 59)) ==
|
||||
"");
|
||||
|
||||
REQUIRE(!in_session(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::posix_time::time_duration(0, 0, 0),
|
||||
boost::posix_time::time_duration(16, 0, 0)));
|
||||
REQUIRE (session_name (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)) ==
|
||||
"2015-07-16");
|
||||
|
||||
REQUIRE(in_session(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)));
|
||||
REQUIRE (session_name (datetime::make_ptime (2015,7,17,17,51,0,0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)) ==
|
||||
"2015-07-17");
|
||||
|
||||
REQUIRE(!in_session(datetime::make_ptime(2015, 7, 17, 17, 47, 0, 0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)));
|
||||
}
|
||||
REQUIRE (session_name (datetime::make_ptime (2015,7,17,17,47,0,0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)) ==
|
||||
"");
|
||||
|
||||
SECTION("session_name_works") {
|
||||
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::gregorian::Sunday,
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(17, 0, 1)).as_string ==
|
||||
"2015-07-12");
|
||||
|
||||
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::gregorian::Sunday,
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(16, 59, 59)).as_string == "");
|
||||
|
||||
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
boost::posix_time::time_duration(17, 59, 59)).as_string ==
|
||||
"2015-07-17");
|
||||
|
||||
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 18, 0, 0, 0),
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
boost::posix_time::time_duration(17, 59, 59)).as_string == "");
|
||||
|
||||
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)).as_string ==
|
||||
"2015-07-16");
|
||||
|
||||
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 17, 51, 0, 0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)).as_string ==
|
||||
"2015-07-17");
|
||||
|
||||
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 17, 47, 0, 0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)).as_string == "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("JetFIX FileStoreTests", "[jetfix]") {
|
||||
SECTION("empty_store_works") {
|
||||
config::JetFIX::Connection c;
|
||||
c.set_name("test");
|
||||
c.set_sender_compid("CME");
|
||||
c.set_sender_subid("G");
|
||||
c.set_target_compid("1U7001N");
|
||||
c.set_target_subid("BLUESTREAM");
|
||||
|
||||
c.set_start_time("00:00:00");
|
||||
c.set_end_time("23:59:59");
|
||||
TEST_CASE ("JetFIX FileStoreTests", "[jetfix]")
|
||||
{
|
||||
SECTION("empty_store_works")
|
||||
{
|
||||
config::JetFIX::Connection c;
|
||||
c.set_name ("test");
|
||||
c.set_sender_compid ("CME");
|
||||
c.set_sender_subid ("G");
|
||||
c.set_target_compid ("1U7001N");
|
||||
c.set_target_subid ("BLUESTREAM");
|
||||
|
||||
c.set_start_time ("00:00:00");
|
||||
c.set_end_time ("23:59:59");
|
||||
|
||||
utils::TempDir td;
|
||||
|
||||
FIXFileStore fs(c, td.name());
|
||||
REQUIRE(fs.session_active());
|
||||
REQUIRE(fs.replay().size() == 0);
|
||||
REQUIRE(fs.last_seq_num() == 0);
|
||||
REQUIRE(fs.last_seq_num_processed() == 0);
|
||||
|
||||
FIXFileStore fs (c,td.name ());
|
||||
REQUIRE (fs.session_active ());
|
||||
REQUIRE (fs.replay ().size ()==0);
|
||||
REQUIRE (fs.last_seq_num ()==0);
|
||||
REQUIRE (fs.last_seq_num_processed ()==0);
|
||||
}
|
||||
|
||||
SECTION("in_msg_is_stored") {
|
||||
auto td = std::make_shared<utils::TempDir>();
|
||||
SECTION("in_msg_is_stored")
|
||||
{
|
||||
auto td = std::make_shared<utils::TempDir> ();
|
||||
config::JetFIX::Connection c;
|
||||
c.set_name("test");
|
||||
c.set_sender_compid("CME");
|
||||
c.set_sender_subid("G");
|
||||
c.set_target_compid("1U7001N");
|
||||
c.set_target_subid("BLUESTREAM");
|
||||
c.set_name ("test");
|
||||
c.set_sender_compid ("CME");
|
||||
c.set_sender_subid ("G");
|
||||
c.set_target_compid ("1U7001N");
|
||||
c.set_target_subid ("BLUESTREAM");
|
||||
|
||||
c.set_start_time("00:00:00");
|
||||
c.set_end_time("23:59:59");
|
||||
c.set_start_time ("00:00:00");
|
||||
c.set_end_time ("23:59:59");
|
||||
|
||||
FIXEncodingStream stream(c);
|
||||
auto &buf = stream.new_msg(MessageTypes::Logon);
|
||||
buf.add<fix::TargetLocationID>(std::string_view{"US,NC"});
|
||||
buf.add<fix::EncryptMethod>(0);
|
||||
FIXEncodingStream stream (c);
|
||||
auto &buf = stream.new_msg (MessageTypes::Logon);
|
||||
buf.add<fix::TargetLocationID> ("US,NC");
|
||||
buf.add<fix::EncryptMethod> (0);
|
||||
buf.add<fix::HeartBtInt>(30);
|
||||
buf.add<fix::ApplicationSystemName>(std::string_view{"O2"});
|
||||
buf.add<fix::ApplicationSystemVersion>(std::string_view{"1.0"});
|
||||
buf.add<fix::ApplicationSystemVendor>(std::string_view{"BTS"});
|
||||
stream.close();
|
||||
stream.stamp(2, 3, datetime::FIX_timestamp(datetime::now()));
|
||||
auto fix = stream.to_str();
|
||||
|
||||
buf.add<fix::ApplicationSystemName> ("O2");
|
||||
buf.add<fix::ApplicationSystemVersion> ("1.0");
|
||||
buf.add<fix::ApplicationSystemVendor> ("BTS");
|
||||
stream.close ();
|
||||
stream.stamp (2,3,datetime::FIX_timestamp (datetime::now ()));
|
||||
auto fix = stream.to_str ();
|
||||
|
||||
{
|
||||
FIXFileStore fs(c, td->name());
|
||||
fs.store(InMsgBuffer(fix));
|
||||
fs.set_last_msg_processed(3);
|
||||
FIXFileStore fs (c,td->name ());
|
||||
fs.store (InMsgBuffer (fix));
|
||||
fs.set_last_msg_processed (3);
|
||||
}
|
||||
|
||||
FIXFileStore fs(c, td->name());
|
||||
auto replay = fs.replay();
|
||||
REQUIRE(replay.size() == 1);
|
||||
REQUIRE(replay[0].type() == MessageTypes::Logon);
|
||||
REQUIRE(replay[0].to_str() == fix);
|
||||
REQUIRE(fs.last_seq_num() == 0);
|
||||
REQUIRE(fs.last_seq_num_processed() == 3);
|
||||
FIXFileStore fs (c,td->name ());
|
||||
auto replay = fs.replay ();
|
||||
REQUIRE (replay.size ()==1);
|
||||
REQUIRE (replay[0].type ()==MessageTypes::Logon);
|
||||
REQUIRE (replay[0].to_str ()==fix);
|
||||
REQUIRE (fs.last_seq_num ()==0);
|
||||
REQUIRE (fs.last_seq_num_processed ()==3);
|
||||
}
|
||||
|
||||
SECTION("out_msg_is_stored") {
|
||||
auto td = std::make_shared<utils::TempDir>();
|
||||
SECTION("out_msg_is_stored")
|
||||
{
|
||||
auto td = std::make_shared<utils::TempDir> ();
|
||||
config::JetFIX::Connection c;
|
||||
c.set_name("test");
|
||||
c.set_sender_compid("CME");
|
||||
c.set_sender_subid("G");
|
||||
c.set_target_compid("1U7001N");
|
||||
c.set_target_subid("BLUESTREAM");
|
||||
c.set_name ("test");
|
||||
c.set_sender_compid ("CME");
|
||||
c.set_sender_subid ("G");
|
||||
c.set_target_compid ("1U7001N");
|
||||
c.set_target_subid ("BLUESTREAM");
|
||||
|
||||
c.set_start_time("00:00:00");
|
||||
c.set_end_time("23:59:59");
|
||||
c.set_start_time ("00:00:00");
|
||||
c.set_end_time ("23:59:59");
|
||||
|
||||
auto msg_vec = std::make_shared<OutFIX>(c);
|
||||
auto &stream = msg_vec->fix.back();
|
||||
auto &buf = stream.new_msg(MessageTypes::Logon);
|
||||
buf.add<fix::TargetLocationID>(std::string_view{"US,NC"});
|
||||
buf.add<fix::EncryptMethod>(0);
|
||||
auto &stream = msg_vec->fix.back ();
|
||||
auto &buf = stream.new_msg (MessageTypes::Logon);
|
||||
buf.add<fix::TargetLocationID> ("US,NC");
|
||||
buf.add<fix::EncryptMethod> (0);
|
||||
buf.add<fix::HeartBtInt>(30);
|
||||
buf.add<fix::ApplicationSystemName>(std::string_view{"O2"});
|
||||
buf.add<fix::ApplicationSystemVersion>(std::string_view{"1.0"});
|
||||
buf.add<fix::ApplicationSystemVendor>(std::string_view{"BTS"});
|
||||
stream.close();
|
||||
stream.stamp(2, 3, datetime::FIX_timestamp(datetime::now()));
|
||||
|
||||
buf.add<fix::ApplicationSystemName> ("O2");
|
||||
buf.add<fix::ApplicationSystemVersion> ("1.0");
|
||||
buf.add<fix::ApplicationSystemVendor> ("BTS");
|
||||
stream.close ();
|
||||
stream.stamp (2,3,datetime::FIX_timestamp (datetime::now ()));
|
||||
|
||||
{
|
||||
FIXFileStore fs(c, td->name());
|
||||
fs.store(msg_vec);
|
||||
FIXFileStore fs (c,td->name ());
|
||||
fs.store (msg_vec);
|
||||
}
|
||||
|
||||
FIXFileStore fs(c, td->name());
|
||||
auto replay = fs.replay();
|
||||
REQUIRE(replay.size() == 0);
|
||||
REQUIRE(fs.last_seq_num() == 3);
|
||||
REQUIRE(fs.last_seq_num_processed() == 0);
|
||||
FIXFileStore fs (c,td->name ());
|
||||
auto replay = fs.replay ();
|
||||
REQUIRE (replay.size ()==0);
|
||||
REQUIRE (fs.last_seq_num ()==3);
|
||||
REQUIRE (fs.last_seq_num_processed ()==0);
|
||||
}
|
||||
|
||||
SECTION("test_performance") {
|
||||
auto td = std::make_shared<utils::TempDir>();
|
||||
SECTION("test_performance")
|
||||
{
|
||||
auto td = std::make_shared<utils::TempDir> ();
|
||||
config::JetFIX::Connection c;
|
||||
c.set_name("test");
|
||||
c.set_sender_compid("CME");
|
||||
c.set_sender_subid("G");
|
||||
c.set_target_compid("1U7001N");
|
||||
c.set_target_subid("BLUESTREAM");
|
||||
c.set_name ("test");
|
||||
c.set_sender_compid ("CME");
|
||||
c.set_sender_subid ("G");
|
||||
c.set_target_compid ("1U7001N");
|
||||
c.set_target_subid ("BLUESTREAM");
|
||||
|
||||
c.set_start_time("00:00:00");
|
||||
c.set_end_time("23:59:59");
|
||||
c.set_start_time ("00:00:00");
|
||||
c.set_end_time ("23:59:59");
|
||||
|
||||
auto start = utils::TimeStamp::now();
|
||||
auto start = utils::TimeStamp::now ();
|
||||
{
|
||||
FIXFileStore fs(c, td->name());
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
FIXFileStore fs (c,td->name ());
|
||||
for (int i = 0; i < 10000;i++) {
|
||||
auto msg_vec = std::make_shared<std::vector<FIXEncodingStream>>();
|
||||
msg_vec->emplace_back(c);
|
||||
auto &stream = msg_vec->back();
|
||||
auto &buf = stream.new_msg(MessageTypes::Logon);
|
||||
buf.add<fix::TargetLocationID>(std::string_view{"US,NC"});
|
||||
buf.add<fix::EncryptMethod>(0);
|
||||
msg_vec->emplace_back (c);
|
||||
auto &stream = msg_vec->back ();
|
||||
auto &buf = stream.new_msg (MessageTypes::Logon);
|
||||
buf.add<fix::TargetLocationID> ("US,NC");
|
||||
buf.add<fix::EncryptMethod> (0);
|
||||
buf.add<fix::HeartBtInt>(30);
|
||||
buf.add<fix::ApplicationSystemName>(std::string_view{"O2"});
|
||||
buf.add<fix::ApplicationSystemVersion>(std::string_view{"1.0"});
|
||||
buf.add<fix::ApplicationSystemVendor>(std::string_view{"BTS"});
|
||||
stream.close();
|
||||
stream.stamp(i, 3,
|
||||
datetime::FIX_timestamp(datetime::now() -
|
||||
boost::gregorian::days(1)));
|
||||
fs.store(InMsgBuffer(stream.to_str()));
|
||||
buf.add<fix::ApplicationSystemName> ("O2");
|
||||
buf.add<fix::ApplicationSystemVersion> ("1.0");
|
||||
buf.add<fix::ApplicationSystemVendor> ("BTS");
|
||||
stream.close ();
|
||||
stream.stamp (i,3,datetime::FIX_timestamp (datetime::now () - boost::gregorian::days (1)));
|
||||
fs.store (InMsgBuffer (stream.to_str ()));
|
||||
}
|
||||
}
|
||||
auto stop = utils::TimeStamp::now();
|
||||
LOG(Testing, Info, "jetfix store gen: {} ms",
|
||||
(stop - start).milliseconds());
|
||||
|
||||
start = utils::TimeStamp::now();
|
||||
FIXFileStore fs(c, td->name());
|
||||
stop = utils::TimeStamp::now();
|
||||
LOG(Testing, Info, "jetfix store load: {} ms",
|
||||
(stop - start).milliseconds());
|
||||
auto stop = utils::TimeStamp::now ();
|
||||
LOG(Testing,Info,"jetfix store gen: {} ms", (stop-start).milliseconds () );
|
||||
|
||||
start = utils::TimeStamp::now ();
|
||||
FIXFileStore fs (c,td->name ());
|
||||
stop = utils::TimeStamp::now ();
|
||||
LOG(Testing,Info,"jetfix store load: {} ms", (stop-start).milliseconds () );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace jetfix
|
||||
} // namespace bts
|
||||
}}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -120,7 +120,6 @@ void configure_logging(bts::config::Logging const&cfg, bts::config::ThreadGroupC
|
||||
{log::Plugin,"Plugin"},
|
||||
{log::Sdk,"Sdk"},
|
||||
{log::Http,"Http"},
|
||||
{log::iLink3,"iLink3"},
|
||||
};
|
||||
|
||||
real_cfg.sinks["console"] =
|
||||
|
||||
@@ -46,7 +46,6 @@ constexpr log::Subsystem DataFlow {Latency.ordinal+1 };
|
||||
constexpr log::Subsystem Plugin {DataFlow.ordinal+1 };
|
||||
constexpr log::Subsystem Sdk {Plugin.ordinal+1 };
|
||||
constexpr log::Subsystem Http {Sdk.ordinal+1 };
|
||||
constexpr log::Subsystem iLink3 {Http.ordinal+1 };
|
||||
|
||||
struct LoggerHandle {
|
||||
LoggerHandle(LoggerHandle const&) = delete;
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
#include "lib/utils/ValueWrapper.h"
|
||||
namespace bts {
|
||||
using ExchangeSecurityKey = utils::ValueWrapper<struct ExchangeSecurityKeyTag,uint64_t>;
|
||||
}
|
||||
+165
-171
@@ -1,72 +1,71 @@
|
||||
#ifndef _WIN32
|
||||
#include "MBOServiceServer.h"
|
||||
#include "MBOServiceServer.h"
|
||||
|
||||
#include "ExchangeOrderKey.h"
|
||||
#include "MBOProcessor.h"
|
||||
#include "MDClient.h"
|
||||
#include "lib/api/services/OrderService.client.pb.h"
|
||||
#include "lib/domain_model/Security.h"
|
||||
#include "lib/orderman/orderman_utils/orderman_common.h"
|
||||
#include "lib/utils/Dispatcher.h"
|
||||
#include "lib/utils/TimeStamp.h"
|
||||
#include "lib/domain_model/Security.h"
|
||||
#include "MDClient.h"
|
||||
#include "ExchangeOrderKey.h"
|
||||
#include "MBOProcessor.h"
|
||||
|
||||
#include "lib/utils/LockBox.h"
|
||||
|
||||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
|
||||
using namespace bts::api::orderman;
|
||||
|
||||
namespace bts {
|
||||
namespace md {
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
//
|
||||
// Simple class to handle MD recovery and maintain an index of
|
||||
// SecurityKey=>MDConsumerHandle
|
||||
// Simple class to handle MD recovery and maintain an index of SecurityKey=>MDConsumerHandle
|
||||
|
||||
class HandleIndex {
|
||||
MDClient &_client;
|
||||
MDClient& _client;
|
||||
int _sub;
|
||||
std::optional<MDConsumer> _consumer;
|
||||
|
||||
public:
|
||||
utils::LockBox<std::unordered_map<SecurityKey, MDConsumerHandle>> index;
|
||||
public:
|
||||
utils::LockBox<std::unordered_map<SecurityKey,MDConsumerHandle>> index;
|
||||
|
||||
HandleIndex(md::MDClient &client)
|
||||
: _client(client), _sub(0), _consumer(std::nullopt), index() {
|
||||
_sub = _client.on_consumer().subscribe(
|
||||
[=](const MDConsumer &c) { on_consumer(c); });
|
||||
on_consumer(_client.current_consumer());
|
||||
}
|
||||
HandleIndex(md::MDClient& client):
|
||||
_client(client),
|
||||
_sub(0),
|
||||
_consumer(std::nullopt),
|
||||
index() {
|
||||
_sub = _client.on_consumer().subscribe([=](const MDConsumer& c) { on_consumer(c); });
|
||||
on_consumer(_client.current_consumer());
|
||||
}
|
||||
|
||||
~HandleIndex() { _client.on_consumer().unsubscribe(_sub); }
|
||||
|
||||
private:
|
||||
void on_consumer(const MDConsumer &c) {
|
||||
|
||||
private:
|
||||
void on_consumer(const MDConsumer& c) {
|
||||
MDConsumer temp(c);
|
||||
if (temp.all_heartbeats_ok()) {
|
||||
auto existing = _consumer ? _consumer->id() : 0;
|
||||
LOG(md, Info, "Updateing MBOService MDConsumer. Old {} new {}",
|
||||
existing, temp.id());
|
||||
LOG(md,Info, "Updateing MBOService MDConsumer. Old {} new {}", existing, temp.id());
|
||||
// clear the index
|
||||
index.lock([](auto &index) { index.clear(); });
|
||||
index.lock([](auto& index) { index.clear(); });
|
||||
// Swap to new consumer
|
||||
if (_consumer) {
|
||||
_consumer->swap(temp);
|
||||
} else {
|
||||
_consumer = temp;
|
||||
}
|
||||
else { _consumer = temp; }
|
||||
// Subscribe to on_security
|
||||
auto id = _consumer->id();
|
||||
_consumer->on_security(
|
||||
[this, id](const SecurityPtr &, MDConsumerHandle handle) {
|
||||
if (_consumer->id() == id) {
|
||||
index.lock([handle](auto &index) {
|
||||
index[SecurityKey(handle.key())] = handle;
|
||||
});
|
||||
}
|
||||
});
|
||||
_consumer->on_security([this,id](const SecurityPtr&, MDConsumerHandle handle) {
|
||||
if (_consumer->id() == id) {
|
||||
index.lock([handle](auto& index) {
|
||||
index[SecurityKey(handle.key())] = handle;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -74,20 +73,21 @@ class HandleIndex {
|
||||
class ActiveOrder {
|
||||
SecurityKey _security;
|
||||
SparkOrderKey _id;
|
||||
ExchangeOrderKey _ex_id;
|
||||
ExchangeOrderKey _ex_id;
|
||||
int32_t _position;
|
||||
|
||||
public:
|
||||
public:
|
||||
// empty constructor needed for unordered map operator[]
|
||||
// ActiveOrder(): _security(), _id(), _ex_id(), _position(-1) {
|
||||
// bts_assert(false); }
|
||||
ActiveOrder(SecurityKey sec, SparkOrderKey s, ExchangeOrderKey ex)
|
||||
: _security(sec), _id(s), _ex_id(ex), _position(-1) {}
|
||||
// ActiveOrder(): _security(), _id(), _ex_id(), _position(-1) { bts_assert(false); }
|
||||
ActiveOrder(SecurityKey sec, SparkOrderKey s, ExchangeOrderKey ex): _security(sec), _id(s), _ex_id(ex), _position(-1) {}
|
||||
ActiveOrder(SecurityKey sec, SparkOrderKey s, const std::string& ex): _security(sec), _id(s), _ex_id(), _position(-1) {
|
||||
_ex_id = ExchangeOrderKey(std::stoul(ex));
|
||||
}
|
||||
|
||||
SecurityKey security_id() const { return _security; }
|
||||
SparkOrderKey id() const { return _id; }
|
||||
ExchangeOrderKey exchange_id() const { return _ex_id; }
|
||||
int32_t &position() { return _position; };
|
||||
int32_t& position() { return _position; };
|
||||
int32_t position() const { return _position; };
|
||||
bool set_position(int32_t pos) {
|
||||
if (pos != _position) {
|
||||
@@ -108,14 +108,23 @@ class ActiveOrder {
|
||||
// MBOService
|
||||
|
||||
struct MBOServiceImpl {
|
||||
MBOServiceImpl(api::ServiceContext &ctx, utils::Dispatcher &d,
|
||||
md::MDClient &c, MBOServiceBase::PiqPublisher &&pub)
|
||||
: dispatcher(d), client(c),
|
||||
orders(ctx.locate<api::orderman::OrderService>()), handle_index(c),
|
||||
publish(pub), timer(d, 200, [&]() { timer_tick(); }), orders_sub() {}
|
||||
MBOServiceImpl(
|
||||
api::ServiceContext& ctx,
|
||||
utils::Dispatcher& d,
|
||||
md::MDClient& c,
|
||||
MBOServiceBase::PiqPublisher&& pub
|
||||
):
|
||||
dispatcher(d),
|
||||
client(c),
|
||||
orders(ctx.locate<api::orderman::OrderService>()),
|
||||
handle_index(c),
|
||||
publish(pub),
|
||||
timer(d, 200, [&]() {timer_tick();}),
|
||||
orders_sub()
|
||||
{}
|
||||
|
||||
utils::Dispatcher &dispatcher;
|
||||
md::MDClient &client;
|
||||
utils::Dispatcher& dispatcher;
|
||||
md::MDClient& client;
|
||||
OrderService orders;
|
||||
|
||||
HandleIndex handle_index;
|
||||
@@ -129,23 +138,23 @@ struct MBOServiceImpl {
|
||||
void flush();
|
||||
};
|
||||
|
||||
|
||||
|
||||
///////////////////////
|
||||
|
||||
std::optional<uint32_t>
|
||||
search_orders(const ExchangeOrderKey oid,
|
||||
const std::vector<SnapshotOrder> &orders) {
|
||||
std::optional<uint32_t> search_orders(const ExchangeOrderKey oid, const std::vector<SnapshotOrder>& orders) {
|
||||
IntPrice price = {};
|
||||
size_t position = 0;
|
||||
for (size_t x = 0; x < orders.size(); ++x) {
|
||||
const auto &oo = orders[x];
|
||||
const auto& oo = orders[x];
|
||||
if (oo.id == oid) {
|
||||
if (oo.price == price)
|
||||
return {position};
|
||||
else
|
||||
return 0;
|
||||
} else if (price == oo.price) {
|
||||
if (oo.price == price) return { position };
|
||||
else return 0;
|
||||
}
|
||||
else if (price == oo.price) {
|
||||
position += oo.size;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
price = oo.price;
|
||||
position = oo.size;
|
||||
}
|
||||
@@ -153,11 +162,11 @@ search_orders(const ExchangeOrderKey oid,
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
bool update_position(const HandleIndex &handles, ActiveOrder &order) {
|
||||
const auto &index = handles.index;
|
||||
auto handle = index.lock([id = order.security_id()](const auto &index) {
|
||||
bool update_position(const HandleIndex& handles, ActiveOrder& order) {
|
||||
const auto& index = handles.index;
|
||||
auto handle = index.lock([id=order.security_id()](const auto& index) {
|
||||
auto iter = index.find(id);
|
||||
return iter != index.end() ? iter->second : MDConsumerHandle{};
|
||||
return iter != index.end() ? iter->second : MDConsumerHandle {};
|
||||
});
|
||||
|
||||
if (handle.is_initialized()) {
|
||||
@@ -176,9 +185,9 @@ bool update_position(const HandleIndex &handles, ActiveOrder &order) {
|
||||
}
|
||||
|
||||
void MBOServiceImpl::timer_tick() {
|
||||
// Dispatcher thread
|
||||
//Dispatcher thread
|
||||
std::vector<OrderPIQ> rows;
|
||||
for (auto &pair : active) {
|
||||
for (auto& pair : active) {
|
||||
if (update_position(handle_index, pair.second)) {
|
||||
rows.push_back(pair.second.to_piq());
|
||||
}
|
||||
@@ -188,30 +197,29 @@ void MBOServiceImpl::timer_tick() {
|
||||
}
|
||||
}
|
||||
|
||||
const NativeOrderState *native_order_state(const OrderRecord &record) {
|
||||
switch (record.state().custom_case()) {
|
||||
case OrderState::kMarket:
|
||||
return &record.state().market().native_state();
|
||||
case OrderState::kLimit:
|
||||
return &record.state().limit().native_state();
|
||||
case OrderState::kStop:
|
||||
return &record.state().stop().native_state();
|
||||
case OrderState::kStopLimit:
|
||||
return &record.state().stop_limit().native_state();
|
||||
case OrderState::kGlbxIceberg:
|
||||
return &record.state().glbx_iceberg().native_state();
|
||||
default:
|
||||
const NativeOrderState* native_order_state(const OrderRecord& record) {
|
||||
switch(record.state().custom_case()) {
|
||||
case OrderState::kMarket:
|
||||
return &record.state().market().native_state();
|
||||
case OrderState::kLimit:
|
||||
return &record.state().limit().native_state();
|
||||
case OrderState::kStop:
|
||||
return &record.state().stop().native_state();
|
||||
case OrderState::kStopLimit:
|
||||
return &record.state().stop_limit().native_state();
|
||||
case OrderState::kGlbxIceberg:
|
||||
return &record.state().glbx_iceberg().native_state();
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool is_active_exchange_order(const OrderRecord &record) {
|
||||
bool is_active_exchange_order(const OrderRecord& record) {
|
||||
return record.state().status() == ORDER_STATUS_WORKING &&
|
||||
native_order_state(record) != nullptr;
|
||||
}
|
||||
|
||||
void try_remove(MBOServiceImpl &me, std::set<uint32_t> &to_remove,
|
||||
const OrderRecord &record) {
|
||||
void try_remove(MBOServiceImpl& me, std::set<uint32_t>& to_remove, const OrderRecord& record) {
|
||||
auto key = SparkOrderKey(record.key());
|
||||
auto iter = me.active.find(key);
|
||||
if (iter != me.active.end()) {
|
||||
@@ -219,113 +227,103 @@ void try_remove(MBOServiceImpl &me, std::set<uint32_t> &to_remove,
|
||||
to_remove.insert(key.value());
|
||||
}
|
||||
}
|
||||
void try_add(MBOServiceImpl &me, std::vector<OrderPIQ> &to_add,
|
||||
const OrderRecord &record) {
|
||||
void try_add(MBOServiceImpl& me, std::vector<OrderPIQ>& to_add, const OrderRecord& record) {
|
||||
if (is_active_exchange_order(record)) {
|
||||
auto native = native_order_state(record);
|
||||
|
||||
auto ex_key = orderman::get_exchange_order_id(*native);
|
||||
auto u64_key =
|
||||
std::visit(overloaded{[](orderman::ExchangeOrderID const &str) {
|
||||
return std::stoul(str.value().data());
|
||||
},
|
||||
[](orderman::ExchangeOrderID64 oid) {
|
||||
return oid.value();
|
||||
}},
|
||||
ex_key);
|
||||
bts_assert(native);
|
||||
ActiveOrder order(SecurityKey(record.def().security_key()),
|
||||
SparkOrderKey(record.key()), ExchangeOrderKey{u64_key});
|
||||
ActiveOrder order(
|
||||
SecurityKey(record.def().security_key()),
|
||||
SparkOrderKey(record.key()),
|
||||
native->exchange_order_id());
|
||||
update_position(me.handle_index, order);
|
||||
to_add.push_back(order.to_piq());
|
||||
me.active.insert(std::make_pair(order.id(), order));
|
||||
}
|
||||
}
|
||||
|
||||
MBOServiceServer::MBOServiceServer(api::ServiceContext &ctx,
|
||||
utils::Dispatcher &d, md::MDClient &c)
|
||||
: MBOServiceBase(ctx),
|
||||
_me(new MBOServiceImpl(ctx, d, c, make_piq_publisher())) {
|
||||
// subscribe to mdclient ✔
|
||||
// make publishers ✔
|
||||
// subscribe to orders => stash active orders dict
|
||||
_me->orders_sub =
|
||||
_me->orders.subscribe_orders().subscribe([=](const auto &update) {
|
||||
// api thread
|
||||
const auto &added = update.added();
|
||||
const auto &changed = update.changed();
|
||||
const auto &removed = update.removed();
|
||||
_me->dispatcher.post([this, added, changed, removed]() {
|
||||
// dispatcher thread
|
||||
std::vector<OrderPIQ> to_add, to_change;
|
||||
std::set<uint32_t> to_remove;
|
||||
MBOServiceServer::MBOServiceServer(
|
||||
api::ServiceContext& ctx,
|
||||
utils::Dispatcher& d,
|
||||
md::MDClient& c
|
||||
) :
|
||||
MBOServiceBase(ctx),
|
||||
_me(new MBOServiceImpl(ctx,d,c,make_piq_publisher()))
|
||||
{
|
||||
// subscribe to mdclient ✔
|
||||
// make publishers ✔
|
||||
// subscribe to orders => stash active orders dict
|
||||
_me->orders_sub =
|
||||
_me->orders.subscribe_orders().subscribe([=](const auto& update) {
|
||||
// api thread
|
||||
const auto& added = update.added();
|
||||
const auto& changed = update.changed();
|
||||
const auto& removed = update.removed();
|
||||
_me->dispatcher.post([this,added,changed,removed]() {
|
||||
// dispatcher thread
|
||||
std::vector<OrderPIQ> to_add, to_change;
|
||||
std::set<uint32_t> to_remove;
|
||||
|
||||
// Remove
|
||||
for (const auto &r : removed) {
|
||||
// If it was active remove it and add to to_remove
|
||||
try_remove(*_me, to_remove, *r);
|
||||
}
|
||||
// Added
|
||||
for (const auto &add : added) {
|
||||
// If active add look up the position and add to the state
|
||||
try_add(*_me, to_add, *add);
|
||||
}
|
||||
// Changed
|
||||
for (const auto &ch : changed) {
|
||||
// new order is active and old is not look up piq and add to
|
||||
// state
|
||||
bool is_active = is_active_exchange_order(*ch.current());
|
||||
bool was_active = is_active_exchange_order(*ch.previous());
|
||||
if (is_active && !was_active) {
|
||||
try_add(*_me, to_add, *ch.current());
|
||||
} else if (was_active && !is_active) {
|
||||
try_remove(*_me, to_remove, *ch.current());
|
||||
}
|
||||
// is_active && was_active => don't care
|
||||
// !is_active && !was_active => don't care
|
||||
}
|
||||
// Remove
|
||||
for(const auto& r : removed) {
|
||||
// If it was active remove it and add to to_remove
|
||||
try_remove(*_me, to_remove, *r);
|
||||
}
|
||||
// Added
|
||||
for(const auto& add : added) {
|
||||
// If active add look up the position and add to the state
|
||||
try_add(*_me, to_add, *add);
|
||||
}
|
||||
// Changed
|
||||
for(const auto& ch : changed) {
|
||||
// new order is active and old is not look up piq and add to state
|
||||
bool is_active = is_active_exchange_order(*ch.current());
|
||||
bool was_active = is_active_exchange_order(*ch.previous());
|
||||
if (is_active && !was_active) {
|
||||
try_add(*_me, to_add, *ch.current());
|
||||
}
|
||||
else if (was_active && !is_active) {
|
||||
try_remove(*_me, to_remove, *ch.current());
|
||||
}
|
||||
// is_active && was_active => don't care
|
||||
// !is_active && !was_active => don't care
|
||||
}
|
||||
|
||||
_me->publish(&to_add, &to_change, &to_remove);
|
||||
if (!_me->timer.running())
|
||||
_me->timer.start();
|
||||
});
|
||||
});
|
||||
}
|
||||
_me->publish(&to_add, &to_change, &to_remove);
|
||||
if (!_me->timer.running()) _me->timer.start();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
MBOServiceServer::~MBOServiceServer() {}
|
||||
MBOServiceServer::~MBOServiceServer() { }
|
||||
|
||||
void MBOServiceServer::get_orders_for_security(
|
||||
const MBOSecurityQuery &request, const api::Response<PositionData> &reply) {
|
||||
|
||||
void MBOServiceServer::get_orders_for_security(const MBOSecurityQuery& request, const api::Response<PositionData>& reply) {
|
||||
PositionData response;
|
||||
response.set_security_id(request.security_id());
|
||||
auto handle = _me->handle_index.index.lock(
|
||||
[id = request.security_id()](const auto &index) {
|
||||
auto iter = index.find(SecurityKey(id));
|
||||
return iter != index.end() ? iter->second : MDConsumerHandle{};
|
||||
});
|
||||
auto handle = _me->handle_index.index.lock([id=request.security_id()](const auto& index) {
|
||||
auto iter = index.find(SecurityKey(id));
|
||||
return iter != index.end() ? iter->second : MDConsumerHandle {};
|
||||
});
|
||||
|
||||
std::unordered_map<ExchangeOrderKey, SparkOrderKey> reverse;
|
||||
for (const auto &pair : _me->active) {
|
||||
for (const auto& pair : _me->active) {
|
||||
reverse.insert(std::make_pair(pair.second.exchange_id(), pair.first));
|
||||
}
|
||||
|
||||
size_t count = 0;
|
||||
auto tick = handle.get_minimum_tick();
|
||||
if (handle.is_initialized()) {
|
||||
if(handle.is_initialized()) {
|
||||
auto mbo = handle.get_mbo();
|
||||
if (mbo) {
|
||||
for (const auto &o : mbo->bids) {
|
||||
for (const auto& o : mbo->bids) {
|
||||
double price = o.price.price();
|
||||
bool isnan = os::is_nan(request.price_level());
|
||||
if (isnan || securities::test_price_equality(request.price_level(),
|
||||
price, tick)) {
|
||||
if (isnan || securities::test_price_equality(request.price_level(), price, tick)) {
|
||||
++count;
|
||||
if (request.limit() && count > request.limit())
|
||||
break;
|
||||
auto *entry = response.add_bid();
|
||||
if (request.limit() && count > request.limit()) break;
|
||||
auto* entry = response.add_bid();
|
||||
entry->set_exchange_id(o.id.value());
|
||||
if (isnan)
|
||||
entry->set_price(price);
|
||||
if (isnan) entry->set_price(price);
|
||||
entry->set_size(o.size);
|
||||
auto iter = reverse.find(o.id);
|
||||
if (iter != reverse.end()) {
|
||||
@@ -333,18 +331,15 @@ void MBOServiceServer::get_orders_for_security(
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto &o : mbo->asks) {
|
||||
for (const auto& o : mbo->asks) {
|
||||
double price = o.price.price();
|
||||
bool isnan = os::is_nan(request.price_level());
|
||||
if (isnan || securities::test_price_equality(request.price_level(),
|
||||
price, tick)) {
|
||||
if (isnan || securities::test_price_equality(request.price_level(), price, tick)) {
|
||||
++count;
|
||||
if (request.limit() && count > request.limit())
|
||||
break;
|
||||
auto *entry = response.add_ask();
|
||||
if (request.limit() && count > request.limit()) break;
|
||||
auto* entry = response.add_ask();
|
||||
entry->set_exchange_id(o.id.value());
|
||||
if (isnan)
|
||||
entry->set_price(price);
|
||||
if (isnan) entry->set_price(price);
|
||||
entry->set_size(o.size);
|
||||
auto iter = reverse.find(o.id);
|
||||
if (iter != reverse.end()) {
|
||||
@@ -354,10 +349,9 @@ void MBOServiceServer::get_orders_for_security(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
reply(response);
|
||||
}
|
||||
|
||||
} // namespace md
|
||||
} // namespace bts
|
||||
}} //namespace
|
||||
#endif
|
||||
@@ -92,7 +92,7 @@ MDConsumer& MDClient::current_consumer() const {
|
||||
return _self->_consumer;
|
||||
}
|
||||
SecurityOracle MDClient::oracle() const {
|
||||
return SecurityOracle(_self->_cache);
|
||||
return SecurityOracle(*this);
|
||||
}
|
||||
std::set<UserSymbol> MDClient::symbols() const {
|
||||
return _self->_symbols;
|
||||
|
||||
@@ -897,7 +897,7 @@ public:
|
||||
scan_securities(resolve_legs);
|
||||
}
|
||||
|
||||
const Security* get_security(SecurityKey key) const {
|
||||
SecurityPtr get_security(SecurityKey key) const {
|
||||
return _cache.get_security(key);
|
||||
}
|
||||
|
||||
@@ -979,7 +979,7 @@ size_t MDConsumer::walk_security_list(SecurityCallback cb, const string& symbol,
|
||||
|
||||
size_t MDConsumer::scan_securities(bool resolve_legs) { return _pimpl->scan_securities(resolve_legs); }
|
||||
void MDConsumer::on_security(SecurityCallback cb, bool resolve_legs) { _pimpl->on_security(cb, resolve_legs); }
|
||||
const api::Security* MDConsumer::get_security(SecurityKey key) const { return _pimpl->get_security(key); }
|
||||
const api::Security* MDConsumer::get_security(SecurityKey key) const { return _pimpl->get_security(key).get(); }
|
||||
std::vector<api::Security const*> MDConsumer::get_securities() const {return _pimpl->get_securities();}
|
||||
|
||||
MDConsumerChannel MDConsumer::get_channel(const std::string& symbol, SecurityType type, Venue exchange) const {
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
#include "SecurityCache.h"
|
||||
#include "SecurityDB.h"
|
||||
#include "lib/utils/Dispatcher.h"
|
||||
#include "lib/utils/LockBox.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <google/btree/btree_map.h>
|
||||
#include <tbb/concurrent_queue.h>
|
||||
#include <mutex>
|
||||
|
||||
@@ -12,8 +10,8 @@ namespace bts {
|
||||
namespace md {
|
||||
|
||||
struct SecurityCacheImpl {
|
||||
utils::LockBox<btree::btree_map<SecurityKey, SecurityPtr>> cache;
|
||||
utils::LockBox<btree::btree_map<ExchangeSecurityKey, SecurityPtr>> ex_cache;
|
||||
std::mutex cache_mutex;
|
||||
std::unordered_map<SecurityKey, SecurityPtr> cache;
|
||||
tbb::concurrent_queue<SecurityPtr> update_queue;
|
||||
void enqueue_update_db(const SecurityPtr&);
|
||||
void flush();
|
||||
@@ -44,83 +42,61 @@ void SecurityCacheImpl::flush() {
|
||||
SecurityCache::SecurityCache() : _me(std::make_shared<SecurityCacheImpl>()) {}
|
||||
SecurityCache::~SecurityCache() {}
|
||||
|
||||
const Security* SecurityCache::try_get_security(SecurityKey key) const {
|
||||
return _me->cache.lock([key](btree::btree_map<SecurityKey, SecurityPtr>& t) {
|
||||
auto iter = t.find(key);
|
||||
if (iter != t.end()) {
|
||||
return iter->second.get();
|
||||
}
|
||||
return (const api::Security*)nullptr;
|
||||
});
|
||||
}
|
||||
const Security* SecurityCache::try_get_security(ExchangeSecurityKey key) const {
|
||||
return _me->ex_cache.lock([key](btree::btree_map<ExchangeSecurityKey,SecurityPtr>& t) {
|
||||
auto iter = t.find(key);
|
||||
if (iter != t.end()) {
|
||||
return iter->second.get();
|
||||
}
|
||||
return (const api::Security*)nullptr;
|
||||
});
|
||||
SecurityPtr SecurityCache::try_get_security(SecurityKey key) const {
|
||||
std::lock_guard<std::mutex> lock(_me->cache_mutex);
|
||||
auto iter = _me->cache.find(key);
|
||||
if (iter != _me->cache.end()) {
|
||||
return iter->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
const Security* SecurityCache::get_security(SecurityKey key) {
|
||||
const Security* result = try_get_security(key);
|
||||
if (result == nullptr) {
|
||||
// outside lock
|
||||
SecurityPtr SecurityCache::get_security(SecurityKey key) {
|
||||
std::unique_lock<std::mutex> lock(_me->cache_mutex);
|
||||
auto iter = _me->cache.find(key);
|
||||
if (iter != _me->cache.end()) {
|
||||
return iter->second;
|
||||
}
|
||||
else {
|
||||
// unlock for db read
|
||||
lock.unlock();
|
||||
auto security = db::find_security(key);
|
||||
if (security) {
|
||||
LOG(md,Info, "Loaded security from database: {} {}", security->symbol(), security->id());
|
||||
return add_db_security(security);
|
||||
}
|
||||
return nullptr;
|
||||
return security;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<api::Security const*> SecurityCache::get_securities() {
|
||||
std::vector<api::Security const*> SecurityCache::get_securities()
|
||||
{
|
||||
std::vector<api::Security const*> result;
|
||||
result.reserve(100000);
|
||||
|
||||
_me->cache.lock([&result](auto& cache) {
|
||||
for (auto const&p : cache) {
|
||||
result.push_back(p.second.get());
|
||||
}
|
||||
});
|
||||
std::unique_lock<std::mutex> lock(_me->cache_mutex);
|
||||
for (auto const&p : _me->cache)
|
||||
result.push_back(p.second.get());
|
||||
return result;
|
||||
}
|
||||
|
||||
const Security* SecurityCache::add_db_security(const SecurityPtr& security) {
|
||||
SecurityPtr SecurityCache::add_db_security(const SecurityPtr& security) {
|
||||
bts_assert(security);
|
||||
if (security->has_glbx()) {
|
||||
_me->ex_cache.lock([&security](auto& cache) {
|
||||
ExchangeSecurityKey key(security->id());
|
||||
cache.insert(std::make_pair(key, security));
|
||||
});
|
||||
}
|
||||
return _me->cache.lock([&security](auto& cache) {
|
||||
SecurityKey key(security->id());
|
||||
auto result = cache.insert(std::make_pair(key, security));
|
||||
// If result was inserted result.first->second is equal to security
|
||||
// If the value was already present it must be a recently inserted 'live' security and we should use it
|
||||
return result.first->second.get();
|
||||
});
|
||||
std::lock_guard<std::mutex> lock(_me->cache_mutex);
|
||||
SecurityKey key(security->id());
|
||||
auto result = _me->cache.insert(std::make_pair(SecurityKey(security->id()), security));
|
||||
// If result was inserted result.first->second is equal to security
|
||||
// If the value was already present it must be a recently inserted 'live' security and we should use it
|
||||
return result.first->second;
|
||||
}
|
||||
bool SecurityCache::add_live_security(const SecurityPtr& security) {
|
||||
bts_assert(security);
|
||||
if (security->has_glbx()) {
|
||||
_me->ex_cache.lock([&security](auto& cache) {
|
||||
ExchangeSecurityKey key(security->id());
|
||||
cache.insert(std::make_pair(key, security));
|
||||
});
|
||||
}
|
||||
return _me->cache.lock([&](auto& cache) {
|
||||
SecurityKey key(security->id());
|
||||
// Insert but don't overwrite existing
|
||||
auto result = cache.insert(std::make_pair(SecurityKey(security->id()), security));
|
||||
_me->enqueue_update_db(security);
|
||||
return result.second;
|
||||
});
|
||||
std::lock_guard<std::mutex> lock(_me->cache_mutex);
|
||||
SecurityKey key(security->id());
|
||||
// Insert but don't overwrite existing
|
||||
auto result = _me->cache.insert(std::make_pair(SecurityKey(security->id()), security));
|
||||
_me->enqueue_update_db(security);
|
||||
return result.second;
|
||||
}
|
||||
|
||||
void SecurityCache::flush_to_disk() { _me->flush(); }
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "lib/domain_model/Security.pb.h"
|
||||
#include "MDConsumerHandle.h"
|
||||
#include "lib/domain_model/SecurityKey.h"
|
||||
#include "lib/md/ExchangeSecurityKey.h"
|
||||
#include "SecurityPtr.h"
|
||||
#include <memory>
|
||||
|
||||
@@ -21,18 +20,17 @@ public:
|
||||
~SecurityCache();
|
||||
|
||||
//Load security from cache with fallback to database
|
||||
const Security* get_security(SecurityKey key);
|
||||
SecurityPtr get_security(SecurityKey key);
|
||||
|
||||
// Load all securities from cache, no fallback to database
|
||||
std::vector<api::Security const*> get_securities();
|
||||
|
||||
// Get the security if it's in the cache otherwise return nullptr. Does not query security database.
|
||||
const Security* try_get_security(SecurityKey key) const;
|
||||
const Security* try_get_security(ExchangeSecurityKey key) const;
|
||||
SecurityPtr try_get_security(SecurityKey key) const;
|
||||
|
||||
// returns true if the cache was updated
|
||||
bool add_live_security(const SecurityPtr& security);
|
||||
const Security* add_db_security(const SecurityPtr& security);
|
||||
SecurityPtr add_db_security(const SecurityPtr& security);
|
||||
|
||||
void flush_to_disk();
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include "core/bts_core/utils/bts_no_copy.h"
|
||||
#include "Shm/FixedSecurity.h"
|
||||
#include "../bts_conn_exports.h"
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <atomic>
|
||||
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
|
||||
class BTS_EXPORT SecurityConstructor {
|
||||
// An object "pool" optimized for the case where only one instance is ever used at a time
|
||||
template <class T>
|
||||
class SingleObjectPool<T> {
|
||||
public:
|
||||
using ptr_type = std::unique_ptr<T, std::function<void(T*)>>;
|
||||
ptr_type acquire() {
|
||||
T* pt = _inst ? _inst.release() : new T();
|
||||
return ptr_type(pt, [this](T* ptr) {
|
||||
return_inst(std::unique_ptr<T>(ptr));
|
||||
});
|
||||
}
|
||||
private:
|
||||
void return_inst(std::unique_ptr<T> t) {
|
||||
if (!_inst) {
|
||||
reset(t);
|
||||
_inst = std::move(t);
|
||||
}
|
||||
}
|
||||
unique_ptr<T> _inst;
|
||||
};
|
||||
|
||||
public:
|
||||
SecurityConstructor() : _future(), _option(), _spread() {}
|
||||
|
||||
SingleObjectPool<FixedFutureSecurity>& future() { return _future; }
|
||||
SingleObjectPool<FixedOptionSecurity>& option() { return _option; }
|
||||
SingleObjectPool<FixedSpreadSecurityL>& spread() { return _spread; }
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
void reset(T& t) {
|
||||
new (&t)T();
|
||||
}
|
||||
|
||||
SingleObjectPool<FixedFutureSecurity> _future;
|
||||
SingleObjectPool<FixedOptionSecurity> _option;
|
||||
SingleObjectPool<FixedSpreadSecurityL> _spread;
|
||||
};
|
||||
|
||||
|
||||
}}//namespace
|
||||
|
||||
@@ -4,18 +4,14 @@
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
SecurityOracle::SecurityOracle(SecurityCache& cache): _cache(cache) {}
|
||||
SecurityOracle::SecurityOracle(const MDClient& client): _client(client) {}
|
||||
SecurityOracle::~SecurityOracle() { }
|
||||
const api::Security* SecurityOracle::get_security(SecurityKey key) const {
|
||||
return _cache.get_security(key);
|
||||
}
|
||||
|
||||
const api::Security* SecurityOracle::get_security(ExchangeSecurityKey key) const {
|
||||
return _cache.try_get_security(key);
|
||||
return _client.current_consumer().get_security(key);
|
||||
}
|
||||
|
||||
std::vector<api::Security const*> SecurityOracle::get_securities() const {
|
||||
return _cache.get_securities();
|
||||
return _client.current_consumer().get_securities();
|
||||
}
|
||||
|
||||
}}//namespace
|
||||
@@ -1,8 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/domain_model/SecurityKey.h"
|
||||
#include "lib/md/ExchangeSecurityKey.h"
|
||||
#include "lib/md/SecurityCache.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@@ -11,12 +9,11 @@ namespace api {class Security;}
|
||||
namespace md {
|
||||
class MDClient;
|
||||
class SecurityOracle {
|
||||
SecurityCache& _cache;
|
||||
const MDClient& _client;
|
||||
public:
|
||||
SecurityOracle(SecurityCache&);
|
||||
SecurityOracle(const MDClient&);
|
||||
~SecurityOracle();
|
||||
const api::Security* get_security(SecurityKey key) const;
|
||||
const api::Security* get_security(ExchangeSecurityKey key) const;
|
||||
std::vector<api::Security const*> get_securities() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,209 +0,0 @@
|
||||
|
||||
# Overview
|
||||
|
||||
The core abstraction that everything else is built on is the MDProducer+MDProducerHandle / MDConsumer+MDConsumerHandle.
|
||||
|
||||
A new market data source constructs an MDProducer and adds securities to it. When a security is added you get back an MDProducerHandle representing that security in shared memory. The memory is fully allocated and books can be written immidiately but the security will not be visible to the MDConsumer until the security key is stored on disk (SecurityIDRecorder). The MDProducerHandle assumes a **single writer** for most operations and *may break silently if this constraint is violated*.
|
||||
|
||||
The MDConsumer is the dual of the MDProducer. It provides an on_security() callback which is driven by the call to scan_securities(). No threads are created by MDConsumer/MDProducer instead they get cpu time from periodic calls to scan_securities (consumer), SecurityIDRecorder::do_work (producer). When a security is discovered by scan_securities the callback is called with the Security and the MDConsumerHandle. The MDConsumerHandle is thread safe and can be safely copied and read from concurrently.
|
||||
|
||||
## Single Writer Principle
|
||||
- https://mechanical-sympathy.blogspot.com/2011/09/single-writer-principle.html
|
||||
|
||||
# Core Classes
|
||||
|
||||
'*' = New in spark
|
||||
* MBOProcessor*
|
||||
* MBOServiceServer*
|
||||
* MDClient*
|
||||
* MDConsumer
|
||||
* MDConsumerHandle
|
||||
* MDProducer
|
||||
* MDProducerHandle
|
||||
* PlatformLoader
|
||||
* PriceSize/IntPrice
|
||||
* SecurityCache*
|
||||
* SecurityOracle*
|
||||
* SecurityDB*
|
||||
* SecurityIDRecorder
|
||||
* SecurityMapper*
|
||||
* SettlementRecorder
|
||||
* SyntheticSecurityService
|
||||
* FixedSecurity.h / MDStructure.h
|
||||
* SharedList.h
|
||||
|
||||
## MBOProcessor*
|
||||
|
||||
This class is an optional dependency of MDProducer. It takes the low level incremental updates to the MBO book and constructs the book on a different thread. This is optimized for the UI use case so it tries to get the mbo messages out of the critical path as soon as possible. This uses regular heap memory so is not compatible with out of process operation. It exposes a reader and writer interface.
|
||||
|
||||
Each update goes into a queue and gets processed by MBOProcessorImpl::process_incremental() on a single background thread. This thread drains the queue and constructs the books in place. Then it copies snapshots of the books and publishes them as immutable snapshots which are consumed by the MBOServiceServer/UI. If mbo load gets very high this function will stop publishing snapshots and only update books until the load reduces.
|
||||
|
||||
## MBOServiceServer*
|
||||
|
||||
Reads the snapshots from the MBOProcessor/MBOReader and serves them for the UI.
|
||||
|
||||
## MDClient*
|
||||
|
||||
New in spark.
|
||||
|
||||
This class handles constructing the MDConsumer, calling scan_securities on it and checking for bad heartbeats and re-constructing the MDConsumer if there was a failure. In edge those tasks were the responsibility of each consumer of the market data but it was mitigated because most things used streams rather than MDConsumer directly. MDConsumer is reference counted internally so when the consuming code gets an on_consumer() callback with a new MDConsumer it should keep a copy of the old MDConsumer until it has finished any asyncronous processes involving the MDConsumerHandles from that first consumer. Once an MDConsumer is destroyed the MDConsumerHandles it produced will cause an **Access Violation** on reading because the memory has been unmapped.
|
||||
|
||||
Spark has always used MD in process so, while based on existing functionality, this recovery process hasn't been well tested.
|
||||
|
||||
## MDConsumer
|
||||
|
||||
An MDConsumer maps the shared memory sections and produces MDConsumerHandles. These handles are only valid as long as the MDConsumer exists. It would make some sense to store the MDConsumer reference in the MDConsumerHandle to avoid this but MDConsumerHandle is designed to be *very* small for fast iteration. The MDConsumer also holds a reference to the ISyntheticSecurityService and makes synthetic securities 'look like' regular shared memory securities using polymorphism in the MDConsumerHandle.
|
||||
|
||||
Internally MDConsumer is a collection of MDConsumerInst which each handle a single symbol+type+exchange and the corresponding shared memory blocks.
|
||||
|
||||
* scan_securities - in spark this is always called by MDClient
|
||||
* get_handle - Low level way to get a handle. Does a linear walk though shared memory and can return a void handle (MDConsumerHandle::is_initialize() == false).
|
||||
* get_managed_handle - returns a 'managed handle' this is a shared_ptr to an MDConsumerhandle. The only difference is that this is tracked by the MDConsumer and may transition from uninitialized to initialized. Storing these in a vector and walking them is almost *50% slower* than doing the same thing with an unmanaged handle. If you use these it's probably best to store the uninitialized handles in a nursery and check them periodically. You can dereference a managed handle into a regular handle at any time.
|
||||
* get_channel - Gets a MDConsumerChannel representing common data for a symbol+type+exchange. This is mostly for the trade ticker / rfq and also exposes various counters which get published to dev-stats.
|
||||
|
||||
On Linux MDConsumer maps the shared memory as read-only pages. On Windows it cannot do this because std::atomic uses a different instruction which is considered a write by the CPU so we map it read/write.
|
||||
|
||||
If we have multiple platforms that can produce md for an exchange (i.e. onixs vs emumba) the MDConsumer consults the PlatformMap config key to determine which to read from. The md replayer impersonates the producer it was recorded from.
|
||||
|
||||
### MDConsumerChannel
|
||||
|
||||
read_trades() and read_rfqs() read from a ring buffer stored in the header section of the shared memory. They read directly into a google::protobuf::RepeatedPtrField to avoid extra copies in the QueryServer but can just as easily read into a std::vector. They expose a 'cursor' representing the position in the ring buffer and this cursor is sent all the way to the client so it can request updates.
|
||||
|
||||
## MDConsumerHandle
|
||||
|
||||
An MDConsumerHandle 4 states and would proably be impemented as an std::variant<> if done today. If not for the high performance requirements it could also be a virtual class but I didn't want to pay for a vtable. It is the size of 4 pointers plus the enum tag.
|
||||
|
||||
* VOID - an uninitialized handle
|
||||
* BBO - Legacy from Edge. This represents an option book where we only kept the top to save space. I think this has rotted by now and wont work but I kept it as an example of how to add polymorphism to the shared memory types.
|
||||
* DEPTH - Used for all exchange securities in Spark.
|
||||
* SYNTHETIC - A Synthetic handle. These are bigger so they get stored as a pointer.
|
||||
|
||||
Reading from a BBO/DEPTH handle is done with an optimistic copy. If you inrease the size of the book data this copy can fail more often and get significantly worse perf. The result of the read can be changed, unchanged or busy (timeout). In edge 'busy' happened 1-2 times per day across all reads and gets logged by QueryServer.
|
||||
|
||||
## MDProducer
|
||||
|
||||
Handle to writeable shared memory. Each market data producer "platform" (onixs_cme, onixs_ice, emumba, etc) constructs one.
|
||||
|
||||
## MDProducerHandle
|
||||
|
||||
All updates to a single security go through here. Assumes a single writer thread.
|
||||
|
||||
## PlatformLoader
|
||||
|
||||
In Edge this was the entry point to the run() for the market data producer process. It loaded the bts_md_*.so so each producer process only loaded the third party objects for a particular producer. In spark this is all in process so this is defunct. It looks like it still exists because it has some utility functions that probably belong in another file.
|
||||
|
||||
## PriceSize/IntPrice
|
||||
|
||||
Market data uses integer prices to avoid double problems.
|
||||
|
||||
## SecurityCache*
|
||||
|
||||
Created/Owned by MDClient this owns the Securities.
|
||||
|
||||
It has methods to get a security from the live collection or load them from the SecurityDB on disk if someone asks for one that hasn't been seen yet.
|
||||
* If a security is loaded from disk it 'freezes' it so when the live security arrives it will continue to serve the old security so we don't end up with 2 copies of a single security with different properties.
|
||||
* This class is also responsible for sending the live securities to the SecurityDB where we *always* overwrite stored securities with what comes from the exchange.
|
||||
* Survives beyond the MDConsumer in case of crash/recovery of out of process md.
|
||||
|
||||
## SecurityOracle*
|
||||
Interface on top of SecurityCache exposing the read get_ operations.
|
||||
|
||||
## SecurityDB*
|
||||
* Just a collection of methods for save/load of securities to sqlite.
|
||||
* Stored in binary format so we can use the protobuf versioning
|
||||
|
||||
## SecurityIDRecorder
|
||||
* Manages security to unique 32 bit id mapping across multiple processes
|
||||
* Provides a callback when ids are safely persisted.
|
||||
|
||||
## SecurityMapper*
|
||||
|
||||
* Happens *before* the security gets stored in shared memory.
|
||||
* Replaces the mapping.h from edge with a more organized mechanism.
|
||||
* Owned by the MDProducer each security is passed though SecurityMapper::apply() before it is first stored in shared memory
|
||||
* SecurityMapper is made up of multiple ISecurityMapper instances so each mapping can be in it's own class so it's easier to read each mapping. Currently all mappings are defined in SecurityMaper.cpp
|
||||
* The mappings each have an opportunity to mutate the FixedSecurity.
|
||||
|
||||
## SettlementRecorder
|
||||
|
||||
In Edge SettlementRecorder stored the settlements for a security so we could preserve yesterday/day before settlement. In Spark this broke and nobody seemed to care so it was never fixed.
|
||||
|
||||
## SyntheticSecurityService
|
||||
|
||||
Each synthetic security is a api::Security and a chunk of metadata. This service handles API requests to create/update synthetics and fires callbacks for MDConsumer which does the work of producing synethic books.
|
||||
|
||||
## MDStructure.h
|
||||
|
||||
### Hot vs Cold
|
||||
|
||||
## FixedSecurity.h
|
||||
* variable sized structure in shared mem
|
||||
* For FixedSpreadSecurity we stack allocate a lot of legs then memcpy() into shared memory only the correct number of legs
|
||||
* When accessing FixedSpreadSecurity it is cast back to a large number of legs. Iterate legs based on leg_count() not the static leg count.
|
||||
|
||||
## SharedList.h
|
||||
* Primitive list-like abstraction over shared memory
|
||||
* Allows variable sized entries so always accessed in O(N)
|
||||
* Data never moves so we point into it for O(1)
|
||||
|
||||
# Market Data Relay / Recorder
|
||||
* QueryServer
|
||||
- Stateless request/response
|
||||
- Uses multiple threads for throughput
|
||||
- Uses change timestamps per channel instead of per security
|
||||
- Will over-send books that change around the time of the request
|
||||
|
||||
* RelayClient
|
||||
- Runs in the shell (or outside)
|
||||
- Replicates books from the server (QueryServer) to local shared memory
|
||||
|
||||
* RelayRecorder
|
||||
- Records Protobufs from QueryServer to a file
|
||||
|
||||
# Diagnostic tools
|
||||
* sparkd md dump [symbol] [type] [exchange] [hot?]
|
||||
- **Primary diagnostic tool**
|
||||
- ShmDumper.cpp
|
||||
- Shows current contents of shared memory
|
||||
- append 'hot' to the end to see hot data i.e. books
|
||||
- If you get a "cannot open" check that the file exists in /run/shm/
|
||||
* dumpsecurities
|
||||
- Inspect security database
|
||||
* sparkd md tail
|
||||
- MDPeriodicDumper.cpp
|
||||
- for validating new market data
|
||||
- prints books at given sequence number interval
|
||||
* rectool
|
||||
- print recording to text / convert back to futures.coconut
|
||||
- This is most useful to checking if a particular symbol is in a replay file
|
||||
- Occasionally useful for testing very specific market data transitions
|
||||
|
||||
# Tuning / Dealing with Loss
|
||||
|
||||
## Packet loss
|
||||
#### If a small number 1-5 is lost it's upstream
|
||||
- Use tcpdump to capture
|
||||
- Check the tcpdump for gaps
|
||||
- Ask Pete to contact hosting provider
|
||||
#### If large gap probably overflow
|
||||
- make sure socket buffers sizes, rmem_max, spin_time, data_wait are all set
|
||||
- check affinity is set and working
|
||||
- check ethtool
|
||||
|
||||
|
||||
#### Show ethernet ring buffer sizes
|
||||
ethtool -g eth0
|
||||
#### change ethernet ring buffer rx size
|
||||
sudo ethtool -G [device] rx 4096
|
||||
#### interface statistics
|
||||
ethtool -S eth0
|
||||
- particularly look at:
|
||||
ethtool -S p1p1 | egrep "(bad)|(nodesc)"
|
||||
|
||||
### If increasing the ring buffer doesn't work you can tweak interrupt coalescing using:
|
||||
- /proc/sys/net/core/dev_weight
|
||||
- This is the maximum number of packets that can be dequeued in a single interrupt
|
||||
- https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Performance_Tuning_Guide/s-network-common-queue-issues.html
|
||||
|
||||
- **NOTE**: We've never used this and it's unlikely it will fix anything
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
|
||||
|
||||
********************
|
||||
classes
|
||||
********************
|
||||
|
||||
btscmd md => PlatformLoader
|
||||
|
||||
PlatformLoader:
|
||||
* Loads the platform specific dll
|
||||
* Calls ->start_marketdata() with a full vector<security_info>
|
||||
|
||||
SharedList<T> / SharedListWriter
|
||||
* Shared memory list object which spans across shared memory segments as necessary
|
||||
* O(N) walk
|
||||
* atomic add()
|
||||
* Single adder / multiple readers
|
||||
* no delete
|
||||
* Custom header
|
||||
|
||||
SecurityIDRecorder
|
||||
* add_security(security, lambda callback) -> int returns security id instantly
|
||||
* security_persisted callback when security id is safely persisted
|
||||
|
||||
SecurityIndex
|
||||
* Platform Implementation helper
|
||||
* Maps exhange_id to (ProducerHandle + Data)
|
||||
*
|
||||
|
||||
CacheEntry / CacheEntryDepth (CacheStructure.h)
|
||||
* CacheEntry(symbol, depth, # legs) -- size determined in constructor
|
||||
* Simple inheritance tree for optional depth
|
||||
* Has FixedSecurity
|
||||
* Fits in SharedList<T>
|
||||
* CRITICAL fields are at the front cache aligned. bbo/depth. Security goes at the end
|
||||
|
||||
* size, is_public(), is_persisted, is_resolved (spread)
|
||||
* statistics like bbo/trade counters
|
||||
* is_status_ok
|
||||
* bbo, depth, trade, status, open, close
|
||||
|
||||
FixedSecurity / FixsdSpreadSecurity
|
||||
* Normalized version of our protobuf security
|
||||
* Has methods to convert to pb Security
|
||||
* Size known at construction w/ # legs - spread legs of type security_key
|
||||
* Can use a union for option/future fields
|
||||
|
||||
MDProducer(symbol, type)
|
||||
* manages lifetime of SharedList instances
|
||||
* Hands out MDProducerHandle - entry for one security
|
||||
|
||||
MDProducerHandle
|
||||
* pointers to shared memory
|
||||
* update methods
|
||||
|
||||
MDConsumer
|
||||
* list of securities
|
||||
* find_security_id(symbol, type, etc)
|
||||
* get_cache_handle(security id#)
|
||||
* Hands out MDCacheHandle
|
||||
- if security is null add MDCacheHandle to a list to be updated
|
||||
next time securities are polled
|
||||
|
||||
MDCacheHandle
|
||||
* If security is not present add this is "null"
|
||||
* has pointers to relevant shared memory
|
||||
|
||||
|
||||
|
||||
********************
|
||||
* Cache Structure
|
||||
********************
|
||||
|
||||
2 Shared memory segment for each (SYMBOL, TYPE) - md_hot (bbo,depth,status), md_cold (others)
|
||||
|
||||
When a new security is discovered
|
||||
1. id is allocated to the security
|
||||
2. New CacheEntry is allocated in appropriate arena (is_public=false)
|
||||
3. md_cache entry count is incremented
|
||||
4. When id is persisted is_public=true, increment version on cache arena
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "lib/persistence/SqliteStore.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
#include "lib/orderman/actors/SODPosition.h"
|
||||
#include "lib/utils/overloaded.h"
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <sys/time.h>
|
||||
@@ -40,7 +39,6 @@ struct FillStore::PImpl {
|
||||
|
||||
FillStore::FillStore(md::SecurityOracle o) : me(new PImpl(o)) {}
|
||||
|
||||
// returns the sod type of a non sod type fill
|
||||
auto sod_fill_kind (const api::orderman::Fill& fill){
|
||||
auto rv = Fill::FILL_KIND_SOD;
|
||||
switch (fill.fill_kind()){
|
||||
@@ -54,7 +52,6 @@ auto sod_fill_kind (const api::orderman::Fill& fill){
|
||||
rv = Fill::FILL_KIND_SOD_STRIP_LEG;
|
||||
break;
|
||||
default:
|
||||
LOG(persist, Error, "Stored fill kinds can not be SOD");
|
||||
rv = Fill::FILL_KIND_SOD;
|
||||
break;
|
||||
}
|
||||
@@ -63,19 +60,24 @@ auto sod_fill_kind (const api::orderman::Fill& fill){
|
||||
|
||||
auto leg_fill_kind (const api::Security& parent,
|
||||
const api::Security& child){
|
||||
if(securities::is_strip(parent))
|
||||
return Fill::FILL_KIND_STRIP_LEG;
|
||||
else{
|
||||
// parent is a spread
|
||||
if(securities::is_spread_of_strips(parent)){
|
||||
// this has 3 levels strip spread -> strip -> outright
|
||||
// first level is an ordinary leg and second is a strip leg.
|
||||
// since we dont get the level passed we have to
|
||||
// use the following heurestics
|
||||
if(securities::is_strip(child))
|
||||
return Fill::FILL_KIND_LEG;
|
||||
if (parent.has_ice()){
|
||||
if(securities::is_strip(parent))
|
||||
return Fill::FILL_KIND_STRIP_LEG;
|
||||
else{
|
||||
// parent is a spread
|
||||
if(securities::is_spread_of_strips(parent)){
|
||||
// this has 3 levels strip spread -> strip -> outright
|
||||
// first level is an ordinary leg and second is a strip leg.
|
||||
// since we dont get the level passed we have to
|
||||
// use the following heurestics
|
||||
if(securities::is_strip(child))
|
||||
return Fill::FILL_KIND_LEG;
|
||||
else
|
||||
return Fill::FILL_KIND_STRIP_LEG;
|
||||
}
|
||||
else
|
||||
return Fill::FILL_KIND_STRIP_LEG;
|
||||
// regular spread
|
||||
return Fill::FILL_KIND_LEG;
|
||||
}
|
||||
}
|
||||
return Fill::FILL_KIND_LEG;
|
||||
@@ -165,21 +167,8 @@ void FillStore::on_execution_report(
|
||||
fill.set_fill_status(api::orderman::Fill::FILL_STATUS_CORRECTED);
|
||||
fill.set_fill_key(fk);
|
||||
|
||||
auto exchange_ts =
|
||||
std::visit(overloaded {
|
||||
[](const orderman::ExchangeTimeStampStr& ts) {
|
||||
return utils::pb::to_timestamp(
|
||||
datetime::parse_FIX_timestamp(to_str(ts)));
|
||||
},
|
||||
[](ExchangeTimeStamp64 ts) {
|
||||
google::protobuf::Timestamp gts;
|
||||
auto seconds = ts.value() / 1E9;
|
||||
gts.set_seconds(seconds);
|
||||
gts.set_nanos(ts.value() - (seconds * 1E9));
|
||||
return gts;
|
||||
}
|
||||
}, er.transact_time);
|
||||
|
||||
auto exchange_ts = utils::pb::to_timestamp(
|
||||
datetime::parse_FIX_timestamp(to_str(er.transact_time)));
|
||||
*fill.mutable_timestamp() = exchange_ts;
|
||||
|
||||
auto it = me->known_orders.find(er.order_key);
|
||||
|
||||
@@ -222,9 +222,7 @@ void GLBXExecutionGateway::on_exe_report(
|
||||
msg.get<fix::ManualOrderIndicator>()
|
||||
? api::orderman::MANUAL_ORDER_INDICATOR_YES
|
||||
: api::orderman::MANUAL_ORDER_INDICATOR_YES;
|
||||
str_to(msg.get<fix::OrderID>(),
|
||||
& std::get<ExchangeOrderID>(
|
||||
data->exchange_order_id));
|
||||
str_to(msg.get<fix::OrderID>(), &data->exchange_order_id);
|
||||
|
||||
if (msg.has<fix::Price>())
|
||||
data->price = securities::decode_exchange_price(
|
||||
@@ -263,9 +261,7 @@ void GLBXExecutionGateway::on_exe_report(
|
||||
: Price(0);
|
||||
if (msg.has<fix::ExecID>())
|
||||
str_to(msg.get<fix::ExecID>(), &data->exchange_fill_id);
|
||||
orderman::ExchangeTimeStampStr t;
|
||||
str_to(msg.get<fix::TransactTimeStr>(), &t);
|
||||
data->transact_time = t;
|
||||
str_to(msg.get<fix::TransactTimeStr>(), &data->transact_time);
|
||||
|
||||
if (msg.has<fix::CustOrderHandlingInst>())
|
||||
data->cust_order_handling_inst = msg.get<fix::CustOrderHandlingInst>();
|
||||
@@ -284,16 +280,12 @@ void GLBXExecutionGateway::on_cancel_reject(
|
||||
decode_clorid(msg.get<fix::ClOrdID>(), &ok, &sk);
|
||||
|
||||
std::string reject_msg;
|
||||
CancelRejectReason reason = CancelRejectReason::Other;
|
||||
if (msg.has<fix::Text>())
|
||||
reject_msg = msg.get<fix::Text>();
|
||||
else if (msg.has<fix::CXlRejReason>()) {
|
||||
if (msg.get<fix::CXlRejReason>() == 2045)
|
||||
reason = CancelRejectReason::UnknownOrder;
|
||||
else if (msg.has<fix::CXlRejReason>())
|
||||
reject_msg = fmt::format("Order cancel was rejected with error code {}",
|
||||
msg.get<fix::CXlRejReason>());
|
||||
}
|
||||
me->on_cancel_reject({ok, reason,reject_msg});
|
||||
me->on_cancel_reject(ok, reject_msg);
|
||||
}
|
||||
|
||||
void GLBXExecutionGateway::on_connection_status_change(bool is_connected) {
|
||||
|
||||
@@ -18,7 +18,6 @@ class GLBXExecutionGateway : public IExecutionGateway {
|
||||
void on_securities(const mercury::Update<NewSecuritiesEvent> &) override;
|
||||
void on_admin_data(const mercury::Update<NewAdminDataEvent> &) override;
|
||||
void send_fix(jetfix::OutFIXPtr const &fix, trace::CorID trace) override;
|
||||
void send_msgs(std::vector<OrderMsg> const&, trace::CorID) override {bts_assert(false);}
|
||||
|
||||
OnExeReport& on_exe_report() override;
|
||||
OnGwStatusChange& on_gw_status_change() override;
|
||||
|
||||
@@ -1,300 +0,0 @@
|
||||
#include "lib/orderman/actors/GLBXiLink3ExecutionGateway.h"
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/orderman_cfg.pb.h"
|
||||
#include "lib/domain_model/Security.h"
|
||||
#include "lib/jetfix/common/OutFIX.h"
|
||||
#include "lib/jetfix/store/session_name.h"
|
||||
#include "lib/orderman/actors/GLBXExecutionGateway.h"
|
||||
#include "lib/orderman/actors/ilink3/IL3GW.h"
|
||||
#include "lib/orderman/actors/ilink3/IL3MessageFramer.h"
|
||||
#include "lib/orderman/actors/ilink3/IL3Reactor.h"
|
||||
#include "lib/orderman/actors/ilink3/IL3SecDB.h"
|
||||
#include "lib/orderman/actors/ilink3/SessionStore.h"
|
||||
#include "lib/orderman/events/NewSecuritiesEvent.h"
|
||||
#include "lib/orderman/orderman_utils/fix_order_codec.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
namespace ilink3 {
|
||||
|
||||
enum class GLBXiLink3ExecutionGateway::State {
|
||||
|
||||
WAITING_FOR_SECURITIES,
|
||||
PAUSED,
|
||||
CONNECTING,
|
||||
READY
|
||||
};
|
||||
|
||||
struct GLBXiLink3ExecutionGateway::PImpl {
|
||||
PImpl(config::JetFIX::Connection const &cfg, trace::PerfLog &log,
|
||||
md::SecurityOracle o)
|
||||
: state(), cfg(cfg), reactor(), start_of_pause(), on_exe_report(),
|
||||
on_gw_status_change(), on_cancel_reject(), perf_log(log), db(o),
|
||||
gw_name(cfg.name()), session_store(), gw(), connection(nullptr),
|
||||
connection_failures(0), started(false), replay_messages(),
|
||||
has_replayed(false) {
|
||||
TCPEndpoint endpoint{cfg.socket_connect_host_ip(),
|
||||
(ushort)cfg.socket_connect_port()};
|
||||
connection = &reactor.register_connection({endpoint});
|
||||
}
|
||||
|
||||
State state;
|
||||
config::JetFIX::Connection const cfg;
|
||||
IL3Reactor reactor;
|
||||
IL3MessageFramer framer;
|
||||
TimeStamp start_of_pause;
|
||||
|
||||
OnExeReport on_exe_report;
|
||||
OnGwStatusChange on_gw_status_change;
|
||||
orderman::OnCancelReject on_cancel_reject;
|
||||
trace::PerfLog &perf_log;
|
||||
IL3SecDB db;
|
||||
GatewayName gw_name;
|
||||
std::optional<SessionStore> session_store;
|
||||
std::optional<IL3GW> gw;
|
||||
IL3Connection *connection;
|
||||
size_t connection_failures;
|
||||
bool started;
|
||||
|
||||
// We need to keep this collection alive for the duration of the
|
||||
// program because we will be passing pointers to ExecutionReport
|
||||
// to other threads
|
||||
std::vector<ExecutionReport> replay_messages;
|
||||
bool has_replayed;
|
||||
};
|
||||
|
||||
GLBXiLink3ExecutionGateway::GLBXiLink3ExecutionGateway(
|
||||
config::JetFIX::Connection const &cfg, trace::PerfLog &log,
|
||||
md::SecurityOracle o)
|
||||
: me(new PImpl(cfg, log, o)) {
|
||||
me->state = State::WAITING_FOR_SECURITIES;
|
||||
}
|
||||
|
||||
GLBXiLink3ExecutionGateway::~GLBXiLink3ExecutionGateway() {}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::start() {
|
||||
bts_assert(!me->started);
|
||||
me->started = true;
|
||||
}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::dispatch_incoming_fix_messages() {
|
||||
if (me->started) {
|
||||
switch (me->state) {
|
||||
case State::WAITING_FOR_SECURITIES:
|
||||
break;
|
||||
case State::PAUSED:
|
||||
on_time();
|
||||
break;
|
||||
case State::READY:
|
||||
case State::CONNECTING:
|
||||
me->reactor.do_work();
|
||||
me->gw->on_time();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::on_time() {
|
||||
bts_assert(me->state == State::PAUSED);
|
||||
|
||||
// If we are still paused bail early, this avoids logging too much
|
||||
// or spending too much CPU
|
||||
if (pause_in_effect())
|
||||
return;
|
||||
|
||||
me->start_of_pause = Timer::now();
|
||||
|
||||
// If we alread exceed the maximum number of failures per run
|
||||
// bail. This is a safety measure to avoid overwhelming the
|
||||
// exchange in the event of a bug or operational problem that
|
||||
// results in repeated connection failures.
|
||||
if (max_failures_reached()) {
|
||||
LOG(iLink3, Warn,
|
||||
"Maximum number of connection failures reached for {}. Reboot to try "
|
||||
"again",
|
||||
me->gw_name.value());
|
||||
return;
|
||||
}
|
||||
|
||||
// If we reach this point we are no longer in the pause window and
|
||||
// we have not exceed our connection failure limit. The only thing
|
||||
// to check now is wheter we are inside the exchange's active
|
||||
// hours.
|
||||
auto current_session = jetfix::session_name(me->cfg);
|
||||
if (current_session.empty()) {
|
||||
LOG(iLink3, Info, "Outside of session in ", me->gw_name.value());
|
||||
return;
|
||||
}
|
||||
// Yep, the stars are all aligned, lets try to connect
|
||||
connect(current_session);
|
||||
}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::connect(jetfix::SessionName const &sn) {
|
||||
bts_assert(me->state == State::PAUSED);
|
||||
transition(State::CONNECTING);
|
||||
Config c;
|
||||
c.cme_session = me->cfg.sender_compid().substr(0, 3);
|
||||
c.firm = me->cfg.sender_compid().substr(3);
|
||||
c.failover_on_disconnect = false;
|
||||
|
||||
me->session_store.emplace(me->db, sn, &me->cfg);
|
||||
if (!me->has_replayed) {
|
||||
me->has_replayed = true;
|
||||
me->replay_messages = me->session_store.value().replay();
|
||||
for (auto const &er : me->replay_messages)
|
||||
me->on_exe_report(er, {});
|
||||
}
|
||||
|
||||
c.raw_message_logger =
|
||||
[store = &me->session_store.value()](auto d, auto sn, auto const &msg) {
|
||||
store->async_store_raw_msg(d, sn, msg);
|
||||
};
|
||||
|
||||
me->gw.emplace(*me->connection, me->framer, &me->db,
|
||||
me->session_store->starting_session_descriptor(), c,
|
||||
&me->cfg);
|
||||
|
||||
me->gw->subscribe_cancel_reject([this](auto &cr) {
|
||||
bts_assert(me->state == State::READY || me->state == State::CONNECTING);
|
||||
me->on_cancel_reject(cr);
|
||||
});
|
||||
|
||||
me->gw->subscribe_execution_reports([this](auto er) {
|
||||
bts_assert(me->state == State::READY || me->state == State::CONNECTING);
|
||||
me->on_exe_report(*er, {});
|
||||
});
|
||||
|
||||
me->gw->subscribe_session(
|
||||
[this](auto const &s) { me->session_store->async_update_session(s); });
|
||||
|
||||
me->gw->subscribe_state([this](auto gw_state) {
|
||||
LOG(iLink3, Info, "Internal gateway state change in {}. State is now {}",
|
||||
me->gw_name.value(),
|
||||
log::CharPtrWrapper{ilink3::state_string(gw_state)});
|
||||
switch (me->state) {
|
||||
case State::CONNECTING:
|
||||
if (gw_state == ilink3::State::READY) {
|
||||
transition(State::READY);
|
||||
me->on_gw_status_change(true);
|
||||
} else if (gw_state == ilink3::State::ERROR) {
|
||||
me->connection_failures++;
|
||||
pause();
|
||||
}
|
||||
break;
|
||||
case State::READY:
|
||||
if (gw_state == ilink3::State::ERROR) {
|
||||
me->connection_failures++;
|
||||
pause();
|
||||
me->on_gw_status_change(false);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
});
|
||||
me->gw->connect();
|
||||
}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::pause() {
|
||||
me->start_of_pause = Timer::now();
|
||||
me->gw.reset();
|
||||
transition(State::PAUSED);
|
||||
}
|
||||
|
||||
bool GLBXiLink3ExecutionGateway::pause_in_effect() const {
|
||||
return sec_diff(Timer::now(), me->start_of_pause) <=
|
||||
me->cfg.seconds_to_pause();
|
||||
}
|
||||
|
||||
bool GLBXiLink3ExecutionGateway::max_failures_reached() const {
|
||||
return me->connection_failures > me->cfg.max_connection_attempts();
|
||||
}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::on_securities(
|
||||
const mercury::Update<NewSecuritiesEvent> &update) {
|
||||
if (update.events) {
|
||||
|
||||
for (auto const &ev : *(update.events)) {
|
||||
auto sec_ptr = ev.security;
|
||||
me->db.add_security(*sec_ptr);
|
||||
}
|
||||
|
||||
if (me->state == State::WAITING_FOR_SECURITIES) {
|
||||
LOG(iLink3, Warn,
|
||||
"Received first set of {} securities. Proceeding "
|
||||
"with initialization of execution gateway {}",
|
||||
update.events->size(), me->gw_name.value());
|
||||
// got our security synopsis, ready to start the GW
|
||||
transition(State::PAUSED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::on_admin_data(
|
||||
const mercury::Update<NewAdminDataEvent> &) {}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::send_msgs(std::vector<OrderMsg> const &msgs,
|
||||
trace::CorID) {
|
||||
|
||||
if (me->state == State::READY) {
|
||||
for (auto &m : msgs) {
|
||||
// NewOrderSingle
|
||||
auto create_ptr = std::get_if<CreateOrderMsg>(&m);
|
||||
if (create_ptr) {
|
||||
me->gw->send_order(*create_ptr);
|
||||
continue;
|
||||
}
|
||||
// CancelReplace
|
||||
auto cancel_replace_ptr = std::get_if<CancelReplaceOrderMsg>(&m);
|
||||
if (cancel_replace_ptr) {
|
||||
me->gw->send_cancel_replace(*cancel_replace_ptr);
|
||||
continue;
|
||||
}
|
||||
// Cancel
|
||||
auto cancel_ptr = std::get_if<CancelOrderMsg>(&m);
|
||||
if (cancel_ptr) {
|
||||
me->gw->send_cancel(*cancel_ptr);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
me->gw->flush();
|
||||
}
|
||||
}
|
||||
|
||||
OnExeReport &GLBXiLink3ExecutionGateway::on_exe_report() {
|
||||
return me->on_exe_report;
|
||||
}
|
||||
|
||||
OnGwStatusChange &GLBXiLink3ExecutionGateway::on_gw_status_change() {
|
||||
return me->on_gw_status_change;
|
||||
}
|
||||
|
||||
orderman::OnCancelReject &GLBXiLink3ExecutionGateway::on_cancel_reject() {
|
||||
return me->on_cancel_reject;
|
||||
}
|
||||
|
||||
log::CharPtrWrapper GLBXiLink3ExecutionGateway::state_name(State st) {
|
||||
switch (st) {
|
||||
case State::WAITING_FOR_SECURITIES:
|
||||
return {"WAITING_FOR_SECURITIES"};
|
||||
case State::PAUSED:
|
||||
return {"PAUSED"};
|
||||
case State::CONNECTING:
|
||||
return {"CONNECTING"};
|
||||
case State::READY:
|
||||
return {"READY"};
|
||||
}
|
||||
bts_assert(false);
|
||||
return {""};
|
||||
}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::transition(State new_state) {
|
||||
LOG(iLink3, Info, "Transitioning {} from {} to {}", me->gw_name.value(),
|
||||
state_name(me->state), state_name(new_state));
|
||||
me->state = new_state;
|
||||
}
|
||||
|
||||
} // namespace ilink3
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -1,48 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "IExecutionGateway.h"
|
||||
#include "lib/logging/logging.h"
|
||||
|
||||
namespace bts {
|
||||
namespace jetfix {struct SessionName;}
|
||||
namespace orderman {
|
||||
namespace ilink3 {
|
||||
|
||||
struct Session;
|
||||
|
||||
class GLBXiLink3ExecutionGateway : public IExecutionGateway {
|
||||
public:
|
||||
GLBXiLink3ExecutionGateway(config::JetFIX::Connection const &, trace::PerfLog &,
|
||||
md::SecurityOracle);
|
||||
virtual ~GLBXiLink3ExecutionGateway();
|
||||
|
||||
void start() override;
|
||||
void dispatch_incoming_fix_messages() override;
|
||||
void on_securities(const mercury::Update<NewSecuritiesEvent> &) override;
|
||||
void on_admin_data(const mercury::Update<NewAdminDataEvent> &) override;
|
||||
void send_fix(jetfix::OutFIXPtr const &, trace::CorID ) override {bts_assert(false);}
|
||||
void send_msgs(std::vector<OrderMsg> const&, trace::CorID) override;
|
||||
|
||||
OnExeReport& on_exe_report() override;
|
||||
OnGwStatusChange& on_gw_status_change() override;
|
||||
OnCancelReject &on_cancel_reject() override;
|
||||
|
||||
private:
|
||||
enum class State;
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me;
|
||||
|
||||
// Time passing
|
||||
void on_time();
|
||||
bool pause_in_effect() const;
|
||||
bool max_failures_reached()const;
|
||||
static log::CharPtrWrapper state_name(State);
|
||||
void transition(State);
|
||||
|
||||
void pause();
|
||||
void connect(jetfix::SessionName const&);
|
||||
};
|
||||
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
}
|
||||
Loaded 100 of 305 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user