Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
04e0297e86 | ||
|
|
562706b968 | ||
|
|
4195207a71 | ||
|
|
71eb89b6a1 | ||
|
|
94e4a0b725 | ||
|
|
40d1fe20e3 | ||
|
|
2ed23159ca | ||
|
|
faa8438adf | ||
|
|
0b35c2ccde | ||
|
|
98eea0ef09 | ||
|
|
4bf237aebe | ||
|
|
da927adef4 | ||
|
|
cf587e26d5 |
No files matched your search
@@ -1,82 +0,0 @@
|
||||
pipeline {
|
||||
agent {
|
||||
label 'os=windows && ram=8gb && installed=python3'
|
||||
}
|
||||
|
||||
parameters {
|
||||
choice(name: 'JOB', choices: ['build-spark-prod'])
|
||||
string(name: 'BUILD_NUMBER', defaultValue: '', description: "The build number for which to make the installer (runs new build if blank).")
|
||||
string(name: 'RELEASE_ID', defaultValue: 'latest', description: "The release id (aka version tag). For ex, 'v1.1.1'")
|
||||
booleanParam(name: 'CLEAN', defaultValue: false, description: "Whether or not to perform a 'clean' build. If true, 'BUILD_NUMBER' must be blank.")
|
||||
string(name: 'CONFIG_SERVER', defaultValue: "http://<server_ip>:<config_port>", description: "Default server url for the installer.")
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Validate Params') {
|
||||
steps {
|
||||
script {
|
||||
if ("${params.BUILD_NUMBER}" != "") {
|
||||
if (params.CLEAN) {
|
||||
error "BUILD_NUMBER must be left blank for CLEAN builds"
|
||||
}
|
||||
if (!("${params.BUILD_NUMBER}" =~ "^[1-9][0-9]*\$")) {
|
||||
error "BUILD_NUMBER must be positive non-zero integer (or left blank)"
|
||||
}
|
||||
}
|
||||
if ("${params.RELEASE_ID}" == "") {
|
||||
error "RELEASE_ID must not be blank"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Build') {
|
||||
when {
|
||||
expression { params.CLEAN || params.BUILD_NUMBER == '' }
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
build(
|
||||
job: params.JOB,
|
||||
parameters: [
|
||||
booleanParam(name: 'CLEAN', value: params.CLEAN),
|
||||
booleanParam(name: 'CLEAN_REPO', value: false),
|
||||
booleanParam(name: 'CLEAN_VENV', value: params.CLEAN)
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Build Installer') {
|
||||
steps {
|
||||
script {
|
||||
src_dir='installer_src'
|
||||
out_dir='installer'
|
||||
out_name="spark-${params.RELEASE_ID}"
|
||||
echo 'Cleaning files leftover from previous builds'
|
||||
fileOperations([
|
||||
fileDeleteOperation(includes: 'publish.zip'),
|
||||
folderDeleteOperation(folderPath: src_dir),
|
||||
folderDeleteOperation(folderPath: out_dir)])
|
||||
if (params.BUILD_NUMBER == '') {
|
||||
copyArtifacts(projectName: params.JOB, selector: lastSuccessfulBuild());
|
||||
} else {
|
||||
copyArtifacts(projectName: params.JOB, selector: specific("${params.BUILD_NUMBER}"));
|
||||
}
|
||||
fileOperations([
|
||||
fileUnZipOperation(filePath: 'publish.zip', targetLocation: src_dir),
|
||||
fileCreateOperation(fileName: "${src_dir}\\spark.version", fileContent: params.RELEASE_ID)])
|
||||
innosetup_exe="C:\\Program Files (x86)\\Inno Setup 6\\ISCC.exe"
|
||||
innosetup_args = String.join(
|
||||
" ",
|
||||
"spark-prod-client.iss",
|
||||
"/DMySourceDir=${src_dir}",
|
||||
"/DMyAppVersion=${params.RELEASE_ID}",
|
||||
"/DMyConfigServer=\"${params.CONFIG_SERVER}\"",
|
||||
"/O${out_dir}",
|
||||
"/F${out_name}");
|
||||
bat "@call \"${innosetup_exe}\" ${innosetup_args}"
|
||||
}
|
||||
archiveArtifacts artifacts: "${out_dir}\\${out_name}.exe", followSymlinks: false, onlyIfSuccessful: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
pipeline {
|
||||
agent {
|
||||
label 'os=windows && ram=8gb && installed=vs2022 && installed=python3'
|
||||
}
|
||||
|
||||
parameters {
|
||||
booleanParam(name: 'CLEAN', defaultValue: false, description: 'Perform a clean build')
|
||||
booleanParam(name: 'CLEAN_VENV', defaultValue: false, description: 'Create the python venv from scratch (delete existing)')
|
||||
gitParameter(
|
||||
name: 'TAG',
|
||||
type: 'PT_BRANCH_TAG',
|
||||
defaultValue: 'origin/spark_crypto.prod',
|
||||
listSize: '0',
|
||||
sortMode: 'ASCENDING_SMART')
|
||||
}
|
||||
stages {
|
||||
stage('Build') {
|
||||
steps {
|
||||
checkout([
|
||||
$class: 'GitSCM',
|
||||
branches: [[name: "${params.TAG}"]],
|
||||
extensions: [
|
||||
[
|
||||
$class: 'SubmoduleOption',
|
||||
disableSubmodules: false,
|
||||
recursiveSubmodules: true,
|
||||
trackingSubmodules: true,
|
||||
parentCredentials: true,
|
||||
],
|
||||
[
|
||||
$class: 'CloneOption',
|
||||
],
|
||||
[
|
||||
$class: 'PruneStaleBranch'
|
||||
],
|
||||
[
|
||||
$class: 'PruneStaleTag'
|
||||
],
|
||||
[
|
||||
$class: 'WipeWorkspace'
|
||||
]
|
||||
],
|
||||
userRemoteConfigs: [[url: "https://john_colvin:ATBBLTcLcmD4ysvbC8D9j5sXhpMAF4312F8F@bitbucket.org/bluetradesys/spark.git"]]
|
||||
])
|
||||
script {
|
||||
// Python venv
|
||||
if ("${params.CLEAN_VENV}") {
|
||||
echo "Cleaning python virtual environment..."
|
||||
bat "@call rmdir /s /q .venv > nul 2>&1"
|
||||
}
|
||||
bat '@call tools\\ensure_venv.cmd'
|
||||
// Main build
|
||||
if ("${params.CLEAN}") {
|
||||
echo "Cleaning build"
|
||||
bat "@call rmdir /s /q .venv > nul 2>&1"
|
||||
}
|
||||
bat '@call tools\\jenkins_build_spark.cmd --target publish'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Archive') {
|
||||
steps {
|
||||
dir ('build\\Release\\bin\\net7.0-windows\\win-x64') {
|
||||
bat """
|
||||
"C:\\Program Files\\7-Zip\\7z.exe" a -tzip ..\\..\\..\\..\\..\\spark.zip publish
|
||||
"""
|
||||
}
|
||||
archiveArtifacts artifacts: 'spark.zip', followSymlinks: false, onlyIfSuccessful: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,8 +160,8 @@ namespace mbts.spark {
|
||||
|
||||
public static IEnumerable<bts.api.SecurityTuple> get_vs_sectups(
|
||||
int vs_id, ThreadedBlackboard bb) {
|
||||
VolSurfaceUsageListImmutable vs_usage_list = bb.read_state(SparkTags.VolSurfaceUsageTag);
|
||||
return vs_usage_list.get_sectups(vs_id);
|
||||
var vs_usage_list = bb.read_state(SparkTags.VolSurfaceUsageTag);
|
||||
return (vs_usage_list?.get_sectups(vs_id)).empty_if_null();
|
||||
}
|
||||
|
||||
|
||||
@@ -242,4 +242,4 @@ namespace mbts.spark {
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,9 +63,9 @@ namespace mbts.spark {
|
||||
// find the symbol vs vs_id, get the committed vs, see if it is
|
||||
// owned by the current user, and only then publish it
|
||||
HashSet<string> syms = new HashSet<string>();
|
||||
VolSurfaceUsageListImmutable usage = _bb.read_state(SparkTags.VolSurfaceUsageTag);
|
||||
var usage = _bb.read_state(SparkTags.VolSurfaceUsageTag);
|
||||
string current_user = _bb.read_state(SparkTags.CurrentUser).name;
|
||||
foreach (var u in usage.UsageList) {
|
||||
foreach (var u in (usage?.UsageList).empty_if_null()) {
|
||||
VolSurfaceInput vs_input =
|
||||
_bb.read_state(SparkTags.VolSurfaceCommittedInputTag(u.VsId));
|
||||
if (vs_input != null) {
|
||||
@@ -135,4 +135,4 @@ namespace mbts.spark {
|
||||
_bb.data_callback -= _on_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ namespace mbts.spark {
|
||||
// ii. IntepGreeks for each vs
|
||||
public class VolSurfaceInterpGreeksMultiplexer : IDisposable {
|
||||
private readonly ThreadedBlackboard _bb;
|
||||
private readonly ITag<VolSurfaceUsageListImmutable> _in_bb_vs_usage_tag;
|
||||
private readonly ITag<VolSurfaceUsageListImmutable?> _in_bb_vs_usage_tag;
|
||||
private IDictionary<int, ITag<VSTheos>> _vs_theo_tags =
|
||||
new Dictionary<int, ITag<VSTheos>>();
|
||||
private VolSurfaceUsageListImmutable _vs_usage_map =
|
||||
@@ -48,8 +48,8 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
private void _analyze_usages() {
|
||||
_vs_usage_map = _bb.read_state(_in_bb_vs_usage_tag,
|
||||
new VolSurfaceUsageListImmutable(new VolSurfaceUsageList()));
|
||||
_vs_usage_map = _bb.read_state(_in_bb_vs_usage_tag) ??
|
||||
new VolSurfaceUsageList().immutable();
|
||||
bts.Log.Gen.info($"VolSurfaceInterpGreeksMultiplexer._analyze_usages " +
|
||||
$"count: {_vs_usage_map.UsageList.Count()}");
|
||||
foreach (int vs_id in _vs_usage_map.vss()) {
|
||||
|
||||
@@ -1281,7 +1281,7 @@ namespace mbts.spark {
|
||||
if (!_settings.piq_column.show)
|
||||
return;
|
||||
int origin_index = LadderRender.index_of(_price_list, _mkt_break_lines.origin, _price_comparer);
|
||||
LadderRender.render_piqs(_piq_vis_tup.visual, _last_vis_tup.glyph_context, origin_index, _price_list, _vm.price_vs_piq, _settings.row_height, _spec, _settings.piq_column, _fmt_mkt_quantity);
|
||||
LadderRender.render_piqs(_piq_vis_tup.visual, _last_vis_tup.glyph_context, _price_list, _vm.price_vs_piq, _settings.row_height, _spec, _settings.piq_column, _fmt_mkt_quantity);
|
||||
}
|
||||
|
||||
void _refresh_sizes() {
|
||||
|
||||
@@ -368,30 +368,32 @@ namespace mbts.spark {
|
||||
|
||||
public delegate void RenderCell<T>(DrawingContext dc, int row, T data_item);
|
||||
|
||||
static void _render_cells<T>(DrawingVisual dv, double row_height, IEnumerable<(double price, T value)> data, LadderColumnSettings settings, IList<double> prices, RegionalTickFactors spec, RenderCell<T> render_cell) {
|
||||
static void _render_cells<T>(DrawingVisual dv, double row_height, IEnumerable<(double price, T value)> cells, LadderColumnSettings settings, IList<double> prices, RegionalTickFactors spec, RenderCell<T> render_cell) {
|
||||
using (var dc = dv.RenderOpen())
|
||||
using (_draw_with_clip(dc, settings, row_height, prices.Count)) {
|
||||
if (data.is_null_or_empty())
|
||||
if (prices.is_null_or_empty() || cells.is_null_or_empty()) {
|
||||
return;
|
||||
int curr_index = 0;
|
||||
double curr_price = prices[curr_index];
|
||||
foreach (var (price, value) in data) {
|
||||
if (double.IsNaN(price))
|
||||
continue;
|
||||
// prices are in descending order, so get diff from curr_price - price
|
||||
var tick_diff = spec.tickdiff(curr_price, price) ?? 0;
|
||||
Log.assert(
|
||||
tick_diff > (int.MaxValue - curr_index),
|
||||
$"Unable to index ladder row for price {price}: tick count exceeds int.MaxValue");
|
||||
curr_index += (int)tick_diff;
|
||||
curr_price = price;
|
||||
if (curr_index >= 0 && curr_index < prices.Count) {
|
||||
render_cell(dc, curr_index, value);
|
||||
} else break;
|
||||
}
|
||||
var min_price = prices[prices.Count - 1];
|
||||
var max_price = prices[0];
|
||||
Log.assert(min_price.is_real() && max_price.is_real() && min_price <= max_price);
|
||||
var indexed_cells = cells
|
||||
.Where(item => item.price.is_real() && item.price.is_within_range(min_price, max_price))
|
||||
.Select(row => {
|
||||
checked {
|
||||
return (row.price, row.value, (int)spec.tickdiff(max_price, row.price));
|
||||
}
|
||||
});
|
||||
foreach (var (price, value, idx) in indexed_cells) {
|
||||
var check_price = spec.tickdown(max_price, idx);
|
||||
Log.assert(spec.tick_equals(price, check_price));
|
||||
Log.assert(idx >= 0 && idx < prices.Count);
|
||||
render_cell(dc, idx, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal static void render_last(DrawingVisual dv, GlyphContext glyph_context, NativePriceSize last, int index, double row_height, LadderColumnSettings settings, Func<uint, string> fmt_value) {
|
||||
if (fmt_value is null)
|
||||
fmt_value = FormattingDelegates.default_string<uint>();
|
||||
@@ -405,38 +407,18 @@ namespace mbts.spark {
|
||||
internal static void render_piqs(
|
||||
DrawingVisual dv,
|
||||
GlyphContext glyph_context,
|
||||
int origin_index,
|
||||
IList<double> prices,
|
||||
IEnumerable<(double price, uint piq)> pvp,
|
||||
double row_height,
|
||||
RegionalTickFactors spec,
|
||||
LadderColumnSettings settings,
|
||||
Func<uint, string> fmt_value) {
|
||||
//
|
||||
using (var dc = dv.RenderOpen()) {
|
||||
using (_draw_with_clip(dc, settings, row_height, prices.Count)) {
|
||||
if (!prices.within_range(origin_index) || pvp.is_null_or_empty())
|
||||
return;
|
||||
if (fmt_value is null)
|
||||
fmt_value = FormattingDelegates.default_string<uint>();
|
||||
var foreground = settings.foreground.rgb_brush();
|
||||
int curr_index = origin_index;
|
||||
double curr_price = prices[curr_index];
|
||||
foreach (var entry in pvp) {
|
||||
double price = entry.price;
|
||||
// prices are in descending order, so get diff from curr_price - price
|
||||
var tick_diff = spec.tickdiff(curr_price, price).assert_value();
|
||||
checked {
|
||||
curr_index += (int)tick_diff;
|
||||
}
|
||||
curr_price = price;
|
||||
if (curr_index >= 0 && curr_index < prices.Count) {
|
||||
var gr = format_text(fmt_value(entry.piq), curr_index, row_height, settings, glyph_context);
|
||||
dc.DrawGlyphRun(foreground, gr);
|
||||
} else break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Func<uint, string> fmt_value
|
||||
) {
|
||||
fmt_value ??= FormattingDelegates.default_string<uint>();
|
||||
var fg = settings.foreground.rgb_brush();
|
||||
_render_cells(dv, row_height, pvp, settings, prices, spec, (dc, row, piq) =>
|
||||
dc.DrawGlyphRun(
|
||||
fg, format_text(fmt_value(piq), row, row_height, settings, glyph_context)));
|
||||
}
|
||||
|
||||
public static void render_mkt_break(DrawingVisual dv, int index, double row_height, uint color) =>
|
||||
|
||||
@@ -59,7 +59,9 @@ namespace bts.shell.manual_fills {
|
||||
nameof(quantity_display),
|
||||
() => {
|
||||
var sec_meta = security.HasValue ? _sec_meta_store.get(security.Value) : null;
|
||||
return sec_meta?.QuantityDisplay ?? Security.Defaults.quantity_display_settingsi;
|
||||
return sec_meta?.HasQuantityDisplay ?? false ?
|
||||
sec_meta.Value.QuantityDisplay :
|
||||
Security.Defaults.quantity_display_settingsi;
|
||||
});
|
||||
// TODO (prob): remove conversion_data. Replace get_qty_display_divisor delegates w/
|
||||
// TickDisplaySettingsImmutable for qty, obtained via ISecurityMetadataStore.
|
||||
|
||||
@@ -293,7 +293,10 @@ namespace bts.shell.pnl {
|
||||
return _quantity_display_backing.Value;
|
||||
}
|
||||
if (security.HasValue) {
|
||||
_quantity_display_backing = _sec_meta_store.get(security.Value)?.QuantityDisplay;
|
||||
var sec_meta = _sec_meta_store.get(security.Value);
|
||||
if (sec_meta?.HasQuantityDisplay ?? false) {
|
||||
_quantity_display_backing = sec_meta.Value.QuantityDisplay;
|
||||
}
|
||||
}
|
||||
return _quantity_display_backing ??= Security.Defaults.quantity_display_settingsi;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace bts.shell {
|
||||
|
||||
void _on_orders(TableUpdate<(SecurityImmutable? sec, OrderRecordImmutable order), uint> update) {
|
||||
// must update notification_service_data_cache first, some of the predicate/triggers (esp. ToastNotifications) will use the notification_service_data_cache to lookup order-history
|
||||
_data_cache.update(update.as_iincremental());
|
||||
_data_cache.update(update);
|
||||
foreach (var o in update.added.Concat(update.changed))
|
||||
_order_notifications.process_item(o);
|
||||
}
|
||||
|
||||
@@ -1,89 +1,157 @@
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
|
||||
using mbts.spark;
|
||||
using mbts.utils;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace bts.shell {
|
||||
// Any predicate-sound/notifications that need to reference previous data (i.e. notifications based on change/time, or state changes) should use the INotificationServiceDataCache.
|
||||
// The INotificationService updates these caches in its IObservable.OnNext callbacks, just before calling all of the predicate-trigger methods.
|
||||
// Therfore, data referenced through this interface is guarenteed to be up-to-date, and thread safe. It also reduces performance overhead by avoiding redundant bookeeping.
|
||||
// Note: last_order_reset_time can be used by sound/toast-notification sources to avoid sending false-positive notifications for old orders (i.e. all the orders that arrive in the first update on startup/server restart)
|
||||
// --------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// IMPOARTANT!!! The current implementation of this interface is NOT INTENDED FOR GENERAL USE - order_history is NOT THREAD-SAFE
|
||||
interface INotificationServiceDataCache {
|
||||
DateTime last_order_reset_time { get; }
|
||||
bool is_first_order_update { get; }
|
||||
IReadOnlyDictionary<uint, List<TimeStampedData<OrderSecurity>>> order_history { get; }
|
||||
}
|
||||
|
||||
static class NotificationServiceDataCacheExtensions {
|
||||
public static OrderSecurity? get_previous_order_state(this INotificationServiceDataCache notification_service_data_cache, uint key) {
|
||||
if (notification_service_data_cache.order_history.TryGetValue(key, out List<TimeStampedData<OrderSecurity>> l)) {
|
||||
if (l.Count > 1) {
|
||||
return l[l.Count - 2].data;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
struct TimeStampedData<T> {
|
||||
public readonly T data;
|
||||
public readonly DateTime time_stamp;
|
||||
|
||||
public TimeStampedData(T data, DateTime time_stamp) {
|
||||
this.data = data;
|
||||
this.time_stamp = time_stamp;
|
||||
}
|
||||
}
|
||||
|
||||
partial class NotificationService : INotificationService, IDisposable {
|
||||
class DataCache : INotificationServiceDataCache {
|
||||
const int _buffer_size = 10;
|
||||
readonly Dictionary<uint, OrderSecurity> _order_cache = new Dictionary<uint, OrderSecurity>();
|
||||
readonly Dictionary<uint, List<TimeStampedData<OrderSecurity>>> _order_history = new Dictionary<uint, List<TimeStampedData<OrderSecurity>>>();
|
||||
|
||||
public IReadOnlyDictionary<uint, List<TimeStampedData<OrderSecurity>>> order_history => _order_history;
|
||||
|
||||
public DateTime last_order_reset_time { get; private set; }
|
||||
public bool is_first_order_update { get; private set; }
|
||||
|
||||
internal void update(IIncrementalUpdate<(SecurityImmutable? sec, OrderRecordImmutable order), uint> data) {
|
||||
DateTime now = DateTime.Now;
|
||||
if (data.removed.Count == _order_cache.Count) {
|
||||
last_order_reset_time = now;
|
||||
_order_cache.Clear();
|
||||
}
|
||||
is_first_order_update = _order_cache.Count == 0 && data.added.Count > 0;
|
||||
foreach (var kv in data.removed) {
|
||||
if (data.added.ContainsKey(kv.Key)) {
|
||||
_order_cache[kv.Key] = kv.Value;
|
||||
_order_history[kv.Key].Add(new TimeStampedData<OrderSecurity>(kv.Value, now));
|
||||
} else {
|
||||
_order_cache.Remove(kv.Key);
|
||||
// TODO: maybe these shouldn't be removed?
|
||||
// if we add delta/time predicates that need to refer to order history, we might need to keep them around
|
||||
// although, if the server is telling us to remove them, perhaps we shouldn't consider such data.
|
||||
_order_history.Remove(kv.Key);
|
||||
}
|
||||
}
|
||||
foreach (var kv in data.added) {
|
||||
if (data.removed.ContainsKey(kv.Key))
|
||||
continue;
|
||||
_order_cache.Add(kv.Key, kv.Value);
|
||||
_order_history.AddOrUpdate(kv.Key,
|
||||
k => new List<TimeStampedData<OrderSecurity>> { new TimeStampedData<OrderSecurity>(kv.Value, now) },
|
||||
(k, l) => {
|
||||
l.Add(new TimeStampedData<OrderSecurity>(kv.Value, now));
|
||||
if (l.Count >= 10)
|
||||
l.RemoveAt(0);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.api.orderman;
|
||||
|
||||
using mbts.spark;
|
||||
using mbts.utils;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace bts.shell {
|
||||
// Any predicate-sound/notifications that need to reference previous data (i.e. notifications based on change/time, or state changes) should use the INotificationServiceDataCache.
|
||||
// The INotificationService updates these caches in its IObservable.OnNext callbacks, just before calling all of the predicate-trigger methods.
|
||||
// Therfore, data referenced through this interface is guarenteed to be up-to-date, and thread safe. It also reduces performance overhead by avoiding redundant bookeeping.
|
||||
// Note: last_order_reset_time can be used by sound/toast-notification sources to avoid sending false-positive notifications for old orders (i.e. all the orders that arrive in the first update on startup/server restart)
|
||||
// --------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// IMPOARTANT!!! The current implementation of this interface is NOT INTENDED FOR GENERAL USE - order_history is NOT THREAD-SAFE
|
||||
interface INotificationServiceDataCache {
|
||||
bool is_first_order_update { get; }
|
||||
IReadOnlyDictionary<uint, List<TimeStampedData<OrderSecurity>>> order_history { get; }
|
||||
}
|
||||
|
||||
static class NotificationServiceDataCacheExtensions {
|
||||
public static OrderSecurity? get_previous_order_state(this INotificationServiceDataCache notification_service_data_cache, uint key) {
|
||||
if (notification_service_data_cache.order_history.TryGetValue(key, out List<TimeStampedData<OrderSecurity>> l)) {
|
||||
if (l.Count > 1) {
|
||||
return l[l.Count - 2].data;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
struct TimeStampedData<T> {
|
||||
public readonly T data;
|
||||
public readonly DateTime time_stamp;
|
||||
|
||||
public TimeStampedData(T data, DateTime time_stamp) {
|
||||
this.data = data;
|
||||
this.time_stamp = time_stamp;
|
||||
}
|
||||
}
|
||||
|
||||
partial class NotificationService : INotificationService, IDisposable {
|
||||
class DataCache : INotificationServiceDataCache {
|
||||
const int _ORDER_HISTORY_BUFFER_SIZE = 10;
|
||||
const int _TABLE_HISTORY_BUFFER_SIZE = 5;
|
||||
|
||||
readonly Dictionary<uint, OrderSecurity> _order_cache = new Dictionary<uint, OrderSecurity>();
|
||||
readonly Dictionary<uint, List<TimeStampedData<OrderSecurity>>> _order_history = new Dictionary<uint, List<TimeStampedData<OrderSecurity>>>();
|
||||
readonly List<(TableUpdate<(SecurityImmutable?, OrderRecordImmutable), uint>, DateTime)> _table_history = new(_TABLE_HISTORY_BUFFER_SIZE);
|
||||
readonly object _lock = new();
|
||||
|
||||
public IReadOnlyDictionary<uint, List<TimeStampedData<OrderSecurity>>> order_history => _order_history;
|
||||
|
||||
public bool is_first_order_update { get; private set; }
|
||||
|
||||
internal void update(TableUpdate<(SecurityImmutable? sec, OrderRecordImmutable order), uint> table) {
|
||||
// First, try processing the update per usual (incrementally). If it throws,
|
||||
// then log the exception and reset the state.
|
||||
DateTime now = DateTime.Now;
|
||||
lock (_lock) {
|
||||
_circular_buffer_add(_table_history, (table, now), _TABLE_HISTORY_BUFFER_SIZE);
|
||||
try {
|
||||
impl();
|
||||
return;
|
||||
} catch (Exception ex) {
|
||||
var table_history_desc = _fmt_order_table_history_safe();
|
||||
Log.Ui.error(
|
||||
$"Error processing order update in NotificationService: {ex}.\n" +
|
||||
$"***Last table updates below***\n" +
|
||||
table_history_desc);
|
||||
}
|
||||
// This is the 'escape' path. It really shouldn't throw.
|
||||
reset();
|
||||
}
|
||||
|
||||
void impl() {
|
||||
if (table.state.Count == 0) {
|
||||
_order_cache.Clear();
|
||||
}
|
||||
is_first_order_update = _order_cache.Count == 0 && table.state.Count > 0;
|
||||
foreach (var order in table.removed) {
|
||||
var k = table.key(order);
|
||||
_order_cache.Remove(k);
|
||||
_order_history.Remove(k);
|
||||
}
|
||||
foreach (var ch in table.changes) {
|
||||
var k = table.key(ch.New);
|
||||
_order_cache[k] = ch.New;
|
||||
_order_history[k].Add(new(ch.New, now));
|
||||
}
|
||||
foreach (var order in table.added) {
|
||||
var k = table.key(order);
|
||||
_order_cache[k] = order;
|
||||
var hist = _order_history.GetOrAdd(k, _ => new());
|
||||
_circular_buffer_add(hist, new(order, now), _ORDER_HISTORY_BUFFER_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
void reset() {
|
||||
_order_cache.Clear();
|
||||
_order_history.Clear();
|
||||
_table_history.Clear();
|
||||
foreach (var (k, order) in table.state) {
|
||||
_order_cache[k] = order;
|
||||
_order_history.GetOrAdd(k, _ => new()).Add(new(order, now));
|
||||
}
|
||||
is_first_order_update = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void _circular_buffer_add<T>(List<T> list, T item, int buffer_size) {
|
||||
Log.assert(buffer_size > 0);
|
||||
if (list.Count > buffer_size - 1) {
|
||||
// Remove oldest items (trim front)
|
||||
list.RemoveRange(
|
||||
0, list.Count - (buffer_size - 1));
|
||||
}
|
||||
list.Add(item);
|
||||
}
|
||||
|
||||
string _fmt_order_table_history_safe() {
|
||||
return _fmt_table_history_safe(_table_history, fmt_order_tup);
|
||||
|
||||
static string fmt_order_tup((SecurityImmutable?, OrderRecordImmutable) order_tup) {
|
||||
var (sec, order) = order_tup;
|
||||
var order_desc = OrderUtils.short_description(order, sec.spec_or_default());
|
||||
var sec_desc = sec?.ToString() ?? ("sid=" + order.security_key().ToString());
|
||||
return $"{sec_desc} {order_desc}";
|
||||
}
|
||||
}
|
||||
|
||||
static string _fmt_table_history_safe<T, TKey>(
|
||||
List<(TableUpdate<T, TKey>, DateTime)> table_history, Func<T, string> fmt_value) where TKey : IEquatable<TKey> {
|
||||
var table_history_desc = new System.Text.StringBuilder();
|
||||
for (int i = 0; i < table_history.Count; i++) {
|
||||
var (table, time_stamp) = table_history[i];
|
||||
table_history_desc.AppendLine(
|
||||
$"Update - {table_history.Count - i}, at {time_stamp:yyyy-MM-dd hh:mm:ss.ffffff}");
|
||||
table_history_desc.AppendLine(_fmt_table_safe(table, fmt_value));
|
||||
}
|
||||
return table_history_desc.ToString();
|
||||
}
|
||||
|
||||
static string _fmt_table_safe<T, TKey>(
|
||||
TableUpdate<T, TKey> table, Func<T, string> fmt_value) where TKey : IEquatable<TKey> {
|
||||
try {
|
||||
return table.description(fmt_value);
|
||||
} catch (Exception ex) {
|
||||
return $"Exception while formatting TableUpdate: ${ex}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,8 @@ namespace mbts {
|
||||
}
|
||||
var sec = order.security;
|
||||
var sec_meta = sec.HasValue ? _sec_meta_store.get(sec.Value) : null;
|
||||
var qty_display = sec_meta?.QuantityDisplay ??
|
||||
var qty_display = sec_meta?.HasQuantityDisplay ?? false ?
|
||||
sec_meta.Value.QuantityDisplay :
|
||||
Security.Defaults.quantity_display_settingsi;
|
||||
return ToastNotifications.order_completed(order, qty_display);
|
||||
}
|
||||
|
||||
@@ -266,8 +266,8 @@ namespace mbts.spark {
|
||||
|
||||
// List of symbol to volsurface mapping.
|
||||
// Publisher: VolSurfaceBlackboardManager
|
||||
public static ITag<VolSurfaceUsageListImmutable> VolSurfaceUsageTag { get; } =
|
||||
_mk_tag<VolSurfaceUsageListImmutable>();
|
||||
public static ITag<VolSurfaceUsageListImmutable?> VolSurfaceUsageTag { get; } =
|
||||
_mk_tag<VolSurfaceUsageListImmutable?>();
|
||||
|
||||
// The AW2 machinary can compute and publish the theos
|
||||
// right back locally(vs the server doing that) if configured that way.
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<Style x:Key="LogViewer.TextBox" TargetType="TextBox">
|
||||
<Setter Property="Background" Value="{StaticResource TextBox.BackgroundBrush}" />
|
||||
<Setter Property="Foreground" Value="{StaticResource TextBox.ForegroundBrush}" />
|
||||
<Setter Property="Background" Value="{u:BTSColor UI.TextBox.default_background}" />
|
||||
<Setter Property="Foreground" Value="{u:BTSColor UI.TextBox.default_foreground}" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
</Style>
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
@echo off
|
||||
@setlocal
|
||||
|
||||
if not defined VENV_DIR (
|
||||
set VENV_DIR=%~dp0..\.venv
|
||||
)
|
||||
set BUILD_SPARK_PY="%~dp0py\build_spark.py"
|
||||
@REM Build script designed for our jenkins build job(s). It assumes the py
|
||||
@REM venv already exists.
|
||||
|
||||
setlocal
|
||||
set tools_dir=%~dp0
|
||||
set venv_dir=%~dp0..\.venv\
|
||||
call "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat"
|
||||
call "%VENV_DIR%\Scripts\activate"
|
||||
call python "%BUILD_SPARK_PY%" %*
|
||||
call "%venv_dir%Scripts\activate.bat"
|
||||
call python "%tools_dir%py\build_spark.py" %*
|
||||
|
||||
EXIT /B %ERRORLEVEL%
|
||||
Reference in new issue
Block a user