Compare commits
353
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c4bb25f5f | ||
|
|
56005accdc | ||
|
|
0bac9236b4 | ||
|
|
54c382dac9 | ||
|
|
9916fafedb | ||
|
|
8ffdc2f9ee | ||
|
|
7cbc0e44f6 | ||
|
|
9adc002c9b | ||
|
|
819fa629de | ||
|
|
d0b38fa172 | ||
|
|
07329061b1 | ||
|
|
5dc1b53267 | ||
|
|
0291b2a8b2 | ||
|
|
1ee4915fcd | ||
|
|
723e2d2268 | ||
|
|
5e296f76eb | ||
|
|
8e39b0b7ff | ||
|
|
1beb9460ba | ||
|
|
e00eae1129 | ||
|
|
95595c4cbf | ||
|
|
aad36a4972 | ||
|
|
cc03f47d70 | ||
|
|
5c5e5c23ef | ||
|
|
4b531a2a1a | ||
|
|
35530bec0b | ||
|
|
5853bb2436 | ||
|
|
bfdf45d30d | ||
|
|
a330bc5020 | ||
|
|
66f68ef3ec | ||
|
|
d6e651129b | ||
|
|
d4a59b8253 | ||
|
|
569f1460a4 | ||
|
|
2f369dbd57 | ||
|
|
444e486862 | ||
|
|
b42504d827 | ||
|
|
18ac85a454 | ||
|
|
788a1a06c5 | ||
|
|
787b485bce | ||
|
|
788df0e888 | ||
|
|
916532f7c5 | ||
|
|
3c511bb177 | ||
|
|
49f13755c6 | ||
|
|
dcb4b1ae7e | ||
|
|
2152b48fe2 | ||
|
|
b6f2f99f21 | ||
|
|
c44df8ec06 | ||
|
|
493f082d6d | ||
|
|
bbe76b2709 | ||
|
|
ce8eda24fc | ||
|
|
9f9113bf9a | ||
|
|
a199595938 | ||
|
|
83de5fac75 | ||
|
|
c688657d53 | ||
|
|
a5c62c66b1 | ||
|
|
6d595d18ee | ||
|
|
946e8f1c47 | ||
|
|
b765c3756d | ||
|
|
54dc7bf6c3 | ||
|
|
6142a08db6 | ||
|
|
ca59976e00 | ||
|
|
7f7a160916 | ||
|
|
c8eb51c303 | ||
|
|
4160233a58 | ||
|
|
c5f79f754b | ||
|
|
5f568d681a | ||
|
|
83a2147428 | ||
|
|
9dd2cee6d9 | ||
|
|
57365013bd | ||
|
|
3d55ef075b | ||
|
|
14da6461b1 | ||
|
|
e84d3df024 | ||
|
|
ed38fe0ce9 | ||
|
|
b5daee3bcf | ||
|
|
f5c8c29f5a | ||
|
|
89fa2eae50 | ||
|
|
41b8c9238c | ||
|
|
28b66306da | ||
|
|
0bdbc1897a | ||
|
|
c3d9443a89 | ||
|
|
400db13a78 | ||
|
|
1d7d5858d5 | ||
|
|
8792f24c5d | ||
|
|
76d35b16eb | ||
|
|
81f7fe72ab | ||
|
|
649ba11edb | ||
|
|
2fc6d7c262 | ||
|
|
45421eedce | ||
|
|
8ecb3118e4 | ||
|
|
3fdb10890d | ||
|
|
2a6224c88d | ||
|
|
8d6ddc8250 | ||
|
|
6cc8590a1c | ||
|
|
063d908775 | ||
|
|
93565f0ebf | ||
|
|
1d7fcf5d18 | ||
|
|
897d20f12f | ||
|
|
a928925252 | ||
|
|
4088affa15 | ||
|
|
7def6aacd2 | ||
|
|
94ae1780cd | ||
|
|
2c65c4376b | ||
|
|
68bb3dbfa1 | ||
|
|
82a73693a6 | ||
|
|
612cd4a4c8 | ||
|
|
b3828dfc53 | ||
|
|
01f26567ed | ||
|
|
90d21c9c15 | ||
|
|
6351c1340e | ||
|
|
18cdddf76d | ||
|
|
b14c8bb1ac | ||
|
|
ceff286120 | ||
|
|
59aa4677e8 | ||
|
|
996cd4c856 | ||
|
|
9287149c26 | ||
|
|
306b56a999 | ||
|
|
812cf0a43f | ||
|
|
2c539fd833 | ||
|
|
334295ed67 | ||
|
|
c157b9cdfd | ||
|
|
8280b7a815 | ||
|
|
fb7f982c65 | ||
|
|
75b50d93e8 | ||
|
|
865bdac9df | ||
|
|
ebe5f468d7 | ||
|
|
1bc8d886f4 | ||
|
|
38e352e0d3 | ||
|
|
f6079e7031 | ||
|
|
8c51488190 | ||
|
|
9aad08ada6 | ||
|
|
2d3d11ba59 | ||
|
|
6087953185 | ||
|
|
851654c8a5 | ||
|
|
57a4745e29 | ||
|
|
32cd00895e | ||
|
|
dee5f2684f | ||
|
|
f639a526cf | ||
|
|
d168d8712e | ||
|
|
78a9605383 | ||
|
|
a713b1018e | ||
|
|
9f626dd10c | ||
|
|
8ec7fdd60a | ||
|
|
ffb2245ae6 | ||
|
|
21051c9a0b | ||
|
|
1c8bd34144 | ||
|
|
f614fb7e7d | ||
|
|
b222cd3e55 | ||
|
|
4f2be64813 | ||
|
|
bfb73ffc5a | ||
|
|
9bb7025752 | ||
|
|
bbfbd0b691 | ||
|
|
5628e96a90 | ||
|
|
ef517b7554 | ||
|
|
ba06af327d | ||
|
|
b8b03172bc | ||
|
|
fb5c3c1e6e | ||
|
|
faaa7b11d4 | ||
|
|
92a0467e1e | ||
|
|
3bb2025ea2 | ||
|
|
f2730ff0d7 | ||
|
|
7fcff9e5b4 | ||
|
|
51f83f4880 | ||
|
|
88cb510aea | ||
|
|
452c642af0 | ||
|
|
3fafc5004e | ||
|
|
fd8e502140 | ||
|
|
b499a5c38b | ||
|
|
2320383b16 | ||
|
|
59b3e73330 | ||
|
|
9d9a1b86c4 | ||
|
|
21cc2cefbf | ||
|
|
904df4260d | ||
|
|
af785d5d0b | ||
|
|
1d796856ca | ||
|
|
35f0d5a53f | ||
|
|
2b2fdd2b94 | ||
|
|
9e4539a902 | ||
|
|
a76c8ffd98 | ||
|
|
d7474cb8da | ||
|
|
890a23a537 | ||
|
|
ab17eee260 | ||
|
|
8701fb7132 | ||
|
|
89fcb3092b | ||
|
|
c9856b96ae | ||
|
|
04477a4b7c | ||
|
|
99371a2ead | ||
|
|
70487a8ef7 | ||
|
|
44c419fdaf | ||
|
|
5eb151f9a0 | ||
|
|
855a939c51 | ||
|
|
7071d9b961 | ||
|
|
adf14491bc | ||
|
|
7e0e8f2801 | ||
|
|
4a37e2d6a6 | ||
|
|
12b2371a69 | ||
|
|
c19d173983 | ||
|
|
203164f372 | ||
|
|
6f69f1c2e2 | ||
|
|
ad1a585b5c | ||
|
|
f29e367ec7 | ||
|
|
18127383f0 | ||
|
|
b450c757c9 | ||
|
|
836683bcbe | ||
|
|
c271af30d8 | ||
|
|
31fab94208 | ||
|
|
a9b5067d7a | ||
|
|
7a31b025a2 | ||
|
|
31897a1b2e | ||
|
|
f93bc592cb | ||
|
|
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 | ||
|
|
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
@@ -50,3 +50,5 @@ trace_data/
|
||||
*.tmp/*
|
||||
/.venv*/*
|
||||
.cache/
|
||||
src/web/api/tsconfig.*.g.json
|
||||
/.cpm_cache/**
|
||||
@@ -7,6 +7,3 @@
|
||||
[submodule "docker/windows"]
|
||||
path = docker/windows
|
||||
url = git@bitbucket.org:bluetradesys/windows_docker.git
|
||||
[submodule "src/deribit-crypto-connector-demo-application"]
|
||||
path = src/deribit-crypto-connector-demo-application
|
||||
url = git@gitlab.com:cryptoexchanges1/deribit-crypto-connector-demo-application.git
|
||||
+53
-49
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
project(spark)
|
||||
|
||||
if(WIN32)
|
||||
@@ -7,7 +7,12 @@ else()
|
||||
set(platform "linux")
|
||||
endif()
|
||||
|
||||
set(EXTERNALS_ROOT "${CMAKE_SOURCE_DIR}/externals/${platform}")
|
||||
set(
|
||||
EXTERNALS_ROOT
|
||||
"${CMAKE_SOURCE_DIR}/externals/${platform}"
|
||||
CACHE
|
||||
STRING
|
||||
"External dependencies root folder (should contain folders: lib, bin, include")
|
||||
set(SPARK_PYTHON "${EXTERNALS_ROOT}/python")
|
||||
set(SPARK_BIN "${EXTERNALS_ROOT}/bin")
|
||||
set(SPARK_INCLUDE "${EXTERNALS_ROOT}/include")
|
||||
@@ -18,62 +23,61 @@ set(BUILD_WEB ON CACHE BOOL "Build the web server")
|
||||
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")
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/CPM.cmake)
|
||||
|
||||
# CPM packages
|
||||
CPMAddPackage("gh:nlohmann/json@3.11.2")
|
||||
CPMAddPackage("gh:fmtlib/fmt#8.1.1")
|
||||
CPMAddPackage("gh:ericniebler/range-v3#0.12.0")
|
||||
CPMAddPackage("gh:ReactiveX/RxCpp@4.1.1")
|
||||
CPMAddPackage("gh:google/double-conversion@3.2.1")
|
||||
CPMAddPackage("gh:cameron314/concurrentqueue@1.0.3")
|
||||
CPMAddPackage("gh:cameron314/readerwriterqueue@1.0.6")
|
||||
CPMAddPackage("gh:HowardHinnant/date@3.0.1")
|
||||
|
||||
# websocketpp
|
||||
CPMAddPackage("gh:zaphoyd/websocketpp#0.8.2")
|
||||
add_library(websocketpp INTERFACE)
|
||||
set_target_properties(websocketpp PROPERTIES CMAKE_CXX_FLAGS "-Wno-null-pointer-subtraction")
|
||||
|
||||
# abseil
|
||||
CPMAddPackage(
|
||||
NAME absl
|
||||
GITHUB_REPOSITORY abseil/abseil-cpp
|
||||
GIT_TAG 20220623.1
|
||||
DOWNLOAD_ONLY True
|
||||
)
|
||||
add_library(absl INTERFACE)
|
||||
|
||||
string(TOUPPER ${CMAKE_BUILD_TYPE} _build_type_u)
|
||||
# benchmark
|
||||
CPMAddPackage(
|
||||
NAME benchmark
|
||||
GITHUB_REPOSITORY google/benchmark
|
||||
VERSION 1.5.0
|
||||
OPTIONS
|
||||
"BENCHMARK_ENABLE_TESTING OFF"
|
||||
"CMAKE_CXX_FLAGS_${_build_type_u} -Wno-unused-but-set-variable -Wno-deprecated-declarations"
|
||||
"BENCHMARK_DOWNLOAD_DEPENDENCIES ON"
|
||||
"CMAKE_CXX_STANDARD 17"
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
# subdirs
|
||||
add_subdirectory(src/lib)
|
||||
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_EXCHANGE_BINANCE)
|
||||
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_dependencies(sparkd benchmark)
|
||||
add_subdirectory(src/lib)
|
||||
if (BUILD_WEB)
|
||||
add_dependencies(libspark benchmark)
|
||||
if(BUILD_WEB)
|
||||
add_subdirectory(src/web)
|
||||
endif()
|
||||
add_subdirectory(doc/user)
|
||||
@@ -90,9 +94,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"
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
{
|
||||
"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 /wd4250 /wd4251 /wd4244 /wd4267 /wd4355 /wd4275 /wd4345 /bigobj /EHsc /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",
|
||||
"CMAKE_CXX_FLAGS_DEBUG": "/MTd",
|
||||
"CMAKE_CXX_FLAGS_RELEASE": "/MT",
|
||||
"CMAKE_SHARED_LINKER_FLAGS_RELEASE": "/DEBUG /OPT:REF /OPT:ICF /LTCG",
|
||||
"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}/sparkd",
|
||||
"CMAKE_EXE_LINKER_FLAGS": "-Wno-undef",
|
||||
"CPM_SOURCE_CACHE": "${sourceDir}/.cpm_cache/",
|
||||
"EXTERNALS_ROOT": "${sourceDir}/externals/linux",
|
||||
"CMAKE_CXX_STANDARD": "17",
|
||||
"WEB_TSCONFIG_NAME": "${presetName}",
|
||||
"BUILD_SDK": {
|
||||
"type": "BOOL",
|
||||
"value": "OFF"
|
||||
},
|
||||
"BUILD_WEB": {
|
||||
"type": "BOOL",
|
||||
"value": "ON"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd-dev-clang",
|
||||
"inherits": "sparkd",
|
||||
"displayName": "Development (clang)",
|
||||
"description": "Debug build compiled w/ clang",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug",
|
||||
"CMAKE_EXPORT_COMPILE_COMMANDS": {
|
||||
"type": "BOOL",
|
||||
"value": "ON"
|
||||
},
|
||||
"CMAKE_C_COMPILER": "clang",
|
||||
"CMAKE_CXX_COMPILER": "clang++",
|
||||
"CMAKE_CXX_FLAGS_DEBUG": "-fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-deprecated-builtins -Wno-array-parameter -Wno-ignored-qualifiers --std=c++17 -fdiagnostics-color"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd-dev-gcc",
|
||||
"inherits": "sparkd",
|
||||
"displayName": "Development (gcc)",
|
||||
"description": "Debug build compiled w/ gcc",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug",
|
||||
"CMAKE_EXPORT_COMPILE_COMMANDS": {
|
||||
"type": "BOOL",
|
||||
"value": "ON"
|
||||
},
|
||||
"CMAKE_C_COMPILER": "gcc",
|
||||
"CMAKE_CXX_COMPILER": "g++",
|
||||
"CMAKE_CXX_FLAGS_DEBUG": "-fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++17 -fdiagnostics-color -Wno-stringop-overread -DDEBUG"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "sparkd-prod-clang",
|
||||
"inherits": "sparkd",
|
||||
"displayName": "Production (clang)",
|
||||
"description": "Release build compiled w/ clang",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release",
|
||||
"CMAKE_C_COMPILER": "clang",
|
||||
"CMAKE_CXX_COMPILER": "clang++",
|
||||
"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-prod-gcc",
|
||||
"inherits": "sparkd",
|
||||
"displayName": "Production (gcc)",
|
||||
"description": "Release build compiled w/ gcc",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release",
|
||||
"CMAKE_C_COMPILER": "gcc",
|
||||
"CMAKE_CXX_COMPILER": "g++",
|
||||
"CMAKE_CXX_FLAGS_RELEASE": "-fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++17 -fdiagnostics-color -Wno-stringop-overread -fno-omit-frame-pointer -DNDEBUG -O3"
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"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"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
# CPM Code (https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/get_cpm.cmake)
|
||||
set(CPM_DOWNLOAD_VERSION 0.36.0)
|
||||
|
||||
if(CPM_SOURCE_CACHE)
|
||||
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
|
||||
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
|
||||
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
|
||||
else()
|
||||
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
|
||||
endif()
|
||||
|
||||
# Expand relative path. This is important if the provided path contains a tilde (~)
|
||||
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
|
||||
|
||||
if(NOT(EXISTS ${CPM_DOWNLOAD_LOCATION}))
|
||||
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
|
||||
file(DOWNLOAD
|
||||
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
|
||||
${CPM_DOWNLOAD_LOCATION}
|
||||
)
|
||||
endif()
|
||||
|
||||
include(${CPM_DOWNLOAD_LOCATION})
|
||||
@@ -106,8 +106,9 @@ 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
|
||||
"PYTHONPATH=${SPARK_PYTHON}" ${Protobuf_PROTOC_EXECUTABLE} ARGS
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/tools/venv_exec.sh
|
||||
ARGS
|
||||
${Protobuf_PROTOC_EXECUTABLE}
|
||||
--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
|
||||
|
||||
@@ -46,6 +46,7 @@ function setup_build
|
||||
assert_dir $repo_root
|
||||
assert_dir $build_root
|
||||
set compiler "$argv[1]"
|
||||
set c_compiler (which cc)
|
||||
set build_type "$argv[2]"
|
||||
|
||||
if test \( -z "$build_type" \) -o \( \( "$build_type" != debug \) -a \( "$build_type" != release \) \)
|
||||
@@ -59,6 +60,7 @@ function setup_build
|
||||
else
|
||||
# set compiler_arg "/usr/lib/ccache/clang++"
|
||||
set compiler_arg "clang++"
|
||||
set c_compiler (which clang)
|
||||
end
|
||||
else if test "$build_type" = release
|
||||
set build_type_arg Release
|
||||
@@ -85,7 +87,7 @@ function setup_build
|
||||
rm -rf "$build_dest"
|
||||
mkdir -p "$build_dest"
|
||||
cd "$build_dest"
|
||||
cmake -G Ninja -DCMAKE_BUILD_TYPE=$build_type_arg -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_CXX_COMPILER=$compiler_arg $repo_root
|
||||
cmake -G Ninja -DCMAKE_BUILD_TYPE=$build_type_arg -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_C_COMPILER=$c_compiler -DCMAKE_CXX_COMPILER=$compiler_arg $repo_root
|
||||
end
|
||||
|
||||
# The while loop below removes arguments (via shift) as it parses them.
|
||||
|
||||
+1
-1
Submodule docker/linux updated: 05967d0f18...56c61231f3.
+1
-1
Submodule externals updated: 99c440f568...38322377cf.
@@ -12,6 +12,7 @@ pycodestyle==2.7.0
|
||||
pycparser==2.20
|
||||
pylint==2.10.2
|
||||
PyMeta3==0.5.1
|
||||
termcolor==1.1.0
|
||||
toml==0.10.2
|
||||
wrapt==1.12.1
|
||||
yapf==0.31.0
|
||||
@@ -52,8 +52,7 @@
|
||||
<Exec Command="set PYTHONPATH=$(SparkRoot)\.venv\Scripts\python" />
|
||||
<Exec
|
||||
Command="
|
||||
$(SparkRoot)\tools\build_protos.cmd ^
|
||||
%(Proto3.FullPath) ^
|
||||
$(protoc) %* %(Proto3.FullPath) ^
|
||||
--error_format=msvs ^
|
||||
--proto_path=$(SourceRoot) ^
|
||||
--plugin="protoc-gen-service=$(ProtocPluginBase)\plugin.cmd" ^
|
||||
|
||||
@@ -15,7 +15,9 @@ namespace mbts.spark {
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Core;
|
||||
using Spark.Core.Collections;
|
||||
using Spark.Core.Disposables;
|
||||
using Spark.ViewModel.Commands;
|
||||
|
||||
using System;
|
||||
@@ -33,13 +35,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,32 +83,32 @@ 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();
|
||||
}
|
||||
});
|
||||
}),
|
||||
ObservableAutoWrapper.connect_item_hooks(
|
||||
rows, r => r.observe_is_dirty().Subscribe(_ => _is_dirty.refresh())),
|
||||
_is_dirty.observe_current(true).OnDispatcher().Subscribe(can_revert_observer),
|
||||
Disposable.wrap_collection(rows),
|
||||
Disposable.Create(() => {
|
||||
rows.DisposeAll();
|
||||
_smart_copy_roll_target_to_selection_cmd?.can_exe_sub?.Dispose();
|
||||
_smart_copy_riskless_rate_to_selection_cmd?.can_exe_sub?.Dispose();
|
||||
}));
|
||||
@@ -195,10 +197,18 @@ namespace mbts.spark {
|
||||
};
|
||||
|
||||
void _set_driver_to_nearest_exp(IEnumerable<AnalyticsExpirationParametersRowVM> rows) {
|
||||
Func<ExpirationDriverImmutable, bool> is_unexpired = (d) => {
|
||||
var st = d.Security.to_sec_exp().security_tuple.to_api_sec_tuple();
|
||||
var exp = d.Security.Expiration.date_time();
|
||||
return SecurityExpirationHelper.is_unexpired(st, exp);
|
||||
};
|
||||
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)
|
||||
.Where(d => is_unexpired(d))
|
||||
.TryGetMinElement(
|
||||
d => (r.security.expiration - d.Security.Expiration.date_time()).Ticks.abs(),
|
||||
out var nearest_exp)) {
|
||||
r.driver = nearest_exp;
|
||||
}
|
||||
}
|
||||
@@ -285,7 +295,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);
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace mbts.ui.shell {
|
||||
using mbts.ui.converters;
|
||||
using mbts.ui.extensions;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace mbts.spark {
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
|
||||
@@ -6,6 +6,8 @@ namespace mbts.spark {
|
||||
|
||||
using mbts.analytics;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -40,6 +42,12 @@ namespace mbts.spark {
|
||||
exp_params_out_src.Subscribe(save_exp_params));
|
||||
|
||||
void save_exp_params(IEnumerable<AnalyticsExpirationParameters> exp_params) {
|
||||
Func<AnalyticsExpirationParameters, bool> is_unexpired = (p) => {
|
||||
var st = p.driver_security.security_tuple.to_api_sec_tuple();
|
||||
var exp = p.security.expiration;
|
||||
return SecurityExpirationHelper.is_unexpired(st, exp);
|
||||
};
|
||||
exp_params = exp_params.Where(t => is_unexpired(t));
|
||||
// listens to the commit tag and saves it
|
||||
Log.Gen.info($"AnalyticsParametersManager received commit req. count:{exp_params.Count()}");
|
||||
var to_save = new ExpirationParameterEntryList();
|
||||
|
||||
@@ -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
|
||||
@@ -138,14 +142,74 @@ 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);
|
||||
// f(contract keyed theos, securities) -> id keyed theos
|
||||
// (so the newer UI controls can access theos vis sec keys)
|
||||
var theo_sub =
|
||||
_bus.subscribe(SparkTags.TC2Tags.AllLiveTheosTag)
|
||||
.CombineLatest(bus.subscribe(SparkTags.SystemContractsTag),
|
||||
(theos, sc_data) => (theos, sc_data)).Subscribe(
|
||||
tup => {
|
||||
var keyed_theos = _assemble_keyed_theos(tup.sc_data, tup.theos);
|
||||
_bus.post(SparkTags.KeyedTheos, keyed_theos);
|
||||
}
|
||||
);
|
||||
_disps.Add(theo_sub);
|
||||
}
|
||||
|
||||
static IReadOnlyDictionary<uint, VolSurfaceTheoPoint> _assemble_keyed_theos(
|
||||
SystemContractData sc_data,
|
||||
IReadOnlyDictionary<string, ExpStrikeKeyedData<TheoPoint>> theos) {
|
||||
if (sc_data is null || theos is null) {
|
||||
return new Dictionary<uint, VolSurfaceTheoPoint>(0);
|
||||
}
|
||||
|
||||
HighPerformanceTimer timer = new HighPerformanceTimer();
|
||||
timer.start();
|
||||
Dictionary<uint, VolSurfaceTheoPoint> rv = new Dictionary<uint, VolSurfaceTheoPoint>();
|
||||
foreach (var kv in theos) {
|
||||
var symbol = kv.Key;
|
||||
ExpStrikeKeyedData<TheoPoint> sym_theos = kv.Value;
|
||||
if (sym_theos == null)
|
||||
continue;
|
||||
foreach (var s_kv in sym_theos.get_data_linearly()) {
|
||||
DateTime exp = s_kv.first;
|
||||
double strike = s_kv.second;
|
||||
TheoPoint tp = s_kv.third;
|
||||
// TODO: fix exchange later
|
||||
Tuple<uint?, uint?> keys =
|
||||
sc_data.get_option_sec_id(Venue.Deribit, symbol, exp, strike);
|
||||
if (keys != null) {
|
||||
var c_key = keys.Item1;
|
||||
var p_key = keys.Item2;
|
||||
if (c_key.HasValue) {
|
||||
rv[c_key.Value] = new VolSurfaceTheoPoint(tp, true);
|
||||
}
|
||||
if (p_key.HasValue) {
|
||||
rv[p_key.Value] = new VolSurfaceTheoPoint(tp, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
timer.stop();
|
||||
Log.Gen.info($"VolSurfaceBusManager keyed theos count: {rv.Count} " +
|
||||
$"time: {timer.lastIntervalTime}");
|
||||
return rv;
|
||||
}
|
||||
|
||||
public ThreadedBlackboard bb() {
|
||||
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;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
|
||||
namespace mbts.analytics {
|
||||
using mbts.spark;
|
||||
|
||||
// TheoPoint (from edge) has both calls and puts in the same structure.
|
||||
// This shoudl dis-entangle that
|
||||
public class VolSurfaceTheoPoint {
|
||||
public readonly double theo = double.NaN;
|
||||
public readonly double delta = double.NaN;
|
||||
public readonly double driver = double.NaN;
|
||||
public VolSurfaceTheoPoint(TheoPoint tp, bool is_call) {
|
||||
if (tp != null) {
|
||||
theo = is_call ? tp.fwd_normalized_call : tp.fwd_normalized_put;
|
||||
delta = is_call ? tp.cdelta : tp.pdelta;
|
||||
driver = tp.driver;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ using bts.api;
|
||||
using mbts.ui;
|
||||
using MathNet.Numerics.Providers.FourierTransform;
|
||||
using BCG;
|
||||
using System.Windows.Automation;
|
||||
using bts.collections;
|
||||
|
||||
namespace mbts.spark {
|
||||
// Publishes theos for all options (on the side, also publishes the theos for TC2)
|
||||
@@ -68,19 +70,14 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
private void _log_theos(SystemContractData sc_data,
|
||||
IReadOnlyDictionary<uint, GreeksTuple> greeks_map,
|
||||
DateTime? exp_filt = null) {
|
||||
IReadOnlyDictionary<uint, GreeksTuple> greeks_map) {
|
||||
string rv = "LiveTheosPublisher data: ";
|
||||
foreach (var kv in greeks_map) {
|
||||
var id = kv.Key;
|
||||
var g_tup = kv.Value;
|
||||
if (sc_data.sec_md_map.TryGetValue(id, out var smd)) {
|
||||
if (exp_filt == null ||
|
||||
(smd.security.security_type() == SecurityType.Option &&
|
||||
smd.security.Option.expiration_date().Equals(exp_filt.Value))) {
|
||||
string sec_str = smd.ToString();
|
||||
rv += "\n" + $"id: {id} sec: {sec_str} greeks: {g_tup}";
|
||||
}
|
||||
string sec_str = smd.ToString();
|
||||
rv += "\n" + $"id: {id} sec: {sec_str} greeks: {g_tup}";
|
||||
}
|
||||
}
|
||||
bts.Log.Gen.info(rv);
|
||||
@@ -134,6 +131,7 @@ namespace mbts.spark {
|
||||
return;
|
||||
}
|
||||
var k_theos = new Dictionary<SecurityStrike, TheoPoint>();
|
||||
// option spreads
|
||||
foreach (var kv in sc_data.strike_map) {
|
||||
foreach (SecurityStrike k in kv.Value) {
|
||||
var (call_id, put_id) = k.call_put_id;
|
||||
@@ -142,26 +140,59 @@ namespace mbts.spark {
|
||||
k_theos[k] = tp;
|
||||
// put it in the output map
|
||||
if (call_id.HasValue) {
|
||||
var normalized_theo = VolSurfaceCoreFunctions.normalize_theo(tp.call, tp.driver);
|
||||
res.Add(call_id.Value,
|
||||
new GreeksTuple(tp.vol, tp.driver, tp.call, tp.cdelta, tp.cgamma,
|
||||
tp.cvega, tp.c_theta, Double.NaN));
|
||||
tp.cvega, tp.c_theta, Double.NaN, normalized_theo));
|
||||
}
|
||||
if (put_id.HasValue) {
|
||||
var normalized_theo = VolSurfaceCoreFunctions.normalize_theo(tp.put, tp.driver);
|
||||
res.Add(put_id.Value,
|
||||
new GreeksTuple(tp.vol, tp.driver, tp.put, tp.pdelta, tp.pgamma,
|
||||
tp.pvega, tp.p_theta, Double.NaN));
|
||||
tp.pvega, tp.p_theta, Double.NaN, normalized_theo));
|
||||
}
|
||||
}
|
||||
}
|
||||
// futures
|
||||
var future_theos = _get_future_theos();
|
||||
res.AddRange(future_theos);
|
||||
// spreads, all option and future non tied spreads
|
||||
foreach (var spr in sc_data.spreads) {
|
||||
GreeksTuple gtup = StatelessSpreadCalculator.compute_non_tied_spread(spr.security, res);
|
||||
res.Add(spr.security.Id, gtup);
|
||||
}
|
||||
// copy and publish
|
||||
IReadOnlyDictionary<uint, GreeksTuple> res_ro = res;
|
||||
bts.Log.Gen.info($"LiveTheoPublisher._interp_and_publish posting " +
|
||||
$"count: {res_ro.Count}");
|
||||
$"count: {res_ro.Count}");
|
||||
_timer.stop();
|
||||
_logger.log(_log_id, _log_id, _timer.lastIntervalTime);
|
||||
_bb.post(SparkTags.Greeks, res_ro);
|
||||
// oh and those TC2 theos for comptability
|
||||
_publish_tc2_theos(k_theos);
|
||||
}
|
||||
|
||||
// If we do any rolls like SP for futures, it will be here
|
||||
IDictionary<UInt32, GreeksTuple> _get_future_theos() {
|
||||
var rv = new Dictionary<UInt32, GreeksTuple>();
|
||||
SystemContractData sc_data = _bb.read_state(SparkTags.SystemContractsTag);
|
||||
if (sc_data == null)
|
||||
return rv;
|
||||
foreach (var kv in sc_data.exp_map) {
|
||||
var id = kv.Value;
|
||||
SecurityMD sec_md;
|
||||
if (sc_data.sec_md_map.TryGetValue(id, out sec_md)) {
|
||||
if (sec_md.security.HasFuture) {
|
||||
SecurityExpiration exp = kv.Key;
|
||||
double pr = sec_md.md.fixing_price;
|
||||
rv.Add(sec_md.security.Id,
|
||||
new GreeksTuple(0, pr, pr, 1, 0, 0, 0, 0, pr));
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
// recomputes and publishes them periodicially
|
||||
void _publish_future_theos() {
|
||||
if (DateTime.Now - _last_future_theos_published < _futures_theos_publish_period)
|
||||
|
||||
@@ -107,6 +107,22 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
public SecurityImmutable? get_option_contract(
|
||||
Venue venue, string symbol, DateTime exp, double strike, PutOrCall cp) {
|
||||
var k_tup = get_option_sec_id(venue, symbol, exp, strike);
|
||||
if (k_tup != null) {
|
||||
var id = cp == PutOrCall.Call ? k_tup.Item1 : k_tup.Item2;
|
||||
if (id.HasValue) {
|
||||
var id_val = id.Value;
|
||||
SecurityMD sec_md;
|
||||
if (sec_md_map.TryGetValue(id_val, out sec_md)) {
|
||||
return sec_md.security;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Tuple<uint?, uint?> get_option_sec_id(
|
||||
Venue venue, string symbol, DateTime exp, double strike) {
|
||||
var s_exp = new SecurityExpiration(venue, SecurityType.Option, symbol, exp);
|
||||
@@ -242,5 +258,12 @@ namespace mbts.spark {
|
||||
kv.Value.Count > 0).Select(kv => kv.Key.expiration);
|
||||
}
|
||||
|
||||
public IEnumerable<SecurityMD> spreads {
|
||||
get {
|
||||
return sec_md_map.Where(kv => kv.Value.security.HasSpread)
|
||||
.Select(kv => kv.Value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@ using mbts.analytics;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
|
||||
using Spark.Core;
|
||||
using Spark.Core.Disposables;
|
||||
using Spark.Core.Collections;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -51,7 +55,7 @@ namespace mbts.spark {
|
||||
var vs_removes = removed.Select(exp => exp.ToVSExp());
|
||||
|
||||
var true_removed = removed.Where(rmv => !vs_adds.Contains(rmv.ToVSExp()));
|
||||
var true_added = added.Where(add => !vs_removes.Contains(add.ToVSExp()));
|
||||
var true_added = added.Except(vs_removes.Concat(_hidden_exps), v => v.ToVSExp());
|
||||
var changed_calc_modes = added.Where(add => vs_removes.Contains(add.ToVSExp()));
|
||||
|
||||
foreach (var tr in true_removed) {
|
||||
@@ -61,16 +65,10 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var ta in true_added) {
|
||||
if (_hidden_exps.Contains(ta.ToVSExp()) ||
|
||||
!rows.TryGetFirst(r => r.expiration.expiration == ta.expiration, out var row)) {
|
||||
continue;
|
||||
}
|
||||
visible_rows.InsertSorted(row,
|
||||
Comparer<IExpirationBasedRow>.Create(
|
||||
(r1, r2) => r1.expiration.CompareTo(r2.expiration))
|
||||
.wrap<IExpirationBasedRow, object>());
|
||||
}
|
||||
var comp = ComparerWrapper<object>.wrap_cast(
|
||||
NullCheckComparer.create<IExpirationBasedRow>(
|
||||
(r1, r2) => r1.expiration.CompareTo(r2.expiration)));
|
||||
visible_rows.InsertSorted(true_added, comp);
|
||||
|
||||
foreach (var ccm in changed_calc_modes) {
|
||||
int index = visible_rows
|
||||
|
||||
@@ -10,6 +10,8 @@ namespace mbts.spark {
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -47,6 +49,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 +62,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;
|
||||
@@ -113,7 +117,7 @@ namespace mbts.spark {
|
||||
})
|
||||
.BufferLatest(TimeSpan.FromSeconds(0.1))
|
||||
.OnDispatcher()
|
||||
.SelectManyInSeries(series => Observable.Create<SeriesVM>(o => {
|
||||
.SelectSeries(series => Observable.Create<SeriesVM>(o => {
|
||||
o.OnNext(null);
|
||||
return Disposable.Create(series
|
||||
.Select(svm => svm.points.Subscribe((s, e) => o.OnNext(svm)))
|
||||
|
||||
@@ -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,10 @@ namespace mbts.spark.VolSurface {
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
|
||||
using Spark.Core;
|
||||
using Spark.Core.Disposables;
|
||||
using Spark.Core.Collections;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -25,17 +30,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,16 +71,31 @@ 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;
|
||||
this.model.on_committed_grid_change -= _on_grid_updated;
|
||||
Disposable.dispose(rows);
|
||||
rows.DisposeAll(true);
|
||||
Disposable.dispose(ref _shift_editor);
|
||||
}),
|
||||
_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 +115,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 +141,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 +165,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 +243,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 +268,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) {
|
||||
@@ -324,7 +349,7 @@ namespace mbts.spark.VolSurface {
|
||||
model.set_candidate_grid(current_grid);
|
||||
|
||||
class ColumnsModel : IDisposable {
|
||||
IDisposable _dispose;
|
||||
IDisposable? _dispose;
|
||||
|
||||
public ColumnsModel(VolSurfaceColumn row_header_col) {
|
||||
views_with_header_ro = ObservableAutoWrapper.create_read_only_wrapper(views_with_header);
|
||||
|
||||
@@ -8,6 +8,8 @@ namespace mbts.spark {
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -79,6 +81,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,19 @@ namespace mbts.spark.VolSurface {
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.shell;
|
||||
|
||||
using Spark.Core;
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
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 +24,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 +34,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 +51,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 +80,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 +99,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));
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ namespace mbts.spark {
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
using Spark.Core.Protobuf;
|
||||
|
||||
using System;
|
||||
@@ -539,7 +540,7 @@ namespace mbts.spark {
|
||||
public ObservableCollection<VSSymbol> symbols { get; private set; }
|
||||
|
||||
public void Dispose() =>
|
||||
Disposable.dispose(symbols);
|
||||
symbols.DisposeAll(true);
|
||||
}
|
||||
|
||||
public class VSSymbolStructureVM : DisposableViewModelBase {
|
||||
@@ -550,11 +551,11 @@ namespace mbts.spark {
|
||||
_selected_driver_grid = backing<VSSymbolGridVM>(nameof(selected_driver_grid));
|
||||
settings.core_settings.master_slave_relationships ??= new List<VolSurfaceSymbolRelationship>();
|
||||
settings.core_settings.implied_vol_marketdata_relationships ??= new List<VolSurfaceSymbolRelationship>();
|
||||
_dispose = new DisposableCombo(
|
||||
_dispose = Disposable.Create(
|
||||
driver_grids.Subscribe((s, e) =>
|
||||
selected_driver_grid ??= driver_grids.FirstOrDefault()),
|
||||
bus.subscribe(SparkTags.ExpirationParametersInputTag).OnDispatcher().Subscribe(on_exp_params_input)) +
|
||||
new Action(() => Disposable.dispose(driver_grids));
|
||||
bus.subscribe(SparkTags.ExpirationParametersInputTag).OnDispatcher().Subscribe(on_exp_params_input),
|
||||
Disposable.Create(() => driver_grids.DisposeAll(true)));
|
||||
|
||||
void on_exp_params_input(AnalyticsExpirationParametersMap data) {
|
||||
var driver_map = data.get_option_driver_map();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace mbts.spark {
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.shell;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
using Spark.ViewModel.Commands;
|
||||
|
||||
using System;
|
||||
@@ -60,6 +61,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 +187,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;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
using mbts.ui.shell;
|
||||
|
||||
using Spark.Core;
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
using mbts.analytics;
|
||||
using mbts.ui.controls;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
using Spark.Core.Protobuf;
|
||||
|
||||
using System;
|
||||
@@ -126,6 +127,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 +160,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 +584,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 +627,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) {
|
||||
|
||||
@@ -172,6 +172,18 @@ namespace mbts.spark {
|
||||
return new(sec.Exchange, sec.ContractCase, sec.Symbol, exp_date, sec.Id);
|
||||
}
|
||||
|
||||
public static SecurityTuple security_tuple(this Security sec) {
|
||||
return security_tuple(new SecurityImmutable(sec));
|
||||
}
|
||||
|
||||
public static SecurityTuple security_tuple(this SecurityImmutable sec) {
|
||||
bts.api.SecurityTuple rv = new SecurityTuple();
|
||||
rv.Symbol = sec.Symbol;
|
||||
rv.Type = sec.security_type();
|
||||
rv.Venue = sec.Exchange;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static ExpirationDriver to_exp_driver(this SecurityExpiration sec_exp) =>
|
||||
new() {
|
||||
Security = new() {
|
||||
|
||||
@@ -5,6 +5,8 @@ using bts.api.core;
|
||||
using bts.collections;
|
||||
using bts.utils;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Composition;
|
||||
@@ -41,7 +43,7 @@ namespace mbts.spark {
|
||||
on_users = Observable.Return(DictionaryHelper.wrap_value(user.id, user.name));
|
||||
all_user_tuples = user.permissions == UserTuple.Permissions.Admin ?
|
||||
service.subscribei_admin_data()
|
||||
.Select(u => u.all.TryFirst())
|
||||
.Select(u => u.all.FirstOrNull())
|
||||
.Where(ad => ad.HasValue)
|
||||
.Select(ad => ad.Value.Users
|
||||
.Where(u => user.can_access_user_data(u.Id))
|
||||
@@ -50,11 +52,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; }
|
||||
@@ -76,7 +80,7 @@ namespace mbts.spark {
|
||||
}));
|
||||
|
||||
public AccountTuple? get_default_account() =>
|
||||
_account_map.Select(kv => new AccountTuple(kv.Key, kv.Value)).TryFirst();
|
||||
_account_map.Select(kv => new AccountTuple(kv.Key, kv.Value)).FirstOrNull();
|
||||
|
||||
public void Dispose() =>
|
||||
Disposable.dispose(ref _dispose);
|
||||
|
||||
@@ -10,7 +10,8 @@ namespace mbts.analytics {
|
||||
double gamma = double.NaN,
|
||||
double vega = double.NaN,
|
||||
double theta = double.NaN,
|
||||
double rho = double.NaN) {
|
||||
double rho = double.NaN,
|
||||
double normalized_theo = double.NaN) {
|
||||
this.vol = vol;
|
||||
this.driver = driver;
|
||||
this.theo = theo;
|
||||
@@ -19,6 +20,7 @@ namespace mbts.analytics {
|
||||
this.vega = vega;
|
||||
this.theta = theta;
|
||||
this.rho = rho;
|
||||
this.normalized_theo = normalized_theo;
|
||||
}
|
||||
|
||||
public static GreeksTuple empty => new();
|
||||
@@ -31,6 +33,7 @@ namespace mbts.analytics {
|
||||
public double vega { get; }
|
||||
public double theta { get; }
|
||||
public double rho { get; }
|
||||
public double normalized_theo { get; }
|
||||
|
||||
public bool Equals(GreeksTuple other) =>
|
||||
vol.Equals(other.vol) &&
|
||||
@@ -65,7 +68,8 @@ namespace mbts.analytics {
|
||||
double? gamma = null,
|
||||
double? vega = null,
|
||||
double? theta = null,
|
||||
double? rho = null) =>
|
||||
double? rho = null,
|
||||
double? normalized_theo = null) =>
|
||||
new(
|
||||
vol ?? greeks_tuple.vol,
|
||||
driver ?? greeks_tuple.driver,
|
||||
@@ -74,12 +78,7 @@ namespace mbts.analytics {
|
||||
gamma ?? greeks_tuple.gamma,
|
||||
vega ?? greeks_tuple.vega,
|
||||
theta ?? greeks_tuple.theta,
|
||||
rho ?? greeks_tuple.rho);
|
||||
|
||||
public static double normalized_theo(this in GreeksTuple greeks_tuple) =>
|
||||
greeks_tuple.theo / greeks_tuple.driver;
|
||||
|
||||
public static double normalized_delta(this in GreeksTuple greeks_tuple) =>
|
||||
greeks_tuple.delta / greeks_tuple.driver;
|
||||
rho ?? greeks_tuple.rho,
|
||||
normalized_theo ?? greeks_tuple.normalized_theo);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ namespace mbts {
|
||||
|
||||
using ProtoBuf;
|
||||
|
||||
using Spark.Core;
|
||||
using Spark.Core.Collections;
|
||||
using Spark.Core.Protobuf;
|
||||
|
||||
@@ -100,17 +101,13 @@ namespace mbts {
|
||||
|
||||
public static IComparer<SecurityExpiration> get_comparer(Properties prop) {
|
||||
return prop switch {
|
||||
Properties.Type => wrap(s => s.security_type),
|
||||
Properties.Symbol => wrap(s => s.symbol),
|
||||
Properties.Expiration => wrap(s => s.expiration),
|
||||
Properties.Venue => wrap(s => s.exchange),
|
||||
Properties.Id => wrap(s => s.id).to_safe(),
|
||||
Properties.Type => ComparerWrapper<SecurityExpiration>.wrap(s => s.security_type),
|
||||
Properties.Symbol => ComparerWrapper<SecurityExpiration>.wrap(s => s.symbol),
|
||||
Properties.Expiration => ComparerWrapper<SecurityExpiration>.wrap(s => s.expiration),
|
||||
Properties.Venue => ComparerWrapper<SecurityExpiration>.wrap(s => s.exchange),
|
||||
Properties.Id => ComparerWrapper<SecurityExpiration>.wrap(s => s.id),
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
|
||||
static IComparer<SecurityExpiration> wrap<T>(
|
||||
Func<SecurityExpiration, T> selector, IComparer<T>? comparer = null) =>
|
||||
(comparer ?? Comparer<T>.Default).wrap(selector);
|
||||
}
|
||||
|
||||
public static IComparer<SecurityExpiration> get_comparer(params Properties[] hierarchy) =>
|
||||
@@ -189,6 +186,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 {
|
||||
|
||||
@@ -943,7 +943,15 @@ namespace mbts.analytics {
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region inverse contracts
|
||||
// Bitcoin contracts, for example, where the strike is in USD, and the theo
|
||||
// needs to be in terms of the underlying contract
|
||||
public static double normalize_theo(double theo, double fwd) {
|
||||
return fwd == 0 ? Double.NaN : (theo / fwd);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Other Pricing Utilities
|
||||
|
||||
|
||||
@@ -19,9 +19,8 @@ namespace mbts.analytics
|
||||
/// with default inputs
|
||||
public static VolSurfaceInput sync_input_expirations_to_master_list(VolSurfaceInput vs_input, IEnumerable<VolSurfaceExpiration> system_exp_list)
|
||||
{
|
||||
var vs_exp_map = vs_input.surface_parameters.curve_parameters_map
|
||||
.empty_if_null().Select(t => t.Item1).ToHashSet();
|
||||
var sys_exp_map = system_exp_list.ToHashSet();
|
||||
HashSet<VolSurfaceExpiration> vs_exp_map = new HashSet<VolSurfaceExpiration>(vs_input.surface_parameters.curve_parameters_map.Select(t => t.Item1)),
|
||||
sys_exp_map = new HashSet<VolSurfaceExpiration>(system_exp_list);
|
||||
sys_exp_map.difference(
|
||||
vs_exp_map,
|
||||
out HashSet<VolSurfaceExpiration> deleted_exps,
|
||||
@@ -681,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
|
||||
}
|
||||
}
|
||||
@@ -674,7 +674,7 @@ namespace mbts.analytics {
|
||||
var vol_time = VolSurfaceCoreFunctions.compute_vol_time(
|
||||
vs_input, vs_standard_time.server_time_utc);
|
||||
var exp_inp_data = vs_nonvol_input.get_option_exp_input();
|
||||
foreach (var (exp, curve_params) in vs_input.surface_parameters.curve_parameters_map.empty_if_null()) {
|
||||
foreach (var (exp, curve_params) in vs_input.surface_parameters.curve_parameters_map) {
|
||||
var time_shift = DoubleHelper.CoerceNaN(curve_params.core_parameters.time_shift);
|
||||
_compute_option_bizt(
|
||||
vs_input, exp, vol_time, time_shift, out var biz_yrs, out var biz_days_per_yr);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using bts.api;
|
||||
|
||||
using mbts;
|
||||
using mbts.config;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Composition;
|
||||
using System.Diagnostics;
|
||||
|
||||
@@ -8,17 +8,16 @@ using mbts.ui;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.utilities;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Composition;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows;
|
||||
using bts.api.analytics;
|
||||
using BCG;
|
||||
|
||||
using Disposable = mbts.Disposable;
|
||||
|
||||
namespace bts {
|
||||
[Export(typeof(IShellDaemon))]
|
||||
class AnalyticsDaemon : IShellDaemon, IDisposable {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
|
||||
using mbts;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
@@ -7,6 +7,8 @@ using mbts;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Composition;
|
||||
|
||||
@@ -11,6 +11,7 @@ using System.Reactive.Linq;
|
||||
|
||||
using SecurityKey = System.UInt32;
|
||||
using MDHandle = mbts.co2.FakeMDConsumerHandle;
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
namespace bts {
|
||||
//[Export(typeof(IShellDaemon))]
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace bts.daemons {
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
@@ -17,7 +19,7 @@ namespace bts.daemons {
|
||||
|
||||
[Export(typeof(IShellDaemon))]
|
||||
public sealed class FakeSymbolDriverDaemon : IShellDaemon, IDisposable {
|
||||
IDisposable _dispose;
|
||||
IDisposable? _dispose;
|
||||
|
||||
public FakeSymbolDriverDaemon(IBus bus) {
|
||||
int tid_counter = 1;
|
||||
@@ -68,6 +70,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 +84,11 @@ namespace bts.daemons {
|
||||
price,
|
||||
theo ?? price + 10 * new Random().NextDouble(),
|
||||
account,
|
||||
account_id,
|
||||
true,
|
||||
DateTime.Now,
|
||||
"FakeTrader");
|
||||
"FakeTrader",
|
||||
1);
|
||||
return t1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,15 +8,14 @@ using mbts.ui;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.utilities;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Composition;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows;
|
||||
|
||||
using Disposable = mbts.Disposable;
|
||||
|
||||
namespace bts {
|
||||
[Export(typeof(IShellDaemon))]
|
||||
class GlobalAlertsDaemon : IShellDaemon, IDisposable {
|
||||
@@ -39,13 +38,14 @@ namespace bts {
|
||||
_notification_service = notification_service;
|
||||
_launcher = new ThreadedWindowLauncher(_window_name);
|
||||
_dispose = Disposable.Create(
|
||||
bus.subscribe(SparkTags.ShowGlobalAlertsTag)
|
||||
.Subscribe(_ => _launcher.show(_view_factory)),
|
||||
_hub.subscribe_default_settings()
|
||||
.SubscribeEach(s => new CompositeDisposable(
|
||||
s.alerts.trade_alerts.Where(t => t.is_enabled).Select(
|
||||
a => _notification_service.link_to_trades(
|
||||
a.predicate.security_criteria, a.predicate.create(), a.sound)))));
|
||||
bus.subscribe(SparkTags.ShowGlobalAlertsTag).Subscribe(_ =>
|
||||
_launcher.show(_view_factory)),
|
||||
_hub.subscribe_default_settings().SubscribeEach(s =>
|
||||
Disposable.Create(s.alerts.trade_alerts
|
||||
.Where(t => t.is_enabled)
|
||||
.Select(a => _notification_service.link_to_trades(
|
||||
a.predicate.security_criteria, a.predicate.create(), a.sound))
|
||||
.ToList())));
|
||||
}
|
||||
|
||||
Window _view_factory() {
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace bts {
|
||||
using mbts.ui;
|
||||
|
||||
using Spark.Core.Data;
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
@@ -142,6 +143,6 @@ namespace bts {
|
||||
}
|
||||
|
||||
public void Dispose() =>
|
||||
Disposable.dispose(_resources);
|
||||
_resources.DisposeAll(true);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using BCG;
|
||||
|
||||
using bts.api;
|
||||
using bts.api.synthetic;
|
||||
using bts.collections;
|
||||
using bts.md;
|
||||
using bts.utils;
|
||||
|
||||
@@ -10,6 +11,8 @@ using mbts.co2;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -27,16 +30,22 @@ namespace bts {
|
||||
IDisposable _dispose;
|
||||
Dictionary<uint, SecurityMD> _server_sec_map = new Dictionary<uint, SecurityMD>();
|
||||
Dictionary<uint, SecurityMD> _fake_sec_map = new Dictionary<uint, SecurityMD>();
|
||||
private readonly IList<IDisposable> _subs = new List<IDisposable>();
|
||||
|
||||
[ImportingConstructor]
|
||||
public MergedMDDaemon(IBus bus) {
|
||||
//TempTester.test_analytics();
|
||||
bts.Log.Gen.info("MergedMDDaemon started");
|
||||
_bus = bus;
|
||||
_bus.subscribe(SparkTags.ServerSecuritiesTag).OnDispatcher().Subscribe(
|
||||
d => _on_server_sec_map(d));
|
||||
_bus.subscribe(SparkTags.FakeSecuritiesTag).OnDispatcher().Subscribe(
|
||||
d => _on_fake_sec_map(d));
|
||||
_subs.Add(_bus.subscribe(SparkTags.ServerSecuritiesTag).OnDispatcher().Subscribe(
|
||||
d => _on_server_sec_map(d)));
|
||||
_subs.Add(_bus.subscribe(SparkTags.FakeSecuritiesTag).OnDispatcher().Subscribe(
|
||||
d => _on_fake_sec_map(d)));
|
||||
// This is done periodically to remove expired contracts
|
||||
// (disabling it right now because we are not sure if deleting securities
|
||||
// works with the various UI windows)
|
||||
// _subs.Add(_bus.subscribe(SparkTags.SparkTimer).BufferLatest(TimeSpan.FromMinutes(1))
|
||||
// .Subscribe(t => _merge_and_post()));
|
||||
}
|
||||
|
||||
private void _log_options(IReadOnlyDictionary<uint, SecurityMD> sec_map) {
|
||||
@@ -54,33 +63,27 @@ namespace bts {
|
||||
|
||||
private void _on_server_sec_map(IReadOnlyDictionary<uint, SecurityMD> sec_map) {
|
||||
_log_options(sec_map);
|
||||
bts.Log.Gen.info(String.Format("MergedMDDaemon._on_server_sec_map sz:{0}", sec_map.Count()));
|
||||
bts.Log.Gen.info(String.Format("MergedMDDaemon._on_server_sec_map sz: {0}", sec_map.Count()));
|
||||
_server_sec_map = new Dictionary<uint, SecurityMD>(sec_map);
|
||||
_merge_and_post();
|
||||
}
|
||||
|
||||
private void _on_fake_sec_map(IReadOnlyDictionary<uint, SecurityMD> sec_map) {
|
||||
bts.Log.Gen.info(String.Format("MergedMDDaemon._on_fake_sec_map sz:{0}", sec_map.Count()));
|
||||
bts.Log.Gen.info(String.Format("MergedMDDaemon._on_fake_sec_map sz: {0}", sec_map.Count()));
|
||||
_fake_sec_map = new Dictionary<uint, SecurityMD>(sec_map);
|
||||
_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;
|
||||
}
|
||||
return true;
|
||||
var sec = sec_md.security;
|
||||
return SecurityExpirationHelper.is_unexpired(sec);
|
||||
};
|
||||
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;
|
||||
}
|
||||
bts.Log.Gen.info(String.Format("MergedMDDaemon._merge_and_post sz:{0}", to_pub.Count()));
|
||||
bts.Log.Gen.info(String.Format("MergedMDDaemon._merge_and_post sz: {0}", to_pub.Count()));
|
||||
_bus.post(SparkTags.SecuritiesTag, to_pub);
|
||||
SystemContractData sc_data = new SystemContractData(to_pub);
|
||||
_bus.post(SparkTags.SystemContractsTag, sc_data);
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
using bts.api.orderman;
|
||||
using bts.spark;
|
||||
|
||||
using mbts;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Composition;
|
||||
|
||||
@@ -10,6 +10,8 @@ using mbts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.spark;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
using bts.api;
|
||||
using mbts.ui;
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Composition;
|
||||
using System.Reactive.Linq;
|
||||
using System.Collections.Generic;
|
||||
using mbts.spark;
|
||||
using bts.api.orderman;
|
||||
using bts.collections;
|
||||
using System.Linq;
|
||||
using Microsoft.Scripting.Utils;
|
||||
|
||||
namespace bts {
|
||||
[Export(typeof(IShellDaemon))]
|
||||
class RFQDaemon : IShellDaemon, IDisposable {
|
||||
private readonly IBus _bus;
|
||||
private readonly bts.api.orderman.OrderService _order_service;
|
||||
private List<IDisposable> _subs = new List<IDisposable>();
|
||||
|
||||
[ImportingConstructor]
|
||||
public RFQDaemon(IBus bus, bts.api.orderman.OrderService order_service) {
|
||||
bts.Log.Gen.info("RFQDaemon started");
|
||||
_bus = bus;
|
||||
_order_service = order_service;
|
||||
var d = bus.subscribe(SparkTags.RFQSend)
|
||||
.Subscribe(_handle_rfq);
|
||||
}
|
||||
|
||||
private void _handle_rfq(RFQRequestImmutable rfq) {
|
||||
bts.Log.Gen.info($"RFQDaemon._handle_rfq");
|
||||
_order_service.send_rfq(rfq);
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
foreach (var d in _subs) {
|
||||
d.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
using mbts.spark;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Composition;
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace bts.daemons {
|
||||
using mbts.ui;
|
||||
|
||||
using Spark.Core.Collections;
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -29,10 +30,11 @@ 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>();
|
||||
IDisposable _dispose;
|
||||
IDisposable? _dispose;
|
||||
|
||||
[ImportingConstructor]
|
||||
public ReportDaemon(
|
||||
@@ -48,6 +50,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 +62,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 +160,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);
|
||||
|
||||
@@ -5,6 +5,8 @@ using mbts;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Composition;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using bts.api.core;
|
||||
using bts.metrics;
|
||||
|
||||
using mbts;
|
||||
using mbts.config;
|
||||
using mbts.ui;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Composition;
|
||||
using System.Linq;
|
||||
|
||||
@@ -60,6 +60,7 @@ namespace mbts.ui {
|
||||
LetterDKey = nameof(LetterDKey),
|
||||
MenuOrientationGeometryKey = nameof(MenuOrientationGeometryKey),
|
||||
OrdersGeometryKey = nameof(OrdersGeometryKey),
|
||||
PaperPlaneGeometryKey = nameof(PaperPlaneGeometryKey),
|
||||
PauseGeometryKey = nameof(PauseGeometryKey),
|
||||
PaymentGeometryKey = nameof(PaymentGeometryKey),
|
||||
PencilGeometryKey = nameof(PencilGeometryKey),
|
||||
@@ -203,6 +204,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);
|
||||
@@ -229,17 +231,23 @@ namespace mbts.ui {
|
||||
public static ImageSource Import => load_resource_and_freeze("Import");
|
||||
public static ImageSource Key => create_icon(KeyGeometryKey);
|
||||
public static ImageSource Knight { get { return load_resource_and_freeze("Knight"); } }
|
||||
public static ImageSource manual_fills => create_icon(DataEditGeometryKey);
|
||||
public static ImageSource MenuOrientation => create_icon(MenuOrientationGeometryKey);
|
||||
public static ImageSource open_orders => Book;
|
||||
public static ImageSource options_view => Sheets;
|
||||
public static ImageSource paper_plane => create_icon(
|
||||
PaperPlaneGeometryKey, null, new(Brushes.Black, 2));
|
||||
public static ImageSource Pause => create_icon(PauseGeometryKey);
|
||||
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);
|
||||
public static ImageSource RubberStamp => create_icon(RubberStampGeometryKey);
|
||||
public static ImageSource RedoCircular => create_icon(UndoCircularGeometryKey, Brushes.Black, null, new ScaleTransform(-1, 1));
|
||||
public static ImageSource rfq => paper_plane;
|
||||
public static ImageSource Spawn { get { return load_resource_and_freeze("Spawn"); } }
|
||||
public static ImageSource Speaker => create_icon(SpeakerGeometryKey);
|
||||
public static ImageSource Star => create_icon(StarGeometryKey);
|
||||
|
||||
@@ -325,6 +325,18 @@
|
||||
M50.14375,33.389126C50.416863,33.394688,50.653496,33.587773,50.705998,33.864617L50.015995,45.114388C49.810295,46.291462,49.130394,45.097489,49.130394,45.097489L47.65659,42.640538C42.747776,49.635197 34.633152,54.221001 25.433924,54.221001 14.884193,54.221001 5.7437552,48.204125 1.2449617,39.419205 0.80087067,38.552021 0.21358696,37.705738 0.052086769,36.736958 -0.49735315,33.490925 3.4507786,32.901036 4.8049124,34.432404 5.3674143,35.067692 6.034036,36.16407 6.5079177,37.026051 10.106778,43.799416 17.2321,48.413819 25.433924,48.413819 32.656544,48.413819 39.026364,44.826695 42.903977,39.351506L40.229367,38.854115C40.229367,38.854115,38.677464,38.647118,39.742466,37.996033L50.024895,33.398526C50.064972,33.391365,50.104733,33.388333,50.14375,33.389126z M23.030291,9.0310004L27.889918,9.0310004 27.889918,13.028299C30.539786,13.205498,32.324932,13.958096,33.464161,14.528294L33.964176,14.775793 32.417435,20.038878 31.706417,19.68068C30.579987,19.11958 28.839241,18.244583 26.149073,18.244583 24.006916,18.244583 22.723183,19.122181 22.723183,20.590876 22.723183,21.894272 23.943314,22.804369 27.551308,24.187165 32.706444,26.124659 34.911,28.702853 34.911,32.817341 34.911,36.892929 32.090527,40.05172 27.673611,40.989117L27.673611,45.540001 22.767485,45.540001 22.767485,41.330414C20.252919,41.155815,17.695551,40.424118,16.101811,39.404721L15.683999,39.137619 17.221739,33.731438 17.969059,34.180634C19.088988,34.851235 21.402748,35.97873 24.340325,35.97873 26.734886,35.97873 28.276728,34.921635 28.276728,33.291336 28.276728,31.986641 27.547409,30.853846 23.986016,29.57255 20.083815,28.144253 16.095511,26.04406 16.095511,21.239174 16.095511,17.280985 18.737379,14.291395 23.030291,13.329098z M25.268765,0C35.819447,2.7347414E-07 44.961449,6.0155495 49.458798,14.804573 49.902695,15.669173 50.490094,16.516972 50.651287,17.48427 51.198281,20.734265 47.255726,21.318962 45.901341,19.789065 45.336346,19.153567 44.669552,18.051968 44.19566,17.19517 40.5957,10.421881 33.473275,5.8072398 25.268765,5.8072393 18.047545,5.8072398 11.678013,9.3918336 7.8003562,14.867073L10.474627,15.367072C10.474627,15.367072,12.026909,15.574172,10.962921,16.223872L0.67933281,20.826762C0.36037083,20.880062,0.057029126,20.669165,0.00099972012,20.354063L0.69093342,9.1118043C0.89552094,7.9296158,1.5738537,9.124924,1.5738539,9.124924L3.0452772,11.583379C7.9566038,4.584462,16.073666,2.7347414E-07,25.268765,0z
|
||||
</sys:String>
|
||||
|
||||
<!-- Paper Plane (the icon is free to use if we include this information in our credit section)
|
||||
Icon by <a href="https://freeicons.io/profile/2257">www.wishforge.games</a> on <a href="https://freeicons.io">freeicons.io</a>
|
||||
-->
|
||||
<x:Array x:Key="{x:Static mbts:Icons.PaperPlaneGeometryKey}" Type="sys:String">
|
||||
<sys:String>
|
||||
M26.4,2.9L3.8,15c-0.7,0.4-0.7,1.5,0.1,1.8l20.8,8.7c0.6,0.3,1.3-0.2,1.4-0.8l1.7-20.8 C27.9,3,27.1,2.5,26.4,2.9z
|
||||
</sys:String>
|
||||
<sys:String>
|
||||
M26,4L13,20v7.3c0,0.9,1.2,1.4,1.8,0.7L19,23
|
||||
</sys:String>
|
||||
</x:Array>
|
||||
|
||||
<sys:String x:Key="{x:Static mbts:Icons.PauseGeometryKey}">
|
||||
M17.94,0L29.150001,0 29.150001,32 17.94,32z M0,0L11.210002,0 11.210002,32 0,32z
|
||||
</sys:String>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
using Spark.Core.Reactive;
|
||||
|
||||
using System;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#nullable enable
|
||||
namespace Spark.Model {
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.co2;
|
||||
|
||||
using mbts.spark;
|
||||
|
||||
using Spark.Api.Reactive;
|
||||
using Spark.Core;
|
||||
|
||||
using System.Composition;
|
||||
|
||||
class SecurityResolverExporter : VirtualSingleton<SecurityResolverExporter> {
|
||||
readonly LazyOnce<SecurityResolver>? _resolver;
|
||||
|
||||
[ImportingConstructor]
|
||||
public SecurityResolverExporter(IBus bus, MarketDataRelay md_relay) =>
|
||||
_resolver = new(() => new(md_relay, bus.subscribe(SparkTags.SecuritiesTag)));
|
||||
|
||||
[Export]
|
||||
public SecurityResolver resolver =>
|
||||
Log.notnull(_resolver);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.ui.settings {
|
||||
public interface ISavedWindowFactory {
|
||||
Task<IShellWindow> restore(WindowState window);
|
||||
Task<IShellWindow> restore(WindowSettings window);
|
||||
}
|
||||
|
||||
[Export(typeof(ISavedWindowFactory))]
|
||||
@@ -28,7 +28,7 @@ namespace mbts.ui.settings {
|
||||
[Import]
|
||||
public ObservableCollection<IShellModule> modules { get; set; }
|
||||
|
||||
public Task<IShellWindow> restore(WindowState window) {
|
||||
public Task<IShellWindow> restore(WindowSettings window) {
|
||||
Log.Ui.info("Loading window '{0}'".fmt(window.title));
|
||||
bool changed;
|
||||
int count = 0;
|
||||
@@ -49,7 +49,7 @@ namespace mbts.ui.settings {
|
||||
/// 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) {
|
||||
private bool apply_compatability_migrations(ref WindowSettings window) {
|
||||
foreach (var test in _compat) {
|
||||
try {
|
||||
if (test.apply(ref window)) {
|
||||
|
||||
@@ -14,9 +14,9 @@ using System.Windows.Threading;
|
||||
namespace mbts.ui.settings {
|
||||
public interface ISettingsCollector {
|
||||
// Get the save state for every open window
|
||||
Task<List<WindowState>> get_window_state();
|
||||
Task<WindowState> get_window_state(IShellWindow window);
|
||||
IEnumerable<ModuleState> get_module_state();
|
||||
Task<List<WindowSettings>> get_window_state();
|
||||
Task<WindowSettings> get_window_state(IShellWindow window);
|
||||
IEnumerable<ModuleSettings> get_module_state();
|
||||
WindowPosition get_launcher_state();
|
||||
}
|
||||
|
||||
@@ -39,9 +39,9 @@ namespace mbts.ui.settings {
|
||||
|
||||
IWindowsInterop _interop => _wm;
|
||||
|
||||
public async Task<List<WindowState>> get_window_state() {
|
||||
public async Task<List<WindowSettings>> get_window_state() {
|
||||
var windows = _wm.list_windows();
|
||||
var rv = new List<WindowState>(windows.Count);
|
||||
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)) {
|
||||
@@ -54,12 +54,12 @@ namespace mbts.ui.settings {
|
||||
return rv;
|
||||
}
|
||||
|
||||
public IEnumerable<ModuleState> get_module_state() {
|
||||
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 ModuleState() {
|
||||
yield return new ModuleSettings() {
|
||||
name = module.key(),
|
||||
app_data = out_stream.ToArray(),
|
||||
};
|
||||
@@ -70,7 +70,7 @@ namespace mbts.ui.settings {
|
||||
return _launcher.get_position();
|
||||
}
|
||||
|
||||
public async Task<WindowState> get_window_state(IShellWindow window) {
|
||||
public async Task<WindowSettings> get_window_state(IShellWindow window) {
|
||||
try {
|
||||
if (window == null || window.Owner == null) return null;
|
||||
Dispatcher dispatcher = null;
|
||||
@@ -89,10 +89,10 @@ namespace mbts.ui.settings {
|
||||
}
|
||||
|
||||
var pos = _interop.GetPosition(window);
|
||||
var state = new WindowState() {
|
||||
var state = new WindowSettings() {
|
||||
owner = window.Owner.key(),
|
||||
app_data = dispatcher is null ?
|
||||
(await dispatcher.InvokeAsync(serialize)) : serialize(),
|
||||
serialize() : (await dispatcher.InvokeAsync(serialize)),
|
||||
position = pos,
|
||||
title = string.IsNullOrEmpty(pos.custom_title) ? window.Title : pos.custom_title
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using bts.shell.pnl;
|
||||
using bts.shell.pnl;
|
||||
using bts.utils;
|
||||
|
||||
using mbts.ui.settings;
|
||||
@@ -21,6 +21,8 @@ namespace bts.settings {
|
||||
interface IPNLSettingsMigrationRule : ISettingsMigrationRule<PNLSettings> { }
|
||||
interface ISyntheticManagementMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
interface IReconcileReportMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
interface IDayFillsGridSettingsMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
interface IOpenOrdersGridSettingsMigrationRule : ISettingsMigrationRule<GridSettings> { }
|
||||
|
||||
static class SettingsMigrationHelper {
|
||||
public static bool apply<T>(T settings, IEnumerable<ISettingsMigrationRule<T>> migration_rules, out T new_settings) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using mbts.spark;
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
@@ -34,7 +36,6 @@ namespace mbts.persist {
|
||||
_instance_settings = instance_settings;
|
||||
_get = get;
|
||||
_set = set;
|
||||
hub.request_clear_instance_settings += () => instance_settings = null;
|
||||
}
|
||||
|
||||
public T instance_settings {
|
||||
@@ -88,7 +89,8 @@ namespace mbts.persist {
|
||||
public IWindowSettingsManagerNonShared<T> as_non_shared() =>
|
||||
new NonSharedWrapper(_wsm);
|
||||
|
||||
public void Dispose() => Disposable.dispose(ref _dispose);
|
||||
public void Dispose() =>
|
||||
Disposable.dispose(ref _dispose);
|
||||
}
|
||||
|
||||
public class DisconnectedImpl : IWindowSettingsManager<T> {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
namespace mbts.spark {
|
||||
using bts.shell;
|
||||
using bts.shell.fills;
|
||||
@@ -6,7 +6,6 @@ namespace mbts.spark {
|
||||
using bts.shell.orderbook;
|
||||
using bts.shell.pnl;
|
||||
using bts.shell.time_and_sales;
|
||||
using bts.utils;
|
||||
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
@@ -35,6 +34,8 @@ namespace mbts.spark {
|
||||
_notification = NotificationSettings.Default,
|
||||
_market_view_grid = MarketViewSettings.DefaultGridSettings,
|
||||
_fills_grid = FillsSettings.DefaultGridSettings,
|
||||
_day_fills_grid = DayFillsSettings.default_grid(),
|
||||
_open_orders_grid = OpenOrdersSettings.default_grid(),
|
||||
_time_and_sales_grid = TimeAndSalesSettings.DefaultGridSettings,
|
||||
_synthetic_management = SyntheticManagementSettings.default_grid_settings,
|
||||
_reconcile_report = ReconcileReportSettings.Default().grid,
|
||||
@@ -65,6 +66,10 @@ namespace mbts.spark {
|
||||
GridSettings? _time_and_sales_grid;
|
||||
[ProtoMember(7)]
|
||||
GridSettings? _fills_grid;
|
||||
[ProtoMember(15)]
|
||||
GridSettings? _day_fills_grid;
|
||||
[ProtoMember(16)]
|
||||
GridSettings? _open_orders_grid;
|
||||
[ProtoMember(8)]
|
||||
GridSettings? _synthetic_management;
|
||||
[ProtoMember(14)]
|
||||
@@ -76,11 +81,6 @@ namespace mbts.spark {
|
||||
[ProtoMember(13)]
|
||||
GlobalAlertSettings? _alerts;
|
||||
|
||||
/// Actual settings may deviate from those of the theme <see cref="_last_picked_theme"/>, as
|
||||
/// the user is free to change specific properties after selecting a theme.
|
||||
[ProtoMember(15)]
|
||||
string? _last_picked_theme;
|
||||
|
||||
public UserSettings() { }
|
||||
|
||||
public LadderSettings ladder =>
|
||||
@@ -105,6 +105,12 @@ namespace mbts.spark {
|
||||
public GridSettings fills_grid =>
|
||||
_fills_grid ??= FillsSettings.DefaultGridSettings;
|
||||
|
||||
public GridSettings day_fills_grid =>
|
||||
_day_fills_grid ??= DayFillsSettings.default_grid();
|
||||
|
||||
public GridSettings open_orders_grid =>
|
||||
_open_orders_grid ??= OpenOrdersSettings.default_grid();
|
||||
|
||||
public GridSettings synthetic_management_grid =>
|
||||
_synthetic_management ??=
|
||||
SyntheticManagementSettings.default_grid_settings;
|
||||
@@ -122,8 +128,6 @@ namespace mbts.spark {
|
||||
public GlobalAlertSettings alerts =>
|
||||
_alerts ??= new GlobalAlertSettings();
|
||||
|
||||
public string? last_picked_theme => _last_picked_theme;
|
||||
|
||||
public UserSettings with(
|
||||
LadderSettings? ladder = null,
|
||||
LadderSettingsProfile[]? ladder_profiles = null,
|
||||
@@ -131,12 +135,13 @@ namespace mbts.spark {
|
||||
GridSettings? market_view = null,
|
||||
GridSettings? time_and_sales = null,
|
||||
GridSettings? fills = null,
|
||||
GridSettings? day_fills = null,
|
||||
GridSettings? open_orders = null,
|
||||
GridSettings? synthetic_management = null,
|
||||
GridSettings? reconcile_report = null,
|
||||
PNLSettings? pnl = null,
|
||||
OrderBookGridSettings? order_book_grid = null,
|
||||
GlobalAlertSettings? alerts = null,
|
||||
Optional<string?> last_picked_theme = default) {
|
||||
GlobalAlertSettings? alerts = null) {
|
||||
var us = new UserSettings() {
|
||||
_ladder_profiles = ladder_profiles ?? _ladder_profiles,
|
||||
_ladder = ladder ?? _ladder,
|
||||
@@ -144,12 +149,13 @@ namespace mbts.spark {
|
||||
_market_view_grid = market_view ?? _market_view_grid,
|
||||
_time_and_sales_grid = time_and_sales ?? _time_and_sales_grid,
|
||||
_fills_grid = fills ?? _fills_grid,
|
||||
_day_fills_grid = day_fills ?? _day_fills_grid,
|
||||
_open_orders_grid = open_orders ?? _open_orders_grid,
|
||||
_synthetic_management = synthetic_management ?? _synthetic_management,
|
||||
_reconcile_report = reconcile_report ?? _reconcile_report,
|
||||
_pnl = pnl ?? _pnl,
|
||||
_order_book = order_book_grid ?? _order_book,
|
||||
_alerts = alerts ?? _alerts,
|
||||
_last_picked_theme = last_picked_theme.or(_last_picked_theme)
|
||||
_alerts = alerts ?? _alerts
|
||||
};
|
||||
us._last_ladder_profile_id = Math.Max(_last_ladder_profile_id, us.ladder_profiles.Select(p => p.id).MaxOrDefault());
|
||||
return us;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using bts;
|
||||
using bts;
|
||||
using bts.settings;
|
||||
using bts.shell.pnl;
|
||||
using bts.utils;
|
||||
@@ -6,15 +6,12 @@ using bts.utils;
|
||||
using mbts.spark;
|
||||
using mbts.ui.settings;
|
||||
|
||||
using Spark.Settings;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Composition;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.persist {
|
||||
@@ -29,6 +26,8 @@ namespace mbts.persist {
|
||||
|
||||
static readonly IImmutableProperty<UserSettings, GridSettings>
|
||||
_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)),
|
||||
_open_orders_propi = ImmutableProperty.create<UserSettings, GridSettings>(us => us.open_orders_grid, (us, gs) => us.with(open_orders: 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));
|
||||
@@ -38,37 +37,37 @@ namespace mbts.persist {
|
||||
|
||||
readonly object _default_settings_lock = new object();
|
||||
readonly BehaviorSubject<UserSettings> _default_settings_subject = new BehaviorSubject<UserSettings>(UserSettings.factory_defaults);
|
||||
// A 'settings theme' is activated by updating the default settings object, and clearing all
|
||||
// 'instance' settings so existing windows adopt the new theme (i.e., the new defaults).
|
||||
readonly IEnumerable<IFillsGridSettingsMigrationRule> _fills_migration_rules;
|
||||
readonly IEnumerable<IDayFillsGridSettingsMigrationRule> _day_fills_migration_rules;
|
||||
readonly IEnumerable<IOpenOrdersGridSettingsMigrationRule> _open_orders_migration_rules;
|
||||
readonly IEnumerable<IMarketViewGridSettingsMigrationRule> _mview_migration_rules;
|
||||
readonly IEnumerable<IPNLSettingsMigrationRule> _pnl_migration_rules;
|
||||
readonly IEnumerable<ISyntheticManagementMigrationRule> _synth_migration_rules;
|
||||
readonly IEnumerable<IReconcileReportMigrationRule> _reconcile_report_migration_rules;
|
||||
readonly IUserPersist _persist;
|
||||
readonly Dictionary<string, UserSettingsTheme> _themes;
|
||||
|
||||
UserSettings _default_settings;
|
||||
IDisposable _theme_op = null;
|
||||
|
||||
[ImportingConstructor]
|
||||
public UserSettingsHub(
|
||||
IUserPersist persist,
|
||||
[ImportMany] IEnumerable<IFillsGridSettingsMigrationRule> fills_migration_rules,
|
||||
[ImportMany] IEnumerable<IDayFillsGridSettingsMigrationRule> day_fills_migration_rules,
|
||||
[ImportMany] IEnumerable<IOpenOrdersGridSettingsMigrationRule> open_orders_migration_rules,
|
||||
[ImportMany] IEnumerable<IMarketViewGridSettingsMigrationRule> mview_migration_rules,
|
||||
[ImportMany] IEnumerable<IPAndLGridSettingsMigrationRule> pandl_migration_rules,
|
||||
[ImportMany] IEnumerable<IPNLSettingsMigrationRule> pnl_migration_rules,
|
||||
[ImportMany] IEnumerable<ISyntheticManagementMigrationRule> synth_migration_rules,
|
||||
[ImportMany] IEnumerable<IReconcileReportMigrationRule> reconcile_report_migration_rules,
|
||||
[ImportMany] IEnumerable<UserSettingsTheme> themes) {
|
||||
[ImportMany] IEnumerable<IReconcileReportMigrationRule> reconcile_report_migration_rules) {
|
||||
//
|
||||
_persist = persist;
|
||||
_fills_migration_rules = fills_migration_rules ?? Enumerable.Empty<IFillsGridSettingsMigrationRule>();
|
||||
_day_fills_migration_rules = day_fills_migration_rules ?? Enumerable.Empty<IDayFillsGridSettingsMigrationRule>();
|
||||
_open_orders_migration_rules = open_orders_migration_rules ?? Enumerable.Empty<IOpenOrdersGridSettingsMigrationRule>();
|
||||
_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>();
|
||||
_reconcile_report_migration_rules = reconcile_report_migration_rules.empty_if_null();
|
||||
_themes = themes.ToDictionaryCrushed(t => t.name);
|
||||
init();
|
||||
async void init() {
|
||||
UserSettings s;
|
||||
@@ -77,6 +76,8 @@ namespace mbts.persist {
|
||||
if (s != null) {
|
||||
var wrapped_rules = new[] {
|
||||
_fills_migration_rules.merge().wrap(_fills_propi),
|
||||
_day_fills_migration_rules.merge().wrap(_day_fills_propi),
|
||||
_open_orders_migration_rules.merge().wrap(_open_orders_propi),
|
||||
_mview_migration_rules.merge().wrap(_mview_propi),
|
||||
_pnl_migration_rules.merge().wrap(_pnl_propi),
|
||||
_synth_migration_rules.merge().wrap(_synth_propi),
|
||||
@@ -116,26 +117,9 @@ namespace mbts.persist {
|
||||
}
|
||||
}
|
||||
|
||||
public event Action request_clear_instance_settings {
|
||||
add {
|
||||
lock (_default_settings_lock) {
|
||||
_request_clear_instance_settings += value;
|
||||
}
|
||||
}
|
||||
remove {
|
||||
lock (_default_settings_lock) {
|
||||
_request_clear_instance_settings -= value;
|
||||
}
|
||||
}
|
||||
}
|
||||
event Action _request_clear_instance_settings;
|
||||
|
||||
// indicates whether or not the settings have been loaded from the server (this happens once, on startup - see the constructor for details)
|
||||
public bool initialized { get; private set; }
|
||||
|
||||
public IEnumerable<UserSettingsTheme> themes =>
|
||||
_themes.Values;
|
||||
|
||||
internal UserSettings current {
|
||||
get {
|
||||
lock (_default_settings_lock)
|
||||
@@ -178,41 +162,32 @@ namespace mbts.persist {
|
||||
_reconcile_report_migration_rules,
|
||||
_reconcile_report_propi);
|
||||
|
||||
public async Task save_default(UserSettings value, bool clear_instance_settings = false) {
|
||||
// * Notify observers before persisting so the changes are reflected immediately in the ui.
|
||||
// * If instance settings are to be cleared, don't clear them until the new defaults are
|
||||
// ready. We want to avoid the case where windows w/ instance settings consume cpu
|
||||
// loading the original defaults, just to load the new defaults immediately after that.
|
||||
public IWindowSettingsManager<GridSettings> create_day_fills_settings_manager(
|
||||
GridSettings instance_settings) =>
|
||||
_create_settings_manager(
|
||||
instance_settings,
|
||||
_day_fills_migration_rules,
|
||||
_day_fills_propi);
|
||||
|
||||
public IWindowSettingsManager<GridSettings> create_open_orders_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) {
|
||||
Disposable.dispose(ref _theme_op);
|
||||
if (clear_instance_settings) {
|
||||
clear_instance_async().ignore();
|
||||
}
|
||||
_default_settings_subject.OnNext(_default_settings = value);
|
||||
}
|
||||
await _persist_async();
|
||||
|
||||
async Task clear_instance_async() {
|
||||
var cts = new CancellationTokenSource();
|
||||
_theme_op = Disposable.Create(() => cts.Cancel());
|
||||
var next = await _default_settings_subject.Skip(1).FirstOrDefaultAsync();
|
||||
if (!cts.IsCancellationRequested) {
|
||||
_request_clear_instance_settings?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IWindowSettingsManager<T> _create_settings_manager<T>(T instance_settings, IEnumerable<ISettingsMigrationRule<T>> migration_rules, IImmutableProperty<UserSettings, T> propi) where T : class {
|
||||
if (instance_settings != null && migration_rules.merge().apply(instance_settings, out var new_settings))
|
||||
instance_settings = new_settings;
|
||||
var wsm = new WindowSettingsManager<T>(this, instance_settings, propi.get, propi.set);
|
||||
lock (_default_settings_lock) {
|
||||
request_clear_instance_settings += clear_instance_settings;
|
||||
}
|
||||
return wsm;
|
||||
void clear_instance_settings() {
|
||||
wsm.instance_settings = null;
|
||||
}
|
||||
return new WindowSettingsManager<T>(this, instance_settings, propi.get, propi.set);
|
||||
}
|
||||
|
||||
async Task _persist_async() {
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
#nullable enable
|
||||
namespace Spark.Settings {
|
||||
using mbts.spark;
|
||||
|
||||
using System.Composition;
|
||||
|
||||
class UserSettingsTheme {
|
||||
public UserSettingsTheme() {
|
||||
name = string.Empty;
|
||||
value = new();
|
||||
}
|
||||
|
||||
public UserSettingsTheme(string name, UserSettings value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public string name { get; }
|
||||
public UserSettings value { get; }
|
||||
}
|
||||
|
||||
class ExportedThemes {
|
||||
[Export]
|
||||
public UserSettingsTheme light_theme =>
|
||||
new("Light", UserSettings.factory_defaults);
|
||||
|
||||
[Export]
|
||||
public UserSettingsTheme dark_theme =>
|
||||
new("Dark", UserSettings.factory_defaults.with(
|
||||
market_view: bts.shell.market_view.MarketViewSettings.dark_theme_grid_settings,
|
||||
time_and_sales: bts.shell.time_and_sales.TimeAndSalesSettings.dark_theme_grid_settings,
|
||||
fills: bts.shell.fills.FillsSettings.dark_theme_grid_settings,
|
||||
synthetic_management: bts.shell.SyntheticManagementSettings.dark_theme_grid_settings,
|
||||
ladder: LadderSettings.dark_theme));
|
||||
}
|
||||
}
|
||||
@@ -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,77 +0,0 @@
|
||||
using ProtoBuf;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.ui.shell {
|
||||
public enum DockState {
|
||||
FLOATING = 1,
|
||||
TOP = 2,
|
||||
BOTTOM = 3,
|
||||
LEFT = 4,
|
||||
RIGHT = 5,
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
public class WindowPosition {
|
||||
[ProtoMember(3)]
|
||||
public int width;
|
||||
[ProtoMember(4)]
|
||||
public int height;
|
||||
[ProtoMember(5)]
|
||||
public int left;
|
||||
[ProtoMember(6)]
|
||||
public int top;
|
||||
[ProtoMember(7)]
|
||||
public bool is_maximized;
|
||||
[ProtoMember(8)]
|
||||
public string host_id;
|
||||
[ProtoMember(9)]
|
||||
public int tab_index;
|
||||
|
||||
[ProtoMember(100), DefaultValue(false)]
|
||||
public bool horizontal = false;
|
||||
[ProtoMember(101), DefaultValue(true)]
|
||||
public bool show_text = true;
|
||||
[ProtoMember(102), DefaultValue(true)]
|
||||
public bool always_on_top = true;
|
||||
//[ProtoMember(103)] //used
|
||||
|
||||
[ProtoMember(104)]
|
||||
public string custom_title;
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
public class WindowState {
|
||||
[ProtoMember(1)]
|
||||
public string owner;
|
||||
[ProtoMember(2)]
|
||||
public byte[] app_data;
|
||||
|
||||
//optional bool is_open = 3 [default = true];
|
||||
//optional bool is_favorite = 4;
|
||||
//optional string title = 5;
|
||||
|
||||
//optional string id = 6;
|
||||
// optional bool is_loaded = 7 [default = false];
|
||||
[ProtoMember(8)]
|
||||
public WindowPosition position;
|
||||
|
||||
[ProtoMember(9)]
|
||||
public string title; // for debugging
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
public class ModuleState {
|
||||
[ProtoMember(1)]
|
||||
public string name;
|
||||
[ProtoMember(2)]
|
||||
public byte[] app_data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace Spark.Model.Trading {
|
||||
|
||||
using mbts.spark;
|
||||
|
||||
using Spark.Api.Reactive;
|
||||
using Spark.Core.Reactive;
|
||||
|
||||
using System;
|
||||
@@ -25,7 +26,7 @@ namespace Spark.Model.Trading {
|
||||
public OrderDataSource(
|
||||
IBus bus,
|
||||
AdminModel admin_model,
|
||||
SecurityStore security_store,
|
||||
SecurityResolver sec_resolver,
|
||||
OrderService order_service,
|
||||
ISecurityAuxiliaryDataModel security_auxiliary_model,
|
||||
ErrorReporter error_reporter
|
||||
@@ -38,7 +39,7 @@ namespace Spark.Model.Trading {
|
||||
order_service.subscribei_orders()
|
||||
.Naggle(interval, scheduler),
|
||||
o => o.account_id())
|
||||
.join(security_store, o => o.security_key())
|
||||
.join(sec_resolver, o => o.security_key())
|
||||
.Table()
|
||||
.Cache();
|
||||
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
#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.Api.Reactive;
|
||||
using Spark.Core;
|
||||
using Spark.Core.Disposables;
|
||||
using Spark.Core.Reactive;
|
||||
using Spark.Model.Trading;
|
||||
using Spark.Trading;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -29,13 +33,13 @@ namespace bts.api.position {
|
||||
readonly ErrorReporter _error_reporter;
|
||||
readonly TableUpdateDemuxer<(SecurityImmutable?, PositionUnitImmutable), int, uint> _security_positions_demuxer;
|
||||
|
||||
IDisposable _dispose;
|
||||
ThreadSafeDisposable? _dispose;
|
||||
|
||||
[ImportingConstructor]
|
||||
public PositionModel(
|
||||
IBus bus,
|
||||
AdminModel admin_model,
|
||||
SecurityStore security_store,
|
||||
SecurityResolver sec_resolver,
|
||||
PositionService position_service,
|
||||
OrderService order_service,
|
||||
OrderDataSource order_data,
|
||||
@@ -52,7 +56,7 @@ namespace bts.api.position {
|
||||
on_exchange_positions = order_service.subscribei_exchange_positions()
|
||||
.Filter(ep => ep.SecurityKey != 0)
|
||||
.SelectKeyValue(ep => ep, ep => new AccountSecurityKey(ep.AccountId, ep.SecurityKey))
|
||||
.join(security_store, ep => ep.SecurityKey)
|
||||
.join(sec_resolver, ep => ep.SecurityKey)
|
||||
.Table()
|
||||
.Cache();
|
||||
|
||||
@@ -60,31 +64,15 @@ namespace bts.api.position {
|
||||
.permission_filter(
|
||||
_position_service.subscribei_position_data().Naggle(interval, scheduler),
|
||||
p => p.AccountId)
|
||||
.join(security_store, pos => pos.SecurityId)
|
||||
.join(sec_resolver, pos => pos.SecurityId)
|
||||
.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, sec_resolver);
|
||||
|
||||
// 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,
|
||||
@@ -114,15 +102,14 @@ namespace bts.api.position {
|
||||
merged_positions = ReconcileReportDataSource.create(on_exchange_positions, on_positions)
|
||||
.Cache();
|
||||
|
||||
_dispose = Disposable.Create(
|
||||
on_positions.Subscribe(_security_positions_demuxer));
|
||||
_dispose = new(on_positions.Subscribe(_security_positions_demuxer));
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -155,6 +142,6 @@ namespace bts.api.position {
|
||||
"reset positions");
|
||||
|
||||
public void Dispose() =>
|
||||
Disposable.dispose_thread_safe(ref _dispose);
|
||||
Disposable.dispose(ref _dispose);
|
||||
}
|
||||
}
|
||||
@@ -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,10 @@ namespace mbts.spark {
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
|
||||
using Spark.Core.Data;
|
||||
using Spark.Core.Disposables;
|
||||
using Spark.Core.Reactive;
|
||||
using Spark.Trading;
|
||||
using Spark.ViewModel;
|
||||
|
||||
using System;
|
||||
@@ -35,7 +40,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,15 +60,21 @@ 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();
|
||||
_dispose = new DisposableCombo(
|
||||
_dispose = Disposable.Create(
|
||||
vol_surfaces_src.Subscribe(_on_vol_surfaces),
|
||||
reports_src.Subscribe(_on_reports),
|
||||
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 +131,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 +203,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,7 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Button
|
||||
@@ -101,36 +106,17 @@
|
||||
Style="{StaticResource LargeMenuButton}"
|
||||
/>
|
||||
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Rectangle
|
||||
Margin="5,1,5,0"
|
||||
Fill="{DynamicResource StartMenuMouseOverBackground}"
|
||||
HorizontalAlignment="Stretch"
|
||||
Height="1"
|
||||
/>
|
||||
|
||||
<c:HelpButton
|
||||
Grid.Column="1"
|
||||
ManPage="AW2"
|
||||
ToolTip="Click Here for help"
|
||||
/>
|
||||
</Grid>
|
||||
|
||||
<ToggleButton
|
||||
Grid.Row="2"
|
||||
Grid.Row="1"
|
||||
c:RadioButtonGroupManager.Value="vol_surfaces"
|
||||
c:RadioButtonGroupManager.Manager="{StaticResource WindowTypeRadioButtonGroupManager}"
|
||||
Content="Vol Surfaces"
|
||||
Margin="0,6,0,0"
|
||||
Content="Vol Surface"
|
||||
IsChecked="{Binding Path='(u:ExpandCollapseAnimator.IsExpanded)', ElementName=VolSurfacesContent, Mode=TwoWay}"
|
||||
Style="{StaticResource LargeMenuToggleButton}"
|
||||
/>
|
||||
|
||||
<ContentControl Grid.Row="3" Height="0">
|
||||
<ContentControl Grid.Row="2" Height="0">
|
||||
<ContentControl
|
||||
x:Name="VolSurfacesContent"
|
||||
Content="{Binding vol_surface_launcher_vm}"
|
||||
@@ -139,16 +125,16 @@
|
||||
</ContentControl>
|
||||
|
||||
<ToggleButton
|
||||
Grid.Row="4"
|
||||
Grid.Row="3"
|
||||
c:RadioButtonGroupManager.Value="slide_reports"
|
||||
c:RadioButtonGroupManager.Manager="{StaticResource WindowTypeRadioButtonGroupManager}"
|
||||
Margin="0,6,0,0"
|
||||
Content="Slide Reports"
|
||||
Content="Slide"
|
||||
IsChecked="{Binding Path='(u:ExpandCollapseAnimator.IsExpanded)', ElementName=SlideReportContent, Mode=TwoWay}"
|
||||
Style="{StaticResource LargeMenuToggleButton}"
|
||||
/>
|
||||
|
||||
<ContentControl Grid.Row="5" Height="0">
|
||||
<ContentControl Grid.Row="4" Height="0">
|
||||
<ContentControl
|
||||
x:Name="SlideReportContent"
|
||||
Content="{Binding slide_report_launcher_vm}"
|
||||
@@ -157,16 +143,16 @@
|
||||
</ContentControl>
|
||||
|
||||
<ToggleButton
|
||||
Grid.Row="6"
|
||||
Grid.Row="5"
|
||||
c:RadioButtonGroupManager.Value="combo_reports"
|
||||
c:RadioButtonGroupManager.Manager="{StaticResource WindowTypeRadioButtonGroupManager}"
|
||||
Margin="0,6,0,0"
|
||||
Content="Combo Report"
|
||||
Content="Combo"
|
||||
IsChecked="{Binding Path='(u:ExpandCollapseAnimator.IsExpanded)', ElementName=ComboReportContent, Mode=TwoWay}"
|
||||
Style="{StaticResource LargeMenuToggleButton}"
|
||||
/>
|
||||
|
||||
<ContentControl Grid.Row="7" Height="0">
|
||||
<ContentControl Grid.Row="6" Height="0">
|
||||
<ContentControl
|
||||
x:Name="ComboReportContent"
|
||||
Content="{Binding combo_report_launcher_vm}"
|
||||
@@ -174,5 +160,32 @@
|
||||
/>
|
||||
</ContentControl>
|
||||
|
||||
<ToggleButton
|
||||
Grid.Row="7"
|
||||
c:RadioButtonGroupManager.Value="pnl"
|
||||
c:RadioButtonGroupManager.Manager="{StaticResource WindowTypeRadioButtonGroupManager}"
|
||||
Margin="0,6,0,0"
|
||||
Content="P&L"
|
||||
IsChecked="{Binding Path='(u:ExpandCollapseAnimator.IsExpanded)', ElementName=PNLContent, Mode=TwoWay}"
|
||||
Style="{StaticResource LargeMenuToggleButton}" />
|
||||
|
||||
<ContentControl Grid.Row="8" Height="0">
|
||||
<Grid x:Name="PNLContent">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Button
|
||||
Content="Summary"
|
||||
Command="{Binding launch_pnl_cmd}"
|
||||
Style="{StaticResource LaunchButton}" />
|
||||
<Button
|
||||
Grid.Row="1"
|
||||
Content="Day Fills"
|
||||
Command="{Binding launch_day_fills_cmd}"
|
||||
Style="{StaticResource LaunchButton}" />
|
||||
</Grid>
|
||||
</ContentControl>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -4,6 +4,8 @@ namespace mbts.ui.controls {
|
||||
using mbts.ui.converters;
|
||||
using mbts.ui.extensions;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -65,12 +65,9 @@
|
||||
</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-->
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
using mbts.ui.converters;
|
||||
using mbts.ui.extensions;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
using mbts.ui.extensions;
|
||||
using mbts.ui.shell;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows;
|
||||
@@ -41,12 +43,12 @@
|
||||
|
||||
public void thread_init() {
|
||||
_vm = new VolSurfaceVM(new VolSurfaceDisplayModel(vs_id, _bus, true), vs_id, _bus, _startup_data);
|
||||
DisposableCombo hooks = new();
|
||||
var hooks = new ImmutableDisposable();
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -8,16 +8,16 @@ namespace mbts.ui.shell {
|
||||
|
||||
public interface IBookmarks {
|
||||
Task save_bookmark(IShellWindow window);
|
||||
void save_bookmark(WindowState window);
|
||||
void remove(WindowState 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) {
|
||||
@@ -31,17 +31,17 @@ namespace mbts.ui.shell {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
using mbts.ui;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
|
||||
using CellAnimation = mbts.ui.spark.CellAnimation;
|
||||
using Columns = mbts.spark.MarketViewColumnType;
|
||||
|
||||
namespace mbts.spark {
|
||||
internal partial class MarketViewVM : IDisposable {
|
||||
private class AnimationManager {
|
||||
private IDisposable _remove_position_increase, _remove_position_decrease,
|
||||
_remove_day_change_increase, _remove_day_change_decrease,
|
||||
_remove_working_bids_filled, _remove_working_asks_filled;
|
||||
private bool _position_increased, _position_decreased,
|
||||
_day_change_increased, _day_change_decreased,
|
||||
_working_bids_active, _working_bids_inside, _working_bids_filled,
|
||||
_working_asks_active, _working_asks_inside, _working_asks_filled;
|
||||
|
||||
public void animate_position(bool increased) {
|
||||
if (increased) {
|
||||
Disposable.dispose(ref _remove_position_increase);
|
||||
Disposable.dispose(ref _remove_position_decrease);
|
||||
_position_decreased = false;
|
||||
_position_increased = true;
|
||||
_remove_position_increase = TaskHelper.DelayAction(flash_duration, () => { _position_increased = false; _fire_animations_changed(); });
|
||||
} else {
|
||||
Disposable.dispose(ref _remove_position_decrease);
|
||||
Disposable.dispose(ref _remove_position_increase);
|
||||
_position_increased = false;
|
||||
_position_decreased = true;
|
||||
_remove_position_decrease = TaskHelper.DelayAction(flash_duration, () => { _position_decreased = false; _fire_animations_changed(); });
|
||||
}
|
||||
_fire_animations_changed();
|
||||
}
|
||||
public void animate_day_change(bool increased) {
|
||||
if (increased) {
|
||||
Disposable.dispose(ref _remove_day_change_increase);
|
||||
Disposable.dispose(ref _remove_day_change_decrease);
|
||||
_day_change_decreased = false;
|
||||
_day_change_increased = true;
|
||||
_remove_day_change_increase = TaskHelper.DelayAction(flash_duration, () => { _day_change_increased = false; _fire_animations_changed(); });
|
||||
} else {
|
||||
Disposable.dispose(ref _remove_day_change_decrease);
|
||||
Disposable.dispose(ref _remove_day_change_increase);
|
||||
_day_change_increased = false;
|
||||
_day_change_decreased = true;
|
||||
_remove_day_change_decrease = TaskHelper.DelayAction(flash_duration, () => { _day_change_decreased = false; _fire_animations_changed(); });
|
||||
}
|
||||
_fire_animations_changed();
|
||||
}
|
||||
public void animate_working_bids_active(bool active) {
|
||||
if (_working_bids_active != active) {
|
||||
_working_bids_active = active;
|
||||
_fire_animations_changed();
|
||||
}
|
||||
}
|
||||
public void animate_working_bids_inside(bool inside) {
|
||||
if (_working_bids_inside != inside) {
|
||||
_working_bids_inside = inside;
|
||||
_fire_animations_changed();
|
||||
}
|
||||
}
|
||||
public void animate_working_bids_filled() {
|
||||
Disposable.dispose(ref _remove_working_bids_filled);
|
||||
if (!_working_bids_filled) {
|
||||
_working_bids_filled = true;
|
||||
_fire_animations_changed();
|
||||
}
|
||||
_remove_working_bids_filled = TaskHelper.DelayAction(flash_duration, () => { _working_bids_filled = false; _fire_animations_changed(); });
|
||||
}
|
||||
public void animate_working_asks_active(bool active) {
|
||||
if (_working_asks_active != active) {
|
||||
_working_asks_active = active;
|
||||
_fire_animations_changed();
|
||||
}
|
||||
}
|
||||
public void animate_working_asks_inside(bool inside) {
|
||||
if (_working_asks_inside != inside) {
|
||||
_working_asks_inside = inside;
|
||||
_fire_animations_changed();
|
||||
}
|
||||
}
|
||||
public void animate_working_asks_filled() {
|
||||
Disposable.dispose(ref _remove_working_asks_filled);
|
||||
if (!_working_asks_filled) {
|
||||
_working_asks_filled = true;
|
||||
_fire_animations_changed();
|
||||
}
|
||||
_remove_working_asks_filled = TaskHelper.DelayAction(flash_duration, () => { _working_asks_filled = false; _fire_animations_changed(); });
|
||||
}
|
||||
public IEnumerable<CellAnimation> get_animations() {
|
||||
if (_position_increased) yield return Bank.PositionIncrease;
|
||||
else if (_position_decreased) yield return Bank.PositionDecrease;
|
||||
if (_working_bids_filled) yield return Bank.WorkingBidsFilled;
|
||||
else if (_working_bids_inside) yield return Bank.WorkingBidsInside;
|
||||
else if (_working_bids_active) yield return Bank.WorkingBidsActive;
|
||||
if (_working_asks_filled) yield return Bank.WorkingAsksFilled;
|
||||
else if (_working_asks_inside) yield return Bank.WorkingAsksInside;
|
||||
else if (_working_asks_active) yield return Bank.WorkingAsksActive;
|
||||
if (_day_change_increased) yield return Bank.DayChangeIncrease;
|
||||
else if (_day_change_decreased) yield return Bank.DayChangeDecrease;
|
||||
}
|
||||
|
||||
private void _fire_animations_changed() { AnimationsChanged?.Invoke(); }
|
||||
public event Action AnimationsChanged;
|
||||
|
||||
private static readonly Animations Bank = new Animations(new CellAnimation(Columns.Position, CellAnimation.Type.UpArrow, Brushes.Green),
|
||||
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, 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, new SolidColorBrush(BTSColors.MarketData.ask)),
|
||||
new CellAnimation(Columns.WorkingAsks, CellAnimation.Type.Border, Brushes.Red));
|
||||
private static readonly TimeSpan flash_duration = TimeSpan.FromSeconds(2);
|
||||
}
|
||||
|
||||
private class Animations {
|
||||
public Animations(CellAnimation positionIncrease, CellAnimation positionDecrease,
|
||||
CellAnimation dayChangeIncrease, CellAnimation dayChangeDecrease,
|
||||
CellAnimation workingBidsActive, CellAnimation workingBidsInside, CellAnimation workingBidsFilled,
|
||||
CellAnimation workingAsksActive, CellAnimation workingAsksInside, CellAnimation workingAsksFilled) {
|
||||
PositionIncrease = positionIncrease;
|
||||
PositionDecrease = positionDecrease;
|
||||
DayChangeIncrease = dayChangeIncrease;
|
||||
DayChangeDecrease = dayChangeDecrease;
|
||||
WorkingBidsActive = workingBidsActive;
|
||||
WorkingBidsInside = workingBidsInside;
|
||||
WorkingBidsFilled = workingBidsFilled;
|
||||
WorkingAsksActive = workingAsksActive;
|
||||
WorkingAsksInside = workingAsksInside;
|
||||
WorkingAsksFilled = workingAsksFilled;
|
||||
}
|
||||
public readonly CellAnimation PositionIncrease, PositionDecrease, DayChangeIncrease, DayChangeDecrease, WorkingBidsActive, WorkingBidsInside, WorkingBidsFilled, WorkingAsksActive, WorkingAsksInside, WorkingAsksFilled;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,9 @@
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Api.Position;
|
||||
using Spark.Core;
|
||||
using Spark.Core.Disposables;
|
||||
using Spark.Trading;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -27,12 +30,12 @@
|
||||
using TickFactors = bts.api.domain.TickFactorsImmutable;
|
||||
|
||||
partial class MarketViewVM {
|
||||
public class Row : DisposableViewModelBase, ISecurityMDRow, IEquatable<Row>, DIYGrid.IRowVM, DIYGrid.IActionableRowVM {
|
||||
public class Row : DisposableViewModelBase, IEquatable<Row>, DIYGrid.IRowVM, DIYGrid.IActionableRowVM {
|
||||
readonly IBus _bus;
|
||||
readonly OrdersModel _orders_model;
|
||||
readonly AnimationManager _animation = new();
|
||||
readonly MarketViewRowAnimationModel _animation = new();
|
||||
readonly MyOrderSummarizer _order_summarizer;
|
||||
readonly DeferrableActionWrapper _raise_invalidated;
|
||||
readonly DeferrableAction _raise_invalidated;
|
||||
|
||||
readonly Property<double> _bid_price;
|
||||
readonly Property<double> _ask_price;
|
||||
@@ -83,7 +86,7 @@
|
||||
_orders_model = orders_model;
|
||||
_order_summarizer = new(
|
||||
smd.quantity_display.HasTickFactors ?
|
||||
smd.quantity_display.TickFactors : new(new() { TickBase = 1, TickUnit = 1}));
|
||||
smd.quantity_display.TickFactors : new(new() { TickBase = 1, TickUnit = 1 }));
|
||||
_raise_invalidated = new(() => invalidated?.Invoke());
|
||||
|
||||
_day_position = new CellProperty<double>(this, nameof(day_position), fmt_display_qty_double);
|
||||
@@ -110,14 +113,16 @@
|
||||
_ask_implied_size = backing(nameof(iask_qty), 0u, convert_display_qty_uint);
|
||||
_ask_merged_size = backing(nameof(ask_qty), 0u, convert_display_qty_uint);
|
||||
|
||||
_working_best_bid = new CellProperty<double>(this, nameof(working_best_bid), this.format_price, double.NaN);
|
||||
_working_best_ask = new CellProperty<double>(this, nameof(working_best_ask), this.format_price, double.NaN);
|
||||
_working_best_bid = new CellProperty<double>(
|
||||
this, nameof(working_best_bid), format_price, double.NaN);
|
||||
_working_best_ask = new CellProperty<double>(
|
||||
this, nameof(working_best_ask), format_price, double.NaN);
|
||||
|
||||
// greeks
|
||||
_greeks = backing(nameof(greeks), GreeksTuple.empty);
|
||||
_vol = backing(nameof(vol), _greeks.observe_current(true), g => g.vol);
|
||||
_driver = backing(nameof(driver), _greeks.observe_current(true), g => g.driver);
|
||||
_theo = backing(nameof(theo), _greeks.observe_current(true), g => g.theo);
|
||||
_theo = backing(nameof(theo), _greeks.observe_current(true), g => g.normalized_theo);
|
||||
_delta = backing(nameof(delta), _greeks.observe_current(true), g => g.delta);
|
||||
_gamma = backing(nameof(gamma), _greeks.observe_current(true), g => g.gamma);
|
||||
_vega = backing(nameof(vega), _greeks.observe_current(true), g => g.vega);
|
||||
@@ -136,7 +141,7 @@
|
||||
ask_implied_size_click = new DelegateCommand(() => _show_order_ticket(MarketViewColumnType.AskImpliedQty));
|
||||
working_asks_click = new DelegateCommand(() => _show_order_book(MarketViewColumnType.WorkingAsks));
|
||||
|
||||
_animation.AnimationsChanged += on_animations_changed;
|
||||
_animation.animations_changed += on_animations_changed;
|
||||
|
||||
_dispose = Disposable.Create(
|
||||
attach_prop_changed_cb(_bid_direct_size, mk_echo_prop_changed_cb<(uint, uint)>(nameof(dbid_qty_text))),
|
||||
@@ -150,7 +155,7 @@
|
||||
_inside_bids.OnDispatcher().Subscribe(v => _animation.animate_working_bids_inside(v.newval)),
|
||||
_inside_asks.OnDispatcher().Subscribe(v => _animation.animate_working_asks_inside(v.newval)),
|
||||
_day_change.OnDispatcher().Subscribe(v => _animation.animate_day_change(v.newval > v.oldval)),
|
||||
Disposable.Create(() => _animation.AnimationsChanged -= on_animations_changed));
|
||||
Disposable.Create(() => _animation.animations_changed -= on_animations_changed));
|
||||
|
||||
void on_animations_changed() => RaisePropertyChanged(nameof(animations));
|
||||
|
||||
@@ -208,7 +213,6 @@
|
||||
public SecurityMD security_md { get; }
|
||||
public SecurityImmutable security => security_md.security;
|
||||
public uint security_key => security_md.security.Id;
|
||||
SecurityMD ISecurityMDRow.md => security_md;
|
||||
|
||||
public bool inside_bids => _inside_bids.value;
|
||||
public bool inside_asks => _inside_asks.value;
|
||||
@@ -291,8 +295,7 @@
|
||||
public double rho => _rho.Value;
|
||||
|
||||
// animations
|
||||
public IList<ui.spark.CellAnimation> animations => _animation.get_animations().ToList();
|
||||
public ObservableCollection<RowAnimation> row_animations { get; } = new();
|
||||
public IList<ui.spark.CellAnimation> animations => _animation.animations.ToList();
|
||||
|
||||
public bool is_visible {
|
||||
get => _is_visible;
|
||||
@@ -316,8 +319,11 @@
|
||||
(_display_qty_divisor_backing = _orders_model.security_auxiliary_model.get_display_quantity_divisor(security)).Value;
|
||||
IMDConsumerHandle _md => security_md.md;
|
||||
|
||||
public string format_price(double price) =>
|
||||
security.ContractSpec.format(price);
|
||||
|
||||
public void raise_invalidated() =>
|
||||
_raise_invalidated.execute();
|
||||
_raise_invalidated.Invoke();
|
||||
|
||||
public void refresh() {
|
||||
bool dirty = false;
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
#nullable enable
|
||||
namespace mbts.spark {
|
||||
using mbts.ui;
|
||||
|
||||
using Spark.Core;
|
||||
using Spark.Core.Async;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Media;
|
||||
|
||||
using CellAnimation = ui.spark.CellAnimation;
|
||||
using ColType = MarketViewColumnType;
|
||||
|
||||
class MarketViewRowAnimationModel {
|
||||
static readonly TimeSpan _flash_duration = TimeSpan.FromSeconds(2);
|
||||
static readonly MarketViewAnimations _bank = new() {
|
||||
position_increase = new(ColType.Position, CellAnimation.Type.UpArrow, Brushes.Green),
|
||||
position_decrease = new(ColType.Position, CellAnimation.Type.DownArrow, Brushes.Red),
|
||||
day_change_increase = new(ColType.DayChange, CellAnimation.Type.UpArrow, Brushes.Green),
|
||||
day_change_decrease = new(ColType.DayChange, CellAnimation.Type.DownArrow, Brushes.Red),
|
||||
working_bids_active = new(ColType.WorkingBids, CellAnimation.Type.Border, BTSColors.warning.to_brush()),
|
||||
working_bids_inside = new(ColType.WorkingBids, CellAnimation.Type.Border, BTSColors.MarketData.bid.to_brush()),
|
||||
working_bids_filled = new(ColType.WorkingBids, CellAnimation.Type.Border, Brushes.Green),
|
||||
working_asks_active = new(ColType.WorkingAsks, CellAnimation.Type.Border, BTSColors.warning.to_brush()),
|
||||
working_asks_inside = new(ColType.WorkingAsks, CellAnimation.Type.Border, BTSColors.MarketData.ask.to_brush()),
|
||||
working_asks_filled = new(ColType.WorkingAsks, CellAnimation.Type.Border, Brushes.Red)
|
||||
};
|
||||
|
||||
readonly ValueTimeline<CellAnimation?> _position;
|
||||
readonly ValueTimeline<CellAnimation?> _day_change;
|
||||
readonly ValueTimeline<CellAnimation?> _working_bids_active;
|
||||
readonly ValueTimeline<CellAnimation?> _working_bids_inside;
|
||||
readonly ValueTimeline<CellAnimation?> _working_bids_filled;
|
||||
readonly ValueTimeline<CellAnimation?> _working_asks_active;
|
||||
readonly ValueTimeline<CellAnimation?> _working_asks_inside;
|
||||
readonly ValueTimeline<CellAnimation?> _working_asks_filled;
|
||||
readonly DeferrableAction _refresh;
|
||||
|
||||
public MarketViewRowAnimationModel() {
|
||||
_refresh = new(() => animations_changed?.Invoke());
|
||||
_position = mk_animation_model();
|
||||
_day_change = mk_animation_model();
|
||||
_working_bids_filled = mk_animation_model();
|
||||
_working_bids_inside = mk_animation_model();
|
||||
_working_bids_active = mk_animation_model();
|
||||
_working_asks_filled = mk_animation_model();
|
||||
_working_asks_inside = mk_animation_model();
|
||||
_working_asks_active = mk_animation_model();
|
||||
ValueTimeline<CellAnimation?> mk_animation_model() {
|
||||
var animation_model = new ValueTimeline<CellAnimation?>(null);
|
||||
animation_model.value_changed += _refresh.Invoke;
|
||||
return animation_model;
|
||||
}
|
||||
}
|
||||
|
||||
public event Action? animations_changed;
|
||||
|
||||
public IEnumerable<CellAnimation> animations {
|
||||
get {
|
||||
return impl().SelectWhereValues();
|
||||
|
||||
IEnumerable<CellAnimation?> impl() {
|
||||
yield return _position.value;
|
||||
yield return _day_change.value;
|
||||
yield return _working_bids_active.value;
|
||||
yield return _working_bids_inside.value;
|
||||
yield return _working_bids_filled.value;
|
||||
yield return _working_asks_active.value;
|
||||
yield return _working_asks_inside.value;
|
||||
yield return _working_asks_filled.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void animate_position(bool increased) {
|
||||
var anim = increased ? _bank.position_increase : _bank.position_decrease;
|
||||
_position.begin((anim, _flash_duration)).ignore();
|
||||
}
|
||||
|
||||
public void animate_day_change(bool increased) {
|
||||
var anim = increased ? _bank.day_change_increase : _bank.day_change_decrease;
|
||||
_day_change.begin((anim, _flash_duration)).ignore();
|
||||
}
|
||||
|
||||
public void animate_working_bids_active(bool active) =>
|
||||
_working_bids_active.value = active ? _bank.working_bids_active : null;
|
||||
|
||||
public void animate_working_bids_inside(bool inside) =>
|
||||
_working_bids_inside.value = inside ? _bank.working_bids_active : null;
|
||||
|
||||
public void animate_working_bids_filled() =>
|
||||
_working_bids_filled.begin((
|
||||
_bank.working_bids_filled, _flash_duration)).ignore();
|
||||
|
||||
public void animate_working_asks_active(bool active) =>
|
||||
_working_asks_active.value = active ? _bank.working_asks_active : null;
|
||||
|
||||
public void animate_working_asks_inside(bool inside) =>
|
||||
_working_asks_inside.value = inside ? _bank.working_asks_inside : null;
|
||||
|
||||
public void animate_working_asks_filled() =>
|
||||
_working_asks_filled.begin((
|
||||
_bank.working_asks_filled, _flash_duration)).ignore();
|
||||
|
||||
readonly struct MarketViewAnimations {
|
||||
public CellAnimation position_increase { get; init; }
|
||||
public CellAnimation position_decrease { get; init; }
|
||||
public CellAnimation day_change_increase { get; init; }
|
||||
public CellAnimation day_change_decrease { get; init; }
|
||||
public CellAnimation working_bids_active { get; init; }
|
||||
public CellAnimation working_bids_inside { get; init; }
|
||||
public CellAnimation working_bids_filled { get; init; }
|
||||
public CellAnimation working_asks_active { get; init; }
|
||||
public CellAnimation working_asks_inside { get; init; }
|
||||
public CellAnimation working_asks_filled { get; init; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,27 +36,7 @@ namespace bts.shell.market_view {
|
||||
}
|
||||
|
||||
public static GridSettings DefaultGridSettings =>
|
||||
GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criteria, enable_background_color: true);
|
||||
|
||||
public static GridSettings dark_theme_grid_settings =>
|
||||
DefaultGridSettings.with(
|
||||
selection_highlight: BTSDarkColors.selection_highlight.argb_color(),
|
||||
background: BTSDarkColors.background.argb_color(),
|
||||
font_color: BTSDarkColors.foreground.argb_color(),
|
||||
columns: DefaultColumns.all.Select(c => {
|
||||
Color? fg = c.strong_id<Columns>() switch {
|
||||
Columns.Ask or Columns.AskDirectQty or Columns.AskMergedQty or Columns.AskImpliedQty or Columns.WorkingAsks => BTSDarkColors.ask_foreground,
|
||||
Columns.Bid or Columns.BidDirectQty or Columns.BidMergedQty or Columns.BidImpliedQty or Columns.WorkingBids => BTSDarkColors.bid_foreground,
|
||||
_ => null,
|
||||
};
|
||||
Color? bg = c.strong_id<Columns>() switch {
|
||||
Columns.Ask or Columns.Bid => BTSDarkColors.dark_background,
|
||||
_ => null
|
||||
};
|
||||
return c.with(
|
||||
background_color_override: new(bg),
|
||||
font_color_override: new(fg));
|
||||
}));
|
||||
GridSettings.Default.with(DefaultColumns.all, DefaultColumns.default_sorting_criteria);
|
||||
|
||||
public static fills.FillsSettings DefaultAuxiliaryFills {
|
||||
get {
|
||||
@@ -106,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 {
|
||||
@@ -122,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);
|
||||
@@ -157,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,12 @@ namespace mbts.spark {
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Core;
|
||||
using Spark.Core.Collections;
|
||||
using Spark.Core.Data;
|
||||
using Spark.Core.Disposables;
|
||||
using Spark.Core.Reflection;
|
||||
using Spark.Trading;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -47,8 +50,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 +66,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;
|
||||
@@ -176,8 +179,8 @@ namespace mbts.spark {
|
||||
|
||||
// greeks
|
||||
add_col(ColKey.Volatility, r => fmt_greek(r.vol), nameof(Row.vol), vol_filter, FilterType.DoubleMinMax, ColWidth.Greeks);
|
||||
add_col(ColKey.Driver, r => fmt_greek(r.driver), nameof(Row.driver), driver_filter, FilterType.DoubleMinMax, ColWidth.Greeks);
|
||||
add_col(ColKey.Theo, r => fmt_greek(r.theo), nameof(Row.theo), theo_filter, FilterType.DoubleMinMax, ColWidth.Greeks);
|
||||
add_col(ColKey.Driver, r => r.format_price(r.driver), nameof(Row.driver), driver_filter, FilterType.DoubleMinMax, ColWidth.Greeks);
|
||||
add_col(ColKey.Theo, r => r.format_price(r.theo), nameof(Row.theo), theo_filter, FilterType.DoubleMinMax, ColWidth.Greeks);
|
||||
add_col(ColKey.Delta, r => fmt_greek(r.delta), nameof(Row.delta), delta_filter, FilterType.DoubleMinMax, ColWidth.Greeks);
|
||||
add_col(ColKey.Gamma, r => fmt_greek(r.gamma), nameof(Row.gamma), gamma_filter, FilterType.DoubleMinMax, ColWidth.Greeks);
|
||||
add_col(ColKey.Vega, r => fmt_greek(r.vega), nameof(Row.vega), vega_filter, FilterType.DoubleMinMax, ColWidth.Greeks);
|
||||
@@ -187,7 +190,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 +199,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 +494,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 +509,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,274 +1,290 @@
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.api.position;
|
||||
using bts.collections;
|
||||
using bts.shell;
|
||||
using bts.shell.fills;
|
||||
using bts.shell.market_view;
|
||||
using bts.spark;
|
||||
using bts.view;
|
||||
|
||||
using mbts.persist;
|
||||
using mbts.ui;
|
||||
using mbts.ui.settings;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Core.Data;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows;
|
||||
|
||||
namespace mbts.spark {
|
||||
class MarketViewWindow : SparkWindow<MarketViewSettings>, ISharedWindow, ISlowMeasureContentSize {
|
||||
const string _window_type = "MarketView", _window_type_display_name = "Market View";
|
||||
|
||||
readonly OrdersModel _orders_model;
|
||||
readonly ISecurityMetadataStore _sec_meta_store;
|
||||
readonly IPositionModel _position_model;
|
||||
readonly AllowOnce _init_guard = new AllowOnce("MarketView");
|
||||
readonly UserSettingsHub _settings_hub;
|
||||
readonly IWindowSettingsManager<GridSettings> _settings_manager;
|
||||
|
||||
List<SortingCriteria> _current_sorting_criteria;
|
||||
MarketViewVM _vm;
|
||||
MarketViewView _view;
|
||||
MarketViewSettings _state;
|
||||
IReadOnlyList<SparkCommand> _commands;
|
||||
IDisposable _subscriptions;
|
||||
SecurityCriteria
|
||||
_selected_security_criteria_backing,
|
||||
_sorted_selected_security_criteria_backing;
|
||||
SparkMenuDisplayVM _menu_display_vm;
|
||||
SimpleGridSettingsManager<MarketViewVM.Row> _grid_settings_manager;
|
||||
|
||||
public MarketViewWindow(
|
||||
MarketViewWindowFactory factory,
|
||||
IBus bus,
|
||||
OrdersModel orders_model,
|
||||
IPositionModel position_model,
|
||||
ISecurityMetadataStore sec_meta_store,
|
||||
MarketViewSettings state,
|
||||
UserSettingsHub settings_hub)
|
||||
: base("Market View", bus, factory, SparkCommands.ShowMarketView.icon) {
|
||||
_orders_model = orders_model;
|
||||
_position_model = position_model;
|
||||
_sec_meta_store = sec_meta_store;
|
||||
_state = state;
|
||||
_settings_hub = settings_hub;
|
||||
_settings_manager = settings_hub.create_mview_settings_manager(state.grid);
|
||||
Icon.Freeze();
|
||||
thread_id = config.Configuration.get<bts.config.MultiThreadedWindows>().market_view ? "MarketView" : null;
|
||||
_dispose = Disposable.Create(() => {
|
||||
Disposable.dispose(ref _subscriptions);
|
||||
_vm.Dispose();
|
||||
Commands.OfType<IDisposable>().DisposeAll();
|
||||
});
|
||||
}
|
||||
|
||||
event Action<SecurityCriteria> _security_criteria_changed;
|
||||
|
||||
public override string window_type => _window_type;
|
||||
public override UIElement Content => _view;
|
||||
public override IEnumerable<SparkCommand> Commands => _commands;
|
||||
public override MarketViewSettings SaveState =>
|
||||
_state = new MarketViewSettings(
|
||||
_state.security_criteria,
|
||||
_vm.get_filter_states(),
|
||||
_settings_manager.instance_settings,
|
||||
_current_sorting_criteria) {
|
||||
menu_display = _menu_display_vm.create()
|
||||
};
|
||||
|
||||
public override double MinWidth => MarketViewSettings.DefaultGridSettings.columns.Where(c => c.is_visible).Sum(gcs => gcs.width)
|
||||
+ SPARK_MENU_COLLAPSED_WIDTH
|
||||
+ LAUNCHER_BUTTON_BORDER_WIDTH
|
||||
+ EXTRA_FOR_NO_HORIZONTAL_SCROLLBAR_WIDTH;
|
||||
|
||||
public string thread_id { get; }
|
||||
|
||||
SecurityCriteria _selected_security_criteria {
|
||||
get {
|
||||
if (_selected_security_criteria_backing == null) {
|
||||
if (_sorted_selected_security_criteria_backing != null) {
|
||||
_selected_security_criteria_backing = _sorted_selected_security_criteria_backing;
|
||||
} else if (_vm != null)
|
||||
_selected_security_criteria_backing = SecurityCriteria.from_securities(_vm.selected_rows.Select(r => r.security));
|
||||
}
|
||||
return _selected_security_criteria_backing;
|
||||
}
|
||||
}
|
||||
|
||||
SecurityCriteria _sorted_selected_security_criteria => _sorted_selected_security_criteria_backing ?? (
|
||||
_sorted_selected_security_criteria_backing = _vm != null ?
|
||||
SecurityCriteria.from_securities(_vm.selected_rows.Ordered(_vm.comparer).Select(r => r.security)) :
|
||||
null);
|
||||
|
||||
bool _has_selected_rows() => _vm != null && _vm.selected_rows.Count > 0;
|
||||
|
||||
public void thread_init() {
|
||||
_init_guard.check_access();
|
||||
Log.notnull(_state);
|
||||
_menu_display_vm = new SparkMenuDisplayVM();
|
||||
_menu_display_vm.load_from(_state.menu_display);
|
||||
var update_securities_cmd = SparkCommands.change_securities_callback(_window_type_display_name);
|
||||
var security_md_map_src = Observable.Create<IReadOnlyDictionary<uint, SecurityMD>>(o => {
|
||||
IDisposable sub = null;
|
||||
_security_criteria_changed += on_security_criteria_changed;
|
||||
on_security_criteria_changed(_state.security_criteria);
|
||||
return Disposable.Create(dispose);
|
||||
void on_security_criteria_changed(SecurityCriteria security_criteria) {
|
||||
sub?.Dispose();
|
||||
sub = _state.security_criteria
|
||||
.subscribe_md_map(_bus.subscribe(SparkTags.SecuritiesTag)).Subscribe(o.OnNext);
|
||||
}
|
||||
void dispose() =>
|
||||
Disposable.dispose(ref sub);
|
||||
});
|
||||
_vm = new MarketViewVM(
|
||||
_bus,
|
||||
_orders_model,
|
||||
_position_model,
|
||||
_sec_meta_store,
|
||||
_settings_hub,
|
||||
security_md_map_src
|
||||
.BufferLatest(TimeSpan.FromSeconds(1))
|
||||
.Table(SecurityMD.key_fn)
|
||||
.Where(t => t.has_changes())
|
||||
.OnDispatcher());
|
||||
var sort_man = new ColumnSortManager(_vm.columns, MarketViewColumnType.Security.ToString());
|
||||
_current_sorting_criteria = _state.sorting_criteria.ToList();
|
||||
sort_man.SortingCriteria = _state.sorting_criteria;
|
||||
_vm.load_filters(_state.filters);
|
||||
_vm.comparer = sort_man.BuildComparer<MarketViewColumnType, MarketViewVM.Row>(MarketViewVM.get_column_comparer);
|
||||
_view = new MarketViewView { DataContext = _vm };
|
||||
_view._grid.Sorting += on_grid_sorting;
|
||||
_grid_settings_manager = new SimpleGridSettingsManager<MarketViewVM.Row>(_vm.columns, null, _vm.rows);
|
||||
_grid_settings_manager.load_from(_settings_manager.current_settings());
|
||||
/// The 'CanExecute' plumbing for the cmds below is designed to avoid potentially costly .ToList() operations on the selected_rows/securities.
|
||||
/// Some of the cmds post ITags with data that is, or has, a SecurityCriteria member; the SecurityCriteria constructor creates a new List of the specified securities.
|
||||
/// For these commands, the objective is to evaluate 'CanExecute' without instantiating the SecurityCriteria (or more importantly, without creating a new List).
|
||||
// show time and sales
|
||||
var show_tas_cmd = new DelegateCommand(() => {
|
||||
var sc = _selected_security_criteria;
|
||||
if (sc.is_defined())
|
||||
_bus.post(SparkTags.ShowTimeAndSalesTag, sc);
|
||||
}, _has_selected_rows);
|
||||
var show_tas_actual_cmd = SparkCommands.ShowTimeAndSales;
|
||||
var show_tas_cmd_wrapper = new SparkCommandCommand(show_tas_actual_cmd.title, show_tas_actual_cmd.icon, show_tas_cmd);
|
||||
// show fills
|
||||
var show_fills_cmd = new DelegateCommand(() => {
|
||||
var sc = _selected_security_criteria;
|
||||
_bus.post(SparkTags.ShowFillsTag, new FillsSettings(
|
||||
new FillsFilterStates {
|
||||
security = sc.is_defined() ? sc : _state.security_criteria
|
||||
}));
|
||||
});
|
||||
var show_fills_actual_cmd = SparkCommands.ShowFills();
|
||||
var show_fills_cmd_wrapper = new SparkCommandCommand(show_fills_actual_cmd.title, show_fills_actual_cmd.icon, show_fills_cmd, SparkCommands.KeyGestures.ShowFills);
|
||||
var show_mini_fills_cmd = new DelegateCommand(() => _view.show_mini_fills(_vm.selected_securities), () => _vm.selected_securities.Count > 0);
|
||||
var show_ticket_cmd = new DelegateCommand(() => {
|
||||
var smd = _vm.current_security_md;
|
||||
if (smd.HasValue)
|
||||
_view.show_order_ticket(smd.Value);
|
||||
}, () => _vm.current_security_md.HasValue);
|
||||
var show_ticket_actual_cmd = SparkCommands.ShowOrderTicketFromSecurity(SparkCommands.KeyGestures.ShowOrderTicket);
|
||||
// show synthetic create
|
||||
var show_synth_create_cmd = new DelegateCommand(() => {
|
||||
var sc = _sorted_selected_security_criteria;
|
||||
if (sc.is_defined())
|
||||
_bus.post(SparkTags.ShowSyntheticCreateTag, sc);
|
||||
}, () => _vm.selected_rows.Count > 0 && _vm.selected_rows.Count <= 24);
|
||||
var show_synth_create_actual_cmd = SparkCommands.ShowSyntheticCreate();
|
||||
var show_synth_create_cmd_wrapper = new SparkCommandCommand(show_synth_create_actual_cmd.title, show_synth_create_actual_cmd.icon, show_synth_create_cmd, SparkCommands.KeyGestures.ShowSyntheticCreate);
|
||||
var show_working_orders_cmd = new DelegateCommand(() => _view.show_working_orders(_vm.selected_securities), () => _vm.selected_securities.Count > 0);
|
||||
|
||||
var current_sec_md_src = Observable.Create<SecurityMD?>(o => {
|
||||
notify(null, null);
|
||||
_vm.current_row_changed += notify;
|
||||
return Disposable.Create(() => _vm.current_row_changed -= notify);
|
||||
void notify(MarketViewVM.Row oldval, MarketViewVM.Row newval) {
|
||||
if (newval != null)
|
||||
o.OnNext(newval.security_md);
|
||||
else o.OnNext(null);
|
||||
}
|
||||
});
|
||||
_commands = new List<SparkCommand> {
|
||||
SparkCommands.ShowLadders(SparkCommands.KeyGestures.ShowLadder).complete(_vm.selected_rows.Observe().Select(_ => _vm.selected_rows.WrapSelectorRO(r => r.security_md)), smds => smds.Count > 0),
|
||||
SparkCommands.ShowOrderTicketFromSecurity(SparkCommands.KeyGestures.ShowOrderTicket).complete(current_sec_md_src, md => md.HasValue, ConvertUtils.ValueOrDefault),
|
||||
show_fills_cmd_wrapper,
|
||||
show_tas_cmd_wrapper,
|
||||
show_synth_create_cmd_wrapper,
|
||||
// Note: the commands commented out below open the mini popup versions of their respective windows
|
||||
// TODO: determine if/how to integrate the mini popups into the toolbar.
|
||||
//new SparkCommandCommand("Working Orders", Icons.Orders, show_working_orders_cmd),
|
||||
//new SparkCommandCommand("Fills", show_fills_actual_cmd.icon, show_mini_fills_cmd),
|
||||
//new SparkCommandCommand(show_ticket_actual_cmd.title, show_ticket_actual_cmd.icon, show_ticket_cmd),
|
||||
SparkCommands.change_securities_command(() => (update_securities_cmd, _state.security_criteria)),
|
||||
// wrap the grid settings view factory in a dialogCommand here since the vm is destroyed/recreated when the security criteria changes
|
||||
SparkCommands.window_settings_command(new DialogCommand(() => {
|
||||
var vm = new ShellSettingsDialogVM<GridSettings, SimpleGridSettingsVM>(
|
||||
_settings_manager,
|
||||
us => us.market_view_grid,
|
||||
UserSettings.FileExtensions.GRID,
|
||||
s => _grid_settings_manager.create_vm(
|
||||
// we need to get the most up to date GridSettings when launching b/c users may
|
||||
// have changed some settings on the grid directly, like column widths.
|
||||
s.with(_vm.columns.Select(c => c.create()))
|
||||
)
|
||||
);
|
||||
vm.SubscribeDisposed(literal_title_source.OnDispatcher().Subscribe(t => vm.title = t));
|
||||
var dialog = new ShellSettingsDialog { DataContext = vm };
|
||||
vm.RequestClose += (s, e) => WindowUtilities.force_close(dialog);
|
||||
return dialog;
|
||||
})),
|
||||
_menu_display_vm.spark_cmd
|
||||
};
|
||||
//
|
||||
_vm.selected_rows.CollectionChanged += on_selection_changed;
|
||||
_subscriptions = new CompositeDisposable(
|
||||
_bus.subscribe(update_securities_cmd.tag).OnDispatcher().Subscribe(c => {
|
||||
_state = new MarketViewSettings(c, _state.filters, _state.grid, _state.sorting_criteria.ToList());
|
||||
_security_criteria_changed?.Invoke(c);
|
||||
}),
|
||||
_settings_manager.subscribe_current().OnDispatcher().Subscribe(new CompositeObserver<GridSettings>(_grid_settings_manager) {
|
||||
s => _vm.selection_highlight = s.selection_highlight
|
||||
})) {
|
||||
() => {
|
||||
_vm.selected_rows.CollectionChanged -= on_selection_changed;
|
||||
_view._grid.Sorting -= on_grid_sorting;
|
||||
}
|
||||
};
|
||||
|
||||
void on_selection_changed(object sender, NotifyCollectionChangedEventArgs e) {
|
||||
// invalidate selected security criteria
|
||||
_selected_security_criteria_backing = null;
|
||||
_sorted_selected_security_criteria_backing = null;
|
||||
show_tas_cmd.RaiseCanExecuteChanged();
|
||||
show_fills_cmd.RaiseCanExecuteChanged();
|
||||
show_synth_create_cmd.RaiseCanExecuteChanged();
|
||||
show_working_orders_cmd.RaiseCanExecuteChanged();
|
||||
show_mini_fills_cmd.RaiseCanExecuteChanged();
|
||||
show_ticket_cmd.RaiseCanExecuteChanged();
|
||||
}
|
||||
|
||||
void on_grid_sorting(object sender, ui.controls.DIYGridSortingEventArgs e) {
|
||||
_sorted_selected_security_criteria_backing = null;
|
||||
sort_man.OnColumnClick(e.Column, KeyboardExtensions.IsShiftDown());
|
||||
_vm.comparer = sort_man.BuildComparer<MarketViewColumnType, MarketViewVM.Row>(MarketViewVM.get_column_comparer);
|
||||
_current_sorting_criteria = sort_man.SortingCriteria.ToList();
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnParentViewCreated(SparkWindowView parent_view) =>
|
||||
_menu_display_vm.safe_bind_to_view(parent_view);
|
||||
}
|
||||
}
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.collections;
|
||||
using bts.shell;
|
||||
using bts.shell.fills;
|
||||
using bts.shell.market_view;
|
||||
using bts.spark;
|
||||
using bts.view;
|
||||
|
||||
using mbts.persist;
|
||||
using mbts.ui;
|
||||
using mbts.ui.settings;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Core;
|
||||
using Spark.Core.Data;
|
||||
using Spark.Core.Disposables;
|
||||
using Spark.Trading;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows;
|
||||
|
||||
namespace mbts.spark {
|
||||
class MarketViewWindow : SparkWindow<MarketViewSettings>, ISharedWindow, ISlowMeasureContentSize {
|
||||
const string _window_type = "MarketView", _window_type_display_name = "Market View";
|
||||
|
||||
readonly OrdersModel _orders_model;
|
||||
readonly ISecurityMetadataStore _sec_meta_store;
|
||||
readonly IPositionModel _position_model;
|
||||
readonly AllowOnce _init_guard = new AllowOnce("MarketView");
|
||||
readonly UserSettingsHub _settings_hub;
|
||||
readonly IWindowSettingsManager<GridSettings> _settings_manager;
|
||||
|
||||
List<SortingCriteria> _current_sorting_criteria;
|
||||
MarketViewVM _vm;
|
||||
MarketViewView _view;
|
||||
MarketViewSettings _state;
|
||||
IReadOnlyList<SparkCommand> _commands;
|
||||
IDisposable _subscriptions;
|
||||
SecurityCriteria
|
||||
_selected_security_criteria_backing,
|
||||
_sorted_selected_security_criteria_backing;
|
||||
SparkMenuDisplayVM _menu_display_vm;
|
||||
SimpleGridSettingsManager<MarketViewVM.Row> _grid_settings_manager;
|
||||
|
||||
public MarketViewWindow(
|
||||
MarketViewWindowFactory factory,
|
||||
IBus bus,
|
||||
OrdersModel orders_model,
|
||||
IPositionModel position_model,
|
||||
ISecurityMetadataStore sec_meta_store,
|
||||
MarketViewSettings state,
|
||||
UserSettingsHub settings_hub)
|
||||
: base("Market View", bus, factory, SparkCommands.ShowMarketView.icon) {
|
||||
_orders_model = orders_model;
|
||||
_position_model = position_model;
|
||||
_sec_meta_store = sec_meta_store;
|
||||
_state = state;
|
||||
_settings_hub = settings_hub;
|
||||
_settings_manager = settings_hub.create_mview_settings_manager(state.grid);
|
||||
Icon.Freeze();
|
||||
thread_id = config.Configuration.get<bts.config.MultiThreadedWindows>().market_view ? "MarketView" : null;
|
||||
_dispose = Disposable.Create(() => {
|
||||
Disposable.dispose(ref _subscriptions);
|
||||
_vm.Dispose();
|
||||
Commands.OfType<IDisposable>().DisposeAll();
|
||||
});
|
||||
}
|
||||
|
||||
event Action<SecurityCriteria> _security_criteria_changed;
|
||||
|
||||
public override string window_type => _window_type;
|
||||
public override UIElement Content => _view;
|
||||
public override IEnumerable<SparkCommand> Commands => _commands;
|
||||
public override MarketViewSettings SaveState =>
|
||||
_state = new MarketViewSettings(
|
||||
_state.security_criteria,
|
||||
_vm.get_filter_states(),
|
||||
_settings_manager.instance_settings,
|
||||
_current_sorting_criteria) {
|
||||
menu_display = _menu_display_vm.create()
|
||||
};
|
||||
|
||||
public override double MinWidth => MarketViewSettings.DefaultGridSettings.columns.Where(c => c.is_visible).Sum(gcs => gcs.width)
|
||||
+ SPARK_MENU_COLLAPSED_WIDTH
|
||||
+ LAUNCHER_BUTTON_BORDER_WIDTH
|
||||
+ EXTRA_FOR_NO_HORIZONTAL_SCROLLBAR_WIDTH;
|
||||
|
||||
public string thread_id { get; }
|
||||
|
||||
SecurityCriteria _selected_security_criteria {
|
||||
get {
|
||||
if (_selected_security_criteria_backing == null) {
|
||||
if (_sorted_selected_security_criteria_backing != null) {
|
||||
_selected_security_criteria_backing = _sorted_selected_security_criteria_backing;
|
||||
} else if (_vm != null)
|
||||
_selected_security_criteria_backing = SecurityCriteria.from_securities(_vm.selected_rows.Select(r => r.security));
|
||||
}
|
||||
return _selected_security_criteria_backing;
|
||||
}
|
||||
}
|
||||
|
||||
SecurityCriteria _sorted_selected_security_criteria => _sorted_selected_security_criteria_backing ?? (
|
||||
_sorted_selected_security_criteria_backing = _vm != null ?
|
||||
SecurityCriteria.from_securities(_vm.selected_rows.Ordered(_vm.comparer).Select(r => r.security)) :
|
||||
null);
|
||||
|
||||
bool _has_selected_rows() => _vm != null && _vm.selected_rows.Count > 0;
|
||||
|
||||
public void thread_init() {
|
||||
_init_guard.check_access();
|
||||
Log.notnull(_state);
|
||||
_menu_display_vm = new SparkMenuDisplayVM();
|
||||
_menu_display_vm.load_from(_state.menu_display);
|
||||
var update_securities_cmd = SparkCommands.change_securities_callback(_window_type_display_name);
|
||||
var security_md_map_src = Observable.Create<IReadOnlyDictionary<uint, SecurityMD>>(o => {
|
||||
IDisposable sub = null;
|
||||
_security_criteria_changed += on_security_criteria_changed;
|
||||
on_security_criteria_changed(_state.security_criteria);
|
||||
return Disposable.Create(dispose);
|
||||
void on_security_criteria_changed(SecurityCriteria security_criteria) {
|
||||
sub?.Dispose();
|
||||
sub = _state.security_criteria
|
||||
.subscribe_md_map(_bus.subscribe(SparkTags.SecuritiesTag)).Subscribe(o.OnNext);
|
||||
}
|
||||
void dispose() =>
|
||||
Disposable.dispose(ref sub);
|
||||
});
|
||||
_vm = new MarketViewVM(
|
||||
_bus,
|
||||
_orders_model,
|
||||
_position_model,
|
||||
_sec_meta_store,
|
||||
_settings_hub,
|
||||
security_md_map_src
|
||||
.BufferLatest(TimeSpan.FromSeconds(1))
|
||||
.Table(SecurityMD.key_fn)
|
||||
.Where(t => t.has_changes())
|
||||
.OnDispatcher());
|
||||
var sort_man = new ColumnSortManager(_vm.columns, MarketViewColumnType.Security.ToString());
|
||||
_current_sorting_criteria = _state.sorting_criteria.ToList();
|
||||
sort_man.SortingCriteria = _state.sorting_criteria;
|
||||
_vm.load_filters(_state.filters);
|
||||
_vm.comparer = sort_man.BuildComparer<MarketViewColumnType, MarketViewVM.Row>(MarketViewVM.get_column_comparer);
|
||||
_view = new MarketViewView { DataContext = _vm };
|
||||
_view._grid.Sorting += on_grid_sorting;
|
||||
_grid_settings_manager = new SimpleGridSettingsManager<MarketViewVM.Row>(_vm.columns, null, _vm.rows);
|
||||
_grid_settings_manager.load_from(_settings_manager.current_settings());
|
||||
/// The 'CanExecute' plumbing for the cmds below is designed to avoid potentially costly .ToList() operations on the selected_rows/securities.
|
||||
/// Some of the cmds post ITags with data that is, or has, a SecurityCriteria member; the SecurityCriteria constructor creates a new List of the specified securities.
|
||||
/// For these commands, the objective is to evaluate 'CanExecute' without instantiating the SecurityCriteria (or more importantly, without creating a new List).
|
||||
// show time and sales
|
||||
var show_tas_cmd = new DelegateCommand(() => {
|
||||
var sc = _selected_security_criteria;
|
||||
if (sc.is_defined())
|
||||
_bus.post(SparkTags.ShowTimeAndSalesTag, sc);
|
||||
}, _has_selected_rows);
|
||||
var show_tas_actual_cmd = SparkCommands.ShowTimeAndSales;
|
||||
var show_tas_cmd_wrapper = new SparkCommandCommand(show_tas_actual_cmd.title, show_tas_actual_cmd.icon, show_tas_cmd);
|
||||
// show fills
|
||||
var show_fills_cmd = new DelegateCommand(() => {
|
||||
var sc = _selected_security_criteria;
|
||||
_bus.post(SparkTags.ShowFillsTag, new FillsSettings(
|
||||
new FillsFilterStates {
|
||||
security = sc.is_defined() ? sc : _state.security_criteria
|
||||
}));
|
||||
});
|
||||
var show_fills_actual_cmd = SparkCommands.ShowFills();
|
||||
var show_fills_cmd_wrapper = new SparkCommandCommand(show_fills_actual_cmd.title, show_fills_actual_cmd.icon, show_fills_cmd, SparkCommands.KeyGestures.ShowFills);
|
||||
var show_mini_fills_cmd = new DelegateCommand(() => _view.show_mini_fills(_vm.selected_securities), () => _vm.selected_securities.Count > 0);
|
||||
var show_ticket_cmd = new DelegateCommand(() => {
|
||||
var smd = _vm.current_security_md;
|
||||
if (smd.HasValue)
|
||||
_view.show_order_ticket(smd.Value);
|
||||
}, () => _vm.current_security_md.HasValue);
|
||||
var show_ticket_actual_cmd = SparkCommands.ShowOrderTicketFromSecurity(SparkCommands.KeyGestures.ShowOrderTicket);
|
||||
// show synthetic create
|
||||
var show_synth_create_cmd = new DelegateCommand(() => {
|
||||
var sc = _sorted_selected_security_criteria;
|
||||
if (sc.is_defined())
|
||||
_bus.post(SparkTags.ShowSyntheticCreateTag, sc);
|
||||
}, () => _vm.selected_rows.Count > 0 && _vm.selected_rows.Count <= 24);
|
||||
var show_synth_create_actual_cmd = SparkCommands.ShowSyntheticCreate();
|
||||
var show_synth_create_cmd_wrapper = new SparkCommandCommand(show_synth_create_actual_cmd.title, show_synth_create_actual_cmd.icon, show_synth_create_cmd, SparkCommands.KeyGestures.ShowSyntheticCreate);
|
||||
var show_working_orders_cmd = new DelegateCommand(() => _view.show_working_orders(_vm.selected_securities), () => _vm.selected_securities.Count > 0);
|
||||
|
||||
var current_sec_md_src = Observable.Create<SecurityMD?>(o => {
|
||||
notify(null, null);
|
||||
_vm.current_row_changed += notify;
|
||||
return Disposable.Create(() => _vm.current_row_changed -= notify);
|
||||
void notify(MarketViewVM.Row oldval, MarketViewVM.Row newval) {
|
||||
if (newval != null)
|
||||
o.OnNext(newval.security_md);
|
||||
else o.OnNext(null);
|
||||
}
|
||||
});
|
||||
_commands = new List<SparkCommand> {
|
||||
SparkCommands.ShowLadders(SparkCommands.KeyGestures.ShowLadder).complete(
|
||||
current_sec_md_src,
|
||||
smd => smd.HasValue,
|
||||
_ => _vm.selected_security_mds.ToList()),
|
||||
SparkCommands.ShowOrderTicketFromSecurity(SparkCommands.KeyGestures.ShowOrderTicket).complete(current_sec_md_src, md => md.HasValue, ConvertUtils.ValueOrDefault),
|
||||
show_fills_cmd_wrapper,
|
||||
show_tas_cmd_wrapper,
|
||||
show_synth_create_cmd_wrapper,
|
||||
SparkCommands.show_spread_box().complete(
|
||||
current_sec_md_src,
|
||||
smd => smd.HasValue,
|
||||
_ => _vm.selected_securities.ToImmutableList(s => s.Id)),
|
||||
SparkCommands.send_rfq.complete(
|
||||
current_sec_md_src,
|
||||
smd => smd.HasValue,
|
||||
smd => new(new() {
|
||||
Security = new() {
|
||||
SecurityId = smd.assert_value().security.Id
|
||||
}
|
||||
})),
|
||||
// Note: the commands commented out below open the mini popup versions of their respective windows
|
||||
// TODO: determine if/how to integrate the mini popups into the toolbar.
|
||||
//new SparkCommandCommand("Working Orders", Icons.Orders, show_working_orders_cmd),
|
||||
//new SparkCommandCommand("Fills", show_fills_actual_cmd.icon, show_mini_fills_cmd),
|
||||
//new SparkCommandCommand(show_ticket_actual_cmd.title, show_ticket_actual_cmd.icon, show_ticket_cmd),
|
||||
SparkCommands.change_securities_command(() => (update_securities_cmd, _state.security_criteria)),
|
||||
// wrap the grid settings view factory in a dialogCommand here since the vm is destroyed/recreated when the security criteria changes
|
||||
SparkCommands.window_settings_command(new DialogCommand(() => {
|
||||
var vm = new ShellSettingsDialogVM<GridSettings, SimpleGridSettingsVM>(
|
||||
_settings_manager,
|
||||
us => us.market_view_grid,
|
||||
UserSettings.FileExtensions.GRID,
|
||||
s => _grid_settings_manager.create_vm(
|
||||
// we need to get the most up to date GridSettings when launching b/c users may
|
||||
// have changed some settings on the grid directly, like column widths.
|
||||
s.with(_vm.columns.Select(c => c.create()))
|
||||
)
|
||||
);
|
||||
vm.SubscribeDisposed(literal_title_source.OnDispatcher().Subscribe(t => vm.title = t));
|
||||
var dialog = new ShellSettingsDialog { DataContext = vm };
|
||||
vm.RequestClose += (s, e) => WindowUtilities.force_close(dialog);
|
||||
return dialog;
|
||||
})),
|
||||
_menu_display_vm.spark_cmd
|
||||
};
|
||||
//
|
||||
_vm.selected_rows.CollectionChanged += on_selection_changed;
|
||||
_subscriptions = Disposable.Create(
|
||||
_bus.subscribe(update_securities_cmd.tag).OnDispatcher().Subscribe(c => {
|
||||
_state = new MarketViewSettings(c, _state.filters, _state.grid, _state.sorting_criteria.ToList());
|
||||
_security_criteria_changed?.Invoke(c);
|
||||
}),
|
||||
_settings_manager.subscribe_current().OnDispatcher().Subscribe(new CompositeObserver<GridSettings>(_grid_settings_manager) {
|
||||
s => _vm.selection_highlight = s.selection_highlight
|
||||
}),
|
||||
Disposable.Create(() => {
|
||||
_vm.selected_rows.CollectionChanged -= on_selection_changed;
|
||||
_view._grid.Sorting -= on_grid_sorting;
|
||||
}));
|
||||
|
||||
void on_selection_changed(object sender, NotifyCollectionChangedEventArgs e) {
|
||||
// invalidate selected security criteria
|
||||
_selected_security_criteria_backing = null;
|
||||
_sorted_selected_security_criteria_backing = null;
|
||||
show_tas_cmd.RaiseCanExecuteChanged();
|
||||
show_fills_cmd.RaiseCanExecuteChanged();
|
||||
show_synth_create_cmd.RaiseCanExecuteChanged();
|
||||
show_working_orders_cmd.RaiseCanExecuteChanged();
|
||||
show_mini_fills_cmd.RaiseCanExecuteChanged();
|
||||
show_ticket_cmd.RaiseCanExecuteChanged();
|
||||
}
|
||||
|
||||
void on_grid_sorting(object sender, ui.controls.DIYGridSortingEventArgs e) {
|
||||
_sorted_selected_security_criteria_backing = null;
|
||||
sort_man.OnColumnClick(e.Column, KeyboardExtensions.IsShiftDown());
|
||||
_vm.comparer = sort_man.BuildComparer<MarketViewColumnType, MarketViewVM.Row>(MarketViewVM.get_column_comparer);
|
||||
_current_sorting_criteria = sort_man.SortingCriteria.ToList();
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnParentViewCreated(SparkWindowView parent_view) =>
|
||||
_menu_display_vm.safe_bind_to_view(parent_view);
|
||||
}
|
||||
}
|
||||
@@ -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) =>
|
||||
|
||||
Loaded 100 of 1056 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user