Compare commits
151
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11de1c552e | ||
|
|
977fe53b94 | ||
|
|
0080bce7ec | ||
|
|
87379bba82 | ||
|
|
8f6d8c0eea | ||
|
|
6ca2753951 | ||
|
|
470ca0093e | ||
|
|
7e1715964f | ||
|
|
39e929a614 | ||
|
|
a9aa06f275 | ||
|
|
54510c9e59 | ||
|
|
cb56429f04 | ||
|
|
ac8147cc0f | ||
|
|
82ac189ac9 | ||
|
|
5721ff78b6 | ||
|
|
7afd2947f1 | ||
|
|
c3e3862c5f | ||
|
|
bf2dc9ecca | ||
|
|
e0e188a02c | ||
|
|
79ba1654d3 | ||
|
|
2aab0d18a5 | ||
|
|
312c8ded11 | ||
|
|
3f86779da6 | ||
|
|
716d3b8482 | ||
|
|
24f6dbc4f0 | ||
|
|
3e943fa35e | ||
|
|
457f878b41 | ||
|
|
ac2b2d042a | ||
|
|
829d2cdbf6 | ||
|
|
3cd9693b36 | ||
|
|
2b52ecf2ef | ||
|
|
faab60cbc1 | ||
|
|
b6be0d649d | ||
|
|
2a65c45d21 | ||
|
|
dc6ae2ac29 | ||
|
|
df4250c33a | ||
|
|
53504ef6f0 | ||
|
|
10afb1af06 | ||
|
|
a9149dfa87 | ||
|
|
5afa6695e7 | ||
|
|
d2a6d54090 | ||
|
|
794ac25c01 | ||
|
|
37214e9480 | ||
|
|
90ab551778 | ||
|
|
9a4ec46440 | ||
|
|
c86d283755 | ||
|
|
941956c1b5 | ||
|
|
67e3d22104 | ||
|
|
7e41c93f9a | ||
|
|
086ccbb3fa | ||
|
|
329ddc576d | ||
|
|
1faef425ab | ||
|
|
bb068cf6b2 | ||
|
|
f7cade41c6 | ||
|
|
47afd3a911 | ||
|
|
ef80d2a41d | ||
|
|
44ef080e9f | ||
|
|
fef8d2c413 | ||
|
|
201746e561 | ||
|
|
8e375a0b7f | ||
|
|
045f3dc060 | ||
|
|
6b6012236d | ||
|
|
9cee798939 | ||
|
|
c79bdb12e0 | ||
|
|
bce77d65de | ||
|
|
0db814ef2d | ||
|
|
31b5ec4bd3 | ||
|
|
e15cdfd76e | ||
|
|
eb150ba82c | ||
|
|
d763275179 | ||
|
|
2b96a8a5c4 | ||
|
|
31866c76b7 | ||
|
|
a2da946e03 | ||
|
|
528bab34e7 | ||
|
|
776b9e4f94 | ||
|
|
168d328e97 | ||
|
|
f871dbd230 | ||
|
|
1662b56ea0 | ||
|
|
f3302dbac0 | ||
|
|
181072f3e7 | ||
|
|
f654312123 | ||
|
|
c46d97646a | ||
|
|
41742359e9 | ||
|
|
024723925e | ||
|
|
76b834768e | ||
|
|
89284bea87 | ||
|
|
532154640b | ||
|
|
ab8468d498 | ||
|
|
84b0332778 | ||
|
|
20b601f290 | ||
|
|
47002cae4c | ||
|
|
eaaffe369a | ||
|
|
7292a31c00 | ||
|
|
389d762a93 | ||
|
|
9704ebf096 | ||
|
|
de320338ca | ||
|
|
668dfd9130 | ||
|
|
a2960b23a8 | ||
|
|
55744edc25 | ||
|
|
7ece5d18cb | ||
|
|
8005ac8635 | ||
|
|
c00a71fdfa | ||
|
|
197c915968 | ||
|
|
6d77a07bbe | ||
|
|
adfb560dd1 | ||
|
|
508d20e4e0 | ||
|
|
72457619f7 | ||
|
|
18d5b83a95 | ||
|
|
653362b947 | ||
|
|
b7477b8f93 | ||
|
|
105f1fceaf | ||
|
|
cb65489ab7 | ||
|
|
96772727df | ||
|
|
960a618fe1 | ||
|
|
505cd37225 | ||
|
|
a5f66b8ac6 | ||
|
|
2021f29f62 | ||
|
|
9ccf3e0f87 | ||
|
|
7cfc53eba8 | ||
|
|
f9d269c750 | ||
|
|
67d5161fd1 | ||
|
|
d6e9bbce71 | ||
|
|
76ec2c0fa2 | ||
|
|
e82a2c9402 | ||
|
|
60ce106e24 | ||
|
|
1eb4952422 | ||
|
|
3043582889 | ||
|
|
f604db6517 | ||
|
|
f95b0c19d7 | ||
|
|
627b44d53b | ||
|
|
655bf87e92 | ||
|
|
6d06a1920d | ||
|
|
70af51e163 | ||
|
|
2c17fe334e | ||
|
|
5eca2cd3ac | ||
|
|
4b5ff8cad4 | ||
|
|
89d5b25cc7 | ||
|
|
3e10d403b4 | ||
|
|
1ebf06d49a | ||
|
|
2be857a851 | ||
|
|
1de22a82e8 | ||
|
|
f275308cc8 | ||
|
|
79de0dd4d8 | ||
|
|
5cedf74406 | ||
|
|
e5de6b4ad7 | ||
|
|
e467195de1 | ||
|
|
913a5b4a7e | ||
|
|
feb8bd9b79 | ||
|
|
846ecfa776 | ||
|
|
d98fb399a8 | ||
|
|
4a1c1d023a |
No files matched your search
@@ -1,28 +0,0 @@
|
||||
[settings]
|
||||
os=Windows
|
||||
compiler='Visual Studio'
|
||||
build_type=Debug
|
||||
arch=x86_64
|
||||
compiler.version=17
|
||||
compiler.runtime=MTd
|
||||
|
||||
[options]
|
||||
boost:without_graph=True
|
||||
boost:without_iostreams=True
|
||||
boost:without_json=True
|
||||
boost:without_log=True
|
||||
boost:without_math=True
|
||||
boost:without_nowide=True
|
||||
boost:without_program_options=True
|
||||
boost:without_python=True
|
||||
boost:without_random=True
|
||||
boost:without_serialization=True
|
||||
boost:without_test=True
|
||||
boost:without_timer=True
|
||||
boost:without_wave=True
|
||||
boost:layout=system
|
||||
boost:multithreading=True
|
||||
|
||||
[build_requires]
|
||||
|
||||
[env]
|
||||
@@ -1,28 +0,0 @@
|
||||
[settings]
|
||||
os=Windows
|
||||
compiler='Visual Studio'
|
||||
build_type=Release
|
||||
arch=x86_64
|
||||
compiler.version=17
|
||||
compiler.runtime=MT
|
||||
|
||||
[options]
|
||||
boost:without_graph=True
|
||||
boost:without_iostreams=True
|
||||
boost:without_json=True
|
||||
boost:without_log=True
|
||||
boost:without_math=True
|
||||
boost:without_nowide=True
|
||||
boost:without_program_options=True
|
||||
boost:without_python=True
|
||||
boost:without_random=True
|
||||
boost:without_serialization=True
|
||||
boost:without_test=True
|
||||
boost:without_timer=True
|
||||
boost:without_wave=True
|
||||
boost:layout=system
|
||||
boost:multithreading=True
|
||||
|
||||
[build_requires]
|
||||
|
||||
[env]
|
||||
@@ -3,16 +3,10 @@
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-format": {
|
||||
"version": "5.1.250801",
|
||||
"version": "5.1.225507",
|
||||
"commands": [
|
||||
"dotnet-format"
|
||||
]
|
||||
},
|
||||
"protobuf-net.protogen": {
|
||||
"version": "3.1.17",
|
||||
"commands": [
|
||||
"protogen"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,5 +50,3 @@ trace_data/
|
||||
*.tmp/*
|
||||
/.venv*/*
|
||||
.cache/
|
||||
src/web/api/tsconfig.*.g.json
|
||||
.conan/windows/install/*
|
||||
+50
-22
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(spark)
|
||||
|
||||
if(WIN32)
|
||||
@@ -7,45 +7,73 @@ else()
|
||||
set(platform "linux")
|
||||
endif()
|
||||
|
||||
set(
|
||||
EXTERNALS_ROOT
|
||||
"${CMAKE_SOURCE_DIR}/externals/${platform}"
|
||||
CACHE
|
||||
STRING
|
||||
"External dependencies root folder (should contain folders: lib, bin, include")
|
||||
set(EXTERNALS_ROOT "${CMAKE_SOURCE_DIR}/externals/${platform}")
|
||||
set(SPARK_PYTHON "${EXTERNALS_ROOT}/python")
|
||||
set(SPARK_BIN "${EXTERNALS_ROOT}/bin")
|
||||
set(SPARK_INCLUDE "${EXTERNALS_ROOT}/include")
|
||||
set(SPARK_LIB "${EXTERNALS_ROOT}/lib/${CMAKE_BUILD_TYPE}")
|
||||
set(TOOLS "${CMAKE_SOURCE_DIR}/tools")
|
||||
set(BUILD_SDK OFF CACHE BOOL "Build the sdk")
|
||||
set(BUILD_WEB ON CACHE BOOL "Build the web server")
|
||||
|
||||
include(${CMAKE_SOURCE_DIR}/.conan/${platform}/install/debug/conanbuildinfo.cmake)
|
||||
set(CONAN_SYSTEM_INCLUDES ON)
|
||||
conan_basic_setup()
|
||||
|
||||
include_directories(BEFORE SYSTEM ${SPARK_INCLUDE} ${EXTERNALS_ROOT}/include/zlib)
|
||||
link_directories(${SPARK_LIB})
|
||||
|
||||
if(WIN32)
|
||||
# flags
|
||||
set(
|
||||
CMAKE_CXX_FLAGS
|
||||
"${CMAKE_CXX_FLAGS} \
|
||||
/MP \
|
||||
/WX /wd4251 /wd4250 /wd4251 /wd4244 /wd4267 /wd4355 /wd4275 /wd4345 \
|
||||
/bigobj \
|
||||
/DCURL_STATICLIB \
|
||||
/D_WINSOCK_DEPRECATED_NO_WARNINGS \
|
||||
/D__TBB_NO_IMPLICIT_LINKAGE \
|
||||
/DBOOST_ALL_NO_LIB \
|
||||
/std:c++17 \
|
||||
/D_SCL_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_WARNINGS /D_WIN32_WINNT=0x0600")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} /MT")
|
||||
set(
|
||||
CMAKE_SHARED_LINKER_FLAGS_RELEASE
|
||||
"${CMAKE_SHARED_LINKER_FLAGS_RELEASE} \
|
||||
/DEBUG \
|
||||
/OPT:REF \
|
||||
/OPT:ICF \
|
||||
/LTCG")
|
||||
|
||||
# subdirs
|
||||
add_subdirectory(src/lib)
|
||||
add_custom_command(
|
||||
OUTPUT ${CMAKE_BINARY_DIR}/Directory.Build.Props
|
||||
COMMAND cp ARGS ${TOOLS}/cpp.build.props ${CMAKE_BINARY_DIR}/Directory.Build.Props
|
||||
DEPENDS ${TOOLS}/cpp.build.props
|
||||
COMMENT "Copy cpp.build.props -> Directory.Build.Props")
|
||||
add_custom_target(client_layout ALL DEPENDS ${CMAKE_BINARY_DIR}/Directory.Build.Props)
|
||||
else()
|
||||
# make sparkd look for libspark.so in its directory
|
||||
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
|
||||
set(CMAKE_INSTALL_RPATH ".")
|
||||
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install/${CMAKE_BUILD_TYPE}/sparkd")
|
||||
add_compile_definitions(SPARK_ENABLE_CCAPI)
|
||||
add_compile_definitions(CCAPI_ENABLE_SERVICE_MARKET_DATA)
|
||||
add_compile_definitions(CCAPI_ENABLE_EXCHANGE_FTX)
|
||||
add_compile_definitions(CCAPI_ENABLE_LOG_WARN)
|
||||
|
||||
# flags
|
||||
set(
|
||||
CMAKE_CXX_FLAGS_DEBUG
|
||||
"${CMAKE_CXX_FLAGS_DEBUG} \
|
||||
-fPIC \
|
||||
-Wall \
|
||||
-pedantic \
|
||||
-Wextra \
|
||||
-Werror \
|
||||
-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")
|
||||
|
||||
# subdirs
|
||||
add_subdirectory(src/server/sparkd)
|
||||
add_subdirectory(src/lib)
|
||||
if(BUILD_WEB)
|
||||
if (BUILD_WEB)
|
||||
add_subdirectory(src/web)
|
||||
endif()
|
||||
add_subdirectory(doc/user)
|
||||
@@ -62,9 +90,9 @@ else()
|
||||
COMMAND ln ARGS -sf ${CMAKE_BINARY_DIR}/data_files ${CMAKE_BINARY_DIR}/server
|
||||
COMMAND ln ARGS -sf ${CMAKE_BINARY_DIR}/src/lib/libspark.so ${CMAKE_BINARY_DIR}/server
|
||||
COMMAND
|
||||
ln ARGS -sf
|
||||
${EXTERNALS_ROOT}/lib/Release/libOnixS.IceImpactMulticastPriceFeedHandlerCpp.so.3.16.0.0
|
||||
${CMAKE_BINARY_DIR}/server
|
||||
ln ARGS -sf
|
||||
${EXTERNALS_ROOT}/lib/Release/libOnixS.IceImpactMulticastPriceFeedHandlerCpp.so.3.16.0.0
|
||||
${CMAKE_BINARY_DIR}/server
|
||||
COMMAND ln ARGS -sf ${EXTERNALS_ROOT}/lib/Release/libACE-5.7.5.so ${CMAKE_BINARY_DIR}/server
|
||||
COMMAND mkdir ARGS -p ${CMAKE_BINARY_DIR}/server/plugins
|
||||
COMMENT "Creating server runtime layout"
|
||||
|
||||
@@ -1,224 +0,0 @@
|
||||
{
|
||||
"version": 4,
|
||||
"cmakeMinimumRequired": {
|
||||
"major": 3,
|
||||
"minor": 23,
|
||||
"patch": 0
|
||||
},
|
||||
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "spark",
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Windows"
|
||||
},
|
||||
"generator": "Visual Studio 17 2022",
|
||||
"binaryDir": "${sourceDir}/build",
|
||||
"cacheVariables": {
|
||||
"CMAKE_CXX_FLAGS": "/MP /WX /bigobj /EHsc /DCURL_STATICLIB /D_WINSOCK_DEPRECATED_NO_WARNINGS /D__TBB_NO_IMPLICIT_LINKAGE /DBOOST_ALL_NO_LIB /std:c++17 /D_WIN32_WINNT=0x0600",
|
||||
"CMAKE_CXX_FLAGS_DEBUG": "/MTd",
|
||||
"CMAKE_CXX_FLAGS_RELEASE": "/MT",
|
||||
"CMAKE_SHARED_LINKER_FLAGS_RELEASE": "/DEBUG /OPT:REF /OPT:ICF /LTCG",
|
||||
"CONAN_COMPILER": "Visual Studio",
|
||||
"CONAN_COMPILER_VERSION": "17",
|
||||
"EXTERNALS_ROOT": "${sourceDir}/externals/windows"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd",
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Linux"
|
||||
},
|
||||
"hidden": true,
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/build/${presetName}",
|
||||
"cacheVariables": {
|
||||
"platform": "",
|
||||
"CMAKE_BUILD_WITH_INSTALL_RPATH": {
|
||||
"type": "BOOL",
|
||||
"value": "ON"
|
||||
},
|
||||
"CMAKE_INSTALL_RPATH": ".",
|
||||
"CMAKE_INSTALL_PREFIX": "${sourceDir}/install/${presetName}",
|
||||
"CMAKE_EXE_LINKER_FLAGS": "-Wno-undef",
|
||||
"EXTERNALS_ROOT": "${sourceDir}/externals/linux",
|
||||
"CMAKE_C_COMPILER": "cc",
|
||||
"CMAKE_CXX_STANDARD": "17",
|
||||
"WEB_TSCONFIG_NAME": "${presetName}",
|
||||
"BUILD_SDK": {
|
||||
"type": "BOOL",
|
||||
"value": "OFF"
|
||||
},
|
||||
"BUILD_WEB": {
|
||||
"type": "BOOL",
|
||||
"value": "ON"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd-dev",
|
||||
"hidden": true,
|
||||
"inherits": "sparkd",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug",
|
||||
"CMAKE_CXX_FLAGS_DEBUG": "-fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++17 -fdiagnostics-color",
|
||||
"CMAKE_EXPORT_COMPILE_COMMANDS": {
|
||||
"type": "BOOL",
|
||||
"value": "ON"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd-prod",
|
||||
"hidden": true,
|
||||
"inherits": "sparkd",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release",
|
||||
"CMAKE_CXX_FLAGS_RELEASE": "-fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++17 -fdiagnostics-color -fno-omit-frame-pointer -DNDEBUG -O3"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd-dev-clang",
|
||||
"inherits": "sparkd-dev",
|
||||
"displayName": "Development (clang)",
|
||||
"description": "Debug build compiled w/ clang",
|
||||
"cacheVariables": {
|
||||
"CMAKE_CXX_COMPILER": "clang++"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd-dev-gcc",
|
||||
"inherits": "sparkd-dev",
|
||||
"displayName": "Development (gcc)",
|
||||
"description": "Debug build compiled w/ gcc",
|
||||
"cacheVariables": {
|
||||
"CMAKE_CXX_COMPILER": "g++"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd-prod-clang",
|
||||
"inherits": "sparkd-prod",
|
||||
"displayName": "Production (clang)",
|
||||
"description": "Release build compiled w/ clang",
|
||||
"cacheVariables": {
|
||||
"CMAKE_CXX_COMPILER": "clang++"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd-prod-gcc",
|
||||
"inherits": "sparkd-prod",
|
||||
"displayName": "Production (gcc)",
|
||||
"description": "Release build compiled w/ gcc",
|
||||
"cacheVariables": {
|
||||
"CMAKE_CXX_COMPILER": "g++"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd-publish",
|
||||
"inherits": "sparkd",
|
||||
"displayName": "Publish",
|
||||
"description": "Publish build compiled w/ gcc and ready to ship",
|
||||
"cacheVariables": {
|
||||
"CMAKE_CXX_COMPILER": "g++"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
"buildPresets": [
|
||||
{
|
||||
"name": "spark",
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Windows"
|
||||
},
|
||||
"hidden": true,
|
||||
"jobs": 4
|
||||
},
|
||||
|
||||
{
|
||||
"name": "spark-dev",
|
||||
"displayName": "Development",
|
||||
"inherits": "spark",
|
||||
"configurePreset": "spark",
|
||||
"configuration": "Debug"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "spark-prod",
|
||||
"displayName": "Production",
|
||||
"inherits": "spark",
|
||||
"configurePreset": "spark",
|
||||
"configuration": "Release"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd",
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Linux"
|
||||
},
|
||||
"hidden": true,
|
||||
"jobs": 4,
|
||||
"targets": [
|
||||
"data_files_dir",
|
||||
"doc_manual_bundle",
|
||||
"install",
|
||||
"libspark",
|
||||
"rapidjson_project",
|
||||
"server_layout",
|
||||
"sparkd",
|
||||
"web_ui_bundle"
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd-dev-clang",
|
||||
"configurePreset": "sparkd-dev-clang",
|
||||
"displayName": "Development (clang)",
|
||||
"inherits": "sparkd"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd-dev-gcc",
|
||||
"configurePreset": "sparkd-dev-gcc",
|
||||
"displayName": "Development (gcc)",
|
||||
"inherits": "sparkd"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd-prod-clang",
|
||||
"configurePreset": "sparkd-prod-clang",
|
||||
"displayName": "Production (clang)",
|
||||
"inherits": "sparkd"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd-prod-gcc",
|
||||
"configurePreset": "sparkd-prod-gcc",
|
||||
"displayName": "Production (gcc)",
|
||||
"inherits": "sparkd"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd-publish",
|
||||
"configurePreset": "sparkd-publish",
|
||||
"displayName": "Publish",
|
||||
"inherits": "sparkd",
|
||||
"targets": "install"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
set(Protobuf_PROTOC_EXECUTABLE "${SPARK_BIN}/protoc")
|
||||
set(PROTOBUF_INCLUDE_DIRS "${SPARK_INCLUDE}")
|
||||
set(PROTOBUF_STATIC_LIB "libprotobuf")
|
||||
|
||||
function(Protobuf_Generate_Cpp SRCS HDRS)
|
||||
set(${SRCS})
|
||||
@@ -104,9 +106,8 @@ function(Service_Compiler_Generate_Cpp SRCS HDRS)
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.client.pb.h"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.server.pb.cc"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.server.pb.h"
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/tools/venv_exec.sh
|
||||
ARGS
|
||||
${Protobuf_PROTOC_EXECUTABLE}
|
||||
COMMAND
|
||||
"PYTHONPATH=${SPARK_PYTHON}" ${Protobuf_PROTOC_EXECUTABLE} ARGS
|
||||
--cpp_out=${CMAKE_BINARY_DIR}/src
|
||||
--plugin=protoc-gen-service=${CMAKE_SOURCE_DIR}/src/lib/api/service_compiler/plugin.py
|
||||
--service_out=lang=cpp,make_file_name=${ABS_FIL}:${CMAKE_BINARY_DIR}/src
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
from conans import ConanFile
|
||||
|
||||
|
||||
class SparkCryptoConan(ConanFile):
|
||||
name = "spark_crypto"
|
||||
version = "0.1"
|
||||
author = "Blue Trading Solutions"
|
||||
topics = (
|
||||
"crypto", "trading", "options", "futures", "derivatives", "api",
|
||||
"risk", "volatility", "finance")
|
||||
requires = [
|
||||
"boost/1.79.0", "catch2/3.0.1", "cmake/3.23.2", "fmt/8.1.1",
|
||||
"libcurl/7.83.1", "nlohmann_json/3.10.5", "openssl/1.1.1o",
|
||||
"protobuf/3.21.1", "onetbb/2021.3.0", "zlib/1.2.12"
|
||||
]
|
||||
generators = ("cmake", "virtualenv")
|
||||
@@ -1,40 +0,0 @@
|
||||
import os
|
||||
import subprocess
|
||||
import argparse
|
||||
|
||||
|
||||
def _exit(code=0, msg=None):
|
||||
if msg is not None:
|
||||
print(msg)
|
||||
exit(code)
|
||||
|
||||
|
||||
def _literal_linesep():
|
||||
ls = os.linesep
|
||||
if ls == '\r\n':
|
||||
return r'\r\n'
|
||||
if ls == '\n':
|
||||
return r'\n'
|
||||
return ls
|
||||
|
||||
|
||||
def _get_arg_parser():
|
||||
parser = argparse.ArgumentParser(description='Build spark_client.sln')
|
||||
parser.add_argument('input', nargs='?', help='The CMakeDeps file to dump')
|
||||
return parser
|
||||
|
||||
|
||||
def _main():
|
||||
parser = _get_arg_parser()
|
||||
args = parser.parse_args()
|
||||
cmd_args = ['sed', fr"'s/;/{_literal_linesep()}/g'", args.input]
|
||||
return subprocess.run(cmd_args)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
res = _main()
|
||||
if res.returncode != 0:
|
||||
_exit(1, str(res))
|
||||
except Exception as e:
|
||||
_exit(1, str(e))
|
||||
+1
-1
Submodule docker/linux updated: 191d74b404...05967d0f18.
+1
-1
Submodule externals updated: bd8fda33b6...99c440f568.
@@ -1,39 +1,17 @@
|
||||
astroid==2.7.3
|
||||
autopep8==1.5.7
|
||||
bottle==0.12.21
|
||||
certifi==2022.6.15
|
||||
cffi==1.14.6
|
||||
charset-normalizer==2.1.0
|
||||
colorama==0.4.4
|
||||
conan==1.50.0
|
||||
fasteners==0.17.3
|
||||
gitdb==4.0.9
|
||||
idna==3.3
|
||||
isort==5.9.3
|
||||
Jinja2==3.1.2
|
||||
lazy-object-proxy==1.6.0
|
||||
MarkupSafe==2.1.1
|
||||
mccabe==0.6.1
|
||||
node-semver==0.6.1
|
||||
patch-ng==1.17.4
|
||||
platformdirs==2.3.0
|
||||
pluginbase==1.0.1
|
||||
protobuf==3.19.1
|
||||
pybars3==0.9.7
|
||||
pycodestyle==2.7.0
|
||||
pycparser==2.20
|
||||
Pygments==2.12.0
|
||||
PyJWT==2.4.0
|
||||
pylint==2.10.2
|
||||
PyMeta3==0.5.1
|
||||
python-dateutil==2.8.2
|
||||
PyYAML==6.0
|
||||
requests==2.28.1
|
||||
six==1.16.0
|
||||
smmap==5.0.0
|
||||
termcolor==1.1.0
|
||||
toml==0.10.2
|
||||
tqdm==4.64.0
|
||||
urllib3==1.26.9
|
||||
wrapt==1.12.1
|
||||
yapf==0.31.0
|
||||
@@ -0,0 +1,41 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26730.10
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sparkd", "src\server\sparkd\sparkd.vcxproj", "{BBBAFD38-312D-4A8D-9AF0-F2BDEE72CE6F}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libspark", "build\src\lib\libspark.vcxproj", "{502FD050-679A-3B50-B438-098500700919}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
MinSizeRel|x64 = MinSizeRel|x64
|
||||
Release|x64 = Release|x64
|
||||
RelWithDebInfo|x64 = RelWithDebInfo|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{BBBAFD38-312D-4A8D-9AF0-F2BDEE72CE6F}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{BBBAFD38-312D-4A8D-9AF0-F2BDEE72CE6F}.Debug|x64.Build.0 = Debug|x64
|
||||
{BBBAFD38-312D-4A8D-9AF0-F2BDEE72CE6F}.MinSizeRel|x64.ActiveCfg = Release|x64
|
||||
{BBBAFD38-312D-4A8D-9AF0-F2BDEE72CE6F}.MinSizeRel|x64.Build.0 = Release|x64
|
||||
{BBBAFD38-312D-4A8D-9AF0-F2BDEE72CE6F}.Release|x64.ActiveCfg = Release|x64
|
||||
{BBBAFD38-312D-4A8D-9AF0-F2BDEE72CE6F}.Release|x64.Build.0 = Release|x64
|
||||
{BBBAFD38-312D-4A8D-9AF0-F2BDEE72CE6F}.RelWithDebInfo|x64.ActiveCfg = Release|x64
|
||||
{BBBAFD38-312D-4A8D-9AF0-F2BDEE72CE6F}.RelWithDebInfo|x64.Build.0 = Release|x64
|
||||
{502FD050-679A-3B50-B438-098500700919}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{502FD050-679A-3B50-B438-098500700919}.Debug|x64.Build.0 = Debug|x64
|
||||
{502FD050-679A-3B50-B438-098500700919}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
|
||||
{502FD050-679A-3B50-B438-098500700919}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
|
||||
{502FD050-679A-3B50-B438-098500700919}.Release|x64.ActiveCfg = Release|x64
|
||||
{502FD050-679A-3B50-B438-098500700919}.Release|x64.Build.0 = Release|x64
|
||||
{502FD050-679A-3B50-B438-098500700919}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
|
||||
{502FD050-679A-3B50-B438-098500700919}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {6A7249D7-B40C-4656-9347-60072D0B8FDB}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
+12
-22
@@ -1,10 +1,10 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.2.32616.157
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30114.105
|
||||
MinimumVisualStudioVersion = 15.0.26124.0
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_api", "src\client\spark_api\spark_api.csproj", "{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libspark", "build\src\lib\libspark.vcxproj", "{FDC3A021-386E-3A2C-A7EB-CBE94A95BE25}"
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libspark", "build\src\lib\libspark.vcxproj", "{9FA60215-26AF-3EB7-AB89-D4F4B126EF40}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Spark", "src\client\spark\Spark.csproj", "{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}"
|
||||
EndProject
|
||||
@@ -14,13 +14,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_core", "src\client\sp
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_sdk", "src\client\spark_sdk\spark_sdk.csproj", "{6963C314-83C4-4667-B0D0-C2F7AE208C29}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{FDC3A021-386E-3A2C-A7EB-CBE94A95BE25} = {FDC3A021-386E-3A2C-A7EB-CBE94A95BE25}
|
||||
{9FA60215-26AF-3EB7-AB89-D4F4B126EF40} = {9FA60215-26AF-3EB7-AB89-D4F4B126EF40}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_test", "src\client\spark_test\spark_test.csproj", "{ECD78CC5-138F-4809-A764-2358C2AC2E82}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client_layout", "build\client_layout.vcxproj", "{7BD9B47C-9AEA-3F81-B8E4-73C74C1932A9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
@@ -37,14 +35,14 @@ Global
|
||||
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.Release|x64.Build.0 = Release|x64
|
||||
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.RelWithDebInfo|x64.ActiveCfg = Release|x64
|
||||
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.RelWithDebInfo|x64.Build.0 = Release|x64
|
||||
{FDC3A021-386E-3A2C-A7EB-CBE94A95BE25}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{FDC3A021-386E-3A2C-A7EB-CBE94A95BE25}.Debug|x64.Build.0 = Debug|x64
|
||||
{FDC3A021-386E-3A2C-A7EB-CBE94A95BE25}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
|
||||
{FDC3A021-386E-3A2C-A7EB-CBE94A95BE25}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
|
||||
{FDC3A021-386E-3A2C-A7EB-CBE94A95BE25}.Release|x64.ActiveCfg = Release|x64
|
||||
{FDC3A021-386E-3A2C-A7EB-CBE94A95BE25}.Release|x64.Build.0 = Release|x64
|
||||
{FDC3A021-386E-3A2C-A7EB-CBE94A95BE25}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
|
||||
{FDC3A021-386E-3A2C-A7EB-CBE94A95BE25}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
|
||||
{9FA60215-26AF-3EB7-AB89-D4F4B126EF40}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{9FA60215-26AF-3EB7-AB89-D4F4B126EF40}.Debug|x64.Build.0 = Debug|x64
|
||||
{9FA60215-26AF-3EB7-AB89-D4F4B126EF40}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
|
||||
{9FA60215-26AF-3EB7-AB89-D4F4B126EF40}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
|
||||
{9FA60215-26AF-3EB7-AB89-D4F4B126EF40}.Release|x64.ActiveCfg = Release|x64
|
||||
{9FA60215-26AF-3EB7-AB89-D4F4B126EF40}.Release|x64.Build.0 = Release|x64
|
||||
{9FA60215-26AF-3EB7-AB89-D4F4B126EF40}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
|
||||
{9FA60215-26AF-3EB7-AB89-D4F4B126EF40}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
|
||||
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Debug|x64.Build.0 = Debug|x64
|
||||
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.MinSizeRel|x64.ActiveCfg = Release|x64
|
||||
@@ -85,14 +83,6 @@ Global
|
||||
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.Release|x64.Build.0 = Release|x64
|
||||
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.RelWithDebInfo|x64.ActiveCfg = Release|x64
|
||||
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.RelWithDebInfo|x64.Build.0 = Release|x64
|
||||
{7BD9B47C-9AEA-3F81-B8E4-73C74C1932A9}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{7BD9B47C-9AEA-3F81-B8E4-73C74C1932A9}.Debug|x64.Build.0 = Debug|x64
|
||||
{7BD9B47C-9AEA-3F81-B8E4-73C74C1932A9}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
|
||||
{7BD9B47C-9AEA-3F81-B8E4-73C74C1932A9}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
|
||||
{7BD9B47C-9AEA-3F81-B8E4-73C74C1932A9}.Release|x64.ActiveCfg = Release|x64
|
||||
{7BD9B47C-9AEA-3F81-B8E4-73C74C1932A9}.Release|x64.Build.0 = Release|x64
|
||||
{7BD9B47C-9AEA-3F81-B8E4-73C74C1932A9}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
|
||||
{7BD9B47C-9AEA-3F81-B8E4-73C74C1932A9}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -29,8 +29,8 @@
|
||||
|
||||
<PropertyGroup Label="ProtoBuf">
|
||||
<ProtocPluginBase>$(SparkRoot)\src\lib\api\service_compiler</ProtocPluginBase>
|
||||
<protoc>protoc</protoc>
|
||||
<protogen>dotnet protogen</protogen>
|
||||
<protoc>$(Externals)\bin\protoc.exe</protoc>
|
||||
<protogen>$(Externals)\bin\protogen.exe</protogen>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemDefinitionGroup>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<Target
|
||||
Name="CompileProto2"
|
||||
Condition="'@(Proto2)'!=''"
|
||||
Inputs="$(MSBuildProjectFile);%(Proto2.FullPath)"
|
||||
Inputs="$(MSBuildProjectFile);$(protogen);%(Proto2.FullPath)"
|
||||
Outputs="$(GenDir)\proto2\%(Proto2.filename).cs"
|
||||
AfterTargets="PreBuildEvent">
|
||||
<PropertyGroup>
|
||||
@@ -17,6 +17,9 @@
|
||||
DestinationFolder="$(WorkingDirectory)"
|
||||
SkipUnchangedFiles="True"
|
||||
UseHardLinksIfPossible="True" />
|
||||
<Error
|
||||
Text="protogen.exe does not exist. If you forgot to clone with externals try: git submodule update --init --recursive"
|
||||
Condition="!Exists($(protogen))" />
|
||||
<Exec
|
||||
Command="$(Protogen) %(Proto2.filename)%(proto2.extension) --csharp_out=. -I. -I$(SourceRoot) -I$(Externals)\include"
|
||||
WorkingDirectory="$(WorkingDirectory)" />
|
||||
@@ -34,7 +37,7 @@
|
||||
Name="CompileProto3"
|
||||
AfterTargets="GetAssemblyVersion"
|
||||
Condition="'@(Proto3)'!=''"
|
||||
Inputs="
|
||||
Inputs="$(protoc);
|
||||
%(Proto3.Identity);$(ProtocPluginBase)\plugin.py;
|
||||
$(ProtocPluginBase)\templates\c#\client.pb.cs;
|
||||
$(ProtocPluginBase)\templates\c#\server.pb.cs;
|
||||
@@ -49,7 +52,7 @@
|
||||
<Exec Command="set PYTHONPATH=$(SparkRoot)\.venv\Scripts\python" />
|
||||
<Exec
|
||||
Command="
|
||||
$(protoc) ^
|
||||
$(SparkRoot)\tools\build_protos.cmd ^
|
||||
%(Proto3.FullPath) ^
|
||||
--error_format=msvs ^
|
||||
--proto_path=$(SourceRoot) ^
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace mbts.spark {
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Core;
|
||||
using Spark.Core.Collections;
|
||||
using Spark.ViewModel.Commands;
|
||||
|
||||
@@ -33,13 +34,13 @@ namespace mbts.spark {
|
||||
class AnalyticsExpirationParametersVM : DisposableViewModelBase, IHandleRowSelection {
|
||||
readonly IBus _bus;
|
||||
readonly ObservableCollection<AnalyticsExpirationParameters> _parameters = new();
|
||||
readonly DeferrableActionWrapper _sync_visible_rows;
|
||||
readonly DeferrableAction _sync_visible_rows;
|
||||
readonly Property<AnalyticsExpirationParametersRowVM?> _copy_row_source;
|
||||
readonly Property<bool> _auto_copy_rolls_is_checked;
|
||||
readonly Property<bool> _auto_copy_rates_is_checked;
|
||||
readonly DelegateProperty<bool> _is_dirty;
|
||||
readonly ObservableHashSet<AnalyticsExpirationParametersRowVM> _selected_rows = new();
|
||||
readonly DeferrableActionWrapper _raise_selected_rows_changed;
|
||||
readonly DeferrableAction _raise_selected_rows_changed;
|
||||
readonly IRaiseCanExecuteChangedCommand _set_driver_to_nearest_exp_cmd;
|
||||
|
||||
AnalyticsExpirationParametersMap? _parameter_map;
|
||||
@@ -81,24 +82,24 @@ namespace mbts.spark {
|
||||
selected_rows_changed += _ => _set_driver_to_nearest_exp_cmd.RaiseCanExecuteChanged();
|
||||
|
||||
_dispose = Disposable.Create(
|
||||
_selected_rows.Subscribe((s, e) => _raise_selected_rows_changed.execute()),
|
||||
_selected_rows.Subscribe((s, e) => _raise_selected_rows_changed.Invoke()),
|
||||
ObservableAutoWrapper.connect(_parameters, rows, p => new(this, p), r => r.Dispose()),
|
||||
ObservableAutoWrapper.connect(
|
||||
non_options,
|
||||
explicit_drivers,
|
||||
sec => new ExpirationDriverImmutable(new() { Security = sec.to_api_sec_exp() })),
|
||||
rows.Subscribe((s, e) => _sync_visible_rows.execute()),
|
||||
rows.Subscribe((s, e) => _sync_visible_rows.Invoke()),
|
||||
_bus.subscribe(SparkTags.ExpirationParametersInputTag).OnDispatcher().Subscribe(
|
||||
CompositeObserver.create(
|
||||
Observer.Create<AnalyticsExpirationParametersMap>(_on_parameter_map),
|
||||
can_commit_observer.wrap<bool, AnalyticsExpirationParametersMap>(m => m is not null))),
|
||||
ObservableAutoWrapper.connect_item_hooks(selected_symbols, sym => {
|
||||
if (selected_symbol_ref_count.increment_adds_key(sym)) {
|
||||
_sync_visible_rows.execute();
|
||||
_sync_visible_rows.Invoke();
|
||||
}
|
||||
return Disposable.Create(() => {
|
||||
if (selected_symbol_ref_count.decrement_removes_key(sym)) {
|
||||
_sync_visible_rows.execute();
|
||||
_sync_visible_rows.Invoke();
|
||||
}
|
||||
});
|
||||
}),
|
||||
@@ -196,9 +197,11 @@ namespace mbts.spark {
|
||||
|
||||
void _set_driver_to_nearest_exp(IEnumerable<AnalyticsExpirationParametersRowVM> rows) {
|
||||
foreach (var r in rows) {
|
||||
if (drivers.Where(d => d.HasSecurity).TryGetMinElement(
|
||||
d => (r.security.expiration - d.Security.Expiration.date_time()).Ticks.abs(),
|
||||
out var nearest_exp)) {
|
||||
if (drivers
|
||||
.Where(d => d.HasSecurity && d.Security.Symbol == r.security.symbol)
|
||||
.TryGetMinElement(
|
||||
d => (r.security.expiration - d.Security.Expiration.date_time()).Ticks.abs(),
|
||||
out var nearest_exp)) {
|
||||
r.driver = nearest_exp;
|
||||
}
|
||||
}
|
||||
@@ -285,7 +288,7 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
symbols.sync_with(_parameters.Select(p => p.security.symbol).Distinct().Ordered());
|
||||
using var _ = _sync_visible_rows.defer_execution();
|
||||
using var _ = _sync_visible_rows.defer();
|
||||
if (is_first_update) {
|
||||
// select all symbols on first update
|
||||
selected_symbols.sync_with(symbols);
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace mbts.spark {
|
||||
|
||||
public SingleVolSurfaceRequestCalculator(int vs_id, IEnumerable<string> symbols,
|
||||
ThreadedBlackboard threaded_bb) {
|
||||
bts.Log.Gen.info($"SingleVolSurfaceRequestCalculator cons vs_id:{vs_id}");
|
||||
bts.Log.Gen.info($"SingleVolSurfaceRequestCalculator cons vs_id: {vs_id}");
|
||||
_vs_id = vs_id;
|
||||
_symbols = new HashSet<string>(symbols);
|
||||
_bb = threaded_bb;
|
||||
@@ -89,8 +89,8 @@ namespace mbts.spark {
|
||||
effective_req.cascade_up,
|
||||
effective_req.cascade_down);
|
||||
_timer.stop();
|
||||
bts.Log.Gen.info($"SingleVolSurfaceRequestCalculator._recompute_and_publish time:" +
|
||||
$"{_timer.lastIntervalTime} vs_output:{_last_output.log_string()}");
|
||||
bts.Log.Gen.info($"SingleVolSurfaceRequestCalculator._recompute_and_publish time: " +
|
||||
$"{_timer.lastIntervalTime}");
|
||||
_bb.post(SparkTags.VolSurfaceCalculationResponseTag(_vs_id),
|
||||
new VolSurfaceCalculationResponse(_last_output, effective_req.request_id));
|
||||
}
|
||||
|
||||
@@ -11,18 +11,22 @@ namespace mbts.analytics {
|
||||
// tags, into IReadOnlyDictionary of symbol vs data publsihed under one tag
|
||||
public class SymbolAggregationPublisher<TData> : IDisposable {
|
||||
private readonly ThreadedBlackboard _bb;
|
||||
private readonly ITag<SystemContractData> _sc_data_tag;
|
||||
private readonly SecurityType _sec_type;
|
||||
Func<string, ITag<TData>> _get_tag;
|
||||
// the tag on which the output will be published
|
||||
ITag<IReadOnlyDictionary<string, TData>> _out_tag;
|
||||
private readonly ITag<SystemContractData> _sc_data_tag;
|
||||
private Dictionary<string, ITag<TData>> _tag_map =
|
||||
new Dictionary<string, ITag<TData>>();
|
||||
private HashSet<object> _obj_tags = new HashSet<object>();
|
||||
private bool _dirty = true;
|
||||
public SymbolAggregationPublisher(
|
||||
ThreadedBlackboard bb,
|
||||
SecurityType sec_type,
|
||||
Func<string, ITag<TData>> get_tag,
|
||||
ITag<IReadOnlyDictionary<string, TData>> out_tag) {
|
||||
_bb = bb;
|
||||
_sec_type = sec_type;
|
||||
_get_tag = get_tag;
|
||||
_out_tag = out_tag;
|
||||
_sc_data_tag = SparkTags.SystemContractsTag;
|
||||
@@ -48,15 +52,20 @@ namespace mbts.analytics {
|
||||
return;
|
||||
}
|
||||
foreach (var st in sc_data.sectup_map) {
|
||||
if (st.security_type != _sec_type) {
|
||||
continue;
|
||||
}
|
||||
// this is not correct since it is assuming symbol/name is
|
||||
// unique across securty_tuples
|
||||
string symbol = st.security_name;
|
||||
if (!_tag_map.ContainsKey(symbol)) {
|
||||
var symbol_tag = _get_tag(symbol);
|
||||
_tag_map.Add(symbol, symbol_tag);
|
||||
_obj_tags.Add(symbol_tag);
|
||||
_bb.subscribe(symbol_tag);
|
||||
_dirty = true;
|
||||
var tag = _get_tag(symbol);
|
||||
if (tag != null) {
|
||||
_tag_map.Add(symbol, tag);
|
||||
_obj_tags.Add(tag);
|
||||
_bb.subscribe(tag);
|
||||
_dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ using System.Collections;
|
||||
using mbts.spark;
|
||||
using System.DirectoryServices.ActiveDirectory;
|
||||
using Spark.Core.Protobuf;
|
||||
using mbts.ui;
|
||||
// using mbts.bb;
|
||||
|
||||
namespace mbts.spark {
|
||||
@@ -101,11 +102,14 @@ namespace mbts.spark {
|
||||
_subs.Add(new AnalyticsParametersManager(bus, _analytics_service));
|
||||
_subs.Add(new ResourceAllocator(bus, _bb));
|
||||
_subs.Add(new SymbolAggregationPublisher<OptionDriverPriceMap>(
|
||||
_bb, (sym) => SparkTags.OptionDriverBBOTag(sym),
|
||||
_bb, SecurityType.Option, sym => SparkTags.OptionDriverBBOTag(sym),
|
||||
SparkTags.AllOptionDriverBBOTag));
|
||||
_subs.Add(new SymbolAggregationPublisher<OptionTheoInterpolationData>(
|
||||
_bb, (sym) => SparkTags.SymbolInterpGreeksTag(sym),
|
||||
_bb, SecurityType.Option, sym => SparkTags.SymbolInterpGreeksTag(sym),
|
||||
SparkTags.AllInterpGreeks));
|
||||
_subs.Add(new SymbolAggregationPublisher<ExpStrikeKeyedData<TheoPoint>>(
|
||||
_bb, SecurityType.Option, sym => SparkTags.TC2Tags.LiveTheosTag(sym),
|
||||
SparkTags.TC2Tags.AllLiveTheosTag));
|
||||
_subs.Add(new LiveTheoPublisher(_bb));
|
||||
_subs.Add(new VolSurfaceInterpGreeksMultiplexer(_bb));
|
||||
// usage
|
||||
@@ -117,10 +121,10 @@ namespace mbts.spark {
|
||||
}
|
||||
Log.Ui.info($"VolSurfaceUsageList name_to_ids count: {name_to_ids.Count}");
|
||||
var vs_usage = mbts.config.Configuration.get<bts.config.toggles.VolSurfaceUsage>();
|
||||
Log.Ui.info($"VolSurfaceUsageList vs_usage acount: {vs_usage.VolSurfaceUsages.Count}");
|
||||
foreach (var u in vs_usage.VolSurfaceUsages) {
|
||||
string option_name = u.OptionName;
|
||||
string vs_name = u.VsName;
|
||||
Log.Ui.info($"VolSurfaceUsageList vs_usage acount: {vs_usage.vol_surface_usage.Count}");
|
||||
foreach (var u in vs_usage.vol_surface_usage) {
|
||||
string option_name = u.option_name;
|
||||
string vs_name = u.vs_name;
|
||||
int vs_key;
|
||||
if (name_to_ids.TryGetValue(vs_name, out vs_key)) {
|
||||
ulist.UsageList.Add(new VolSurfaceUsageEntry() {
|
||||
@@ -138,6 +142,7 @@ namespace mbts.spark {
|
||||
var list_imm = new VolSurfaceUsageListImmutable(ulist);
|
||||
Log.Ui.info(list_imm.log_string());
|
||||
_bb.post(SparkTags.VolSurfaceUsageTag, list_imm);
|
||||
_spin_vss(list_imm);
|
||||
});
|
||||
_disps.Add(list_sub);
|
||||
}
|
||||
@@ -146,6 +151,13 @@ namespace mbts.spark {
|
||||
return _bb;
|
||||
}
|
||||
|
||||
void _spin_vss(VolSurfaceUsageListImmutable ulist) {
|
||||
foreach (var u in ulist.UsageList) {
|
||||
var vs_id = u.VsId;
|
||||
_bb.post(SparkTags.VolSurfaceActiveUITag(vs_id), true);
|
||||
}
|
||||
}
|
||||
|
||||
void _on_vs_usage_update(Update<VolSurfaceUsageListImmutable, int> update) {
|
||||
// TODO
|
||||
return;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
using mbts.user.settings;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class VolSurfaceDisplayGridColumn : IEquatable<VolSurfaceDisplayGridColumn> {
|
||||
public readonly Func<object, string> format;
|
||||
@@ -18,16 +19,19 @@
|
||||
VolSurfaceColumnSettings settings,
|
||||
Func<object, string> format = null,
|
||||
Func<string, object> parse = null,
|
||||
Func<object, bool, object> tick_move = null) {
|
||||
Func<object, bool, object> tick_move = null,
|
||||
IEqualityComparer<object> comparer = null) {
|
||||
this.settings = settings;
|
||||
this.format = format ?? (v => v?.ToString() ?? string.Empty);
|
||||
this.parse = parse ?? (v => v);
|
||||
this.tick_move = tick_move ?? ((v, is_up) => v);
|
||||
this.comparer = comparer ?? EqualityComparer<object>.Default;
|
||||
}
|
||||
|
||||
public string unique_col_name => settings.id;
|
||||
public string display_name => settings.display_name;
|
||||
public string group => settings.group;
|
||||
public IEqualityComparer<object> comparer { get; }
|
||||
|
||||
internal VolSurfaceColumnType type => settings.type;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
using mbts.user.settings;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
class VolSurfaceDisplayUtilities {
|
||||
public static TickDisplaySettings default_tick_display =>
|
||||
@@ -18,6 +19,10 @@
|
||||
default_tick_display.with(display_multiplier: 100);
|
||||
|
||||
public static double parse_double(object obj) {
|
||||
if (obj is null) {
|
||||
Log.Gen.warn("parse_double received null input (will return nan and continue)");
|
||||
return double.NaN;
|
||||
}
|
||||
Log.assert(obj is double);
|
||||
obj = obj ?? Double.NaN;
|
||||
double rv = obj is Double ? (double)obj : (Double.TryParse(obj.ToString(), out rv) ? rv : Double.NaN);
|
||||
@@ -49,9 +54,31 @@
|
||||
}
|
||||
|
||||
public static Func<object, bool, object> get_double_tickmove(TickFactors tick_factors, int tick_move) =>
|
||||
(data, is_up) => data is double d_data ?
|
||||
tick_factors.tick(d_data, is_up ? tick_move : -tick_move) :
|
||||
data;
|
||||
(data, is_up) => {
|
||||
if (data is not double dbl) {
|
||||
return data;
|
||||
}
|
||||
if (dbl.is_nan()) {
|
||||
return 0D;
|
||||
}
|
||||
return tick_factors.tick(dbl, is_up ? tick_move : -tick_move);
|
||||
};
|
||||
|
||||
public static IEqualityComparer<double> get_double_comparer(
|
||||
TickFactors tick_factors = null, double display_mult = double.NaN) {
|
||||
if (tick_factors is null) {
|
||||
return new TickFactors(10^7, 1).tick_equality_comparer();
|
||||
}
|
||||
// This equality comparer is used to compare actual values (not multiplied by
|
||||
// 'display_mult'), while the TickFactors are used to format the display value (multiplied
|
||||
// by 'display_mult'). Multiply the tick base by 'display_mult' so the equality comparison
|
||||
// is done with the correct number of decimal places.
|
||||
if (display_mult > 0 && Math.Log10(display_mult).is_int()) {
|
||||
tick_factors = tick_factors.with(
|
||||
tick_base: tick_factors.tick_base * display_mult);
|
||||
}
|
||||
return tick_factors.tick_equality_comparer();
|
||||
}
|
||||
|
||||
public static VolSurfaceDisplayGridColumn get_double_output_col(
|
||||
string group,
|
||||
@@ -113,7 +140,10 @@
|
||||
col_config,
|
||||
format: get_double_tostring(col_config.tick_factors, col_config.tick_display),
|
||||
parse: get_parse_double(col_config.tick_factors, col_config.tick_display),
|
||||
tick_move: get_double_tickmove(col_config.tick_factors, col_config.tick_move));
|
||||
tick_move: get_double_tickmove(col_config.tick_factors, col_config.tick_move),
|
||||
comparer: get_double_comparer(
|
||||
col_config.tick_factors, col_config.tick_display.display_multiplier)
|
||||
.cast<double, object>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,27 @@ namespace mbts.spark {
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static string log_string(this VolSurfaceCalculationRequest vs_req) {
|
||||
if (vs_req == null) {
|
||||
return "Null";
|
||||
}
|
||||
string action_str = String.Empty;
|
||||
foreach (var kv in vs_req.action_map) {
|
||||
action_str += $"exp: {kv.Key.ToString()} action: {kv.Value.ToString()}, ";
|
||||
}
|
||||
action_str = action_str.TrimEnd(',', ' ');
|
||||
return $"vs_inp: {vs_req.volsurface_input.log_string()}\nreq_id: {vs_req.request_id}\n" +
|
||||
$"action_map: {action_str}\nup: {vs_req.cascade_up} down: {vs_req.cascade_down}";
|
||||
}
|
||||
|
||||
public static string log_string(this VolSurfaceCalculationResponse resp) {
|
||||
if (resp == null) {
|
||||
return "Null";
|
||||
}
|
||||
return $"req_id: {resp.request_id} vs_output: " +
|
||||
$"{resp.volsurface_calculation_output.volsurface_input.log_string()}";
|
||||
}
|
||||
|
||||
private static string _trim_leading_char(string s, char c) {
|
||||
if (!s.is_null_or_empty() && s.EndsWith(c)) {
|
||||
return s.Remove(s.Length - 1, 1);
|
||||
@@ -71,11 +92,12 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
internal static string log_string(this VolSurfaceDisplayModel.DisplayModelData dm_data) {
|
||||
string rv = String.Empty;
|
||||
string global_grid_str = dm_data.global_grid == null ? "Null" : dm_data.global_grid.log_string();
|
||||
rv += $"global_grid: {global_grid_str} \n";
|
||||
string exp_grid_str = dm_data.exp_grid == null ? "Null" : dm_data.exp_grid.log_string();
|
||||
rv += $"exp_grid: {exp_grid_str} \n";
|
||||
var vs_output = dm_data.vs_output;
|
||||
var exp_grid = dm_data.exp_grid;
|
||||
var vs_output_str = vs_output == null ? "NULL" : vs_output.volsurface_input.log_string();
|
||||
var exp_grid_str = exp_grid == null ? "NULL" : exp_grid.log_string();
|
||||
var rv = $"DisplayModelData\nvs_output:\n{vs_output_str}\n" +
|
||||
$"exp_grid\n{exp_grid_str}\n";
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -91,19 +113,19 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
internal static string log_string(this VolSurfaceDisplayGrid dgrid) {
|
||||
Func<IDictionary<string, object>, string> log_exp = (map) => {
|
||||
Func<IDictionary<string, object>, string> log_exp = (col_val_map) => {
|
||||
string rv = String.Empty;
|
||||
foreach (var kv in map) {
|
||||
foreach (var kv in col_val_map) {
|
||||
string val_string = kv.Value == null ? "Null" : kv.Value.ToString();
|
||||
rv += $"{kv.Key}:{val_string},";
|
||||
rv += $"{kv.Key}: {val_string}, ";
|
||||
}
|
||||
return _trim_leading_char(rv, ',');
|
||||
};
|
||||
string rv = String.Empty;
|
||||
foreach (var kv in dgrid.data_map) {
|
||||
rv += $"Exp:{kv.Key.expiration.ToShortDateString()} Data:{log_exp(kv.Value)},";
|
||||
rv += $"Exp: {kv.Key.expiration.ToShortDateString()} Data: {log_exp(kv.Value)}\n";
|
||||
}
|
||||
return _trim_leading_char(rv, ',');
|
||||
return rv;
|
||||
}
|
||||
|
||||
internal static string log_string(this OptionDriverPriceMap map) {
|
||||
@@ -238,6 +260,15 @@ namespace mbts.spark {
|
||||
return rv;
|
||||
}
|
||||
|
||||
internal static string log_string(this IPNLUnit p) {
|
||||
string rv = "IPNLUnit:";
|
||||
rv += $" account: {p.account} sec: {p.security.security_desc()} driver: {p.driver} theo: {p.theo} settle: {p.settle_price}" +
|
||||
$" start_pos: {p.start_long_pos - p.start_short_pos} day_pos: {p.day_long_pos - p.day_short_pos}" +
|
||||
$" start_pnl: {p.start_pnl} start_delta: {p.start_delta} start_vega: {p.start_vega}" +
|
||||
$" day_pnl: {p.day_pnl} day_delta: {p.day_delta} day_vega: {p.day_vega}";
|
||||
return rv;
|
||||
}
|
||||
|
||||
internal static int tid() {
|
||||
return System.Threading.Thread.CurrentThread.ManagedThreadId;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace mbts.spark {
|
||||
var x_axis = BTSOxyGraphAxisDouble.Default;
|
||||
x_axis.name = "Strike";
|
||||
x_axis.major_grid_line_color = BTSColors.Graph.grid_line;
|
||||
x_axis.tick_line_color = BTSColors.Graph.tick_line;
|
||||
x_axis.position = AxisPosition.BottomLeftToRight;
|
||||
x_axis.minimum = 0;
|
||||
x_axis.maximum = 2000;
|
||||
@@ -59,6 +60,7 @@ namespace mbts.spark {
|
||||
var y_axis = BTSOxyGraphAxisDouble.Default;
|
||||
y_axis.name = "Volatility";
|
||||
y_axis.major_grid_line_color = BTSColors.Graph.grid_line;
|
||||
y_axis.tick_line_color = BTSColors.Graph.tick_line;
|
||||
y_axis.position = AxisPosition.LeftBottomToTop;
|
||||
y_axis.minimum = 0;
|
||||
y_axis.maximum = 1;
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
namespace mbts.spark {
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
|
||||
using System;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Input;
|
||||
|
||||
class VolGridCellVM : DisposableViewModelBase {
|
||||
readonly Property<object> _candidate_value;
|
||||
readonly Property<object> _committed_value;
|
||||
readonly Property<bool> _is_dirty;
|
||||
|
||||
public VolGridCellVM(string column_id) {
|
||||
this.column_id = column_id ?? throw new ArgumentNullException(nameof(column_id));
|
||||
_committed_value = backing<object>(nameof(committed_value));
|
||||
_candidate_value = backing<object>(nameof(candidate_value));
|
||||
_is_dirty = backing(nameof(is_dirty),
|
||||
_committed_value.observe_current(true)
|
||||
.CombineLatest(_candidate_value.observe_current(true))
|
||||
.Select(tup => !Equals(tup.First, tup.Second))
|
||||
.OnDispatcher());
|
||||
}
|
||||
|
||||
public string column_id { get; }
|
||||
|
||||
public object committed_value {
|
||||
get => _committed_value.Value;
|
||||
set => _committed_value.set(value);
|
||||
}
|
||||
|
||||
public object candidate_value {
|
||||
get => _candidate_value.Value;
|
||||
set => _candidate_value.set(value);
|
||||
}
|
||||
|
||||
public bool is_dirty => _is_dirty.Value;
|
||||
|
||||
public IObservable<object> observe_candidate(bool start_immediately = false) =>
|
||||
_candidate_value.observe_current(start_immediately);
|
||||
|
||||
public void revert() =>
|
||||
candidate_value = committed_value;
|
||||
|
||||
public override string ToString() =>
|
||||
$"column_id: {column_id}, committed: {committed_value}, candidate: {candidate_value}";
|
||||
}
|
||||
|
||||
class VolGridCellVM<T> : VolGridCellVM {
|
||||
public VolGridCellVM(string column_id) : base(column_id) { }
|
||||
|
||||
public VolGridCellVM(string column_id, T committed_value, T candidate_value) : base(column_id) {
|
||||
this.committed_value = committed_value;
|
||||
this.candidate_value = candidate_value;
|
||||
}
|
||||
|
||||
public new T committed_value {
|
||||
get => base.committed_value is T v ? v : default;
|
||||
set => base.committed_value = value;
|
||||
}
|
||||
|
||||
public new T candidate_value {
|
||||
get => base.candidate_value is T v ? v : default;
|
||||
set => base.candidate_value = value;
|
||||
}
|
||||
}
|
||||
|
||||
class VolGridTickCellVM : VolGridCellVM {
|
||||
ICommand _tick_up_cmd;
|
||||
ICommand _tick_down_cmd;
|
||||
|
||||
public VolGridTickCellVM(string column_id) : base(column_id) { }
|
||||
|
||||
public event Action<bool> request_tick;
|
||||
|
||||
public ICommand tick_up_cmd =>
|
||||
_tick_up_cmd ??= new DelegateCommand(() =>
|
||||
request_tick?.Invoke(true));
|
||||
|
||||
public ICommand tick_down_cmd =>
|
||||
_tick_down_cmd ??= new DelegateCommand(() =>
|
||||
request_tick?.Invoke(false));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#nullable enable
|
||||
namespace mbts.spark.VolSurface {
|
||||
using System.Windows.Media;
|
||||
|
||||
readonly struct VolSurfaceCellState {
|
||||
public bool is_dirty => committed_text is not null;
|
||||
|
||||
public FormattedText? text { get; init; }
|
||||
public FormattedText? committed_text { get; init; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
#nullable enable
|
||||
namespace mbts.spark {
|
||||
using bts;
|
||||
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.shell;
|
||||
|
||||
using Spark.Core;
|
||||
|
||||
using System;
|
||||
|
||||
class VolSurfaceCellVM : DisposableViewModelBase {
|
||||
readonly Property<object?> _candidate_value;
|
||||
readonly Property<object?> _committed_value;
|
||||
readonly DelegateProperty<bool> _is_dirty;
|
||||
readonly DeferrableAction _refresh;
|
||||
|
||||
public VolSurfaceCellVM(
|
||||
VolSurfaceDisplayGridExpiration expiration, VolSurfaceDisplayGridColumn column) {
|
||||
this.column = column ?? throw new ArgumentNullException(nameof(column));
|
||||
this.expiration = expiration ?? throw new ArgumentNullException(nameof(expiration));
|
||||
_committed_value = backing<object?>(nameof(committed_value), column.comparer);
|
||||
_candidate_value = backing<object?>(nameof(candidate_value), column.comparer);
|
||||
_is_dirty = backing(
|
||||
nameof(is_dirty), () => !column.comparer.Equals(candidate_value, committed_value));
|
||||
_refresh = new(_is_dirty.refresh);
|
||||
_committed_value.Changed += on_committed_changed;
|
||||
_candidate_value.Changed += on_candidate_changed;
|
||||
_is_dirty.Changed += (o, n) => {
|
||||
Log.assert(o != n);
|
||||
Log.Ui.info(
|
||||
$"VolSurface '{expiration}.{column}' is_dirty changed to {n}. " +
|
||||
$"commited: {committed_value}; candidate: {candidate_value}");
|
||||
};
|
||||
|
||||
void on_committed_changed(object? oldval, object? newval) =>
|
||||
_is_dirty.refresh();
|
||||
|
||||
void on_candidate_changed(object? oldval, object? newval) =>
|
||||
_is_dirty.refresh();
|
||||
}
|
||||
|
||||
public event PropertyChange<object?>? candidate_value_changed {
|
||||
add => _candidate_value.Changed += value;
|
||||
remove => _candidate_value.Changed -= value;
|
||||
}
|
||||
|
||||
public VolSurfaceDisplayGridColumn column { get; }
|
||||
public string column_id => column.unique_col_name;
|
||||
public VolSurfaceDisplayGridExpiration expiration { get; }
|
||||
|
||||
public object? committed_value {
|
||||
get => _committed_value.Value;
|
||||
set => _committed_value.set(value);
|
||||
}
|
||||
|
||||
public object? candidate_value {
|
||||
get => _candidate_value.Value;
|
||||
set => _candidate_value.set(value);
|
||||
}
|
||||
|
||||
public bool is_dirty => _is_dirty.Value;
|
||||
|
||||
public IObservable<object?> observe_candidate(bool start_immediately = false) =>
|
||||
_candidate_value.observe_current(start_immediately);
|
||||
|
||||
public void reset(object? committed_value, object? candidate_value) {
|
||||
using var _ = _refresh.defer();
|
||||
this.committed_value = committed_value;
|
||||
this.candidate_value = candidate_value;
|
||||
}
|
||||
|
||||
public void revert() =>
|
||||
candidate_value = committed_value;
|
||||
|
||||
public override string ToString() =>
|
||||
$"column: {column}, committed: {committed_value}, candidate: {candidate_value}";
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ namespace mbts.spark.VolSurface {
|
||||
view.SetBinding(FrameworkElement.DataContextProperty, new Binding() {
|
||||
Converter = _data_context_converter
|
||||
});
|
||||
view.SetBinding(TextBlock.TextProperty, new Binding(nameof(VolGridCellVM.candidate_value)) {
|
||||
view.SetBinding(TextBlock.TextProperty, new Binding(nameof(VolSurfaceCellVM.candidate_value)) {
|
||||
Converter = ValueConverter.create(obj => model.format(obj))
|
||||
});
|
||||
return view;
|
||||
@@ -101,16 +101,16 @@ namespace mbts.spark.VolSurface {
|
||||
view.SetBinding(FrameworkElement.DataContextProperty, new Binding() {
|
||||
Converter = _data_context_converter
|
||||
});
|
||||
view.SetBinding(VolSurfaceCellView.CommittedValueProperty, new Binding(nameof(VolGridCellVM.committed_value)) {
|
||||
view.SetBinding(VolSurfaceCellView.CommittedValueProperty, new Binding(nameof(VolSurfaceCellVM.committed_value)) {
|
||||
Mode = BindingMode.OneWay,
|
||||
Converter = ValueConverter.create(obj => model.format(obj))
|
||||
});
|
||||
view.SetBinding(VolSurfaceCellView.CandidateValueProperty, new Binding(nameof(VolGridCellVM.candidate_value)) {
|
||||
view.SetBinding(VolSurfaceCellView.CandidateValueProperty, new Binding(nameof(VolSurfaceCellVM.candidate_value)) {
|
||||
Mode = BindingMode.TwoWay,
|
||||
Converter = ValueConverter.create<object, string>(obj => model.format(obj), obj => model.parse(obj))
|
||||
});
|
||||
view.SetBinding(VolSurfaceCellView.TickDownCommandProperty, new Binding(nameof(VolGridTickCellVM.tick_down_cmd)));
|
||||
view.SetBinding(VolSurfaceCellView.TickUpCommandProperty, new Binding(nameof(VolGridTickCellVM.tick_up_cmd)));
|
||||
view.SetBinding(VolSurfaceCellView.TickDownCommandProperty, new Binding(nameof(VolSurfaceTickCellVM.tick_down_cmd)));
|
||||
view.SetBinding(VolSurfaceCellView.TickUpCommandProperty, new Binding(nameof(VolSurfaceTickCellVM.tick_up_cmd)));
|
||||
var bd = new Border {
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch,
|
||||
VerticalAlignment = VerticalAlignment.Stretch,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#nullable enable
|
||||
namespace mbts.spark.VolSurface {
|
||||
using bts;
|
||||
using bts.collections;
|
||||
@@ -11,6 +12,8 @@ namespace mbts.spark.VolSurface {
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
|
||||
using Spark.Core;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -25,17 +28,20 @@ namespace mbts.spark.VolSurface {
|
||||
class VolSurfaceGridVM : DisposableViewModelBase {
|
||||
readonly VolSurfaceVM _parent;
|
||||
readonly ObservableCollection<VolSurfaceDisplayGridExpiration> _expirations = new();
|
||||
readonly DeferrableActionWrapper _invalidate_rows;
|
||||
readonly DeferrableAction _invalidate_rows;
|
||||
readonly ColumnsModel _columns_model;
|
||||
|
||||
ISet<string> _hidden_columns;
|
||||
ISet<VolSurfaceExpiration> _hidden_expirations;
|
||||
IDisposable _shift_editor;
|
||||
ISet<VolSurfaceExpiration>? _hidden_expirations;
|
||||
IDisposable? _shift_editor;
|
||||
|
||||
public VolSurfaceGridVM(VolSurfaceVM vm, VolSurfaceDisplayModel model,
|
||||
ISet<string> hidden_columns, ISet<VolSurfaceExpiration> hidden_expirations) {
|
||||
Log.assert(hidden_columns != null);
|
||||
Log.assert(hidden_expirations != null);
|
||||
public VolSurfaceGridVM(
|
||||
VolSurfaceVM vm,
|
||||
VolSurfaceDisplayModel model,
|
||||
ISet<string> hidden_columns,
|
||||
ISet<VolSurfaceExpiration> hidden_expirations) {
|
||||
Log.notnull(hidden_columns);
|
||||
Log.notnull(hidden_expirations);
|
||||
_parent = vm;
|
||||
this.model = model;
|
||||
_columns_model = new(create_exp_column_view());
|
||||
@@ -63,7 +69,8 @@ namespace mbts.spark.VolSurface {
|
||||
};
|
||||
|
||||
_dispose = Disposable.Create(
|
||||
ObservableAutoWrapper.connect(_expirations, rows, exp => new VolSurfaceRowVM(this, exp), row => row.Dispose()),
|
||||
ObservableAutoWrapper.connect(_expirations, rows, row_factory),
|
||||
ObservableAutoWrapper.connect_item_hooks(rows, connect_row),
|
||||
sorted_visible_rows.bind(visible_rows),
|
||||
Disposable.Create(() => {
|
||||
this.model.on_candidate_grid_change -= _on_grid_updated;
|
||||
@@ -73,6 +80,20 @@ namespace mbts.spark.VolSurface {
|
||||
}),
|
||||
_columns_model);
|
||||
|
||||
VolSurfaceRowVM row_factory(VolSurfaceDisplayGridExpiration exp) =>
|
||||
new(this, exp);
|
||||
|
||||
IDisposable connect_row(VolSurfaceRowVM row) {
|
||||
row.request_calculate += request_recalc;
|
||||
return Disposable.Create(() => {
|
||||
row.request_calculate -= request_recalc;
|
||||
row.Dispose();
|
||||
});
|
||||
|
||||
void request_recalc() =>
|
||||
model.set_candidate_grid(current_grid);
|
||||
}
|
||||
|
||||
VolSurfaceColumn create_exp_column_view() {
|
||||
var filter = new ComboCheckBox();
|
||||
filter.SetResourceReference(FrameworkElement.StyleProperty, "ExpirationFilterDropDown");
|
||||
@@ -92,7 +113,7 @@ namespace mbts.spark.VolSurface {
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<IEnumerable<VolSurfaceDisplayGridExpiration>> on_selection_changed;
|
||||
public event Action<IEnumerable<VolSurfaceDisplayGridExpiration>>? on_selection_changed;
|
||||
|
||||
public VolSurfaceDisplayGrid current_grid { get; private set; }
|
||||
public VolSurfaceDisplayGrid committed_grid { get; private set; }
|
||||
@@ -118,6 +139,7 @@ namespace mbts.spark.VolSurface {
|
||||
.Select(group => new DIYGridSuperHeaderVM(group.Key, group.Count(), collapsed_content: _short_header(group.Key)))
|
||||
.ToList();
|
||||
|
||||
public ICommand populate_empty_exps_cmd => _parent.populate_empty_exps_cmd;
|
||||
public ICommand main_settings_cmd => _parent.main_settings_cmd;
|
||||
public ICommand advanced_settings_cmd => _parent.advanced_settings_cmd;
|
||||
public ICommand graph_settings_cmd => _parent.vol_curve_vm.settings_command;
|
||||
@@ -141,13 +163,14 @@ namespace mbts.spark.VolSurface {
|
||||
rows.select_exp().Except(visible_rows.select_exp());
|
||||
|
||||
public void invalidate_rows() =>
|
||||
_invalidate_rows.execute();
|
||||
_invalidate_rows.Invoke();
|
||||
|
||||
public IDisposable defer_invalidate_rows() =>
|
||||
_invalidate_rows.defer_execution();
|
||||
_invalidate_rows.defer();
|
||||
|
||||
public VolSurfaceColumn get_column(string id) =>
|
||||
columns.FirstOrDefault(c => c.id == id) as VolSurfaceColumn;
|
||||
columns.FirstOrDefault(c => c.id == id) as VolSurfaceColumn ??
|
||||
throw new InvalidOperationException($"Failed to find column '{id}'");
|
||||
|
||||
internal void signal_selection_changed() {
|
||||
var e = on_selection_changed;
|
||||
@@ -218,7 +241,7 @@ namespace mbts.spark.VolSurface {
|
||||
!_hidden_columns.Contains(column.unique_col_name);
|
||||
|
||||
void _on_grid_updated() {
|
||||
using var _ = _invalidate_rows.defer_execution();
|
||||
using var _ = _invalidate_rows.defer();
|
||||
var grid_new = model.get_active_grid();
|
||||
// add/remove columns
|
||||
var cols_new = grid_new.get_ordered_columns()
|
||||
@@ -243,7 +266,7 @@ namespace mbts.spark.VolSurface {
|
||||
}
|
||||
current_grid = grid_new;
|
||||
committed_grid = is_dirty ? model.get_committed_grid() : current_grid;
|
||||
_invalidate_rows.execute();
|
||||
_invalidate_rows.Invoke();
|
||||
}
|
||||
|
||||
void _launch_shift_editor(VolSurfaceDisplayGridColumn column, Action<double> commit_shift) {
|
||||
|
||||
@@ -79,6 +79,7 @@ namespace mbts.spark {
|
||||
|
||||
public bool is_input_cell => column?.type == VolSurfaceColumnType.ReadWriteTick;
|
||||
|
||||
public ICommand populate_empty_exps_cmd => _parent.populate_empty_exps_cmd;
|
||||
public ICommand main_settings_cmd => _parent.main_settings_cmd;
|
||||
public ICommand advanced_settings_cmd => _parent.advanced_settings_cmd;
|
||||
public ICommand grid_settings_cmd => _parent.grid_settings_cmd;
|
||||
|
||||
@@ -4,22 +4,18 @@ namespace mbts.spark.VolSurface {
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.shell;
|
||||
|
||||
using Spark.Core;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Media;
|
||||
|
||||
public struct VolSurfaceCellState {
|
||||
public bool is_dirty => committed_text is not null;
|
||||
public FormattedText? text;
|
||||
public FormattedText? committed_text;
|
||||
}
|
||||
|
||||
class VolSurfaceRowVM : DisposableViewModelBase, ISelectable, IFormatCellsToClipboard, DIYGrid.IRowVM {
|
||||
readonly VolSurfaceGridVM _parent;
|
||||
readonly VolSurfaceDisplayGridExpiration _exp;
|
||||
readonly Dictionary<string, CellData> _cells = new();
|
||||
readonly DeferrableAction _request_calculate;
|
||||
|
||||
VolSurfaceRowContextMenuVM? _context_menu;
|
||||
bool _is_selected;
|
||||
@@ -27,6 +23,7 @@ namespace mbts.spark.VolSurface {
|
||||
public VolSurfaceRowVM(VolSurfaceGridVM parent, VolSurfaceDisplayGridExpiration exp) {
|
||||
_parent = parent;
|
||||
_exp = exp;
|
||||
_request_calculate = new(() => request_calculate?.Invoke());
|
||||
_dispose = Disposable.Create(() => {
|
||||
_cells.Values.DisposeAll();
|
||||
_cells.Clear();
|
||||
@@ -36,6 +33,7 @@ namespace mbts.spark.VolSurface {
|
||||
|
||||
public event Action<bool>? is_selected_changed;
|
||||
public event Action? invalidated;
|
||||
public event Action? request_calculate;
|
||||
|
||||
public VolSurfaceDisplayGridExpiration expiration => _exp;
|
||||
|
||||
@@ -52,12 +50,14 @@ namespace mbts.spark.VolSurface {
|
||||
public VolSurfaceRowContextMenuVM context_menu =>
|
||||
_context_menu ??= new(_parent, this);
|
||||
|
||||
public VolGridCellVM get_cell(VolSurfaceDisplayGridColumn column) =>
|
||||
public VolSurfaceCellVM get_cell(VolSurfaceDisplayGridColumn column) =>
|
||||
_cells.GetOrAdd(column.unique_col_name, _ => _create_cell(column)).vm;
|
||||
|
||||
public void invalidate() {
|
||||
foreach (var cell in _cells.Values) {
|
||||
_sync_cell(cell.vm);
|
||||
using (_request_calculate.supress()) {
|
||||
foreach (var cell in _cells.Values) {
|
||||
_sync_cell(cell.vm);
|
||||
}
|
||||
}
|
||||
invalidated?.Invoke();
|
||||
}
|
||||
@@ -79,29 +79,15 @@ namespace mbts.spark.VolSurface {
|
||||
CellData _create_cell(VolSurfaceDisplayGridColumn column) {
|
||||
var cell = column.type switch {
|
||||
VolSurfaceColumnType.ReadWriteTick => create_tick_cell(),
|
||||
_ => new VolGridCellVM(column.unique_col_name),
|
||||
_ => new VolSurfaceCellVM(_exp, column)
|
||||
};
|
||||
_sync_cell(cell);
|
||||
var dispose = cell.observe_candidate().DistinctUntilChanged().OnDispatcher()
|
||||
.Subscribe(value => {
|
||||
var curr = _parent.current_grid.read(expiration, column);
|
||||
if (Equals(value, curr)) {
|
||||
return;
|
||||
}
|
||||
var grid = _parent.current_grid;
|
||||
grid.write(expiration, column, value);
|
||||
_parent.model.set_candidate_grid(grid);
|
||||
});
|
||||
return new(cell, dispose);
|
||||
return new(cell, _connect_cell(cell));
|
||||
|
||||
VolGridTickCellVM create_tick_cell() {
|
||||
var cell = new VolGridTickCellVM(column.unique_col_name);
|
||||
VolSurfaceCellVM create_tick_cell() {
|
||||
var cell = new VolSurfaceTickCellVM(_exp, column);
|
||||
cell.request_tick += is_up => {
|
||||
var col = _parent.get_column(column.unique_col_name);
|
||||
if (col is null) {
|
||||
throw new InvalidOperationException(
|
||||
$"Failed to find column with id {column.unique_col_name}");
|
||||
}
|
||||
if (col.model?.tick_move is var tm) {
|
||||
cell.candidate_value = tm?.Invoke(cell.candidate_value, is_up);
|
||||
return;
|
||||
@@ -112,23 +98,48 @@ namespace mbts.spark.VolSurface {
|
||||
}
|
||||
}
|
||||
|
||||
void _sync_cell(VolGridCellVM cell) {
|
||||
void _sync_cell(VolSurfaceCellVM cell) {
|
||||
if (cell is null) {
|
||||
return;
|
||||
}
|
||||
cell.committed_value = _parent.committed_grid.read(_exp, cell.column_id);
|
||||
cell.candidate_value = _parent.current_grid.read(_exp, cell.column_id);
|
||||
using var _ = _request_calculate.supress();
|
||||
cell.reset(
|
||||
committed_value: _parent.committed_grid.read(_exp, cell.column_id),
|
||||
candidate_value: _parent.current_grid.read(_exp, cell.column_id));
|
||||
}
|
||||
|
||||
IDisposable? _connect_cell(VolSurfaceCellVM cell) {
|
||||
return cell.column.type switch {
|
||||
VolSurfaceColumnType.ReadWriteTick => connect_input(),
|
||||
_ => null
|
||||
};
|
||||
|
||||
IDisposable connect_input() {
|
||||
cell.candidate_value_changed += on_candidate_value_changed;
|
||||
return Disposable.Create(() =>
|
||||
cell.candidate_value_changed -= on_candidate_value_changed);
|
||||
|
||||
void on_candidate_value_changed(object? oldval, object? newval) {
|
||||
var curr = _parent.current_grid.read(expiration, cell.column);
|
||||
if (cell.column.comparer.Equals(newval, curr)) {
|
||||
return;
|
||||
}
|
||||
var grid = _parent.current_grid;
|
||||
grid.write(expiration, cell.column, newval);
|
||||
_request_calculate.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CellData : IDisposable {
|
||||
IDisposable _dispose;
|
||||
IDisposable? _dispose;
|
||||
|
||||
public CellData(VolGridCellVM vm, IDisposable dispose) {
|
||||
public CellData(VolSurfaceCellVM vm, IDisposable? dispose) {
|
||||
this.vm = vm;
|
||||
_dispose = Disposable.Create(vm, dispose);
|
||||
}
|
||||
|
||||
public VolGridCellVM vm { get; }
|
||||
public VolSurfaceCellVM vm { get; }
|
||||
|
||||
public void Dispose() =>
|
||||
Disposable.dispose(ref _dispose);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#nullable enable
|
||||
namespace mbts.spark {
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
class VolSurfaceTickCellVM : VolSurfaceCellVM {
|
||||
ICommand? _tick_up_cmd;
|
||||
ICommand? _tick_down_cmd;
|
||||
|
||||
public VolSurfaceTickCellVM(
|
||||
VolSurfaceDisplayGridExpiration expiration, VolSurfaceDisplayGridColumn column)
|
||||
: base(expiration, column) { }
|
||||
|
||||
public event Action<bool>? request_tick;
|
||||
|
||||
public ICommand tick_up_cmd =>
|
||||
_tick_up_cmd ??= new DelegateCommand(() =>
|
||||
request_tick?.Invoke(true));
|
||||
|
||||
public ICommand tick_down_cmd =>
|
||||
_tick_down_cmd ??= new DelegateCommand(() =>
|
||||
request_tick?.Invoke(false));
|
||||
}
|
||||
}
|
||||
@@ -77,8 +77,8 @@
|
||||
public IRaiseCanExecuteChangedCommand vol_shift { get; }
|
||||
|
||||
IEnumerable<IRaiseCanExecuteChangedCommand> _commands =>
|
||||
ReflectionHelper.property_delegates_of_type<VolSurfaceMacroActionsVM, IRaiseCanExecuteChangedCommand>()
|
||||
.Select(g => g(this));
|
||||
ReflectionHelper.property_getters<VolSurfaceMacroActionsVM, IRaiseCanExecuteChangedCommand>()
|
||||
.Select(pg => pg.get(this));
|
||||
|
||||
public void selection_changed(IEnumerable<VolSurfaceDisplayGridExpiration> selected) {
|
||||
_selected_exps = selected.ToList();
|
||||
|
||||
@@ -60,6 +60,7 @@ namespace mbts.spark {
|
||||
vol_terms_vm = new VolTermsGraphVM(_model, demux);
|
||||
|
||||
// command
|
||||
populate_empty_exps_cmd = new Command(() => { _model.populate_empty_expirations(); });
|
||||
_revert_cmd = new Command(o => _model.revert(), o => _model.is_dirty);
|
||||
_commit_cmd = new Command(o => _model.commit(), o => _model.is_dirty);
|
||||
load_previous_cmd = new Command(
|
||||
@@ -185,6 +186,7 @@ namespace mbts.spark {
|
||||
|
||||
public ICommand revert_cmd => _revert_cmd;
|
||||
public ICommand commit_cmd => _commit_cmd;
|
||||
public ICommand populate_empty_exps_cmd { get; }
|
||||
public ICommand main_settings_cmd => _main_settings_cmd;
|
||||
public ICommand advanced_settings_cmd => _advanced_settings_cmd;
|
||||
public ICommand grid_settings_cmd => _grid_settings_cmd;
|
||||
|
||||
@@ -126,6 +126,20 @@
|
||||
_log_bad_transition(_state, "set candidate grid");
|
||||
}
|
||||
|
||||
public void populate_empty_expirations() {
|
||||
bts.Log.Ui.info(String.Format("VolSurfaceDisplayModel.populate_expirations called with state: {0}",
|
||||
_state.ToString()));
|
||||
if (_state == DisplayModelState.Idle || _state == DisplayModelState.ResponseReady) {
|
||||
DisplayModelData curr_data = _get_current_data();
|
||||
VolSurfaceInput vs_inp =
|
||||
VolSurfaceDataFunctions.populate_empty_expirations(curr_data.vs_output.volsurface_input);
|
||||
_change_state(DisplayModelState.WaitingForCalcResponse);
|
||||
_bus.post(SparkTags.VolSurfaceCalculationRequestTag(_vs_id),
|
||||
new VolSurfaceCalculationRequest(vs_inp, _request_version_no++));
|
||||
} else
|
||||
_log_bad_transition(_state, "populate_expirations");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Globals
|
||||
@@ -145,6 +159,7 @@
|
||||
return (_committed_data != null && _committed_data.vs_output != null) ? _committed_data.vs_output.volsurface_input.surface_parameters.vol_time : DateTime.MinValue;
|
||||
}
|
||||
public void set_candidate_vol_time(DateTime vol_time) {
|
||||
bts.Log.Ui.info($"VolSurfaceDisplayModel.set_candidate_vol_time vs_id: {_vs_id} state: {_state.ToString()} vol_time: {vol_time}");
|
||||
if (_state == DisplayModelState.Idle || _state == DisplayModelState.ResponseReady) {
|
||||
DisplayModelData curr_data = _get_current_data();
|
||||
if (curr_data != null) {
|
||||
@@ -568,9 +583,7 @@
|
||||
private void _change_state(DisplayModelState new_state) {
|
||||
bool dirty_before = _translate_to_dirty(_state),
|
||||
dirty_after = _translate_to_dirty(new_state);
|
||||
// mbts.Logger.log(bts.log.Level.Info, bts.log.Subsystem.ui,
|
||||
// String.Format("State change {0}->{1}", _state.ToString(), new_state.ToString()));
|
||||
bts.Log.Ui.info(String.Format("State change {0}->{1}", _state.ToString(), new_state.ToString()));
|
||||
bts.Log.Ui.info($"VolSurfaceDisplayModel._change_state vs_id: {_vs_id} {_state.ToString()}->{new_state.ToString()}");
|
||||
_state = new_state;
|
||||
if (dirty_before != dirty_after && on_dirty_change != null) {
|
||||
_bus.post(SparkTags.VolSurfaceDirtyStateTag(_vs_id), dirty_after);
|
||||
@@ -613,9 +626,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
private static void _log_bad_transition(DisplayModelState state, string action) {
|
||||
//mbts.Logger.log(bts.log.Level.Error, bts.log.Subsystem.ui, String.Format("{0}:{1}", state, action));
|
||||
bts.Log.Ui.error(String.Format("{0}:{1}", state, action));
|
||||
private void _log_bad_transition(DisplayModelState state, string action) {
|
||||
bts.Log.Ui.error($"VoLSurfaceDisplayModel bad_transaction vs_id: {_vs_id} {state}:{action}");
|
||||
}
|
||||
|
||||
private static bool _translate_to_dirty(DisplayModelState state) {
|
||||
|
||||
@@ -50,11 +50,13 @@ namespace mbts.spark {
|
||||
.Table(UserTuple.key_fn)
|
||||
.Cache() :
|
||||
Observable.Return(TableUpdate<UserTuple, uint>.mk_empty(UserTuple.key_fn).with_added(new[] { user }));
|
||||
_dispose = on_accounts.Subscribe(map => {
|
||||
_account_map = map;
|
||||
var account_tuple_map = MappedDictionary.create(map, (id, name) => new AccountTuple(id, name));
|
||||
bus.post(SparkTags.AccountsTag, account_tuple_map);
|
||||
});
|
||||
_dispose = Disposable.Create(
|
||||
all_user_tuples.Subscribe(t => bus.post(SparkTags.Users, t.state)),
|
||||
on_accounts.Subscribe(map => {
|
||||
_account_map = map;
|
||||
var account_tuple_map = MappedDictionary.create(map, (id, name) => new AccountTuple(id, name));
|
||||
bus.post(SparkTags.AccountsTag, account_tuple_map);
|
||||
}));
|
||||
}
|
||||
|
||||
public IObservable<IReadOnlyDictionary<uint, string>> on_users { get; }
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace mbts.spark {
|
||||
[ImportingConstructor]
|
||||
public AlgoProviderFactory(IAlgoStudioModel studio_model, DynamicOrderHelper dynamic_helper, ISecurityAuxiliaryDataModel security_auxiliary_model) {
|
||||
var from_conf = config.Configuration.get<bts.config.AlgoTypeRuleSet>();
|
||||
if (from_conf.Rules.Count == 0) {
|
||||
if (from_conf.rules.Count == 0) {
|
||||
// There seems to be a config race bug, where the returned config values are empty, despite having entries in spark.conf.
|
||||
// [John]I've only noticed it happen when attached to the debugger,
|
||||
// but best to have a contingency plan in place anyways, to prevent any chance of regression.
|
||||
@@ -108,7 +108,7 @@ namespace mbts.spark {
|
||||
.Select(t => _get_type_data(t))
|
||||
.Concat(dynamic_helper.dynamic_types.Select(dt => _get_type_data(AlgoType.Dynamic, dt)))
|
||||
.ToListLazy();
|
||||
var conf_sets = from_conf.Rules.Select(r => _to_security_algo_set(r, dynamic_helper, algo_type_data)).ToList();
|
||||
var conf_sets = from_conf.rules.Select(r => _to_security_algo_set(r, dynamic_helper, algo_type_data)).ToList();
|
||||
security_algo_provider = new AlgoProvider(conf_sets.Select(tup => tup.standard).ToList(), studio_model, dynamic_helper, security_auxiliary_model);
|
||||
attachable_algo_provider = new AttachableAlgoProvider(conf_sets.Select(tup => tup.attachable).ToList(), studio_model, dynamic_helper, security_auxiliary_model);
|
||||
}
|
||||
@@ -128,9 +128,9 @@ namespace mbts.spark {
|
||||
context == null ?
|
||||
new SecurityCriteriaClause() :
|
||||
new SecurityCriteriaClause(
|
||||
exchanges: context.Exchanges?.Select(EnumHelper.parse<Venue>)?.ToArray(),
|
||||
security_types: context.SecurityTypes?.Select(EnumHelper.parse<Security.ContractOneofCase>)?.Select(t => t.security_type())?.ToArray(),
|
||||
symbols: context.Symbols?.ToArray());
|
||||
exchanges: context.exchanges?.Select(EnumHelper.parse<Venue>)?.ToArray(),
|
||||
security_types: context.security_types?.Select(EnumHelper.parse<Security.ContractOneofCase>)?.Select(t => t.security_type())?.ToArray(),
|
||||
symbols: context.symbols?.ToArray());
|
||||
|
||||
static (SecurityAlgoTypeSetImmutable standard, SecurityAlgoTypeSetImmutable attachable) _to_security_algo_set(
|
||||
bts.config.AlgoTypeRule rule,
|
||||
@@ -141,24 +141,24 @@ namespace mbts.spark {
|
||||
var dynamic_types = ImmutableHashSet<string>.Empty.ToBuilder();
|
||||
var attachable_factory_types = ImmutableHashSet<AlgoType>.Empty.ToBuilder();
|
||||
var attachable_dynamic_types = ImmutableHashSet<string>.Empty.ToBuilder();
|
||||
foreach (var a in rule.Algos) {
|
||||
if (Enum.TryParse(a.Name, out AlgoType sys_algo) && sys_algo != AlgoType.Composite && sys_algo != AlgoType.Dynamic) {
|
||||
on_sys_match(sys_algo, a.IsAttachable);
|
||||
} else if (dynamic_helper.try_parse(a.Name, out var dyn_type)) {
|
||||
on_dyn_match(dyn_type, a.IsAttachable);
|
||||
foreach (var a in rule.algos) {
|
||||
if (Enum.TryParse(a.name, out AlgoType sys_algo) && sys_algo != AlgoType.Composite && sys_algo != AlgoType.Dynamic) {
|
||||
on_sys_match(sys_algo, a.is_attachable);
|
||||
} else if (dynamic_helper.try_parse(a.name, out var dyn_type)) {
|
||||
on_dyn_match(dyn_type, a.is_attachable);
|
||||
} else {
|
||||
foreach (var (name, factory, dynamic) in algo_type_data) {
|
||||
if (Regex.Match(name, a.Name).Success) {
|
||||
if (Regex.Match(name, a.name).Success) {
|
||||
switch (factory) {
|
||||
case AlgoType.None:
|
||||
case AlgoType.Composite:
|
||||
// unexpected, but no need to crash
|
||||
continue;
|
||||
case AlgoType.Dynamic:
|
||||
on_dyn_match(dynamic, a.IsAttachable);
|
||||
on_dyn_match(dynamic, a.is_attachable);
|
||||
break;
|
||||
default:
|
||||
on_sys_match(factory, a.IsAttachable);
|
||||
on_sys_match(factory, a.is_attachable);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -168,13 +168,13 @@ namespace mbts.spark {
|
||||
return (
|
||||
// standard
|
||||
new SecurityAlgoTypeSetImmutable(
|
||||
_to_clause(rule.Context),
|
||||
_to_clause(rule.context),
|
||||
new AlgoTypeSetImmutable(
|
||||
factory_types.ToImmutable(),
|
||||
dynamic_types.ToImmutable())),
|
||||
// attachable
|
||||
new SecurityAlgoTypeSetImmutable(
|
||||
_to_clause(rule.Context),
|
||||
_to_clause(rule.context),
|
||||
new AlgoTypeSetImmutable(
|
||||
attachable_factory_types.ToImmutable(),
|
||||
attachable_dynamic_types.ToImmutable())));
|
||||
|
||||
@@ -189,6 +189,6 @@ namespace mbts {
|
||||
exchange ?? sec_exp.exchange, security_type ?? sec_exp.security_type,
|
||||
symbol ?? sec_exp.symbol,
|
||||
expiration ?? sec_exp.expiration,
|
||||
id.has_value ? id.value : sec_exp.id);
|
||||
id.has_value ? id : sec_exp.id);
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ namespace mbts.analytics {
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return String.Format("{0} {1} {2}",
|
||||
return String.Format("{0} {1} {2}",
|
||||
security_type.ToString().ToUpper().First(), symbol, expiration.ToShortDateString());
|
||||
}
|
||||
|
||||
@@ -74,6 +74,11 @@ namespace mbts.analytics {
|
||||
int rv = expiration.CompareTo(other.expiration);
|
||||
return rv != 0 ? rv : symbol.CompareTo(other.symbol);
|
||||
}
|
||||
|
||||
public double diff_days(VolSurfaceExpiration exp_other) {
|
||||
TimeSpan ts = expiration - exp_other.expiration;
|
||||
return ts.TotalDays;
|
||||
}
|
||||
}
|
||||
|
||||
public static class VolSurfaceExpirationExtensions {
|
||||
|
||||
@@ -680,5 +680,60 @@ namespace mbts.analytics
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Data copying
|
||||
|
||||
public static bool exp_has_input(VolSurfaceSettings vs_settings, VolCurveParameters exp_params) {
|
||||
if (exp_params == null || vs_settings == null)
|
||||
return false;
|
||||
double atm_vol = get_atm_vol(vs_settings, exp_params);
|
||||
double ref_fwd = exp_params.core_parameters.ref_forward;
|
||||
return !Double.IsNaN(atm_vol) && !Double.IsNaN(ref_fwd);
|
||||
}
|
||||
|
||||
public static VolSurfaceExpiration find_nearest_populated_exp(
|
||||
VolSurfaceInput vs_input, VolSurfaceExpiration vs_exp) {
|
||||
VolCurveParameters exp_params = get_curve_parameters(vs_input, vs_exp);
|
||||
if (exp_has_input(vs_input.surface_settings, exp_params))
|
||||
return vs_exp;
|
||||
VolSurfaceExpiration rv = null;
|
||||
double rv_diff_days = Double.MaxValue;
|
||||
foreach (var kv in vs_input.surface_parameters.curve_parameters_map) {
|
||||
var this_exp = kv.Item1;
|
||||
var this_exp_params = kv.Item2;
|
||||
if (exp_has_input(vs_input.surface_settings, this_exp_params)) {
|
||||
double this_exp_diff_days = Math.Abs(vs_exp.diff_days(this_exp));
|
||||
if (this_exp_diff_days < rv_diff_days) {
|
||||
rv = this_exp;
|
||||
rv_diff_days = this_exp_diff_days;
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Copies the empty exps from closest neighbor
|
||||
public static VolSurfaceInput populate_empty_expirations(VolSurfaceInput vs_input) {
|
||||
VolSurfaceInput rv = Spark.Core.Protobuf.ProtobufSerializationHelper.clone(vs_input);
|
||||
rv.surface_parameters.curve_parameters_map.Clear();
|
||||
foreach (var kv in vs_input.surface_parameters.curve_parameters_map) {
|
||||
var vs_exp = kv.Item1;
|
||||
var exp_params = kv.Item2;
|
||||
if (!exp_has_input(vs_input.surface_settings, exp_params)) {
|
||||
VolSurfaceExpiration np_exp = find_nearest_populated_exp(vs_input, vs_exp);
|
||||
if (np_exp != null) {
|
||||
var np_exp_params = get_curve_parameters(vs_input, np_exp);
|
||||
if (np_exp_params != null) {
|
||||
exp_params = Spark.Core.Protobuf.ProtobufSerializationHelper.clone(np_exp_params);
|
||||
}
|
||||
}
|
||||
}
|
||||
rv.surface_parameters.curve_parameters_map.Add(
|
||||
new Tuple<VolSurfaceExpiration, VolCurveParameters>(vs_exp, exp_params));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace bts.ui {
|
||||
Window about = Application.LoadComponent(new Uri("/view/Shell/About.xaml", UriKind.Relative)) as Window;
|
||||
enable_crash_on_dblclick(about);
|
||||
if (about != null) {
|
||||
about.DataContext = new { Version = Configuration.get<bts.config.System>().Version, User = _user };
|
||||
about.DataContext = new { Version = Configuration.get<bts.config.System>().version, User = _user };
|
||||
about.Topmost = true;
|
||||
about.CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (a, b) => about.Close()));
|
||||
about.CommandBindings.Add(new CommandBinding(ApplicationCommands.Open, (arg, e) => {
|
||||
|
||||
@@ -68,6 +68,7 @@ namespace bts.daemons {
|
||||
double price,
|
||||
int size = 1,
|
||||
string account = "ACC A",
|
||||
uint account_id = 1,
|
||||
double? strike = null,
|
||||
PutOrCall? cp = null,
|
||||
double? theo = null
|
||||
@@ -81,9 +82,11 @@ namespace bts.daemons {
|
||||
price,
|
||||
theo ?? price + 10 * new Random().NextDouble(),
|
||||
account,
|
||||
account_id,
|
||||
true,
|
||||
DateTime.Now,
|
||||
"FakeTrader");
|
||||
"FakeTrader",
|
||||
1);
|
||||
return t1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace bts {
|
||||
ss,
|
||||
user,
|
||||
security_metadata,
|
||||
TimeSpan.FromMilliseconds(Configuration.get<RelayOptions>().NaggleMs),
|
||||
TimeSpan.FromMilliseconds(Configuration.get<RelayOptions>().naggle_ms),
|
||||
TimeSpan.FromSeconds(1)) { }
|
||||
|
||||
public MDDaemon(
|
||||
|
||||
@@ -65,18 +65,21 @@ namespace bts {
|
||||
_merge_and_post();
|
||||
}
|
||||
|
||||
private void _merge_and_post() {
|
||||
Func<SecurityMD, bool> is_active = (sec_md) => {
|
||||
if (sec_md.security.HasFuture || sec_md.security.HasOption) {
|
||||
var exp = sec_md.security.security_expiration();
|
||||
if (exp.HasValue) {
|
||||
return exp.Value.Date >= DateTime.Now.Date.AddDays(-1);
|
||||
}
|
||||
return true;
|
||||
private static bool _is_active(SecurityMD sec_md) {
|
||||
if (sec_md.security.Exchange == Venue.Sim)
|
||||
return true;
|
||||
if (sec_md.security.HasFuture || sec_md.security.HasOption) {
|
||||
var exp = sec_md.security.security_expiration();
|
||||
if (exp.HasValue) {
|
||||
return exp.Value.Date >= DateTime.Now.Date.AddDays(-1);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
var to_pub = _server_sec_map.Where(kv => is_active(kv.Value)).ToDictionary(kv => kv.Key, kv => kv.Value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void _merge_and_post() {
|
||||
var to_pub = _server_sec_map.Where(kv => _is_active(kv.Value)).ToDictionary(kv => kv.Key, kv => kv.Value);
|
||||
foreach (var kv in _fake_sec_map) {
|
||||
to_pub[kv.Key] = kv.Value;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace bts.shell {
|
||||
|
||||
[ImportingConstructor]
|
||||
public OrderTicketDaemon(IBus bus, OrdersModel model, UserSettingsHub settings_hub, ErrorReporter error_reporter)
|
||||
: this(bus, model, settings_hub, error_reporter, Configuration.get<bts.config.OrderTicketOptions>().CloseOnSend) { }
|
||||
: this(bus, model, settings_hub, error_reporter, Configuration.get<bts.config.OrderTicketOptions>().close_on_send) { }
|
||||
|
||||
public OrderTicketDaemon(IBus bus, OrdersModel model, UserSettingsHub settings_hub, ErrorReporter error_reporter, bool close_on_send) {
|
||||
_bus = bus;
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace mbts.ui {
|
||||
[ImportingConstructor]
|
||||
public RecenterDaemon(IBus bus) {
|
||||
_bus = bus;
|
||||
_time_to_center = TimeSpan.FromSeconds(config.Configuration.get<bts.config.LadderKnobs>().SecondsToRecenter);
|
||||
_time_to_center = TimeSpan.FromSeconds(config.Configuration.get<bts.config.LadderKnobs>().seconds_to_recenter);
|
||||
_last_recenter = DateTime.UtcNow;
|
||||
|
||||
_dispose = _bus.subscribe(SparkTags.RequestRecenterLadder).Subscribe(_ => trigger_recenter(SparkTags.RecenterLadderNow));
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace bts.daemons {
|
||||
readonly OrderService _order_service;
|
||||
readonly ErrorReporter _error_reporter;
|
||||
readonly IBus _bus;
|
||||
readonly mbts.analytics.PNLReportCalculator _pnl_calc;
|
||||
|
||||
IReadOnlyDictionary<int, ReportImmutable> _report_parameters_map =
|
||||
new Dictionary<int, ReportImmutable>();
|
||||
@@ -48,6 +49,7 @@ namespace bts.daemons {
|
||||
_error_reporter = error_reporter;
|
||||
_order_service = order_service;
|
||||
_report_calculators = new(mk_report_calculator);
|
||||
_pnl_calc = new PNLReportCalculator(bus);
|
||||
|
||||
_dispose = Disposable.Create(
|
||||
bus.subscribe(SparkTags.ReportBlackboardTags.Create).Subscribe(rp => _create_report(rp).ignore()),
|
||||
@@ -59,7 +61,8 @@ namespace bts.daemons {
|
||||
_bus.subscribe(SparkTags.SystemContractsTag).CombineLatest(
|
||||
_order_service.subscribe_fills(), _position_service.subscribe_manual_fills())
|
||||
.Subscribe(tup => _on_all_trade_data(tup.First, tup.Second, tup.Third)),
|
||||
_report_calculators);
|
||||
_report_calculators,
|
||||
_pnl_calc);
|
||||
|
||||
IDisposable mk_report_calculator(int id) {
|
||||
if (!_report_parameters_map.TryGetValue(id, out var r)) {
|
||||
@@ -156,8 +159,8 @@ namespace bts.daemons {
|
||||
|
||||
var fills_tl = fills_filtered.Select(
|
||||
f => new TradeLogRow(f, sc_data.sec_md_map[f.SecurityKey].security));
|
||||
var m_fills_tl = man_fills_filtered.Select(
|
||||
m => new TradeLogRow(m, sc_data.sec_md_map[m.SecurityKey].security));
|
||||
var m_fills_tl = man_fills_filtered.Select(m => new TradeLogRow(
|
||||
m, sc_data.sec_md_map[m.SecurityKey].security, Fill.Types.FillKind.Standard));
|
||||
var merged_fills = fills_tl.Concat(m_fills_tl).ToList();
|
||||
Log.Ui.info($"ReportDaemon posting {merged_fills.Count} trades");
|
||||
_bus.post(SparkTags.TradeLogTag, merged_fills);
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace bts.perf {
|
||||
[ImportingConstructor]
|
||||
public ShellLatencyDaemon(ShellLatencyService service, Lazy<UserTuple> user) {
|
||||
_service = service;
|
||||
_version = Configuration.get<bts.config.System>().Version;
|
||||
_version = Configuration.get<bts.config.System>().version;
|
||||
_username = user.Value.name;
|
||||
_hostname = Environment.MachineName;
|
||||
|
||||
@@ -49,32 +49,32 @@ namespace bts.perf {
|
||||
|
||||
async void _forever_ping_host(Ping pinger) {
|
||||
var config = Configuration.get<bts.config.ShellPingOptions>();
|
||||
string server_ip = Configuration.get<bts.config.System>().ConfigIp;
|
||||
int delay = config.WorkloopMillisecondsInterval;
|
||||
string server_ip = Configuration.get<bts.config.System>().config_ip;
|
||||
int delay = config.workloop_milliseconds_interval;
|
||||
int _current_missed_ping_count = 0;
|
||||
|
||||
if (config.ShellPingIsEnabled && pinger != null) {
|
||||
if (config.shell_ping_is_enabled && pinger != null) {
|
||||
while (true) {
|
||||
try {
|
||||
await Task.Delay(delay);
|
||||
var response = await pinger.SendPingAsync(server_ip, config.TimeoutMillisecondsThreshold);
|
||||
var response = await pinger.SendPingAsync(server_ip, config.timeout_milliseconds_threshold);
|
||||
if (response.Status == IPStatus.Success) {
|
||||
_current_missed_ping_count = 0;
|
||||
if (response.RoundtripTime > config.LoggingMillisecondsThreshold) {
|
||||
if (response.RoundtripTime > config.logging_milliseconds_threshold) {
|
||||
Log.Ui.warn($"Ping response not received in a timely manner:\n" +
|
||||
$"\tAddress:\t{response.Address}\n" +
|
||||
$"\tRoundTrip:\t{response.RoundtripTime} ms");
|
||||
}
|
||||
// potentially reset delay to initial work period (no-op otherwise)
|
||||
delay = config.WorkloopMillisecondsInterval;
|
||||
delay = config.workloop_milliseconds_interval;
|
||||
} else {
|
||||
_current_missed_ping_count++;
|
||||
delay = _get_exp_delay(_current_missed_ping_count, config.WorkloopMillisecondsInterval, config.MaximumBackoffMilliseconds);
|
||||
delay = _get_exp_delay(_current_missed_ping_count, config.workloop_milliseconds_interval, config.maximum_backoff_milliseconds);
|
||||
Log.Ui.warn($"Ping was not successful. Ping response: {response.Status}. Missed ping count: {_current_missed_ping_count}. Backing off for {delay} milliseconds.");
|
||||
}
|
||||
} catch (PingException e) {
|
||||
_current_missed_ping_count++;
|
||||
delay = _get_exp_delay(_current_missed_ping_count, config.WorkloopMillisecondsInterval, config.MaximumBackoffMilliseconds);
|
||||
delay = _get_exp_delay(_current_missed_ping_count, config.workloop_milliseconds_interval, config.maximum_backoff_milliseconds);
|
||||
Log.Ui.error($"Ping exception. {e}\nBacking off for {delay} milliseconds.");
|
||||
}
|
||||
} // end while
|
||||
|
||||
@@ -203,6 +203,7 @@ namespace mbts.ui {
|
||||
public static ImageSource CopyBoxes => create_icon(CopyBoxesGeometryKey, null, _copy_boxes_pen);
|
||||
public static ImageSource CurrencyExchange => create_icon(CurrencyExchangeGeometryKey);
|
||||
public static ImageSource DataEdit => create_icon(DataEditGeometryKey);
|
||||
public static ImageSource DayFills => PNL;
|
||||
public static ImageSource Defrag { get { return load_resource_and_freeze("Defrag"); } }
|
||||
public static ImageSource DetachAlgos => create_icon_and_rotate(DetachAlgosKey, Brushes.Red);
|
||||
public static ImageSource Disk => create_icon(DiskGeometryKey);
|
||||
@@ -235,6 +236,7 @@ namespace mbts.ui {
|
||||
public static ImageSource Payment => create_icon(PaymentGeometryKey);
|
||||
public static ImageSource Pencil => create_icon(PencilGeometryKey);
|
||||
public static ImageSource Play => create_icon(PlayGeometryKey);
|
||||
public static ImageSource PNL => Accounting;
|
||||
public static ImageSource Prohibited => create_icon(ProhibitedGeometryKey);
|
||||
public static ImageSource RecurringSchedule => create_icon(RecurringScheduleGeometryKey);
|
||||
public static ImageSource RecurringScheduleGray => create_icon(RecurringScheduleGeometryKey, Brushes.Gray);
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace bts.shell {
|
||||
}
|
||||
}
|
||||
bool check_version() {
|
||||
string current = Configuration.get<bts.config.System>().Version;
|
||||
string current = Configuration.get<bts.config.System>().version;
|
||||
if (!string.IsNullOrWhiteSpace(current) && current != "private") {
|
||||
using (var key = Registry.CurrentUser.CreateSubKey(@"Software\BTS")) {
|
||||
var value = key.GetValue("version");
|
||||
|
||||
+31
-31
@@ -1,31 +1,31 @@
|
||||
using bts.utils;
|
||||
|
||||
using ProtoBuf;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace mbts.spark {
|
||||
[ProtoContract]
|
||||
class GlobalAlertSettings : IEquatable<GlobalAlertSettings> {
|
||||
[ProtoMember(1)]
|
||||
TradeAlert[] _trade_alerts;
|
||||
|
||||
public GlobalAlertSettings() { }
|
||||
public GlobalAlertSettings(IEnumerable<TradeAlert> trade_alerts) =>
|
||||
_trade_alerts = trade_alerts.ToArray();
|
||||
|
||||
public IReadOnlyList<TradeAlert> trade_alerts => _trade_alerts ?? Array.Empty<TradeAlert>();
|
||||
|
||||
public bool Equals(GlobalAlertSettings other) =>
|
||||
other != null &&
|
||||
trade_alerts.SequenceEqual(other.trade_alerts);
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
Equals(obj as GlobalAlertSettings);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
EqualityComparer.auto_phase(trade_alerts);
|
||||
}
|
||||
}
|
||||
using bts.utils;
|
||||
|
||||
using ProtoBuf;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace mbts.spark {
|
||||
[ProtoContract]
|
||||
class GlobalAlertSettings : IEquatable<GlobalAlertSettings> {
|
||||
[ProtoMember(1)]
|
||||
TradeAlert[] _trade_alerts;
|
||||
|
||||
public GlobalAlertSettings() { }
|
||||
public GlobalAlertSettings(IEnumerable<TradeAlert> trade_alerts) =>
|
||||
_trade_alerts = trade_alerts.ToArray();
|
||||
|
||||
public IReadOnlyList<TradeAlert> trade_alerts => _trade_alerts ?? Array.Empty<TradeAlert>();
|
||||
|
||||
public bool Equals(GlobalAlertSettings other) =>
|
||||
other != null &&
|
||||
trade_alerts.SequenceEqual(other.trade_alerts);
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
Equals(obj as GlobalAlertSettings);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
EqualityComparer.auto_phase(trade_alerts);
|
||||
}
|
||||
}
|
||||
+88
-88
@@ -1,88 +1,88 @@
|
||||
using bts;
|
||||
|
||||
using mbts.ui.shell;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Composition;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.ui.settings {
|
||||
public interface ISavedWindowFactory {
|
||||
Task<IShellWindow> restore(WindowState window);
|
||||
}
|
||||
|
||||
[Export(typeof(ISavedWindowFactory))]
|
||||
public class WindowFactory : ISavedWindowFactory {
|
||||
IShellWindowMigrationRule[] _compat;
|
||||
|
||||
[ImportingConstructor]
|
||||
public WindowFactory([ImportMany] IShellWindowMigrationRule[] migration) {
|
||||
_compat = migration;
|
||||
}
|
||||
|
||||
[Import]
|
||||
public ObservableCollection<IShellModule> modules { get; set; }
|
||||
|
||||
public Task<IShellWindow> restore(WindowState window) {
|
||||
Log.Ui.info("Loading window '{0}'".fmt(window.title));
|
||||
bool changed;
|
||||
int count = 0;
|
||||
do {
|
||||
count++;
|
||||
changed = apply_compatability_migrations(ref window);
|
||||
} while (count < 100 && changed);
|
||||
|
||||
if (count == 100) {
|
||||
Log.Persist.error("Error: Window state migration still changing after 100 iterations. Please check IShellWindowMigrationRule logic.");
|
||||
}
|
||||
|
||||
return restore(window.owner, window.app_data, window.position);
|
||||
}
|
||||
|
||||
/// When we apply the migration changes to a window we stop as soon as one "matches" and updates the state
|
||||
/// Since it's possible that we have multiple levels of migration we run this function until the data stops changing (or 100 iterations)
|
||||
/// ex: If change the data format twice from A to B to C then we would write 2 IShellWindowMigration instances.
|
||||
/// Starting in state A one of the _compat tests changes to state B. Now we need to re-run
|
||||
/// the migrations because state B will match a different rule and be converted to state C.
|
||||
private bool apply_compatability_migrations(ref WindowState window) {
|
||||
foreach (var test in _compat) {
|
||||
try {
|
||||
if (test.apply(ref window)) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.Persist.error("Exception running compat rule {0}.\n{1}".fmt(test.GetType().Name, e.ToString()));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private async Task<IShellWindow> restore(string owner_name, byte[] state, WindowPosition windowPosition) {
|
||||
IShellModule owner = modules.empty_if_null().SingleOrDefault(m => m.key() == owner_name);
|
||||
if (owner == null) {
|
||||
Log.Ui.warn("Could not locate module '{0}'".fmt(owner_name));
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
Task<IShellWindow> task = owner.create(new MemoryStream(state));
|
||||
if (task != null) {
|
||||
IShellWindow window = await task;
|
||||
if (window != null) {
|
||||
window.set_start_position(windowPosition);
|
||||
Log.Ui.info($"Restoring window {owner_name} - {window.diagnostic_name()}.");
|
||||
}
|
||||
return window;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.Ui.error("Failure to re-create window for module {0}. Error: {1}".fmt(owner_name, e.Message));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
using bts;
|
||||
|
||||
using mbts.ui.shell;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Composition;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.ui.settings {
|
||||
public interface ISavedWindowFactory {
|
||||
Task<IShellWindow> restore(WindowSettings window);
|
||||
}
|
||||
|
||||
[Export(typeof(ISavedWindowFactory))]
|
||||
public class WindowFactory : ISavedWindowFactory {
|
||||
IShellWindowMigrationRule[] _compat;
|
||||
|
||||
[ImportingConstructor]
|
||||
public WindowFactory([ImportMany] IShellWindowMigrationRule[] migration) {
|
||||
_compat = migration;
|
||||
}
|
||||
|
||||
[Import]
|
||||
public ObservableCollection<IShellModule> modules { get; set; }
|
||||
|
||||
public Task<IShellWindow> restore(WindowSettings window) {
|
||||
Log.Ui.info("Loading window '{0}'".fmt(window.title));
|
||||
bool changed;
|
||||
int count = 0;
|
||||
do {
|
||||
count++;
|
||||
changed = apply_compatability_migrations(ref window);
|
||||
} while (count < 100 && changed);
|
||||
|
||||
if (count == 100) {
|
||||
Log.Persist.error("Error: Window state migration still changing after 100 iterations. Please check IShellWindowMigrationRule logic.");
|
||||
}
|
||||
|
||||
return restore(window.owner, window.app_data, window.position);
|
||||
}
|
||||
|
||||
/// When we apply the migration changes to a window we stop as soon as one "matches" and updates the state
|
||||
/// Since it's possible that we have multiple levels of migration we run this function until the data stops changing (or 100 iterations)
|
||||
/// ex: If change the data format twice from A to B to C then we would write 2 IShellWindowMigration instances.
|
||||
/// Starting in state A one of the _compat tests changes to state B. Now we need to re-run
|
||||
/// the migrations because state B will match a different rule and be converted to state C.
|
||||
private bool apply_compatability_migrations(ref WindowSettings window) {
|
||||
foreach (var test in _compat) {
|
||||
try {
|
||||
if (test.apply(ref window)) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.Persist.error("Exception running compat rule {0}.\n{1}".fmt(test.GetType().Name, e.ToString()));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private async Task<IShellWindow> restore(string owner_name, byte[] state, WindowPosition windowPosition) {
|
||||
IShellModule owner = modules.empty_if_null().SingleOrDefault(m => m.key() == owner_name);
|
||||
if (owner == null) {
|
||||
Log.Ui.warn("Could not locate module '{0}'".fmt(owner_name));
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
Task<IShellWindow> task = owner.create(new MemoryStream(state));
|
||||
if (task != null) {
|
||||
IShellWindow window = await task;
|
||||
if (window != null) {
|
||||
window.set_start_position(windowPosition);
|
||||
Log.Ui.info($"Restoring window {owner_name} - {window.diagnostic_name()}.");
|
||||
}
|
||||
return window;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.Ui.error("Failure to re-create window for module {0}. Error: {1}".fmt(owner_name, e.Message));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+113
-86
@@ -1,86 +1,113 @@
|
||||
using bts;
|
||||
|
||||
using mbts.ui.shell;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Composition;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace mbts.ui.settings {
|
||||
public interface ISettingsCollector {
|
||||
// Get the save state for every open window
|
||||
IEnumerable<WindowState> get_window_state();
|
||||
WindowState get_window_state(IShellWindow window);
|
||||
IEnumerable<ModuleState> get_module_state();
|
||||
WindowPosition get_launcher_state();
|
||||
}
|
||||
|
||||
[Export(typeof(ISettingsCollector))]
|
||||
class SettingsCollector : ISettingsCollector {
|
||||
WindowManager _wm;
|
||||
ILauncher _launcher;
|
||||
|
||||
[ImportingConstructor]
|
||||
public SettingsCollector(WindowManager wm, ILauncher launcher) {
|
||||
_wm = wm;
|
||||
_launcher = launcher;
|
||||
}
|
||||
|
||||
[Import]
|
||||
public ObservableCollection<IShellModule> modules { get; set; }
|
||||
|
||||
IWindowsInterop _interop => _wm;
|
||||
|
||||
public IEnumerable<WindowState> get_window_state() {
|
||||
foreach (var window in _wm.list_windows()) {
|
||||
// Check that the window is still open since we might be iterating asyncronously
|
||||
if (_wm.contains(window)) {
|
||||
var state = get_window_state(window);
|
||||
if (state != null) {
|
||||
yield return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<ModuleState> get_module_state() {
|
||||
//Note: I'm assuming that the list of modules is stable and I don't have to protect against it changing here
|
||||
foreach (var module in modules.OfTypeSafe<IPersistShellModule>()) {
|
||||
MemoryStream out_stream = new MemoryStream();
|
||||
module.get_state(out_stream);
|
||||
yield return new ModuleState() {
|
||||
name = module.key(),
|
||||
app_data = out_stream.ToArray(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public WindowPosition get_launcher_state() {
|
||||
return _launcher.get_position();
|
||||
}
|
||||
|
||||
public WindowState get_window_state(IShellWindow window) {
|
||||
try {
|
||||
if (window == null || window.Owner == null) return null;
|
||||
MemoryStream out_stream = new MemoryStream();
|
||||
window.GetState(out_stream);
|
||||
|
||||
var pos = _interop.GetPosition(window);
|
||||
var state = new WindowState() {
|
||||
owner = window.Owner.key(),
|
||||
app_data = out_stream.ToArray(),
|
||||
position = pos,
|
||||
title = string.IsNullOrEmpty(pos.custom_title) ? window.Title : pos.custom_title
|
||||
};
|
||||
return state;
|
||||
} catch (Exception e) {
|
||||
Log.Ui.error("Error saving window state for type {0}.\n {1}".fmt(window.GetType(), e.Message));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
using bts;
|
||||
|
||||
using mbts.ui.shell;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Composition;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace mbts.ui.settings {
|
||||
public interface ISettingsCollector {
|
||||
// Get the save state for every open window
|
||||
Task<List<WindowSettings>> get_window_state();
|
||||
Task<WindowSettings> get_window_state(IShellWindow window);
|
||||
IEnumerable<ModuleSettings> get_module_state();
|
||||
WindowPosition get_launcher_state();
|
||||
}
|
||||
|
||||
[Export(typeof(ISettingsCollector))]
|
||||
class SettingsCollector : ISettingsCollector {
|
||||
WindowManager _wm;
|
||||
ILauncher _launcher;
|
||||
|
||||
[ImportingConstructor]
|
||||
public SettingsCollector(WindowManager wm, ILauncher launcher) {
|
||||
_wm = wm;
|
||||
_launcher = launcher;
|
||||
}
|
||||
|
||||
[Import]
|
||||
public ObservableCollection<IShellModule> modules { get; set; }
|
||||
|
||||
[Import]
|
||||
public IShellThreadFactory thread_factory { get; set; }
|
||||
|
||||
IWindowsInterop _interop => _wm;
|
||||
|
||||
public async Task<List<WindowSettings>> get_window_state() {
|
||||
var windows = _wm.list_windows();
|
||||
var rv = new List<WindowSettings>(windows.Count);
|
||||
foreach (var window in windows) {
|
||||
// Check that the window is still open since we might be iterating asyncronously
|
||||
if (_wm.contains(window)) {
|
||||
var state = await get_window_state(window);
|
||||
if (state != null) {
|
||||
rv.Add(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
public IEnumerable<ModuleSettings> get_module_state() {
|
||||
//Note: I'm assuming that the list of modules is stable and I don't have to protect against it changing here
|
||||
foreach (var module in modules.OfTypeSafe<IPersistShellModule>()) {
|
||||
MemoryStream out_stream = new MemoryStream();
|
||||
module.get_state(out_stream);
|
||||
yield return new ModuleSettings() {
|
||||
name = module.key(),
|
||||
app_data = out_stream.ToArray(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public WindowPosition get_launcher_state() {
|
||||
return _launcher.get_position();
|
||||
}
|
||||
|
||||
public async Task<WindowSettings> get_window_state(IShellWindow window) {
|
||||
try {
|
||||
if (window == null || window.Owner == null) return null;
|
||||
Dispatcher dispatcher = null;
|
||||
if (window is ISlowWindow) {
|
||||
var tf = thread_factory;
|
||||
if (tf is not null) {
|
||||
var thread_id = (window as ISharedWindow)?.thread_id;
|
||||
dispatcher = tf.get_dispatcher(thread_id);
|
||||
if (dispatcher is null) {
|
||||
Log.Gen.error(
|
||||
$"Unable to get window state for '{window.Title}.' " +
|
||||
$"Didn't find dispatcher for thread {thread_id}.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var pos = _interop.GetPosition(window);
|
||||
var state = new WindowSettings() {
|
||||
owner = window.Owner.key(),
|
||||
app_data = dispatcher is null ?
|
||||
serialize() : (await dispatcher.InvokeAsync(serialize)),
|
||||
position = pos,
|
||||
title = string.IsNullOrEmpty(pos.custom_title) ? window.Title : pos.custom_title
|
||||
};
|
||||
return state;
|
||||
|
||||
byte[] serialize() {
|
||||
using var ms = new MemoryStream();
|
||||
window.GetState(ms);
|
||||
return ms.ToArray();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.Ui.error("Error saving window state for type {0}.\n {1}".fmt(window.GetType(), e.Message));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+96
-95
@@ -1,95 +1,96 @@
|
||||
using bts.shell.pnl;
|
||||
using bts.utils;
|
||||
|
||||
using mbts.ui.settings;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace bts.settings {
|
||||
interface ISettingsMigrationRule<T> {
|
||||
bool apply(T settings, out T new_settings);
|
||||
}
|
||||
|
||||
// Migration rules of type ISettingsMigrationRule<T>, where 'T' is a common type, such as GridSettings,
|
||||
// should be exposed through explicitly named interfaces that inherit ISettingsMigrationRule<T>.
|
||||
// This avoids magic const names in the MEF import/export contracts, which would otherwise be needed to
|
||||
// determine the various windows to which such rules apply.
|
||||
interface IFillsGridSettingsMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
interface IMarketViewGridSettingsMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
interface IPAndLGridSettingsMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
interface IPNLSettingsMigrationRule : ISettingsMigrationRule<PNLSettings> { }
|
||||
interface ISyntheticManagementMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
interface IReconcileReportMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
|
||||
static class SettingsMigrationHelper {
|
||||
public static bool apply<T>(T settings, IEnumerable<ISettingsMigrationRule<T>> migration_rules, out T new_settings) {
|
||||
bool applied = false;
|
||||
foreach (var r in migration_rules) {
|
||||
if (r.apply(settings, out var migrated)) {
|
||||
settings = migrated;
|
||||
applied = true;
|
||||
}
|
||||
}
|
||||
new_settings = applied ? settings : default;
|
||||
return applied;
|
||||
}
|
||||
|
||||
public static void apply_quiet<T>(ref T settings, IEnumerable<ISettingsMigrationRule<T>> migration_rules) {
|
||||
if (apply(settings, migration_rules, out var new_settings))
|
||||
settings = new_settings;
|
||||
}
|
||||
|
||||
public static ISettingsMigrationRule<T> merge<T>(this IEnumerable<ISettingsMigrationRule<T>> rules) =>
|
||||
new MergeWrapper<T>(rules);
|
||||
|
||||
public static ISettingsMigrationRule<TOuter> wrap<TInner, TOuter>(this ISettingsMigrationRule<TInner> rule, IImmutableProperty<TOuter, TInner> propi) =>
|
||||
new SelectorWrapper<TInner, TOuter>(rule, propi.get, propi.set);
|
||||
|
||||
public static ISettingsMigrationRule<TOuter> wrap<TInner, TOuter>(this ISettingsMigrationRule<TInner> rule, Func<TOuter, TInner> get, Func<TOuter, TInner, TOuter> set) =>
|
||||
new SelectorWrapper<TInner, TOuter>(rule, get, set);
|
||||
|
||||
class MergeWrapper<T> : ISettingsMigrationRule<T> {
|
||||
readonly IEnumerable<ISettingsMigrationRule<T>> _rules;
|
||||
|
||||
public MergeWrapper(IEnumerable<ISettingsMigrationRule<T>> rules) =>
|
||||
_rules = rules;
|
||||
|
||||
public bool apply(T settings, out T new_settings) {
|
||||
bool applied = false;
|
||||
foreach (var r in _rules) {
|
||||
if (r.apply(settings, out var migrated)) {
|
||||
settings = migrated;
|
||||
applied = true;
|
||||
}
|
||||
}
|
||||
new_settings = applied ? settings : default;
|
||||
return applied;
|
||||
}
|
||||
}
|
||||
|
||||
class SelectorWrapper<TInner, TOuter> : ISettingsMigrationRule<TOuter> {
|
||||
readonly ISettingsMigrationRule<TInner> _rule;
|
||||
readonly Func<TOuter, TInner> _get;
|
||||
readonly Func<TOuter, TInner, TOuter> _set;
|
||||
|
||||
public SelectorWrapper(ISettingsMigrationRule<TInner> rule, Func<TOuter, TInner> get, Func<TOuter, TInner, TOuter> set) {
|
||||
_rule = rule;
|
||||
_get = get;
|
||||
_set = set;
|
||||
}
|
||||
|
||||
public bool apply(TOuter settings, out TOuter new_settings) {
|
||||
if (settings != null) {
|
||||
var ival = _get(settings);
|
||||
if (_rule.apply(ival, out var new_ival)) {
|
||||
new_settings = _set(settings, new_ival);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
new_settings = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using bts.shell.pnl;
|
||||
using bts.utils;
|
||||
|
||||
using mbts.ui.settings;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace bts.settings {
|
||||
interface ISettingsMigrationRule<T> {
|
||||
bool apply(T settings, out T new_settings);
|
||||
}
|
||||
|
||||
// Migration rules of type ISettingsMigrationRule<T>, where 'T' is a common type, such as GridSettings,
|
||||
// should be exposed through explicitly named interfaces that inherit ISettingsMigrationRule<T>.
|
||||
// This avoids magic const names in the MEF import/export contracts, which would otherwise be needed to
|
||||
// determine the various windows to which such rules apply.
|
||||
interface IFillsGridSettingsMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
interface IMarketViewGridSettingsMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
interface IPAndLGridSettingsMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
interface IPNLSettingsMigrationRule : ISettingsMigrationRule<PNLSettings> { }
|
||||
interface ISyntheticManagementMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
interface IReconcileReportMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
interface IDayFillsGridSettingsMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
|
||||
static class SettingsMigrationHelper {
|
||||
public static bool apply<T>(T settings, IEnumerable<ISettingsMigrationRule<T>> migration_rules, out T new_settings) {
|
||||
bool applied = false;
|
||||
foreach (var r in migration_rules) {
|
||||
if (r.apply(settings, out var migrated)) {
|
||||
settings = migrated;
|
||||
applied = true;
|
||||
}
|
||||
}
|
||||
new_settings = applied ? settings : default;
|
||||
return applied;
|
||||
}
|
||||
|
||||
public static void apply_quiet<T>(ref T settings, IEnumerable<ISettingsMigrationRule<T>> migration_rules) {
|
||||
if (apply(settings, migration_rules, out var new_settings))
|
||||
settings = new_settings;
|
||||
}
|
||||
|
||||
public static ISettingsMigrationRule<T> merge<T>(this IEnumerable<ISettingsMigrationRule<T>> rules) =>
|
||||
new MergeWrapper<T>(rules);
|
||||
|
||||
public static ISettingsMigrationRule<TOuter> wrap<TInner, TOuter>(this ISettingsMigrationRule<TInner> rule, IImmutableProperty<TOuter, TInner> propi) =>
|
||||
new SelectorWrapper<TInner, TOuter>(rule, propi.get, propi.set);
|
||||
|
||||
public static ISettingsMigrationRule<TOuter> wrap<TInner, TOuter>(this ISettingsMigrationRule<TInner> rule, Func<TOuter, TInner> get, Func<TOuter, TInner, TOuter> set) =>
|
||||
new SelectorWrapper<TInner, TOuter>(rule, get, set);
|
||||
|
||||
class MergeWrapper<T> : ISettingsMigrationRule<T> {
|
||||
readonly IEnumerable<ISettingsMigrationRule<T>> _rules;
|
||||
|
||||
public MergeWrapper(IEnumerable<ISettingsMigrationRule<T>> rules) =>
|
||||
_rules = rules;
|
||||
|
||||
public bool apply(T settings, out T new_settings) {
|
||||
bool applied = false;
|
||||
foreach (var r in _rules) {
|
||||
if (r.apply(settings, out var migrated)) {
|
||||
settings = migrated;
|
||||
applied = true;
|
||||
}
|
||||
}
|
||||
new_settings = applied ? settings : default;
|
||||
return applied;
|
||||
}
|
||||
}
|
||||
|
||||
class SelectorWrapper<TInner, TOuter> : ISettingsMigrationRule<TOuter> {
|
||||
readonly ISettingsMigrationRule<TInner> _rule;
|
||||
readonly Func<TOuter, TInner> _get;
|
||||
readonly Func<TOuter, TInner, TOuter> _set;
|
||||
|
||||
public SelectorWrapper(ISettingsMigrationRule<TInner> rule, Func<TOuter, TInner> get, Func<TOuter, TInner, TOuter> set) {
|
||||
_rule = rule;
|
||||
_get = get;
|
||||
_set = set;
|
||||
}
|
||||
|
||||
public bool apply(TOuter settings, out TOuter new_settings) {
|
||||
if (settings != null) {
|
||||
var ival = _get(settings);
|
||||
if (_rule.apply(ival, out var new_ival)) {
|
||||
new_settings = _set(settings, new_ival);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
new_settings = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File renamed without changes.
+152
-171
@@ -1,171 +1,152 @@
|
||||
using mbts.spark;
|
||||
using mbts.utils;
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.persist {
|
||||
interface IWindowSettingsManager<T> where T : class {
|
||||
T instance_settings { get; set; }
|
||||
T default_settings { get; }
|
||||
event Action<T> instance_settings_changed;
|
||||
IObservable<T> subscribe_default();
|
||||
Task save_default_settings(T value);
|
||||
IWindowSettingsManagerNonShared<T> as_non_shared();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An implementation of IWindowSettingsManager that uses a clone of the actual default settings;
|
||||
/// provides a convenient way to avoid problems that arise from sharing a single default settings object among multiple window instances.
|
||||
/// </summary>
|
||||
interface IWindowSettingsManagerNonShared<T> : IWindowSettingsManager<T>, IDisposable where T : class { }
|
||||
|
||||
class WindowSettingsManager<T> : IWindowSettingsManager<T> where T : class {
|
||||
readonly UserSettingsHub _hub;
|
||||
readonly Func<UserSettings, T> _get;
|
||||
readonly Func<UserSettings, T, UserSettings> _set;
|
||||
T _instance_settings;
|
||||
|
||||
public WindowSettingsManager(UserSettingsHub hub, T instance_settings, Func<UserSettings, T> get, Func<UserSettings, T, UserSettings> set) {
|
||||
_hub = hub;
|
||||
_instance_settings = instance_settings;
|
||||
_get = get;
|
||||
_set = set;
|
||||
}
|
||||
|
||||
public T instance_settings {
|
||||
get => _instance_settings;
|
||||
set {
|
||||
_instance_settings = value;
|
||||
instance_settings_changed?.Invoke(value);
|
||||
}
|
||||
}
|
||||
|
||||
public T default_settings => _get(_hub.current);
|
||||
|
||||
public event Action<T> instance_settings_changed;
|
||||
|
||||
public async Task save_default_settings(T value) =>
|
||||
await _hub.save_default(_set(_hub.current, value));
|
||||
|
||||
public IObservable<T> subscribe_default() =>
|
||||
_hub.subscribe_default_settings().Select(_get).DistinctUntilChanged();
|
||||
|
||||
public IWindowSettingsManagerNonShared<T> as_non_shared() =>
|
||||
new NonSharedWrapper(this);
|
||||
|
||||
class NonSharedWrapper : IWindowSettingsManagerNonShared<T> {
|
||||
readonly IWindowSettingsManager<T> _wsm;
|
||||
readonly BehaviorSubject<T> _default_subject;
|
||||
IDisposable _dispose;
|
||||
|
||||
public NonSharedWrapper(IWindowSettingsManager<T> wsm) {
|
||||
_wsm = wsm;
|
||||
_default_subject = new BehaviorSubject<T>(_wsm.default_settings);
|
||||
_dispose = wsm.subscribe_default().Subscribe(s =>
|
||||
_default_subject.OnNext(default_settings = MiscUtils.clone_proto(s)));
|
||||
}
|
||||
|
||||
public T instance_settings {
|
||||
get => _wsm.instance_settings;
|
||||
set => _wsm.instance_settings = value;
|
||||
}
|
||||
public T default_settings { get; private set; }
|
||||
public event Action<T> instance_settings_changed {
|
||||
add => _wsm.instance_settings_changed += value;
|
||||
remove => _wsm.instance_settings_changed -= value;
|
||||
}
|
||||
public async Task save_default_settings(T value) =>
|
||||
await _wsm.save_default_settings(value);
|
||||
|
||||
public IObservable<T> subscribe_default() =>
|
||||
_default_subject.AsObservable();
|
||||
|
||||
public IWindowSettingsManagerNonShared<T> as_non_shared() =>
|
||||
new NonSharedWrapper(_wsm);
|
||||
|
||||
public void Dispose() => Disposable.dispose(ref _dispose);
|
||||
}
|
||||
|
||||
public class DisconnectedImpl : IWindowSettingsManager<T> {
|
||||
readonly BehaviorSubject<T> _default_settings_subject;
|
||||
T _instance_settings, _default_settings;
|
||||
|
||||
public DisconnectedImpl(T settings) : this(settings, settings) { }
|
||||
public DisconnectedImpl(T instance_settings, T default_settings) {
|
||||
_instance_settings = instance_settings;
|
||||
_default_settings = default_settings;
|
||||
_default_settings_subject = new BehaviorSubject<T>(default_settings);
|
||||
}
|
||||
|
||||
public T instance_settings {
|
||||
get => _instance_settings;
|
||||
set {
|
||||
if (!Equals(_instance_settings, value)) {
|
||||
_instance_settings = value;
|
||||
instance_settings_changed?.Invoke(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public T default_settings {
|
||||
get => _default_settings;
|
||||
set {
|
||||
if (!Equals(_default_settings, _default_settings)) {
|
||||
_default_settings = value;
|
||||
_default_settings_subject.OnNext(value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<T> instance_settings_changed;
|
||||
|
||||
public IWindowSettingsManagerNonShared<T> as_non_shared() => new NonSharedWrapper(this);
|
||||
public Task save_default_settings(T value) {
|
||||
default_settings = value;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
public IObservable<T> subscribe_default() => _default_settings_subject;
|
||||
}
|
||||
}
|
||||
|
||||
static class WindowSettingsManagerExtensions {
|
||||
/// <summary>
|
||||
/// Returns an observable sequence of the settings object used by a particular window.
|
||||
/// <para/>Note: 'Instance' settings take priority over 'default' settings. While the former is present, any changes to the latter will be ignored.
|
||||
/// </summary>
|
||||
public static IObservable<T> subscribe_current<T>(this IWindowSettingsManager<T> wsm) where T : class =>
|
||||
Observable.CombineLatest(
|
||||
Observable.FromEvent<Action<T>, T>(cb => wsm.instance_settings_changed += cb, cb => wsm.instance_settings_changed -= cb)
|
||||
.StartWith(wsm.instance_settings),
|
||||
wsm.subscribe_default(),
|
||||
(i, d) => i ?? d
|
||||
).Where(v => v != null)
|
||||
.DistinctUntilChanged();
|
||||
|
||||
public static IObservable<T> subscribe_current<T>(this IWindowSettingsManager<T> wsm, Func<(T defaults, T instance), T> merge_settings) where T : class, IDefaultableSettings {
|
||||
return Observable.Create<T>(o => {
|
||||
IDisposable defaults_sub = wsm.subscribe_default().Subscribe(_ => o.OnNext(get_current()));
|
||||
wsm.instance_settings_changed += on_instance_settings_changed;
|
||||
return Disposable.Create(() => {
|
||||
defaults_sub.Dispose();
|
||||
wsm.instance_settings_changed -= on_instance_settings_changed;
|
||||
});
|
||||
void on_instance_settings_changed(T _) =>
|
||||
o.OnNext(get_current());
|
||||
});
|
||||
T get_current() {
|
||||
var inst = wsm.instance_settings;
|
||||
if (inst == null) return wsm.default_settings;
|
||||
if (inst.use_defaults) return merge_settings((wsm.default_settings, inst));
|
||||
return inst;
|
||||
}
|
||||
}
|
||||
|
||||
public static T current_settings<T>(this IWindowSettingsManager<T> wsm) where T : class =>
|
||||
wsm.instance_settings ?? wsm.default_settings;
|
||||
}
|
||||
}
|
||||
using mbts.spark;
|
||||
using mbts.utils;
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.persist {
|
||||
interface IWindowSettingsManager<T> where T : class {
|
||||
T instance_settings { get; set; }
|
||||
T default_settings { get; }
|
||||
event Action<T> instance_settings_changed;
|
||||
IObservable<T> subscribe_default();
|
||||
Task save_default_settings(T value);
|
||||
IWindowSettingsManagerNonShared<T> as_non_shared();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An implementation of IWindowSettingsManager that uses a clone of the actual default settings;
|
||||
/// provides a convenient way to avoid problems that arise from sharing a single default settings object among multiple window instances.
|
||||
/// </summary>
|
||||
interface IWindowSettingsManagerNonShared<T> : IWindowSettingsManager<T>, IDisposable where T : class { }
|
||||
|
||||
class WindowSettingsManager<T> : IWindowSettingsManager<T> where T : class {
|
||||
readonly UserSettingsHub _hub;
|
||||
readonly Func<UserSettings, T> _get;
|
||||
readonly Func<UserSettings, T, UserSettings> _set;
|
||||
T _instance_settings;
|
||||
|
||||
public WindowSettingsManager(UserSettingsHub hub, T instance_settings, Func<UserSettings, T> get, Func<UserSettings, T, UserSettings> set) {
|
||||
_hub = hub;
|
||||
_instance_settings = instance_settings;
|
||||
_get = get;
|
||||
_set = set;
|
||||
}
|
||||
|
||||
public T instance_settings {
|
||||
get => _instance_settings;
|
||||
set {
|
||||
_instance_settings = value;
|
||||
instance_settings_changed?.Invoke(value);
|
||||
}
|
||||
}
|
||||
|
||||
public T default_settings => _get(_hub.current);
|
||||
|
||||
public event Action<T> instance_settings_changed;
|
||||
|
||||
public async Task save_default_settings(T value) =>
|
||||
await _hub.save_default(_set(_hub.current, value));
|
||||
|
||||
public IObservable<T> subscribe_default() =>
|
||||
_hub.subscribe_default_settings().Select(_get).DistinctUntilChanged();
|
||||
|
||||
public IWindowSettingsManagerNonShared<T> as_non_shared() =>
|
||||
new NonSharedWrapper(this);
|
||||
|
||||
class NonSharedWrapper : IWindowSettingsManagerNonShared<T> {
|
||||
readonly IWindowSettingsManager<T> _wsm;
|
||||
readonly BehaviorSubject<T> _default_subject;
|
||||
IDisposable _dispose;
|
||||
|
||||
public NonSharedWrapper(IWindowSettingsManager<T> wsm) {
|
||||
_wsm = wsm;
|
||||
_default_subject = new BehaviorSubject<T>(_wsm.default_settings);
|
||||
_dispose = wsm.subscribe_default().Subscribe(s =>
|
||||
_default_subject.OnNext(default_settings = MiscUtils.clone_proto(s)));
|
||||
}
|
||||
|
||||
public T instance_settings {
|
||||
get => _wsm.instance_settings;
|
||||
set => _wsm.instance_settings = value;
|
||||
}
|
||||
public T default_settings { get; private set; }
|
||||
public event Action<T> instance_settings_changed {
|
||||
add => _wsm.instance_settings_changed += value;
|
||||
remove => _wsm.instance_settings_changed -= value;
|
||||
}
|
||||
public async Task save_default_settings(T value) =>
|
||||
await _wsm.save_default_settings(value);
|
||||
|
||||
public IObservable<T> subscribe_default() =>
|
||||
_default_subject.AsObservable();
|
||||
|
||||
public IWindowSettingsManagerNonShared<T> as_non_shared() =>
|
||||
new NonSharedWrapper(_wsm);
|
||||
|
||||
public void Dispose() => Disposable.dispose(ref _dispose);
|
||||
}
|
||||
|
||||
public class DisconnectedImpl : IWindowSettingsManager<T> {
|
||||
readonly BehaviorSubject<T> _default_settings_subject;
|
||||
T _instance_settings, _default_settings;
|
||||
|
||||
public DisconnectedImpl(T settings) : this(settings, settings) { }
|
||||
public DisconnectedImpl(T instance_settings, T default_settings) {
|
||||
_instance_settings = instance_settings;
|
||||
_default_settings = default_settings;
|
||||
_default_settings_subject = new BehaviorSubject<T>(default_settings);
|
||||
}
|
||||
|
||||
public T instance_settings {
|
||||
get => _instance_settings;
|
||||
set {
|
||||
if (!Equals(_instance_settings, value)) {
|
||||
_instance_settings = value;
|
||||
instance_settings_changed?.Invoke(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public T default_settings {
|
||||
get => _default_settings;
|
||||
set {
|
||||
if (!Equals(_default_settings, _default_settings)) {
|
||||
_default_settings = value;
|
||||
_default_settings_subject.OnNext(value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<T> instance_settings_changed;
|
||||
|
||||
public IWindowSettingsManagerNonShared<T> as_non_shared() => new NonSharedWrapper(this);
|
||||
public Task save_default_settings(T value) {
|
||||
default_settings = value;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
public IObservable<T> subscribe_default() => _default_settings_subject;
|
||||
}
|
||||
}
|
||||
|
||||
static class WindowSettingsManagerExtensions {
|
||||
/// <summary>
|
||||
/// Returns an observable sequence of the settings object used by a particular window.
|
||||
/// <para/>Note: 'Instance' settings take priority over 'default' settings. While the former is present, any changes to the latter will be ignored.
|
||||
/// </summary>
|
||||
public static IObservable<T> subscribe_current<T>(this IWindowSettingsManager<T> wsm) where T : class =>
|
||||
Observable.CombineLatest(
|
||||
Observable.FromEvent<Action<T>, T>(cb => wsm.instance_settings_changed += cb, cb => wsm.instance_settings_changed -= cb)
|
||||
.StartWith(wsm.instance_settings),
|
||||
wsm.subscribe_default(),
|
||||
(i, d) => i ?? d
|
||||
).Where(v => v != null)
|
||||
.DistinctUntilChanged();
|
||||
|
||||
public static T current_settings<T>(this IWindowSettingsManager<T> wsm) where T : class =>
|
||||
wsm.instance_settings ?? wsm.default_settings;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#nullable enable
|
||||
namespace mbts.ui.shell {
|
||||
using ProtoBuf;
|
||||
|
||||
using Spark.Core.Protobuf;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
[ProtoContract]
|
||||
public class ModuleSettings : IProtobuf<ModuleSettings> {
|
||||
[ProtoMember(1)]
|
||||
public string? name { get; set; }
|
||||
|
||||
[ProtoMember(2)]
|
||||
public byte[]? app_data { get; set; }
|
||||
|
||||
public bool Equals(ModuleSettings? other) =>
|
||||
other is not null &&
|
||||
name == other.name &&
|
||||
app_data.safe_sequence_equals(other.app_data);
|
||||
|
||||
public override bool Equals(object? obj) =>
|
||||
Equals(obj as ModuleSettings);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
GetType().GetHashCode();
|
||||
|
||||
public ModuleSettings Clone() =>
|
||||
ProtobufSerializationHelper.clone(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
#nullable enable
|
||||
namespace mbts.persist {
|
||||
using bts;
|
||||
using bts.api.core;
|
||||
using bts.api.persistence;
|
||||
using bts.spark;
|
||||
|
||||
using Spark.Core.Protobuf;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Composition;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
public class SettingsPersistenceModel : IPersist, IUserPersist {
|
||||
readonly PersistenceService _persist;
|
||||
readonly ErrorReporter _errors;
|
||||
readonly string _user;
|
||||
|
||||
public SettingsPersistenceModel(
|
||||
string user, PersistenceService persist, ErrorReporter errors) {
|
||||
_user = user;
|
||||
_persist = persist;
|
||||
_errors = errors;
|
||||
}
|
||||
|
||||
public Task set<T>(string ns, string key, T value) {
|
||||
return _persist.store_async(new StoreRequest() {
|
||||
Ns = _user_ns(ns),
|
||||
Record = {
|
||||
new Record() {
|
||||
Key = key,
|
||||
Value = ProtobufSerializationHelper.serialize_to_byte_string(value)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Task clear(string ns, string key) {
|
||||
return _persist.remove_async(new RemoveRequest() {
|
||||
Ns = _user_ns(ns),
|
||||
Key = { key }
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<T?> get<T>(string ns, string key) {
|
||||
var ret = await _persist.retrieve_async(new RetrieveRequest() {
|
||||
Ns = _user_ns(ns),
|
||||
Key = { key }
|
||||
});
|
||||
_check_error(ret, ns, key, out var empty);
|
||||
if (empty) {
|
||||
return default;
|
||||
}
|
||||
return ProtobufSerializationHelper.deserialize<T>(ret.value.Record.Single().Value);
|
||||
}
|
||||
|
||||
public async Task<T[]> get_many<T>(string ns, string key) {
|
||||
var ret = await _persist.retrieve_async(new RetrieveRequest() {
|
||||
Ns = _user_ns(ns),
|
||||
Key = { key }
|
||||
});
|
||||
_check_error(ret, ns, key, out bool empty);
|
||||
if (empty) {
|
||||
return Array.Empty<T>();
|
||||
}
|
||||
return ProtobufSerializationHelper.deserialize_many<T>(
|
||||
ret.value.Record.Single().Value.ToByteArray());
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<PersistResult<T>>> query<T>(string ns, string pattern) {
|
||||
var regex = new Regex(pattern);
|
||||
var results = await _persist.retrieve_all_async(
|
||||
new RetrieveAllRequest() {
|
||||
Ns = _user_ns(ns)
|
||||
});
|
||||
_check_error(results, ns, string.Empty, out bool empty);
|
||||
if (empty) {
|
||||
return Enumerable.Empty<PersistResult<T>>();
|
||||
}
|
||||
return results.value.Record
|
||||
.Where(r => regex.IsMatch(r.Key))
|
||||
.Select(r => new PersistResult<T>() {
|
||||
user = _user,
|
||||
ns = ns,
|
||||
key = r.Key,
|
||||
value = ProtobufSerializationHelper.deserialize<T>(r.Value)
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public IDisposable subscribe<T>(
|
||||
string ns, string pattern, Action<IEnumerable<PersistResult<T>>> callback) =>
|
||||
subscribe<T>(ns, pattern).Subscribe(callback);
|
||||
|
||||
public IObservable<IEnumerable<PersistResult<T>>> subscribe<T>(string ns, string pattern) {
|
||||
var ctx = SynchronizationContext.Current ??
|
||||
throw new InvalidOperationException("Current SynchronizationContext is null");
|
||||
var re = new Regex(pattern);
|
||||
return _persist
|
||||
.subscribe_ns(_user_ns(ns))
|
||||
.Select(update =>
|
||||
update.added
|
||||
.Where(item => re.IsMatch(item.Key))
|
||||
.Select(item => new PersistResult<T>() {
|
||||
user = _user,
|
||||
ns = ns,
|
||||
key = item.Key,
|
||||
value = ProtobufSerializationHelper.deserialize<T>(item.Value)
|
||||
}))
|
||||
.SubscribeOn(ctx);
|
||||
}
|
||||
|
||||
public void Dispose() =>
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
string _user_ns(string ns) =>
|
||||
$"{_user}#{ns}";
|
||||
|
||||
void _check_error(Result<RetrieveResponse> result, string ns, string key, out bool empty) {
|
||||
if (result.success) {
|
||||
switch (result.value.Result) {
|
||||
case RetrieveResponse.Types.Result.EmptyNs:
|
||||
case RetrieveResponse.Types.Result.NoSuchNs:
|
||||
case RetrieveResponse.Types.Result.NoSuchKey:
|
||||
empty = true;
|
||||
return;
|
||||
case RetrieveResponse.Types.Result.EmptyKey:
|
||||
case RetrieveResponse.Types.Result.DuplicateKey:
|
||||
_errors?.report_error(
|
||||
$"Invalid Key {result} '{key}'",
|
||||
"Requested Invalid Settings Key",
|
||||
MessageBoxImage.Information);
|
||||
empty = true;
|
||||
return;
|
||||
default:
|
||||
case RetrieveResponse.Types.Result.Ok:
|
||||
empty = false;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
_errors?.report_error(
|
||||
$"There was an error communicating with the settings server: {result.error_message}",
|
||||
"Failed to retrieve settings from the server");
|
||||
empty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Export(typeof(IPersist))]
|
||||
public class UISettings : SettingsPersistenceModel {
|
||||
[ImportingConstructor]
|
||||
public UISettings([Import("settings")] PersistenceService persist, ErrorReporter err)
|
||||
: base("all_users", persist, err) { }
|
||||
}
|
||||
|
||||
[Export(typeof(IUserPersist))]
|
||||
public class UserUISettings : SettingsPersistenceModel {
|
||||
public UserUISettings(
|
||||
uint user_id, [Import("settings")] PersistenceService persist, ErrorReporter err)
|
||||
: base($"User {user_id}", persist, err) { }
|
||||
|
||||
[ImportingConstructor]
|
||||
public UserUISettings(
|
||||
Lazy<UserTuple> user, [Import("settings")] PersistenceService persist, ErrorReporter err)
|
||||
: this(user.Value.id, persist, err) { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#nullable enable
|
||||
namespace mbts.spark {
|
||||
using bts.utils;
|
||||
|
||||
using System;
|
||||
|
||||
interface ISettingsProfile<T> {
|
||||
uint id { get; }
|
||||
string? name { get; }
|
||||
T? value { get; }
|
||||
SecurityCriteria? security_criteria { get; }
|
||||
}
|
||||
|
||||
readonly struct SettingsProfile<T> : IEquatable<SettingsProfile<T>> where T : class, IEquatable<T> {
|
||||
public static readonly Func<SettingsProfile<T>, uint> key_fn = ns => ns.id;
|
||||
|
||||
public readonly uint id;
|
||||
public readonly string? name;
|
||||
public readonly T? value;
|
||||
public readonly SecurityCriteria? security_criteria;
|
||||
|
||||
public SettingsProfile(uint id, string? name, T? value, SecurityCriteria? security_criteria = null) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.security_criteria = security_criteria;
|
||||
}
|
||||
|
||||
public SettingsProfile<T> with(uint? id = null, string? name = null, T? value = null, SecurityCriteria? security_criteria = null) =>
|
||||
new(id ?? this.id, name ?? this.name, value ?? this.value, security_criteria ?? this.security_criteria);
|
||||
|
||||
public bool Equals(SettingsProfile<T> other) =>
|
||||
id == other.id &&
|
||||
name == other.name &&
|
||||
value.safe_equals(other.value) &&
|
||||
security_criteria.safe_equals(other.security_criteria);
|
||||
|
||||
public override bool Equals(object? obj) =>
|
||||
obj is SettingsProfile<T> other && Equals(other);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
id.GetHashCode();
|
||||
}
|
||||
}
|
||||
+73
-73
@@ -1,73 +1,73 @@
|
||||
using mbts.persist;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.ui.tests {
|
||||
// Stub persistance store for shell unit tests
|
||||
public class TestPersist : IPersist, IUserPersist {
|
||||
public Dictionary<string, Dictionary<string, object>> Values = new Dictionary<string, Dictionary<string, object>>();
|
||||
|
||||
public Task set<T>(string ns, string key, T value) {
|
||||
TaskCompletionSource<object> source = new TaskCompletionSource<object>();
|
||||
try {
|
||||
Values[ns][key] = value;
|
||||
source.TrySetResult(null);
|
||||
} catch (Exception e) {
|
||||
source.TrySetException(e);
|
||||
}
|
||||
|
||||
return source.Task;
|
||||
}
|
||||
|
||||
public Task clear(string ns, string key) {
|
||||
TaskCompletionSource<object> source = new TaskCompletionSource<object>();
|
||||
try {
|
||||
Values[ns].Remove(key);
|
||||
source.TrySetResult(null);
|
||||
} catch (Exception e) {
|
||||
source.TrySetException(e);
|
||||
}
|
||||
return source.Task;
|
||||
}
|
||||
|
||||
public Task<T> get<T>(string ns, string key) {
|
||||
TaskCompletionSource<T> source = new TaskCompletionSource<T>();
|
||||
try {
|
||||
T result = (T)Values[ns][key];
|
||||
source.TrySetResult(result);
|
||||
} catch (Exception e) {
|
||||
source.TrySetException(e);
|
||||
}
|
||||
return source.Task;
|
||||
}
|
||||
|
||||
public Task<T[]> get_many<T>(string ns, string key) {
|
||||
var source = new TaskCompletionSource<T[]>();
|
||||
try {
|
||||
source.TrySetResult((T[])Values[ns][key]);
|
||||
} catch (Exception e) {
|
||||
source.TrySetException(e);
|
||||
}
|
||||
return source.Task;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Tuple<T, DateTime>>> get_history<T>(string ns, string key) {
|
||||
var res = await get<T>(ns, key);
|
||||
return new Tuple<T, DateTime>[] { Tuple.Create(res, DateTime.Today) };
|
||||
}
|
||||
|
||||
public Task<IEnumerable<PersistResult<T>>> query<T>(string ns, string pattern) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IDisposable subscribe<T>(string ns, string pattern, Action<IEnumerable<PersistResult<T>>> callback) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Dispose() { }
|
||||
}
|
||||
}
|
||||
using mbts.persist;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.ui.tests {
|
||||
// Stub persistance store for shell unit tests
|
||||
public class TestPersist : IPersist, IUserPersist {
|
||||
public Dictionary<string, Dictionary<string, object>> Values = new Dictionary<string, Dictionary<string, object>>();
|
||||
|
||||
public Task set<T>(string ns, string key, T value) {
|
||||
TaskCompletionSource<object> source = new TaskCompletionSource<object>();
|
||||
try {
|
||||
Values[ns][key] = value;
|
||||
source.TrySetResult(null);
|
||||
} catch (Exception e) {
|
||||
source.TrySetException(e);
|
||||
}
|
||||
|
||||
return source.Task;
|
||||
}
|
||||
|
||||
public Task clear(string ns, string key) {
|
||||
TaskCompletionSource<object> source = new TaskCompletionSource<object>();
|
||||
try {
|
||||
Values[ns].Remove(key);
|
||||
source.TrySetResult(null);
|
||||
} catch (Exception e) {
|
||||
source.TrySetException(e);
|
||||
}
|
||||
return source.Task;
|
||||
}
|
||||
|
||||
public Task<T> get<T>(string ns, string key) {
|
||||
TaskCompletionSource<T> source = new TaskCompletionSource<T>();
|
||||
try {
|
||||
T result = (T)Values[ns][key];
|
||||
source.TrySetResult(result);
|
||||
} catch (Exception e) {
|
||||
source.TrySetException(e);
|
||||
}
|
||||
return source.Task;
|
||||
}
|
||||
|
||||
public Task<T[]> get_many<T>(string ns, string key) {
|
||||
var source = new TaskCompletionSource<T[]>();
|
||||
try {
|
||||
source.TrySetResult((T[])Values[ns][key]);
|
||||
} catch (Exception e) {
|
||||
source.TrySetException(e);
|
||||
}
|
||||
return source.Task;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Tuple<T, DateTime>>> get_history<T>(string ns, string key) {
|
||||
var res = await get<T>(ns, key);
|
||||
return new Tuple<T, DateTime>[] { Tuple.Create(res, DateTime.Today) };
|
||||
}
|
||||
|
||||
public Task<IEnumerable<PersistResult<T>>> query<T>(string ns, string pattern) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IDisposable subscribe<T>(string ns, string pattern, Action<IEnumerable<PersistResult<T>>> callback) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Dispose() { }
|
||||
}
|
||||
}
|
||||
File renamed without changes.
+113
-69
@@ -1,16 +1,24 @@
|
||||
using bts.shell.pnl;
|
||||
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
using mbts.ui.settings;
|
||||
|
||||
using ProtoBuf;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
#nullable enable
|
||||
namespace mbts.spark {
|
||||
using bts.shell;
|
||||
using bts.shell.fills;
|
||||
using bts.shell.market_view;
|
||||
using bts.shell.orderbook;
|
||||
using bts.shell.pnl;
|
||||
using bts.shell.time_and_sales;
|
||||
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
using mbts.ui.settings;
|
||||
|
||||
using ProtoBuf;
|
||||
|
||||
using Spark.Trading;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
interface IDefaultableSettings {
|
||||
bool use_defaults { get; set; }
|
||||
}
|
||||
@@ -21,21 +29,21 @@ namespace mbts.spark {
|
||||
[ProtoContract]
|
||||
class UserSettings {
|
||||
public static UserSettings factory_defaults =>
|
||||
new UserSettings {
|
||||
new() {
|
||||
_ladder = LadderSettings.Default,
|
||||
_notification = NotificationSettings.Default,
|
||||
_market_view_grid = bts.shell.market_view.MarketViewSettings.DefaultGridSettings,
|
||||
_fills_grid = bts.shell.fills.FillsSettings.DefaultGridSettings,
|
||||
_time_and_sales_grid = bts.shell.time_and_sales.TimeAndSalesSettings.DefaultGridSettings,
|
||||
_synthetic_management_grid = bts.shell.SyntheticManagementWindowFactory.StartupData.DefaultGridSettings,
|
||||
_reconcile_report_grid = Spark.Trading.ReconcileReportSettings.Default().grid,
|
||||
_order_book_grid = bts.shell.orderbook.OrderBookStartupData.DefaultGrid
|
||||
_market_view_grid = MarketViewSettings.DefaultGridSettings,
|
||||
_fills_grid = FillsSettings.DefaultGridSettings,
|
||||
_time_and_sales_grid = TimeAndSalesSettings.DefaultGridSettings,
|
||||
_synthetic_management = SyntheticManagementSettings.default_grid_settings,
|
||||
_reconcile_report = ReconcileReportSettings.Default().grid,
|
||||
_order_book = OrderBookStartupData.DefaultGrid
|
||||
};
|
||||
|
||||
[ProtoMember(1)]
|
||||
LadderSettings _ladder;
|
||||
LadderSettings? _ladder;
|
||||
[ProtoMember(11)]
|
||||
readonly LadderSettingsProfile[] _ladder_profiles;
|
||||
LadderSettingsProfile[]? _ladder_profiles;
|
||||
/// When Profiles Are Deleted, ladders that were using that profile shall copy the profile's settings to a local profile.
|
||||
/// Therefor:
|
||||
/// Deleted profile ids must never be reused.
|
||||
@@ -48,65 +56,96 @@ namespace mbts.spark {
|
||||
uint _last_ladder_profile_id;
|
||||
// removing NotificationSettings these from proto-serialization, since they are disabled by default for now.
|
||||
// This way, when they are enabled, there won't be any backwards compatability issues to worry about, as no clients will have persisted them yet.
|
||||
NotificationSettings _notification;
|
||||
NotificationSettings? _notification;
|
||||
|
||||
[ProtoMember(5)]
|
||||
GridSettings _market_view_grid;
|
||||
GridSettings? _market_view_grid;
|
||||
[ProtoMember(6)]
|
||||
GridSettings _time_and_sales_grid;
|
||||
GridSettings? _time_and_sales_grid;
|
||||
[ProtoMember(7)]
|
||||
GridSettings _fills_grid;
|
||||
GridSettings? _fills_grid;
|
||||
[ProtoMember(15)]
|
||||
GridSettings? _day_fills_grid;
|
||||
[ProtoMember(8)]
|
||||
GridSettings _synthetic_management_grid;
|
||||
GridSettings? _synthetic_management;
|
||||
[ProtoMember(14)]
|
||||
GridSettings _reconcile_report_grid;
|
||||
GridSettings? _reconcile_report;
|
||||
[ProtoMember(9)]
|
||||
bts.shell.orderbook.OrderBookGridSettings _order_book_grid;
|
||||
OrderBookGridSettings? _order_book;
|
||||
[ProtoMember(10)]
|
||||
PNLSettings _pnl;
|
||||
PNLSettings? _pnl;
|
||||
[ProtoMember(13)]
|
||||
GlobalAlertSettings _alerts;
|
||||
GlobalAlertSettings? _alerts;
|
||||
|
||||
public UserSettings() { }
|
||||
|
||||
public UserSettings(LadderSettingsProfile[] ladder_profiles) =>
|
||||
_ladder_profiles = ladder_profiles;
|
||||
public LadderSettings ladder =>
|
||||
_ladder ??= LadderSettings.Default;
|
||||
|
||||
public LadderSettings ladder => _ladder ?? (_ladder = LadderSettings.Default);
|
||||
public IReadOnlyList<LadderSettingsProfile> ladder_profiles => _ladder_profiles ?? Array.Empty<LadderSettingsProfile>();
|
||||
public uint next_ladder_profile_id => _last_ladder_profile_id + 1;
|
||||
public NotificationSettings notification => _notification ?? (_notification = NotificationSettings.Default);
|
||||
public GridSettings market_view_grid => _market_view_grid ?? (_market_view_grid = bts.shell.market_view.MarketViewSettings.DefaultGridSettings);
|
||||
public GridSettings time_and_sales_grid => _time_and_sales_grid ?? (_time_and_sales_grid = GridSettings.Default.with(bts.shell.time_and_sales.TimeAndSalesSettings.DefaultColumns.all));
|
||||
public GridSettings fills_grid => _fills_grid ?? (_fills_grid = bts.shell.fills.FillsSettings.DefaultGridSettings);
|
||||
public GridSettings synthetic_management_grid => _synthetic_management_grid ?? (_synthetic_management_grid = bts.shell.SyntheticManagementWindowFactory.StartupData.DefaultGridSettings);
|
||||
public GridSettings reconcile_report_grid => _reconcile_report_grid ??= Spark.Trading.ReconcileReportSettings.Default().grid;
|
||||
public PNLSettings pnl => _pnl ?? (_pnl = PNLSettings.Default);
|
||||
public bts.shell.orderbook.OrderBookGridSettings order_book_grid => _order_book_grid ?? (_order_book_grid = bts.shell.orderbook.OrderBookStartupData.Default.grid_settings_wrapper());
|
||||
public IReadOnlyList<LadderSettingsProfile> ladder_profiles =>
|
||||
_ladder_profiles ?? Array.Empty<LadderSettingsProfile>();
|
||||
|
||||
public GlobalAlertSettings alerts => _alerts ?? (_alerts = new GlobalAlertSettings());
|
||||
public uint next_ladder_profile_id =>
|
||||
_last_ladder_profile_id + 1;
|
||||
|
||||
public UserSettings with(LadderSettings ladder = null,
|
||||
LadderSettingsProfile[] ladder_profiles = null,
|
||||
NotificationSettings notification = null,
|
||||
GridSettings provided_market_view_gridsettings = null,
|
||||
GridSettings time_and_sales = null,
|
||||
GridSettings provided_fills_gridsettings = null,
|
||||
GridSettings provided_synthetic_management_gridsettings = null,
|
||||
GridSettings reconcile_report_grid = null,
|
||||
PNLSettings pnl = null,
|
||||
bts.shell.orderbook.OrderBookGridSettings order_book_grid = null,
|
||||
GlobalAlertSettings alerts = null) {
|
||||
var us = new UserSettings(ladder_profiles ?? _ladder_profiles) {
|
||||
public NotificationSettings notification =>
|
||||
_notification ??= NotificationSettings.Default;
|
||||
|
||||
public GridSettings market_view_grid =>
|
||||
_market_view_grid ??= MarketViewSettings.DefaultGridSettings;
|
||||
|
||||
public GridSettings time_and_sales_grid =>
|
||||
_time_and_sales_grid ??= GridSettings.Default.with(
|
||||
TimeAndSalesSettings.DefaultColumns.all);
|
||||
|
||||
public GridSettings fills_grid =>
|
||||
_fills_grid ??= FillsSettings.DefaultGridSettings;
|
||||
|
||||
public GridSettings day_fills_grid =>
|
||||
_day_fills_grid ??= DayFillsSettings.default_grid();
|
||||
|
||||
public GridSettings synthetic_management_grid =>
|
||||
_synthetic_management ??=
|
||||
SyntheticManagementSettings.default_grid_settings;
|
||||
|
||||
public GridSettings reconcile_report_grid =>
|
||||
_reconcile_report ??= ReconcileReportSettings.Default().grid ??
|
||||
throw new InvalidOperationException();
|
||||
|
||||
public PNLSettings pnl =>
|
||||
_pnl ??= PNLSettings.Default;
|
||||
|
||||
public OrderBookGridSettings order_book_grid =>
|
||||
_order_book ??= OrderBookStartupData.Default.grid_settings_wrapper();
|
||||
|
||||
public GlobalAlertSettings alerts =>
|
||||
_alerts ??= new GlobalAlertSettings();
|
||||
|
||||
public UserSettings with(
|
||||
LadderSettings? ladder = null,
|
||||
LadderSettingsProfile[]? ladder_profiles = null,
|
||||
NotificationSettings? notification = null,
|
||||
GridSettings? market_view = null,
|
||||
GridSettings? time_and_sales = null,
|
||||
GridSettings? fills = null,
|
||||
GridSettings? day_fills = null,
|
||||
GridSettings? synthetic_management = null,
|
||||
GridSettings? reconcile_report = null,
|
||||
PNLSettings? pnl = null,
|
||||
OrderBookGridSettings? order_book_grid = null,
|
||||
GlobalAlertSettings? alerts = null) {
|
||||
var us = new UserSettings() {
|
||||
_ladder_profiles = ladder_profiles ?? _ladder_profiles,
|
||||
_ladder = ladder ?? _ladder,
|
||||
_notification = notification ?? _notification,
|
||||
_market_view_grid = provided_market_view_gridsettings ?? _market_view_grid,
|
||||
_market_view_grid = market_view ?? _market_view_grid,
|
||||
_time_and_sales_grid = time_and_sales ?? _time_and_sales_grid,
|
||||
_fills_grid = provided_fills_gridsettings ?? _fills_grid,
|
||||
_synthetic_management_grid = provided_synthetic_management_gridsettings ?? _synthetic_management_grid,
|
||||
_reconcile_report_grid = reconcile_report_grid ?? _reconcile_report_grid,
|
||||
_fills_grid = fills ?? _fills_grid,
|
||||
_day_fills_grid = day_fills ?? _day_fills_grid,
|
||||
_synthetic_management = synthetic_management ?? _synthetic_management,
|
||||
_reconcile_report = reconcile_report ?? _reconcile_report,
|
||||
_pnl = pnl ?? _pnl,
|
||||
_order_book_grid = order_book_grid ?? _order_book_grid,
|
||||
_order_book = order_book_grid ?? _order_book,
|
||||
_alerts = alerts ?? _alerts
|
||||
};
|
||||
us._last_ladder_profile_id = Math.Max(_last_ladder_profile_id, us.ladder_profiles.Select(p => p.id).MaxOrDefault());
|
||||
@@ -130,9 +169,9 @@ namespace mbts.spark {
|
||||
[ProtoContract]
|
||||
class NotificationSettings {
|
||||
[ProtoMember(1)]
|
||||
readonly SoundNotificationSettings _sound_notification;
|
||||
readonly SoundNotificationSettings? _sound_notification;
|
||||
[ProtoMember(2)]
|
||||
readonly ToastNotificationSettings _toast_notification;
|
||||
readonly ToastNotificationSettings? _toast_notification;
|
||||
|
||||
public NotificationSettings() { }
|
||||
public NotificationSettings(SoundNotificationSettings sound_notification, ToastNotificationSettings toast_notification) {
|
||||
@@ -142,8 +181,8 @@ namespace mbts.spark {
|
||||
|
||||
public static NotificationSettings Default => new NotificationSettings(SoundNotificationSettings.Default, ToastNotificationSettings.Default);
|
||||
|
||||
public SoundNotificationSettings sound_notification => _sound_notification;
|
||||
public ToastNotificationSettings toast_notification => _toast_notification;
|
||||
public SoundNotificationSettings? sound_notification => _sound_notification;
|
||||
public ToastNotificationSettings? toast_notification => _toast_notification;
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
@@ -155,7 +194,7 @@ namespace mbts.spark {
|
||||
public SoundNotificationSettings(bool enabled) =>
|
||||
_enabled = enabled;
|
||||
|
||||
public static SoundNotificationSettings Default => new SoundNotificationSettings(true);
|
||||
public static SoundNotificationSettings Default => new(true);
|
||||
|
||||
public bool enabled => _enabled;
|
||||
}
|
||||
@@ -172,16 +211,17 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
public static ToastNotificationSettings Default =>
|
||||
new ToastNotificationSettings(Mode.Flash, new Duration { Seconds = 5 }, 320);
|
||||
new(Mode.Flash, new Duration { Seconds = 5 }, 320);
|
||||
|
||||
[ProtoMember(1)]
|
||||
readonly Mode _mode;
|
||||
[ProtoMember(2)]
|
||||
readonly Duration _duration;
|
||||
readonly Duration? _duration;
|
||||
[ProtoMember(3)]
|
||||
readonly double _max_height;
|
||||
|
||||
public ToastNotificationSettings() { }
|
||||
|
||||
public ToastNotificationSettings(Mode mode, Duration duration, double max_height) {
|
||||
_mode = mode;
|
||||
_duration = duration;
|
||||
@@ -189,7 +229,11 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
public Mode mode => _mode;
|
||||
public TimeSpan? duration => _mode == Mode.Flash ? _duration?.ToTimeSpan() ?? TimeSpan.FromSeconds(5) : new TimeSpan?();
|
||||
public TimeSpan duration =>
|
||||
_mode switch {
|
||||
Mode.Flash => _duration?.ToTimeSpan() ?? TimeSpan.FromSeconds(5),
|
||||
_ => new()
|
||||
};
|
||||
public double max_height => _max_height;
|
||||
}
|
||||
}
|
||||
File renamed without changes.
+16
-5
@@ -1,4 +1,4 @@
|
||||
using bts;
|
||||
using bts;
|
||||
using bts.settings;
|
||||
using bts.shell.pnl;
|
||||
using bts.utils;
|
||||
@@ -25,10 +25,11 @@ namespace mbts.persist {
|
||||
const string NAME_SPACE = "settings", DEFAULT_KEY = "default";
|
||||
|
||||
static readonly IImmutableProperty<UserSettings, GridSettings>
|
||||
_fills_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.fills_grid, (us, gs) => us.with(provided_fills_gridsettings: gs)),
|
||||
_mview_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.market_view_grid, (us, gs) => us.with(provided_market_view_gridsettings: gs)),
|
||||
_synth_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.synthetic_management_grid, (us, gs) => us.with(provided_synthetic_management_gridsettings: gs)),
|
||||
_reconcile_report_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.reconcile_report_grid, (us, gs) => us.with(reconcile_report_grid: gs));
|
||||
_fills_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.fills_grid, (us, gs) => us.with(fills: gs)),
|
||||
_day_fills_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.day_fills_grid, (us, gs) => us.with(day_fills: gs)),
|
||||
_mview_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.market_view_grid, (us, gs) => us.with(market_view: gs)),
|
||||
_synth_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.synthetic_management_grid, (us, gs) => us.with(synthetic_management: gs)),
|
||||
_reconcile_report_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.reconcile_report_grid, (us, gs) => us.with(reconcile_report: gs));
|
||||
|
||||
static readonly IImmutableProperty<UserSettings, PNLSettings>
|
||||
_pnl_propi = ImmutableProperty.create<UserSettings, PNLSettings>(us => us.pnl, (us, pnl) => us.with(pnl: pnl));
|
||||
@@ -36,6 +37,7 @@ namespace mbts.persist {
|
||||
readonly object _default_settings_lock = new object();
|
||||
readonly BehaviorSubject<UserSettings> _default_settings_subject = new BehaviorSubject<UserSettings>(UserSettings.factory_defaults);
|
||||
readonly IEnumerable<IFillsGridSettingsMigrationRule> _fills_migration_rules;
|
||||
readonly IEnumerable<IDayFillsGridSettingsMigrationRule> _day_fills_migration_rules;
|
||||
readonly IEnumerable<IMarketViewGridSettingsMigrationRule> _mview_migration_rules;
|
||||
readonly IEnumerable<IPNLSettingsMigrationRule> _pnl_migration_rules;
|
||||
readonly IEnumerable<ISyntheticManagementMigrationRule> _synth_migration_rules;
|
||||
@@ -48,6 +50,7 @@ namespace mbts.persist {
|
||||
public UserSettingsHub(
|
||||
IUserPersist persist,
|
||||
[ImportMany] IEnumerable<IFillsGridSettingsMigrationRule> fills_migration_rules,
|
||||
[ImportMany] IEnumerable<IDayFillsGridSettingsMigrationRule> day_fills_migration_rules,
|
||||
[ImportMany] IEnumerable<IMarketViewGridSettingsMigrationRule> mview_migration_rules,
|
||||
[ImportMany] IEnumerable<IPAndLGridSettingsMigrationRule> pandl_migration_rules,
|
||||
[ImportMany] IEnumerable<IPNLSettingsMigrationRule> pnl_migration_rules,
|
||||
@@ -56,6 +59,7 @@ namespace mbts.persist {
|
||||
//
|
||||
_persist = persist;
|
||||
_fills_migration_rules = fills_migration_rules ?? Enumerable.Empty<IFillsGridSettingsMigrationRule>();
|
||||
_day_fills_migration_rules = day_fills_migration_rules ?? Enumerable.Empty<IDayFillsGridSettingsMigrationRule>();
|
||||
_mview_migration_rules = mview_migration_rules ?? Enumerable.Empty<IMarketViewGridSettingsMigrationRule>();
|
||||
_pnl_migration_rules = pnl_migration_rules ?? Enumerable.Empty<IPNLSettingsMigrationRule>();
|
||||
_synth_migration_rules = synth_migration_rules ?? Enumerable.Empty<ISyntheticManagementMigrationRule>();
|
||||
@@ -152,6 +156,13 @@ namespace mbts.persist {
|
||||
_reconcile_report_migration_rules,
|
||||
_reconcile_report_propi);
|
||||
|
||||
public IWindowSettingsManager<GridSettings> create_day_fills_settings_manager(
|
||||
GridSettings instance_settings) =>
|
||||
_create_settings_manager(
|
||||
instance_settings,
|
||||
_day_fills_migration_rules,
|
||||
_day_fills_propi);
|
||||
|
||||
public async Task save_default(UserSettings value) {
|
||||
// notify observers before persisting so the changes are reflected immediately in the ui
|
||||
lock (_default_settings_lock) {
|
||||
@@ -0,0 +1,71 @@
|
||||
#nullable enable
|
||||
namespace mbts.ui.shell {
|
||||
using ProtoBuf;
|
||||
|
||||
using Spark.Core.Protobuf;
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
[ProtoContract]
|
||||
public class WindowPosition : IProtobuf<WindowPosition> {
|
||||
[ProtoMember(3)]
|
||||
public int width { get; set; }
|
||||
|
||||
[ProtoMember(4)]
|
||||
public int height { get; set; }
|
||||
|
||||
[ProtoMember(5)]
|
||||
public int left { get; set; }
|
||||
|
||||
[ProtoMember(6)]
|
||||
public int top { get; set; }
|
||||
|
||||
[ProtoMember(7)]
|
||||
public bool is_maximized { get; set; }
|
||||
|
||||
[ProtoMember(8)]
|
||||
public string? host_id { get; set; }
|
||||
|
||||
[ProtoMember(9)]
|
||||
public int tab_index { get; set; }
|
||||
|
||||
[ProtoMember(100)]
|
||||
public bool horizontal { get; set; }
|
||||
|
||||
[ProtoMember(101), DefaultValue(true)]
|
||||
public bool show_text { get; set; } = true;
|
||||
|
||||
[ProtoMember(102), DefaultValue(true)]
|
||||
public bool always_on_top { get; set; } = true;
|
||||
|
||||
[ProtoMember(104)]
|
||||
public string? custom_title { get; set; }
|
||||
|
||||
public bool Equals(WindowPosition? other) =>
|
||||
other is not null &&
|
||||
width == other.width &&
|
||||
height == other.height &&
|
||||
left == other.left &&
|
||||
top == other.top &&
|
||||
is_maximized == other.is_maximized &&
|
||||
host_id == other.host_id &&
|
||||
tab_index == other.tab_index &&
|
||||
horizontal == other.horizontal &&
|
||||
show_text == other.show_text &&
|
||||
always_on_top == other.always_on_top &&
|
||||
custom_title == other.custom_title;
|
||||
|
||||
public override bool Equals(object? obj) =>
|
||||
Equals(obj as WindowPosition);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
GetType().GetHashCode();
|
||||
|
||||
public WindowPosition Clone() =>
|
||||
ProtobufSerializationHelper.clone(this);
|
||||
|
||||
object ICloneable.Clone() =>
|
||||
Clone();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#nullable enable
|
||||
namespace mbts.ui.shell {
|
||||
using bts.utils;
|
||||
|
||||
using ProtoBuf;
|
||||
|
||||
using Spark.Core.Protobuf;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
[ProtoContract]
|
||||
public class WindowSettings : IProtobuf<WindowSettings> {
|
||||
[ProtoMember(1)]
|
||||
public string? owner { get; set; }
|
||||
|
||||
[ProtoMember(2)]
|
||||
public byte[]? app_data { get; set; }
|
||||
|
||||
[ProtoMember(8)]
|
||||
public WindowPosition? position { get; set; }
|
||||
|
||||
[ProtoMember(9)]
|
||||
public string? title { get; set; }
|
||||
|
||||
public bool Equals(WindowSettings? other) =>
|
||||
other is not null &&
|
||||
owner == other.owner &&
|
||||
app_data.safe_sequence_equals(other.app_data) &&
|
||||
position.safe_equals(other.position) &&
|
||||
title == other.title;
|
||||
|
||||
public override bool Equals(object? obj) =>
|
||||
Equals(obj as WindowSettings);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
GetType().GetHashCode();
|
||||
|
||||
public WindowSettings Clone() =>
|
||||
ProtobufSerializationHelper.clone(this);
|
||||
|
||||
object ICloneable.Clone() =>
|
||||
Clone();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
#nullable enable
|
||||
namespace bts.api.position {
|
||||
namespace Spark.Trading {
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.api.orderman;
|
||||
using bts.api.position;
|
||||
using bts.shell.pnl;
|
||||
|
||||
using mbts.ui;
|
||||
|
||||
using Spark.Trading;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
@@ -17,10 +16,10 @@ namespace bts.api.position {
|
||||
IObservable<TableUpdate<(SecurityImmutable?, PositionUnitImmutable), int>> on_positions { get; }
|
||||
IObservable<TableUpdate<(SecurityImmutable? sec, RetrievedExchangePositionImmutable exch_pos), AccountSecurityKey>> on_exchange_positions { get; }
|
||||
IObservable<TableUpdate<ReconcileReportRowData, AccountSecurityKey>> merged_positions { get; }
|
||||
IObservable<TableUpdate<DayFillsRowData, DayFillsRowKey>> day_fills { get; }
|
||||
|
||||
// pnl
|
||||
IObservable<TableUpdate<(SecurityImmutable?, PNLUnitImmutable, QuantityConversionData<double>), int>> on_pnl { get; }
|
||||
IObservable<TableUpdate<PNLRowData, AccountSecurityKey>> security_account_pnl { get; }
|
||||
IObservable<TableUpdate<PNLRowData, AccountSecurityKey>> pnl { get; }
|
||||
|
||||
IObservable<TableUpdate<(SecurityImmutable?, PositionUnitImmutable), int>> on_security_positions(
|
||||
uint security_key);
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
#nullable enable
|
||||
namespace bts.api.position {
|
||||
namespace Spark.Trading {
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.api.orderman;
|
||||
using bts.api.position;
|
||||
using bts.collections;
|
||||
using bts.shell.pnl;
|
||||
using bts.spark;
|
||||
|
||||
using mbts;
|
||||
using mbts.analytics;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
|
||||
using Spark.Core;
|
||||
using Spark.Core.Reactive;
|
||||
using Spark.Model.Trading;
|
||||
using Spark.Trading;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -64,27 +67,11 @@ namespace bts.api.position {
|
||||
.Table()
|
||||
.Cache();
|
||||
|
||||
on_pnl = admin_model
|
||||
.permission_filter(
|
||||
_position_service.subscribei_pnl_data().Naggle(interval, scheduler),
|
||||
p => p.Pos.AccountId)
|
||||
.join(security_store, p => p.Pos.SecurityId)
|
||||
.Select(
|
||||
tup => (tup.sec, tup.val, new QuantityConversionData<double>(
|
||||
security_auxiliary_model.get_display_quantity_divisor(tup.sec),
|
||||
QuantityConversionOpType.DivideActual)),
|
||||
tup => tup.val.RecordId)
|
||||
.TableCheckedAutoCorrect(
|
||||
EqualityComparer<(SecurityImmutable?, PNLUnitImmutable, QuantityConversionData<double>)>.Default)
|
||||
.Where(t => t.has_changes())
|
||||
.Cache();
|
||||
day_fills = DayFillsDataSource.create(bus, security_store);
|
||||
|
||||
// security account pnl
|
||||
security_account_pnl = on_pnl
|
||||
#if DEBUG
|
||||
.AssertIncremental(p => new AccountSecurityKey(p.Item2.Pos.AccountId, p.Item2.Pos.SecurityId))
|
||||
#endif
|
||||
.SelectKeyValue(PNLRowDataFactory.create, PNLRowData.key_fn)
|
||||
pnl = bus.subscribe(SparkTags.ReportBlackboardTags.PNL.PNLData)
|
||||
.Select(d => d.position_data.ToDictionary(u => u.id(), PNLRowData.from_pnl_unit))
|
||||
.Table(PNLRowData.key_fn)
|
||||
.FullJoin(
|
||||
order_data.working_account_security_orders,
|
||||
PNLRowData.key_fn,
|
||||
@@ -120,9 +107,9 @@ namespace bts.api.position {
|
||||
|
||||
public IObservable<TableUpdate<(SecurityImmutable? sec, RetrievedExchangePositionImmutable exch_pos), AccountSecurityKey>> on_exchange_positions { get; }
|
||||
public IObservable<TableUpdate<(SecurityImmutable?, PositionUnitImmutable), int>> on_positions { get; }
|
||||
public IObservable<TableUpdate<(SecurityImmutable?, PNLUnitImmutable, QuantityConversionData<double>), int>> on_pnl { get; }
|
||||
public IObservable<TableUpdate<PNLRowData, AccountSecurityKey>> pnl { get; }
|
||||
public IObservable<TableUpdate<ReconcileReportRowData, AccountSecurityKey>> merged_positions { get; }
|
||||
public IObservable<TableUpdate<PNLRowData, AccountSecurityKey>> security_account_pnl { get; }
|
||||
public IObservable<TableUpdate<DayFillsRowData, DayFillsRowKey>> day_fills { get; }
|
||||
|
||||
public IObservable<TableUpdate<(SecurityImmutable?, PositionUnitImmutable), int>> on_security_positions(uint security) =>
|
||||
_security_positions_demuxer.subscribe(security);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#nullable enable
|
||||
namespace bts.api.position {
|
||||
namespace Spark.Trading {
|
||||
using bts.api.core;
|
||||
|
||||
using Spark.Api.Position;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
namespace mbts.spark {
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.api.analytics;
|
||||
using bts.api.core;
|
||||
using bts.collections;
|
||||
using bts.shell;
|
||||
using bts.shell.pnl;
|
||||
using bts.spark;
|
||||
|
||||
using mbts.analytics;
|
||||
@@ -12,7 +14,9 @@ namespace mbts.spark {
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
|
||||
using Spark.Core.Data;
|
||||
using Spark.Core.Reactive;
|
||||
using Spark.Trading;
|
||||
using Spark.ViewModel;
|
||||
|
||||
using System;
|
||||
@@ -35,7 +39,13 @@ namespace mbts.spark {
|
||||
|
||||
[ImportingConstructor]
|
||||
public AnalyticsShellModule(
|
||||
IBus bus, WindowManager wm, UserSettingsHub settings_hub, OrdersModel orders_model) {
|
||||
IBus bus,
|
||||
WindowManager wm,
|
||||
UserSettingsHub settings_hub,
|
||||
OrdersModel orders_model,
|
||||
IPositionModel position_model,
|
||||
ISecurityMetadataStore sec_meta_store,
|
||||
Lazy<UserTuple> user) {
|
||||
_wm = wm;
|
||||
_bus = bus;
|
||||
var reports_demuxer = new TableUpdateDemuxer<ReportImmutable?, int>(default, false);
|
||||
@@ -49,6 +59,10 @@ namespace mbts.spark {
|
||||
new AnalyticsExpirationParametersWindowFactory(this, bus),
|
||||
new SlideReportWindowFactory(this, bus, reports_demuxer.subscribe),
|
||||
new ComboReportWindowFactory(this, bus, reports_demuxer.subscribe),
|
||||
new PNLWindowFactory(
|
||||
this, bus, settings_hub, orders_model, position_model, sec_meta_store),
|
||||
new DayFillsWindowFactory(
|
||||
this, bus, settings_hub, position_model, sec_meta_store, user.Value)
|
||||
};
|
||||
var vol_surfaces_src = _bus.subscribe(SparkTags.VolSurfaceListTag).OnDispatcher();
|
||||
var reports_src = _bus.subscribe(SparkTags.ReportBlackboardTags.ListTag).OnDispatcher();
|
||||
@@ -58,6 +72,8 @@ namespace mbts.spark {
|
||||
nullable_reports_src.Subscribe(reports_demuxer),
|
||||
reports_demuxer,
|
||||
vm.launch_exp_params_view_cmd.subscribe_executed(_launch_exp_params_view),
|
||||
vm.launch_pnl_cmd.subscribe_executed(_launch_pnl),
|
||||
vm.launch_day_fills_cmd.subscribe_executed(_launch_day_fills),
|
||||
// vol surface
|
||||
vm.vol_surface_launcher_vm.launch_cmd.subscribe_executed(_launch_vol_surface),
|
||||
vm.vol_surface_launcher_vm.create_cmd.subscribe_executed(_create_vol_surface),
|
||||
@@ -114,6 +130,12 @@ namespace mbts.spark {
|
||||
_bus.post(SparkTags.show_analytics_exp_params, settings);
|
||||
}
|
||||
|
||||
void _launch_pnl() =>
|
||||
_bus.post(SparkTags.ShowPNLTag, null);
|
||||
|
||||
void _launch_day_fills() =>
|
||||
_bus.post(SparkTags.show_day_fills, DayFillsSettings.Default());
|
||||
|
||||
void _launch_vol_surface(int id) {
|
||||
var windows = _wm.list_windows();
|
||||
if (windows.OfType<VolSurfaceWindow>().TryGetFirst(w => w.vs_id == id, out var win)) {
|
||||
@@ -180,7 +202,8 @@ namespace mbts.spark {
|
||||
_bus.post(SparkTags.ShowSlideReportTag, SlideReportSettings.Default(id));
|
||||
|
||||
void _create_combo_report(string _) {
|
||||
var vm = new ComboReportSettingsVM(_bus.subscribe(SparkTags.AccountsTag));
|
||||
var vm = new ComboReportSettingsVM(
|
||||
_bus.subscribe(SparkTags.AccountsTag), _bus.subscribe(SparkTags.SecuritiesTag));
|
||||
vm.load_from(new(new Report { ReportType = Report.Types.ReportType.Slide }));
|
||||
var win = new ComboReportCreationDialog() {
|
||||
DataContext = vm
|
||||
|
||||
@@ -13,6 +13,10 @@ namespace mbts.spark {
|
||||
public KeyValueLauncherVM<int, string> slide_report_launcher_vm { get; } = new() { type_name = "Slide Report" };
|
||||
public KeyValueLauncherVM<int, string> combo_report_launcher_vm { get; } = new() { type_name = "Combo Report" };
|
||||
|
||||
// pnl
|
||||
public EventCommand launch_pnl_cmd { get; } = new();
|
||||
public EventCommand launch_day_fills_cmd { get; } = new();
|
||||
|
||||
public string? selected_window_type {
|
||||
get => _selected_window_type;
|
||||
set => Set(ref _selected_window_type, value);
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
x:ClassModifier="internal"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:bshell="clr-namespace:bts.shell"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:shell="clr-namespace:mbts.ui.shell"
|
||||
xmlns:trading="clr-namespace:Spark.Trading"
|
||||
x:Name="me"
|
||||
Background="Transparent"
|
||||
MinWidth="250"
|
||||
@@ -17,23 +19,25 @@
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="LaunchButton" TargetType="Button" BasedOn="{StaticResource LargeMenuButton}">
|
||||
<Setter Property="Height" Value="32" />
|
||||
<Setter Property="MinWidth" Value="190" />
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="Padding" Value="16,6,6,6" />
|
||||
</Style>
|
||||
|
||||
<DataTemplate x:Key="LaunchItemTemplate">
|
||||
<Button
|
||||
Height="32"
|
||||
MinWidth="190"
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
Padding="12,6,6,6"
|
||||
Command="{Binding DataContext.launch_cmd, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
|
||||
CommandParameter="{Binding key}"
|
||||
Style="{StaticResource LargeMenuButton}"
|
||||
>
|
||||
Style="{StaticResource LaunchButton}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="Label"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{Binding value}" VerticalAlignment="Center" Margin="4,0,7,0" />
|
||||
<TextBlock Text="{Binding value}" VerticalAlignment="Center" Margin="0,0,7,0" />
|
||||
<Button
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Right"
|
||||
@@ -93,6 +97,8 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Button
|
||||
@@ -174,5 +180,32 @@
|
||||
/>
|
||||
</ContentControl>
|
||||
|
||||
<ToggleButton
|
||||
Grid.Row="8"
|
||||
c:RadioButtonGroupManager.Value="pnl"
|
||||
c:RadioButtonGroupManager.Manager="{StaticResource WindowTypeRadioButtonGroupManager}"
|
||||
Margin="0,6,0,0"
|
||||
Content="P&L Reports"
|
||||
IsChecked="{Binding Path='(u:ExpandCollapseAnimator.IsExpanded)', ElementName=PNLContent, Mode=TwoWay}"
|
||||
Style="{StaticResource LargeMenuToggleButton}" />
|
||||
|
||||
<ContentControl Grid.Row="9" Height="0">
|
||||
<Grid x:Name="PNLContent">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Button
|
||||
Content="{x:Static bshell:PNLWindow.WINDOW_TITLE}"
|
||||
Command="{Binding launch_pnl_cmd}"
|
||||
Style="{StaticResource LaunchButton}" />
|
||||
<Button
|
||||
Grid.Row="1"
|
||||
Content="{x:Static trading:DayFillsWindow.WINDOW_TITLE}"
|
||||
Command="{Binding launch_day_fills_cmd}"
|
||||
Style="{StaticResource LaunchButton}" />
|
||||
</Grid>
|
||||
</ContentControl>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -25,6 +25,7 @@
|
||||
VerticalAlignment="Stretch"
|
||||
HorizontalAlignment="Stretch"
|
||||
Margin="12,12,10,12"
|
||||
MaxHeight="400"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||
Grid.IsSharedSizeScope="True"
|
||||
ItemsSource="{Binding columns}"
|
||||
|
||||
@@ -65,18 +65,15 @@
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<Grid
|
||||
Grid.Row="2"
|
||||
Background="{x:Static u:BTSColors.dialog_skirt_brush}">
|
||||
|
||||
<Grid Grid.Row="2" Background="{u:BTSBrush dialog_skirt}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<!--PAD LEFT-->
|
||||
<ColumnDefinition Width="12" />
|
||||
<!--ADD ITEM BUTTON-->
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<!--SPACING-->
|
||||
<ColumnDefinition Width="8" />
|
||||
<!--TIME PICKER-->
|
||||
<ColumnDefinition Width="80" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<!--PAD RIGHT-->
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
@@ -91,7 +88,6 @@
|
||||
x:Name="time_picker"
|
||||
Grid.Column="3"
|
||||
Background="White"
|
||||
Width="80"
|
||||
TimeTuple="{Binding new_actual_time}"
|
||||
KeyDown="time_picker_KeyDown">
|
||||
<Validation.ErrorTemplate>
|
||||
|
||||
@@ -257,6 +257,9 @@
|
||||
ContextMenuOpening="_on_context_menu_opening">
|
||||
<c:DIYGrid.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem
|
||||
Header="Populate Empty Expirations"
|
||||
Command="{Binding populate_empty_exps_cmd}" />
|
||||
<MenuItem Header="Settings">
|
||||
<MenuItem.Icon>
|
||||
<Image
|
||||
|
||||
@@ -134,7 +134,14 @@
|
||||
// don't initialize more than once
|
||||
if (_time_editor_popup != null) return;
|
||||
var adorner_layer = AdornerLayer.GetAdornerLayer(adorned_grid);
|
||||
_time_editor_popup = new PopupAdorner(adorned_grid, vol_time_popup_button, _get_time_editor_control(), HorizontalPosition.Left, VerticalPosition.Top, 0.5 * ((ToggleButton)sender).ActualWidth, 0d) { IsHitTestVisible = true };
|
||||
_time_editor_popup = new PopupAdorner(
|
||||
adorned_grid,
|
||||
vol_time_popup_button,
|
||||
_get_time_editor_control(),
|
||||
HorizontalPosition.Left,
|
||||
VerticalPosition.Top,
|
||||
44,
|
||||
0d) { IsHitTestVisible = true };
|
||||
_time_editor_popup.SetBinding(PopupAdorner.DataContextProperty, "globals");
|
||||
_time_editor_popup.SetBinding(PopupAdorner.IsOpenProperty, new Binding("vol_time_popup_open") { Mode = BindingMode.TwoWay });
|
||||
_time_editor_popup.Opened += _time_editor_popup_Opened;
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
public override string window_type => WINDOW_TYPE;
|
||||
string ISharedWindow.thread_id =>
|
||||
config.Configuration.get<bts.config.MultiThreadedWindows>().VolSurface ? "VolSurface" : null;
|
||||
config.Configuration.get<bts.config.MultiThreadedWindows>().vol_surface ? "VolSurface" : null;
|
||||
|
||||
public int vs_id => _startup_data.id;
|
||||
public string vs_name { get; }
|
||||
@@ -46,7 +46,7 @@
|
||||
var dummy_view = new Border {
|
||||
Background = BTSColors.UI.default_background.to_brush().frozen(),
|
||||
Padding = new(8),
|
||||
Child = new TextBlock { Text = "Dummy Window" }
|
||||
Child = new TextBlock { Text = "Loading ..." }
|
||||
};
|
||||
_dummy_view = dummy_view;
|
||||
|
||||
|
||||
@@ -2,44 +2,46 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Composition;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.ui.shell {
|
||||
|
||||
public interface IBookmarks {
|
||||
void save_bookmark(IShellWindow window);
|
||||
void save_bookmark(WindowState window);
|
||||
void remove(WindowState window);
|
||||
Task save_bookmark(IShellWindow window);
|
||||
void save_bookmark(WindowSettings window);
|
||||
void remove(WindowSettings window);
|
||||
void clear();
|
||||
IEnumerable<WindowState> bookmarks { get; }
|
||||
IEnumerable<WindowSettings> bookmarks { get; }
|
||||
}
|
||||
|
||||
[Export(typeof(IBookmarks))]
|
||||
public class BookmarksModel : IBookmarks {
|
||||
readonly ISettingsCollector _settings_collector;
|
||||
readonly Dictionary<string, WindowState> _bookmarks = new Dictionary<string, WindowState>();
|
||||
readonly Dictionary<string, WindowSettings> _bookmarks = new();
|
||||
|
||||
[ImportingConstructor]
|
||||
public BookmarksModel(ISettingsCollector settings) {
|
||||
_settings_collector = settings;
|
||||
}
|
||||
public void save_bookmark(IShellWindow window) {
|
||||
var state = _settings_collector.get_window_state(window);
|
||||
|
||||
public async Task save_bookmark(IShellWindow window) {
|
||||
var state = await _settings_collector.get_window_state(window);
|
||||
if (state != null) {
|
||||
_bookmarks[state.title] = state;
|
||||
}
|
||||
}
|
||||
public void save_bookmark(WindowState window) {
|
||||
|
||||
public void save_bookmark(WindowSettings window) =>
|
||||
_bookmarks[window.title] = window;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
_bookmarks.Clear();
|
||||
}
|
||||
|
||||
public void remove(WindowState window) {
|
||||
public void remove(WindowSettings window) {
|
||||
_bookmarks.Remove(window.title);
|
||||
}
|
||||
|
||||
public IEnumerable<WindowState> bookmarks => _bookmarks.Values;
|
||||
public IEnumerable<WindowSettings> bookmarks => _bookmarks.Values;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
namespace bts.shell {
|
||||
using bts.api;
|
||||
using bts.api.position;
|
||||
using bts.spark;
|
||||
|
||||
using mbts.co2;
|
||||
@@ -9,6 +8,7 @@
|
||||
using mbts.ui;
|
||||
|
||||
using Spark.Core.Data;
|
||||
using Spark.Trading;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Composition;
|
||||
|
||||
@@ -111,10 +111,10 @@ namespace mbts.spark {
|
||||
new CellAnimation(Columns.Position, CellAnimation.Type.DownArrow, Brushes.Red),
|
||||
new CellAnimation(Columns.DayChange, CellAnimation.Type.UpArrow, Brushes.Green),
|
||||
new CellAnimation(Columns.DayChange, CellAnimation.Type.DownArrow, Brushes.Red),
|
||||
new CellAnimation(Columns.WorkingBids, CellAnimation.Type.Border, BTSColors.warning_brush),
|
||||
new CellAnimation(Columns.WorkingBids, CellAnimation.Type.Border, BTSColors.warning.to_brush()),
|
||||
new CellAnimation(Columns.WorkingBids, CellAnimation.Type.Border, new SolidColorBrush(BTSColors.MarketData.bid)),
|
||||
new CellAnimation(Columns.WorkingBids, CellAnimation.Type.Border, Brushes.Green),
|
||||
new CellAnimation(Columns.WorkingAsks, CellAnimation.Type.Border, BTSColors.warning_brush),
|
||||
new CellAnimation(Columns.WorkingAsks, CellAnimation.Type.Border, BTSColors.warning.to_brush()),
|
||||
new CellAnimation(Columns.WorkingAsks, CellAnimation.Type.Border, new SolidColorBrush(BTSColors.MarketData.ask)),
|
||||
new CellAnimation(Columns.WorkingAsks, CellAnimation.Type.Border, Brushes.Red));
|
||||
private static readonly TimeSpan flash_duration = TimeSpan.FromSeconds(2);
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Api.Position;
|
||||
using Spark.Core;
|
||||
using Spark.Trading;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -32,7 +34,7 @@
|
||||
readonly OrdersModel _orders_model;
|
||||
readonly AnimationManager _animation = new();
|
||||
readonly MyOrderSummarizer _order_summarizer;
|
||||
readonly DeferrableActionWrapper _raise_invalidated;
|
||||
readonly DeferrableAction _raise_invalidated;
|
||||
|
||||
readonly Property<double> _bid_price;
|
||||
readonly Property<double> _ask_price;
|
||||
@@ -317,7 +319,7 @@
|
||||
IMDConsumerHandle _md => security_md.md;
|
||||
|
||||
public void raise_invalidated() =>
|
||||
_raise_invalidated.execute();
|
||||
_raise_invalidated.Invoke();
|
||||
|
||||
public void refresh() {
|
||||
bool dirty = false;
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace bts.shell.market_view {
|
||||
}
|
||||
|
||||
public static GridSettings DefaultGridSettings =>
|
||||
GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criteria, enable_background_color: true);
|
||||
GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criteria);
|
||||
|
||||
public static fills.FillsSettings DefaultAuxiliaryFills {
|
||||
get {
|
||||
@@ -86,7 +86,7 @@ namespace bts.shell.market_view {
|
||||
}
|
||||
}
|
||||
// and enable background color upgrade
|
||||
return s.with(columns, enable_background_color: true);
|
||||
return s.with(columns);
|
||||
}
|
||||
|
||||
static class DefaultColumns {
|
||||
@@ -102,8 +102,21 @@ namespace bts.shell.market_view {
|
||||
public static GridColumnSettings bid_implied_size => _mk(Columns.BidImpliedQty, ColHeader.ImpliedQty, ColWidth.MergedQty, fg: BTSColors.MarketData.bid);
|
||||
public static GridColumnSettings bid_direct_size => _mk(Columns.BidDirectQty, ColHeader.DirectQty, ColWidth.MergedQty, fg: BTSColors.MarketData.bid);
|
||||
public static GridColumnSettings bid_merged_size => _mk(Columns.BidMergedQty, ColHeader.MergedQty, ColWidth.MergedQty, fg: BTSColors.MarketData.bid);
|
||||
public static GridColumnSettings bid => _mk(Columns.Bid, ColHeader.Bid, ColWidth.MViewPrice, fg: BTSColors.header_text, bg: BTSColors.MarketData.bid);
|
||||
public static GridColumnSettings ask => _mk(Columns.Ask, ColHeader.Ask, ColWidth.MViewPrice, fg: BTSColors.header_text, bg: BTSColors.MarketData.ask);
|
||||
|
||||
public static GridColumnSettings bid => _mk(
|
||||
Columns.Bid,
|
||||
ColHeader.Bid,
|
||||
ColWidth.MViewPrice,
|
||||
fg: BTSColors.header_text,
|
||||
bg: BTSColors.MarketData.bid);
|
||||
|
||||
public static GridColumnSettings ask => _mk(
|
||||
Columns.Ask,
|
||||
ColHeader.Ask,
|
||||
ColWidth.MViewPrice,
|
||||
fg: BTSColors.header_text,
|
||||
bg: BTSColors.MarketData.ask);
|
||||
|
||||
public static GridColumnSettings ask_merged_size => _mk(Columns.AskMergedQty, ColHeader.MergedQty, ColWidth.MergedQty, fg: BTSColors.MarketData.ask);
|
||||
public static GridColumnSettings ask_direct_size => _mk(Columns.AskDirectQty, ColHeader.DirectQty, ColWidth.MergedQty, fg: BTSColors.MarketData.ask);
|
||||
public static GridColumnSettings ask_implied_size => _mk(Columns.AskImpliedQty, ColHeader.ImpliedQty, ColWidth.MergedQty, fg: BTSColors.MarketData.ask);
|
||||
@@ -137,8 +150,8 @@ namespace bts.shell.market_view {
|
||||
}
|
||||
|
||||
public static IEnumerable<GridColumnSettings> all =>
|
||||
ReflectionHelper.static_property_delegates_of_type<GridColumnSettings>(typeof(DefaultColumns))
|
||||
.Select(g => g());
|
||||
ReflectionHelper.static_property_getters<GridColumnSettings>(typeof(DefaultColumns))
|
||||
.Select(pg => pg.get());
|
||||
|
||||
static GridColumnSettings _mk(Columns key, string display_name = null, double width = 80, bool is_visible = true, Color? fg = null, Color? bg = null, HorizontalAlignment h_align = HorizontalAlignment.Right) =>
|
||||
new(col_id(key), display_name, is_visible, font_color_override: fg, width: width, horizontal_alignment: h_align, background_color_override: bg);
|
||||
|
||||
@@ -3,7 +3,6 @@ namespace mbts.spark {
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.api.orderman;
|
||||
using bts.api.position;
|
||||
using bts.collections;
|
||||
using bts.shell.market_view;
|
||||
using bts.utils;
|
||||
@@ -18,8 +17,10 @@ namespace mbts.spark {
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Core;
|
||||
using Spark.Core.Data;
|
||||
using Spark.Core.Reflection;
|
||||
using Spark.Trading;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -47,8 +48,8 @@ namespace mbts.spark {
|
||||
/// Viewmodel class designed for <see cref="ui.spark.MarketViewView"/>
|
||||
/// </summary>
|
||||
partial class MarketViewVM : DisposableViewModelBase, IHandleRowSelection {
|
||||
static readonly IReadOnlyList<Func<MarketViewVM, IDataGridColumnFilter<Row>>> _filter_getters =
|
||||
ReflectionHelper.property_delegates_of_type<MarketViewVM, IDataGridColumnFilter<Row>>().ToReadOnlyList();
|
||||
static readonly IEnumerable<Func<MarketViewVM, IDataGridColumnFilter<Row>>> _filter_getters =
|
||||
ReflectionHelper.property_getters<MarketViewVM, IDataGridColumnFilter<Row>>().Cut2();
|
||||
|
||||
static readonly IComparer<SecurityMD> _sec_md_key_comparer = Comparer<uint>.Default.wrap(SecurityMD.key_fn);
|
||||
static readonly IComparer<Row> _row_key_comparer = _sec_md_key_comparer.wrap<SecurityMD, Row>(r => r.security_md);
|
||||
@@ -63,7 +64,7 @@ namespace mbts.spark {
|
||||
readonly IList<SecurityMD> _wrapped_rows;
|
||||
readonly ListCollectionView _rows_view;
|
||||
readonly Property<Row> _current_row;
|
||||
readonly DeferrableActionWrapper _refresh_filter;
|
||||
readonly DeferrableAction _refresh_filter;
|
||||
|
||||
Func<Row, bool> _filter;
|
||||
IComparer<Row> _comparer;
|
||||
@@ -187,7 +188,7 @@ namespace mbts.spark {
|
||||
// row vm filter
|
||||
// Althoguh securities are filtered at the row 'model' level (SecurityMD), the column base filters have to be applied at the row vm level,
|
||||
// because they access market data, which is polled periodically and cached in the row vm.
|
||||
_refresh_filter = new DeferrableActionWrapper(() => _filter_changed?.Invoke());
|
||||
_refresh_filter = new DeferrableAction(() => _filter_changed?.Invoke());
|
||||
var row_filter_source = Observable.Create<Func<Row, bool>>(o => {
|
||||
notify();
|
||||
_filter_changed += notify;
|
||||
@@ -196,7 +197,7 @@ namespace mbts.spark {
|
||||
o.OnNext(get_filter_states().build_predicate());
|
||||
});
|
||||
foreach (var f in _all_filters) {
|
||||
f.filter_changed += _refresh_filter.execute;
|
||||
f.filter_changed += _refresh_filter.Invoke;
|
||||
}
|
||||
|
||||
_dispose = Disposable.Create(
|
||||
@@ -491,7 +492,7 @@ namespace mbts.spark {
|
||||
_ => null
|
||||
};
|
||||
state.grid = GridSettingsHelper.hide_cols(state.grid, new[] { ui.spark.FillsView.Columns.Security });
|
||||
var sec_keys = securities.Select(SecurityDataHelper.key_fn);
|
||||
var sec_keys = securities.Select(SecurityImmutable.key_fn);
|
||||
if (securities.All(s => s.ContractCase == Security.ContractOneofCase.Synthetic)) {
|
||||
state.root_securities = sec_keys.ToArray();
|
||||
} else {
|
||||
@@ -506,7 +507,8 @@ namespace mbts.spark {
|
||||
IEnumerable<SecurityImmutable> securities, ColKey column) {
|
||||
var (title_desc, fg) = _orderbook_title(column);
|
||||
var filters = new bts.shell.orderbook.FilterStates {
|
||||
security_criteria = SecurityCriteria.from_keys(securities.Select(SecurityDataHelper.key_fn)),
|
||||
security_criteria = SecurityCriteria.from_keys(
|
||||
securities.Select(SecurityImmutable.key_fn)),
|
||||
order_types = securities.All(s => s.ContractCase == Security.ContractOneofCase.Synthetic) ?
|
||||
new[] { new AlgoID(CustomOrderDefinition.CustomOneofCase.Spreader) } :
|
||||
AlgoID.exchange_algo_keys,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.api.position;
|
||||
using bts.collections;
|
||||
using bts.shell;
|
||||
using bts.shell.fills;
|
||||
@@ -17,6 +16,7 @@ using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Core.Data;
|
||||
using Spark.Trading;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -65,7 +65,7 @@ namespace mbts.spark {
|
||||
_settings_hub = settings_hub;
|
||||
_settings_manager = settings_hub.create_mview_settings_manager(state.grid);
|
||||
Icon.Freeze();
|
||||
thread_id = config.Configuration.get<bts.config.MultiThreadedWindows>().MarketView ? "MarketView" : null;
|
||||
thread_id = config.Configuration.get<bts.config.MultiThreadedWindows>().market_view ? "MarketView" : null;
|
||||
_dispose = Disposable.Create(() => {
|
||||
Disposable.dispose(ref _subscriptions);
|
||||
_vm.Dispose();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using bts.api;
|
||||
using bts.api.position;
|
||||
using bts.proto;
|
||||
using bts.settings;
|
||||
using bts.shell.market_view;
|
||||
@@ -10,6 +9,7 @@ using mbts.ui;
|
||||
using mbts.ui.settings;
|
||||
|
||||
using Spark.Core.Data;
|
||||
using Spark.Trading;
|
||||
|
||||
using System;
|
||||
using System.Composition;
|
||||
@@ -83,18 +83,6 @@ namespace bts.shell {
|
||||
}
|
||||
}
|
||||
|
||||
[Export(typeof(IMarketViewGridSettingsMigrationRule))]
|
||||
class InitBackgroundOverrideMigrationRule : IMarketViewGridSettingsMigrationRule {
|
||||
public bool apply(GridSettings settings, out GridSettings new_settings) {
|
||||
if (!settings.enable_background_color) {
|
||||
new_settings = settings.with(enable_background_color: true);
|
||||
return true;
|
||||
}
|
||||
new_settings = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[Export(typeof(IMarketViewGridSettingsMigrationRule))]
|
||||
class EnsureSelectionHighlightTranslucency : IMarketViewGridSettingsMigrationRule {
|
||||
public bool apply(GridSettings settings, out GridSettings new_settings) =>
|
||||
|
||||
@@ -132,8 +132,8 @@ namespace bts.shell.time_and_sales {
|
||||
}
|
||||
|
||||
public static IEnumerable<GridColumnSettings> all =>
|
||||
ReflectionHelper.static_property_delegates_of_type<GridColumnSettings>(typeof(DefaultColumns))
|
||||
.Select(g => g());
|
||||
ReflectionHelper.static_property_getters<GridColumnSettings>(typeof(DefaultColumns))
|
||||
.Select(pg => pg.get());
|
||||
|
||||
static GridColumnSettings _mk_col(
|
||||
ColKey key,
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
using mbts.user.settings;
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Core;
|
||||
using Spark.Core.Reflection;
|
||||
|
||||
using System;
|
||||
@@ -46,7 +47,7 @@
|
||||
readonly RowFactory _row_factory = new();
|
||||
readonly LoggerContext _log;
|
||||
readonly IWindowSettingsManager<GridSettings> _settings_manager;
|
||||
readonly DeferrableActionWrapper
|
||||
readonly DeferrableAction
|
||||
_refresh_filter,
|
||||
_refresh_sort,
|
||||
_refresh_selected_rows;
|
||||
@@ -96,9 +97,9 @@
|
||||
delta_filter = new DoubleMinMax<TimeAndSalesRowVM>(r => r.display_delta, nameof(TimeAndSalesRowVM.display_delta));
|
||||
|
||||
// deferrable filter/sort refresh
|
||||
_refresh_filter = new DeferrableActionWrapper(_refresh_filter_impl);
|
||||
_refresh_sort = new DeferrableActionWrapper(_refresh_sort_impl);
|
||||
_refresh_selected_rows = new DeferrableActionWrapper(() => selected_rows_changed?.Invoke(_selected_rows));
|
||||
_refresh_filter = new DeferrableAction(_refresh_filter_impl);
|
||||
_refresh_sort = new DeferrableAction(_refresh_sort_impl);
|
||||
_refresh_selected_rows = new DeferrableAction(() => selected_rows_changed?.Invoke(_selected_rows));
|
||||
|
||||
// grid settings
|
||||
grid_settings_manager = new SimpleGridSettingsManager<TimeAndSalesRowVM>(
|
||||
@@ -131,11 +132,11 @@
|
||||
// resources
|
||||
var resources = new List<IDisposable>();
|
||||
resources.AddRange(_filters.Select(f => {
|
||||
f.filter_changed += _refresh_filter.execute;
|
||||
return Disposable.Create(() => f.filter_changed -= _refresh_filter.execute);
|
||||
f.filter_changed += _refresh_filter.Invoke;
|
||||
return Disposable.Create(() => f.filter_changed -= _refresh_filter.Invoke);
|
||||
}));
|
||||
_sort_manager.active_sorting_changed += _refresh_sort.execute;
|
||||
resources.Add(Disposable.Create(() => _sort_manager.active_sorting_changed -= _refresh_sort.execute));
|
||||
_sort_manager.active_sorting_changed += _refresh_sort.Invoke;
|
||||
resources.Add(Disposable.Create(() => _sort_manager.active_sorting_changed -= _refresh_sort.Invoke));
|
||||
_dispose = Disposable.Create(resources.ToArray());
|
||||
|
||||
static string fmt_sec(TimeAndSalesRowVM row) => row.security.ToString();
|
||||
@@ -238,7 +239,7 @@
|
||||
var sorted_rows = rows.ToArray();
|
||||
var snapshot = _selected_rows;
|
||||
Array.Sort(sorted_rows, _comparer_backing);
|
||||
using (_refresh_selected_rows.defer_execution()) {
|
||||
using (_refresh_selected_rows.defer()) {
|
||||
for (int i = 0; i < sorted_rows.Length; i++) {
|
||||
if (rows[i].row_key != sorted_rows[i].row_key)
|
||||
rows[i] = sorted_rows[i];
|
||||
@@ -281,15 +282,15 @@
|
||||
}
|
||||
|
||||
IEnumerable<IDataGridColumnFilter<TimeAndSalesRowVM>> _filters =>
|
||||
ReflectionHelper.property_delegates_of_type<TimeAndSalesVM, IDataGridColumnFilter<TimeAndSalesRowVM>>()
|
||||
.Select(fn => fn(this));
|
||||
ReflectionHelper.property_getters<TimeAndSalesVM, IDataGridColumnFilter<TimeAndSalesRowVM>>()
|
||||
.Select(pg => pg.get(this));
|
||||
|
||||
public (TimeAndSalesFilterSettings filters, IReadOnlyList<SortingCriteria> sorting_criteria, GridSettings grid_settings) create() =>
|
||||
(_get_filter_states(), _sorting_criteria, grid_settings_manager.create());
|
||||
|
||||
public void load(TimeAndSalesFilterSettings filters, IEnumerable<SortingCriteria> sorting_criteria, GridSettings grid_settings) {
|
||||
using (_refresh_filter.defer_execution())
|
||||
using (_refresh_sort.defer_execution()) {
|
||||
using (_refresh_filter.defer())
|
||||
using (_refresh_sort.defer()) {
|
||||
_log.info($"begin load settings ({++_load_settings_count})...");
|
||||
var timer = new Stopwatch();
|
||||
timer.Start();
|
||||
@@ -389,7 +390,7 @@
|
||||
bd.removeRange(e.RemovedItems.OfType<TimeAndSalesRowVM>());
|
||||
}
|
||||
_selected_rows = bd.ToImmutable();
|
||||
_refresh_selected_rows.execute();
|
||||
_refresh_selected_rows.Invoke();
|
||||
}
|
||||
|
||||
static IComparer<TimeAndSalesRowVM> _get_column_comparer(string column_name) =>
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
public override Task<IShellWindow> load(TimeAndSalesSettings state) {
|
||||
var conf = Configuration.get<bts.config.TimeAndSalesOptions>();
|
||||
var thread_id = Configuration.get<bts.config.MultiThreadedWindows>().TimeAndSales ?
|
||||
var thread_id = Configuration.get<bts.config.MultiThreadedWindows>().time_and_sales ?
|
||||
TimeAndSalesWindow.WINDOW_TYPE_NAME : null;
|
||||
var settings_man = new WindowSettingsManager<GridSettings>(
|
||||
_settings_hub, state.grid, s => s.time_and_sales_grid, (s, g) => s.with(time_and_sales: g));
|
||||
@@ -52,7 +52,7 @@
|
||||
_consumer,
|
||||
state,
|
||||
settings_man,
|
||||
conf.CanPauseUpdates,
|
||||
conf.can_pause_updates,
|
||||
_security_auxiliary_model.get_display_quantity_divisor,
|
||||
thread_id);
|
||||
return Task.FromResult<IShellWindow>(win);
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace bts.ui {
|
||||
SparkCommands.ShowGlobalAlerts,
|
||||
SparkCommands.ShowWorkspaces
|
||||
};
|
||||
if (Configuration.get<bts.config.toggles.ToastNotifications>().Enabled) {
|
||||
if (Configuration.get<bts.config.toggles.ToastNotifications>().enabled) {
|
||||
actions_list.Add(SparkCommands.ShowSettings);
|
||||
}
|
||||
actions = actions_list;
|
||||
|
||||
@@ -26,9 +26,9 @@ namespace bts {
|
||||
static bool _is_hidden(IShellModule module) {
|
||||
var props = Configuration.get<IShellModuleProps>();
|
||||
string name = module.GetType().Name;
|
||||
foreach (var p in props.Modules) {
|
||||
if (p.Name.ToLower() == name.ToLower()) {
|
||||
return !p.Visible;
|
||||
foreach (var p in props.module) {
|
||||
if (p.name.ToLower() == name.ToLower()) {
|
||||
return !p.visible;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -426,7 +426,7 @@
|
||||
</c:ContractPickerPopup.Background>
|
||||
<c:ContractPickerPopup.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Foreground="{x:Static u:BTSColors.header_text_brush}" Text="{Binding}"/>
|
||||
<TextBlock Foreground="{u:BTSColor header_text}" Text="{Binding}" />
|
||||
</DataTemplate>
|
||||
</c:ContractPickerPopup.HeaderTemplate>
|
||||
</c:ContractPickerPopup>
|
||||
|
||||
@@ -320,7 +320,14 @@ namespace mbts.ui.spark {
|
||||
if (_vm.GetErrors(nameof(SyntheticEditorVM.tick_factors)).Cast<string>().Any())
|
||||
this.draw_border(drawing_context, _tick_factors_picker.value, null, new Pen(Brushes.Red, 1));
|
||||
string error_text = string.Join(", ", _vm.AllErrors);
|
||||
this.draw_relative_text(RelativePosition.Below, error_text, drawing_context, _name_text_box.value, BTSColors.header_error_text_brush, 0, y_offset);
|
||||
this.draw_relative_text(
|
||||
RelativePosition.Below,
|
||||
error_text,
|
||||
drawing_context,
|
||||
_name_text_box.value,
|
||||
BTSColors.header_error_text.to_brush(),
|
||||
0,
|
||||
y_offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,9 +69,9 @@ namespace bts.shell {
|
||||
if (securities.Count == 1) {
|
||||
var sec = securities.First();
|
||||
switch (sec.ContractCase) {
|
||||
case Security.ContractOneofCase.Future: _show_synthetic_create(new ContractLeg[] { SyntheticDataHelper.Defaults.ContractLeg(sec) }); break;
|
||||
case Security.ContractOneofCase.Spread: _show_synthetic_create(sec.Spread.Legs.Select(l => l.CloneToMutable())); break;
|
||||
case Security.ContractOneofCase.Synthetic: _show_synthetic_create(sec.Synthetic.Legs.Select(l => l.CloneToMutable())); break;
|
||||
case api.Security.ContractOneofCase.Future: _show_synthetic_create(new ContractLeg[] { SyntheticDataHelper.Defaults.ContractLeg(sec) }); break;
|
||||
case api.Security.ContractOneofCase.Spread: _show_synthetic_create(sec.Spread.Legs.Select(l => l.CloneToMutable())); break;
|
||||
case api.Security.ContractOneofCase.Synthetic: _show_synthetic_create(sec.Synthetic.Legs.Select(l => l.CloneToMutable())); break;
|
||||
default: Log.Ui.warn($"{GetType()} unable to process security: {sec}"); break;
|
||||
}
|
||||
} else
|
||||
@@ -79,7 +79,7 @@ namespace bts.shell {
|
||||
}
|
||||
|
||||
void _show_synthetic_strategy(SecurityImmutable security) {
|
||||
if (security.ContractCase != Security.ContractOneofCase.Synthetic)
|
||||
if (security.ContractCase != api.Security.ContractOneofCase.Synthetic)
|
||||
Log.Ui.warn($"{GetType()} observed a non-synthetic-security posted on {nameof(SparkTags.ShowSyntheticStrategyTag)}: {security}");
|
||||
else
|
||||
_show_synthetic_strategy_async(security).ignore();
|
||||
@@ -92,7 +92,7 @@ namespace bts.shell {
|
||||
}
|
||||
|
||||
void _show_synthetic_clone((SecurityImmutable security, ExecutionStrategyImmutable strategy) args) {
|
||||
if (args.security.ContractCase == Security.ContractOneofCase.Synthetic) {
|
||||
if (args.security.ContractCase == api.Security.ContractOneofCase.Synthetic) {
|
||||
var mutable_sec = args.security.CloneToMutable();
|
||||
mutable_sec.Id = 0;
|
||||
mutable_sec.Synthetic.Name = _get_clone_name(mutable_sec.Synthetic.Name);
|
||||
@@ -103,10 +103,10 @@ namespace bts.shell {
|
||||
|
||||
void _show_synthetic_create(IEnumerable<ContractLeg> legs) {
|
||||
var syn = SyntheticDataHelper.Defaults.SyntheticContract("Synthetic", legs);
|
||||
var sec = new SecurityImmutable(new Security {
|
||||
var sec = new SecurityImmutable(new api.Security {
|
||||
Synthetic = syn,
|
||||
Symbol = legs.FirstOrDefault()?.Security.Symbol ?? string.Empty,
|
||||
ContractSpec = SecurityDataHelper.Defaults.ContractSpecification
|
||||
ContractSpec = Security.Defaults.ContractSpecification
|
||||
});
|
||||
_show_synthetic_editor(new SyntheticEditorVM(_bus, _model.spreader, sec, new ExecutionStrategyImmutable(SyntheticDataHelper.Defaults.ExecutionStrategy(sec))));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace bts.shell {
|
||||
using mbts.spark.filters;
|
||||
using mbts.ui;
|
||||
|
||||
using ProtoBuf;
|
||||
|
||||
[ProtoContract]
|
||||
class SyntheticManagementFilterSettings {
|
||||
[ProtoMember(1)]
|
||||
public string description;
|
||||
[ProtoMember(2)]
|
||||
public TimeFilterTuple create_time;
|
||||
[ProtoMember(3)]
|
||||
public string name;
|
||||
[ProtoMember(4)]
|
||||
public IntMinMaxState n_legs;
|
||||
[ProtoMember(5)]
|
||||
public UIntMinMaxState n_working_orders;
|
||||
[ProtoMember(6)]
|
||||
public string security_key;
|
||||
[ProtoMember(7)]
|
||||
public uint[] user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
namespace bts.shell {
|
||||
using mbts.ui;
|
||||
using mbts.ui.settings;
|
||||
|
||||
using ProtoBuf;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Columns = mbts.ui.spark.SyntheticManagementView.Columns;
|
||||
using ColHeaders = mbts.ui.controls.DIYGrid.DefaultColumnHeaders;
|
||||
using ColWidths = mbts.ui.controls.DIYGrid.DefaultColumnWidths;
|
||||
|
||||
[ProtoContract]
|
||||
class SyntheticManagementSettings {
|
||||
public const int Version = 1;
|
||||
|
||||
[ProtoMember(1)]
|
||||
public readonly List<SortingCriteria> sorting_criteria;
|
||||
[ProtoMember(2)]
|
||||
public readonly SyntheticManagementFilterSettings filters;
|
||||
[ProtoMember(3)]
|
||||
public readonly GridSettings grid;
|
||||
[ProtoMember(4)]
|
||||
public readonly SparkMenuDisplaySettings menu_display;
|
||||
|
||||
public SyntheticManagementSettings()
|
||||
: this(new List<SortingCriteria>(), null, null) { }
|
||||
|
||||
public SyntheticManagementSettings(
|
||||
List<SortingCriteria> sorting_criteria,
|
||||
SyntheticManagementFilterSettings filters,
|
||||
GridSettings grid = default)
|
||||
: this(sorting_criteria, filters, grid, SparkMenuDisplaySettings.Default) { }
|
||||
|
||||
public SyntheticManagementSettings(
|
||||
List<SortingCriteria> sorting_criteria,
|
||||
SyntheticManagementFilterSettings filters,
|
||||
GridSettings grid,
|
||||
SparkMenuDisplaySettings menu_display) {
|
||||
this.sorting_criteria = sorting_criteria;
|
||||
this.filters = filters;
|
||||
this.grid = grid;
|
||||
this.menu_display = menu_display;
|
||||
}
|
||||
|
||||
public SyntheticManagementSettings with(
|
||||
List<SortingCriteria> sorting_criteria = null,
|
||||
SyntheticManagementFilterSettings filters = null,
|
||||
GridSettings grid = null,
|
||||
SparkMenuDisplaySettings? menu_display = null) =>
|
||||
new(
|
||||
sorting_criteria ?? this.sorting_criteria,
|
||||
filters ?? this.filters,
|
||||
grid ?? this.grid,
|
||||
menu_display ?? this.menu_display);
|
||||
|
||||
public static GridSettings default_grid_settings =>
|
||||
GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criteria);
|
||||
|
||||
public static string col_id(Columns col) =>
|
||||
col.ToString();
|
||||
|
||||
static class DefaultColumns {
|
||||
public static GridColumnSettings name =>
|
||||
new(col_id(Columns.Name), ColHeaders.Name, width: ColWidths.Security);
|
||||
|
||||
public static GridColumnSettings description =>
|
||||
new(col_id(Columns.Description), ColHeaders.Description, width: ColWidths.Description);
|
||||
|
||||
public static GridColumnSettings n_legs =>
|
||||
new(col_id(Columns.n_legs), ColHeaders.N_Legs, width: ColWidths.N_Legs);
|
||||
|
||||
public static GridColumnSettings n_working_orders => new(
|
||||
col_id(Columns.n_working_orders),
|
||||
ColHeaders.N_Working_Orders,
|
||||
width: ColWidths.N_Working_Orders);
|
||||
|
||||
public static GridColumnSettings security_key => new(
|
||||
col_id(Columns.SecurityKey),
|
||||
ColHeaders.SecurityKey,
|
||||
is_visible: false,
|
||||
width: ColWidths.SecurityKey);
|
||||
|
||||
public static GridColumnSettings user =>
|
||||
new(col_id(Columns.User), ColHeaders.User, is_visible: false, width: ColWidths.User);
|
||||
|
||||
public static IEnumerable<SortingCriteria> default_sorting_criteria {
|
||||
get {
|
||||
yield return new SortingCriteria(name.id, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<GridColumnSettings> all {
|
||||
get {
|
||||
yield return name;
|
||||
yield return description;
|
||||
yield return n_legs;
|
||||
yield return n_working_orders;
|
||||
yield return security_key;
|
||||
yield return user;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,13 +22,13 @@ using System.Windows;
|
||||
using static bts.shell.SyntheticManagementWindowFactory;
|
||||
|
||||
namespace mbts.spark {
|
||||
class SyntheticManagementWindow : SparkWindow<StartupData>, ISharedWindow {
|
||||
class SyntheticManagementWindow : SparkWindow<SyntheticManagementSettings>, ISharedWindow {
|
||||
const string
|
||||
_window_type = "SyntheticManagement",
|
||||
_import_title = "Import Synthetics";
|
||||
static readonly TimeSpan _import_op_sec_map_timeout = TimeSpan.FromSeconds(30);
|
||||
SingleValuePump<SyntheticManagementDialogVM> _vm = new SingleValuePump<SyntheticManagementDialogVM>();
|
||||
StartupData _state;
|
||||
SyntheticManagementSettings _state;
|
||||
OrdersModel _orders_model;
|
||||
SyntheticManagementView _view;
|
||||
SparkMenuDisplayVM _menu_display_vm;
|
||||
@@ -36,13 +36,13 @@ namespace mbts.spark {
|
||||
List<SparkCommand> _commands;
|
||||
readonly IWindowSettingsManager<GridSettings> _settings_manager;
|
||||
|
||||
public SyntheticManagementWindow(SyntheticManagementWindowFactory factory, IBus bus, OrdersModel orders_model, StartupData state, IWindowSettingsManager<GridSettings> settings_manager)
|
||||
public SyntheticManagementWindow(SyntheticManagementWindowFactory factory, IBus bus, OrdersModel orders_model, SyntheticManagementSettings state, IWindowSettingsManager<GridSettings> settings_manager)
|
||||
: base("Synthetic Management", bus, factory, SparkCommands.ShowSyntheticManagement.icon) {
|
||||
_orders_model = orders_model;
|
||||
_state = state;
|
||||
_settings_manager = settings_manager;
|
||||
Icon.Freeze();
|
||||
thread_id = config.Configuration.get<bts.config.MultiThreadedWindows>().SyntheticManagement ?
|
||||
thread_id = config.Configuration.get<bts.config.MultiThreadedWindows>().synthetic_management ?
|
||||
"SyntheticManagement" : null;
|
||||
_dispose = Disposable.Create(() => {
|
||||
Disposable.dispose(ref _vm);
|
||||
@@ -56,9 +56,9 @@ namespace mbts.spark {
|
||||
public override string window_type => _window_type;
|
||||
public override UIElement Content => _view;
|
||||
public override IEnumerable<SparkCommand> Commands => _commands;
|
||||
public override StartupData SaveState => _state = _vm.value.create().with(menu_display: _menu_display_vm.safe_create());
|
||||
public override SyntheticManagementSettings SaveState => _state = _vm.value.create().with(menu_display: _menu_display_vm.safe_create());
|
||||
public override double MinWidth =>
|
||||
StartupData.DefaultGridSettings.columns.Sum(gcs => gcs.width)
|
||||
SyntheticManagementSettings.default_grid_settings.columns.Sum(gcs => gcs.width)
|
||||
+ SPARK_MENU_COLLAPSED_WIDTH
|
||||
+ LAUNCHER_BUTTON_BORDER_WIDTH
|
||||
+ EXTRA_FOR_NO_HORIZONTAL_SCROLLBAR_WIDTH;
|
||||
@@ -82,7 +82,7 @@ namespace mbts.spark {
|
||||
can_execute, select_security_id
|
||||
), SparkCommand.create("Change", Icons.ModifySynthetic, SparkTags.ShowSyntheticStrategyTag).complete(
|
||||
current_row_source,
|
||||
r => r != null, r => r?.security ?? SecurityDataHelper.Defaults.SecurityImmutable
|
||||
r => r != null, r => r?.security ?? Security.Defaults.SecurityImmutable
|
||||
), SparkCommand.create("Clone", Icons.CloneSynthetic, SparkTags.ShowSyntheticCloneTag).complete(
|
||||
current_row_connectable_builder.create(observe_row_strategy),
|
||||
rs => rs.HasValue, select_row_strategy_tuple
|
||||
@@ -133,7 +133,7 @@ namespace mbts.spark {
|
||||
(SecurityImmutable, ExecutionStrategyImmutable) select_row_strategy_tuple(RowStrategy? rs) => rs.HasValue ? (rs.Value.security, rs.Value.strategy) : default;
|
||||
bool can_execute(RowModificationParams? rmp) => rmp.HasValue && !rmp.Value.has_working_orders;
|
||||
|
||||
_vm.value = new SyntheticManagementDialogVM(_bus, _orders_model, _settings_manager, _state.sorting_criteria, _state.filters ?? new FilterStates());
|
||||
_vm.value = new SyntheticManagementDialogVM(_bus, _orders_model, _settings_manager, _state.sorting_criteria, _state.filters ?? new SyntheticManagementFilterSettings());
|
||||
if (_view == null) _view = new SyntheticManagementView { DataContext = _vm.value };
|
||||
else _view.DataContext = _vm.value;
|
||||
|
||||
|
||||
@@ -3,23 +3,18 @@ using bts.settings;
|
||||
|
||||
using mbts.persist;
|
||||
using mbts.spark;
|
||||
using mbts.spark.filters;
|
||||
using mbts.ui;
|
||||
using mbts.ui.settings;
|
||||
|
||||
using ProtoBuf;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Composition;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using static mbts.ui.controls.DIYGrid;
|
||||
using static mbts.ui.spark.SyntheticManagementView;
|
||||
|
||||
namespace bts.shell {
|
||||
class SyntheticManagementWindowFactory : ShellWindowFactory<SyntheticManagementWindowFactory.StartupData> {
|
||||
class SyntheticManagementWindowFactory : ShellWindowFactory<SyntheticManagementSettings> {
|
||||
readonly IBus _bus;
|
||||
readonly OrdersModel _orders_model;
|
||||
readonly UserSettingsHub _settings_hub;
|
||||
@@ -33,100 +28,20 @@ namespace bts.shell {
|
||||
|
||||
public static string col_id(Columns col) => col.ToString();
|
||||
|
||||
public override Task<IShellWindow> load(StartupData state) =>
|
||||
public override Task<IShellWindow> load(SyntheticManagementSettings state) =>
|
||||
Task.FromResult<IShellWindow>(_create(state));
|
||||
|
||||
public async void show(SparkTags.Nothing nothing) =>
|
||||
_bus.post(SparkTags.ShowWindow, await load(new StartupData()));
|
||||
_bus.post(SparkTags.ShowWindow, await load(new SyntheticManagementSettings()));
|
||||
|
||||
IShellWindow _create(StartupData state) =>
|
||||
IShellWindow _create(SyntheticManagementSettings state) =>
|
||||
new SyntheticManagementWindow(this, _bus, _orders_model, state, _settings_hub.create_synth_settings_manager(state.grid));
|
||||
|
||||
[ProtoContract]
|
||||
public class StartupData {
|
||||
public const int Version = 1;
|
||||
|
||||
[ProtoMember(1)]
|
||||
public readonly List<SortingCriteria> sorting_criteria;
|
||||
[ProtoMember(2)]
|
||||
public readonly FilterStates filters;
|
||||
[ProtoMember(3)]
|
||||
public readonly GridSettings grid;
|
||||
[ProtoMember(4)]
|
||||
public readonly SparkMenuDisplaySettings menu_display;
|
||||
|
||||
public StartupData() : this(new List<SortingCriteria>(), null, null) { }
|
||||
|
||||
public StartupData(List<SortingCriteria> sorting_criteria, FilterStates filters, GridSettings grid = default)
|
||||
: this(sorting_criteria, filters, grid, SparkMenuDisplaySettings.Default) { }
|
||||
|
||||
public StartupData(List<SortingCriteria> sorting_criteria, FilterStates filters, GridSettings grid, SparkMenuDisplaySettings menu_display) {
|
||||
this.sorting_criteria = sorting_criteria;
|
||||
this.filters = filters;
|
||||
this.grid = grid;
|
||||
this.menu_display = menu_display;
|
||||
}
|
||||
|
||||
public StartupData with(List<SortingCriteria> sorting_criteria = null, FilterStates filters = null, GridSettings grid = null, SparkMenuDisplaySettings? menu_display = null) =>
|
||||
new StartupData(
|
||||
sorting_criteria ?? this.sorting_criteria,
|
||||
filters ?? this.filters,
|
||||
grid ?? this.grid,
|
||||
menu_display ?? this.menu_display);
|
||||
|
||||
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);
|
||||
public static GridColumnSettings description => new GridColumnSettings(col_id(Columns.Description), DefaultColumnHeaders.Description, width: DefaultColumnWidths.Description);
|
||||
public static GridColumnSettings n_legs => new GridColumnSettings(col_id(Columns.n_legs), DefaultColumnHeaders.N_Legs, width: DefaultColumnWidths.N_Legs);
|
||||
public static GridColumnSettings n_working_orders => new GridColumnSettings(col_id(Columns.n_working_orders), DefaultColumnHeaders.N_Working_Orders, width: DefaultColumnWidths.N_Working_Orders);
|
||||
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_criteria {
|
||||
get {
|
||||
yield return new SortingCriteria(name.id, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<GridColumnSettings> all {
|
||||
get {
|
||||
yield return name;
|
||||
yield return description;
|
||||
yield return n_legs;
|
||||
yield return n_working_orders;
|
||||
yield return security_key;
|
||||
yield return user;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
public class FilterStates {
|
||||
[ProtoMember(1)]
|
||||
public string description;
|
||||
[ProtoMember(2)]
|
||||
public TimeFilterTuple create_time;
|
||||
[ProtoMember(3)]
|
||||
public string name;
|
||||
[ProtoMember(4)]
|
||||
public IntMinMaxState n_legs;
|
||||
[ProtoMember(5)]
|
||||
public UIntMinMaxState n_working_orders;
|
||||
[ProtoMember(6)]
|
||||
public string security_key;
|
||||
[ProtoMember(7)]
|
||||
public uint[] user;
|
||||
}
|
||||
|
||||
// migration rules
|
||||
[Export(typeof(ISyntheticManagementMigrationRule))]
|
||||
class AddMissingColumnsMigrationRule : ISyntheticManagementMigrationRule {
|
||||
public bool apply(GridSettings settings, out GridSettings new_settings) =>
|
||||
settings.add_missing_columns(StartupData.DefaultGridSettings.columns, out new_settings);
|
||||
settings.add_missing_columns(SyntheticManagementSettings.default_grid_settings.columns, out new_settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.collections;
|
||||
using bts.shell;
|
||||
using bts.spark;
|
||||
using bts.utils;
|
||||
|
||||
@@ -18,7 +19,6 @@ using System.Reactive.Linq;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
|
||||
using static bts.shell.SyntheticManagementWindowFactory;
|
||||
using static mbts.ui.controls.DIYGrid;
|
||||
using static mbts.ui.spark.SyntheticManagementView;
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace mbts.spark {
|
||||
readonly IWindowSettingsManager<GridSettings> _settings_manager;
|
||||
|
||||
public SyntheticManagementDialogVM(IBus bus, OrdersModel orders_model, IWindowSettingsManager<GridSettings> settings_manager) : this(bus, orders_model, settings_manager, null, null) { }
|
||||
public SyntheticManagementDialogVM(IBus bus, OrdersModel orders_model, IWindowSettingsManager<GridSettings> settings_manager, IReadOnlyCollection<SortingCriteria> sorting, FilterStates filters)
|
||||
public SyntheticManagementDialogVM(IBus bus, OrdersModel orders_model, IWindowSettingsManager<GridSettings> settings_manager, IReadOnlyCollection<SortingCriteria> sorting, SyntheticManagementFilterSettings filters)
|
||||
: base(orders_model.spreader.synthetic_tuples.Select(t => t.state.Values), sorting) {
|
||||
_bus = bus;
|
||||
_orders_model = orders_model;
|
||||
@@ -54,7 +54,7 @@ namespace mbts.spark {
|
||||
Columns.n_working_orders,
|
||||
n_working_orders_filter,
|
||||
DataGridFilterKnownTemplates.UIntMinMax) {
|
||||
id = col_id(Columns.n_working_orders),
|
||||
id = SyntheticManagementSettings.col_id(Columns.n_working_orders),
|
||||
CommandBinding = new Binding(nameof(Row.show_order_book)),
|
||||
TextBinding = new Binding(nameof(Row.n_working_orders)),
|
||||
Header = DefaultColumnHeaders.N_Working_Orders,
|
||||
@@ -65,7 +65,7 @@ namespace mbts.spark {
|
||||
//
|
||||
void add_col(Columns col_key, string header, Func<Row, string> get_text, string prop, IDataGridColumnFilter filter, string filter_template, double width) =>
|
||||
columns.Add(new RenderTextColumn<Row, Columns>(col_key, get_text, filter, filter_template) {
|
||||
id = col_id(col_key),
|
||||
id = SyntheticManagementSettings.col_id(col_key),
|
||||
Header = header,
|
||||
sort_member_path = prop,
|
||||
Width = width
|
||||
@@ -96,8 +96,8 @@ namespace mbts.spark {
|
||||
public GridSettings get_grid_save_state() =>
|
||||
_settings_manager.instance_settings == null ? null : grid_settings_manager.create();
|
||||
|
||||
public StartupData create() =>
|
||||
new StartupData(rows_view.get_sorting_criteria(columns), _get_filter_states(), get_grid_save_state());
|
||||
public SyntheticManagementSettings create() =>
|
||||
new SyntheticManagementSettings(rows_view.get_sorting_criteria(columns), _get_filter_states(), get_grid_save_state());
|
||||
|
||||
protected override Row row_factory(SyntheticTuple row_model) =>
|
||||
new Row(_bus, row_model, _orders_model);
|
||||
@@ -105,8 +105,8 @@ namespace mbts.spark {
|
||||
protected override void on_row_removed(Row row) =>
|
||||
row.Dispose();
|
||||
|
||||
FilterStates _get_filter_states() =>
|
||||
new FilterStates {
|
||||
SyntheticManagementFilterSettings _get_filter_states() =>
|
||||
new SyntheticManagementFilterSettings {
|
||||
description = description_filter.get_state(),
|
||||
create_time = create_time_filter.get_state(),
|
||||
name = name_filter.get_state(),
|
||||
|
||||
@@ -1,25 +1,28 @@
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace bts.shell {
|
||||
public static class ActivityLogCategory {
|
||||
public static ILogViewerCategory order = new LogViewerCategory("Order", BTSColors.Orders.sent_brush);
|
||||
public static ILogViewerCategory fill = new LogViewerCategory("Fill", BTSColors.Orders.filled_dark_brush);
|
||||
public static ILogViewerCategory cancel = new LogViewerCategory("Cancel", BTSColors.Orders.working_cancel_brush);
|
||||
public static ILogViewerCategory modify = new LogViewerCategory("Modify", BTSColors.Orders.modified_brush);
|
||||
public static ILogViewerCategory warn = new LogViewerCategory("Warn", Brushes.Gold);
|
||||
|
||||
public static IEnumerable<ILogViewerCategory> all_categories {
|
||||
get {
|
||||
yield return order;
|
||||
yield return fill;
|
||||
yield return cancel;
|
||||
yield return modify;
|
||||
yield return warn;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace bts.shell {
|
||||
public static class ActivityLogCategory {
|
||||
public static ILogViewerCategory order { get; } = _mk("Order", BTSColors.Orders.sent);
|
||||
public static ILogViewerCategory fill { get; } = _mk("Fill", BTSColors.Orders.filled_dark);
|
||||
public static ILogViewerCategory cancel { get; } = _mk("Cancel", BTSColors.Orders.working_cancel);
|
||||
public static ILogViewerCategory modify { get; } = _mk("Modify", BTSColors.Orders.modified);
|
||||
public static ILogViewerCategory warn { get; } = _mk("Warn", Colors.Gold);
|
||||
|
||||
public static IEnumerable<ILogViewerCategory> all_categories {
|
||||
get {
|
||||
yield return order;
|
||||
yield return fill;
|
||||
yield return cancel;
|
||||
yield return modify;
|
||||
yield return warn;
|
||||
}
|
||||
}
|
||||
|
||||
static ILogViewerCategory _mk(string name, Color color) =>
|
||||
new LogViewerCategory(name, color.to_brush().frozen());
|
||||
}
|
||||
}
|
||||
Loaded 100 of 649 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user