Compare commits
251
Commits
20.1.0_rc12
...
DJ_ICE
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4fd9442e5f | ||
|
|
9a85a475db | ||
|
|
8a1ab0ba9e | ||
|
|
57ac54b6c5 | ||
|
|
4a8433246c | ||
|
|
d6351cd187 | ||
|
|
eef263f2e7 | ||
|
|
2009027586 | ||
|
|
feaad6335d | ||
|
|
b96612d37b | ||
|
|
84f9338005 | ||
|
|
2837f3edfb | ||
|
|
a82932652b | ||
|
|
c9b5ff844f | ||
|
|
b0cbc2cb71 | ||
|
|
b2a2cae9c1 | ||
|
|
93d9a924e9 | ||
|
|
9d699711c1 | ||
|
|
5951691cbd | ||
|
|
cbff70d5a1 | ||
|
|
b59d45ae28 | ||
|
|
ea6e158e63 | ||
|
|
55a32935a9 | ||
|
|
9f895df70c | ||
|
|
8551936383 | ||
|
|
cb0378d785 | ||
|
|
489ac45722 | ||
|
|
d910c65e20 | ||
|
|
cb0e4de6c5 | ||
|
|
71539424cc | ||
|
|
602929b945 | ||
|
|
07591f8e28 | ||
|
|
0cb11b7f8d | ||
|
|
1921f02d30 | ||
|
|
2199efc95d | ||
|
|
54ff55f22f | ||
|
|
ca00f256e1 | ||
|
|
733ce7dfc6 | ||
|
|
fda812d792 | ||
|
|
1bf9d0aa4a | ||
|
|
54eec61f46 | ||
|
|
b84ba1d3f5 | ||
|
|
70bf5e0c95 | ||
|
|
2bae938549 | ||
|
|
e7806d2fec | ||
|
|
090a9dfb17 | ||
|
|
27aa43f44d | ||
|
|
19e087aa69 | ||
|
|
167c8c23a0 | ||
|
|
d235f4be41 | ||
|
|
ec43dbd82d | ||
|
|
f07998d6a6 | ||
|
|
b3dc2cdcd4 | ||
|
|
0963aee137 | ||
|
|
c2f8e92b10 | ||
|
|
7ae0142dff | ||
|
|
c30bab899f | ||
|
|
46544f36f1 | ||
|
|
c7df3ac43c | ||
|
|
db0ffba8ed | ||
|
|
a274a214b4 | ||
|
|
bbcfa3c75a | ||
|
|
89229d65f1 | ||
|
|
0e75cde409 | ||
|
|
42fa6dfaff | ||
|
|
400143c84d | ||
|
|
e915945880 | ||
|
|
9601ebab20 | ||
|
|
b344ab3377 | ||
|
|
ae3080b031 | ||
|
|
f0464331cb | ||
|
|
0648b618bf | ||
|
|
59282b8c70 | ||
|
|
34a86009ce | ||
|
|
0ad9ae9001 | ||
|
|
a296e1e772 | ||
|
|
7f53d8b161 | ||
|
|
243d6827d4 | ||
|
|
00221f9bd9 | ||
|
|
a6171ae405 | ||
|
|
be5d01a797 | ||
|
|
e5d9d324bf | ||
|
|
c34dee9d96 | ||
|
|
e5a98aab41 | ||
|
|
10cd35372b | ||
|
|
ad4515be39 | ||
|
|
ff4d87dd6b | ||
|
|
8ddde3f9da | ||
|
|
51093dc3a5 | ||
|
|
5d5db9ad9f | ||
|
|
fca808fe0d | ||
|
|
07d14f877b | ||
|
|
5ea6dccdd4 | ||
|
|
ac956a5c02 | ||
|
|
1fba09cf94 | ||
|
|
0baa6b875e | ||
|
|
cdacc2d4d4 | ||
|
|
1433541947 | ||
|
|
1070ca7ace | ||
|
|
56fa27dd7e | ||
|
|
d87b522bc6 | ||
|
|
166cb03782 | ||
|
|
c3786d9d64 | ||
|
|
9080e3124b | ||
|
|
d9c536124a | ||
|
|
7de6b2907e | ||
|
|
75f017e9f8 | ||
|
|
7757ab3ea0 | ||
|
|
3186dd383c | ||
|
|
45f751c9c6 | ||
|
|
e4d3774980 | ||
|
|
eedb3ce05d | ||
|
|
6a7d38c0fd | ||
|
|
31ccbfcd19 | ||
|
|
c2abf90cc4 | ||
|
|
8dc4735248 | ||
|
|
d940d9f11d | ||
|
|
1e0c75c6c7 | ||
|
|
3bb9961af4 | ||
|
|
da8088fd8d | ||
|
|
748a65f671 | ||
|
|
66d80136bd | ||
|
|
81189bb2cc | ||
|
|
e5681a50f2 | ||
|
|
69fe4569e3 | ||
|
|
c7caf66f9c | ||
|
|
14504f4a94 | ||
|
|
5b601a4016 | ||
|
|
45aa75e8bb | ||
|
|
b2471d45b2 | ||
|
|
11e2df8c76 | ||
|
|
cba6852655 | ||
|
|
5eeaedde26 | ||
|
|
b63052dbaa | ||
|
|
29f5bc798e | ||
|
|
04603acbb9 | ||
|
|
bc6890055e | ||
|
|
ea94c09c78 | ||
|
|
e3c3bc78fc | ||
|
|
a11d390dcd | ||
|
|
7c74a961d4 | ||
|
|
5db21ad2ca | ||
|
|
f703dabdfe | ||
|
|
237d3eea4b | ||
|
|
818bdec130 | ||
|
|
d257cf2c77 | ||
|
|
079f46404f | ||
|
|
edcc73e934 | ||
|
|
bc7ac8523b | ||
|
|
0c4c2b7231 | ||
|
|
420351c093 | ||
|
|
f69e6b89c5 | ||
|
|
c3e22e4b23 | ||
|
|
880c95d92b | ||
|
|
3231ffb343 | ||
|
|
8d7f1738cf | ||
|
|
9101214e66 | ||
|
|
c6b2e2f21e | ||
|
|
2eac97c1a9 | ||
|
|
b4b0e10f29 | ||
|
|
38d9db4a90 | ||
|
|
6a679ff78c | ||
|
|
aba3f21020 | ||
|
|
fede19fd11 | ||
|
|
3fa8dbf112 | ||
|
|
77ae4703b3 | ||
|
|
a28bfa1175 | ||
|
|
4e4a48283d | ||
|
|
7a761d00ce | ||
|
|
968be6a99a | ||
|
|
03404eb3f1 | ||
|
|
ff1a970982 | ||
|
|
ed890b4d84 | ||
|
|
e87003cc41 | ||
|
|
bc06037843 | ||
|
|
c4c7cebfc5 | ||
|
|
f18bcd2995 | ||
|
|
a6a1b6ac53 | ||
|
|
8c3da4e43c | ||
|
|
06b955dceb | ||
|
|
e75d15146c | ||
|
|
cb07384c9f | ||
|
|
fc9e502539 | ||
|
|
fcbf3388c0 | ||
|
|
899bea940f | ||
|
|
14b7509607 | ||
|
|
25668e8df0 | ||
|
|
5345ba8ff8 | ||
|
|
9bf05973bd | ||
|
|
cea4d05bc4 | ||
|
|
0b7208784b | ||
|
|
059ccbdab6 | ||
|
|
75eaf8c3d4 | ||
|
|
1e8fcd794f | ||
|
|
726329c4bf | ||
|
|
2d01f3f0f4 | ||
|
|
2a595c0fd7 | ||
|
|
5f9866c9e8 | ||
|
|
78f1cf88e0 | ||
|
|
4877436877 | ||
|
|
1b43124756 | ||
|
|
a1feb3fddf | ||
|
|
024328bf8b | ||
|
|
80d7e34bf1 | ||
|
|
8ab69c919b | ||
|
|
99531bcfa0 | ||
|
|
6bd516d4f2 | ||
|
|
1a1d771e1b | ||
|
|
050fcf7c6e | ||
|
|
aadeae3201 | ||
|
|
b72e8aed02 | ||
|
|
0820cc3e9a | ||
|
|
b1ba9a1315 | ||
|
|
39ce4323a1 | ||
|
|
d9fcd290d9 | ||
|
|
05939b02c5 | ||
|
|
aa91638fe4 | ||
|
|
065fc54f73 | ||
|
|
95fb13f58b | ||
|
|
4eb2931cb8 | ||
|
|
5326015a48 | ||
|
|
fcbe319470 | ||
|
|
5ad21c88b2 | ||
|
|
3a9c1d557b | ||
|
|
9d1b03d1e2 | ||
|
|
9a677cf980 | ||
|
|
6fb5b83249 | ||
|
|
95830fafdf | ||
|
|
d68b03bb91 | ||
|
|
e7062ce01e | ||
|
|
932738f98e | ||
|
|
1426b00e83 | ||
|
|
e724409b58 | ||
|
|
9cf828e9a4 | ||
|
|
41408fb609 | ||
|
|
4c21e32838 | ||
|
|
385f3ea402 | ||
|
|
8d6d8cab18 | ||
|
|
01615f824a | ||
|
|
c6779ddc90 | ||
|
|
46eff65435 | ||
|
|
25445d58d0 | ||
|
|
0b313a8aa8 | ||
|
|
54f954fd4b | ||
|
|
980f38ba03 | ||
|
|
9eada2724b | ||
|
|
b5f53ee918 | ||
|
|
efc175f654 | ||
|
|
6074afd999 | ||
|
|
219dff4055 | ||
|
|
9a3b07b622 |
No files matched your search
@@ -37,3 +37,4 @@ trace_data/
|
||||
*.rej
|
||||
/build
|
||||
.clangd/
|
||||
.venv/**
|
||||
+6
-3
@@ -1,9 +1,12 @@
|
||||
[submodule "externals"]
|
||||
path = externals
|
||||
url = git@bitbucket.org:bluetradesys/externals.git
|
||||
url = https://git.wearethefishers.com/petefisher78/externals.git
|
||||
[submodule "docker/linux"]
|
||||
path = docker/linux
|
||||
url = git@bitbucket.org:bluetradesys/linux_docker.git
|
||||
url = https://git.wearethefishers.com/petefisher78/linux_docker.git
|
||||
[submodule "docker/windows"]
|
||||
path = docker/windows
|
||||
url = git@bitbucket.org:bluetradesys/windows_docker.git
|
||||
url = https://git.wearethefishers.com/petefisher78/windows_docker.git
|
||||
[submodule "vcpkg"]
|
||||
path = vcpkg
|
||||
url = https://github.com/microsoft/vcpkg.git
|
||||
Vendored
+9
-5
@@ -8,13 +8,15 @@
|
||||
"program": "${workspaceRoot}/build/ninja_debug/server/sparkd",
|
||||
"args": [
|
||||
"run",
|
||||
// "test",
|
||||
// "-a",
|
||||
// "[ilink3]"
|
||||
"test",
|
||||
"-a",
|
||||
"OutrightVanillaOrder"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceRoot}/build/ninja_debug/server/",
|
||||
"environment": [],
|
||||
"environment": [
|
||||
{ "name": "TZ", "value": "America/Chicago" }
|
||||
],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"setupCommands": [
|
||||
@@ -31,7 +33,9 @@
|
||||
"request": "launch",
|
||||
"program": "/home/bts/spark/build/ninja_debug/server/sparkd",
|
||||
"args": [
|
||||
"run"
|
||||
"test",
|
||||
"-a",
|
||||
"[ilink3]"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "/home/bts/spark/build/ninja_debug/server/",
|
||||
|
||||
+5
-1
@@ -48,10 +48,11 @@ else ()
|
||||
endif()
|
||||
|
||||
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -DNDEBUG -O3")
|
||||
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
|
||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wno-undef")
|
||||
add_subdirectory(src/server/sparkd)
|
||||
add_subdirectory(src/lib)
|
||||
add_subdirectory(src/web)
|
||||
# add_subdirectory(src/web)
|
||||
add_subdirectory(doc/user)
|
||||
add_subdirectory(src/sdk)
|
||||
add_subdirectory(src/data_files)
|
||||
@@ -69,4 +70,7 @@ else ()
|
||||
DEPENDS sparkd data_files_dir)
|
||||
|
||||
add_custom_target(server_layout ALL DEPENDS ${CMAKE_BINARY_DIR}/server)
|
||||
|
||||
install(FILES "${CMAKE_SOURCE_DIR}/externals/linux/lib/${CMAKE_BUILD_TYPE}/libACE-5.7.5.so" DESTINATION bin)
|
||||
install(FILES "${CMAKE_SOURCE_DIR}/externals/linux/lib/${CMAKE_BUILD_TYPE}/libOnixS.IceImpactMulticastPriceFeedHandlerCpp.so.3.16.0.0" DESTINATION bin)
|
||||
endif()
|
||||
@@ -1 +1 @@
|
||||
set(sources /home/ppinto/Dropbox/bts/spark/doc/user/build.sh;content/_index.md;content/bts_spark/Glossary/_index.md;content/bts_spark/Help/_index.md;content/bts_spark/Help/about_spark.png;content/bts_spark/Help/image39.png;content/bts_spark/Help/image58.png;content/bts_spark/Launcher/_index.md;content/bts_spark/Launcher/image38.png;content/bts_spark/Launcher/image68.png;content/bts_spark/Logging-In-to-the-System/_index.md;content/bts_spark/Logging-In-to-the-System/image3.png;content/bts_spark/Logging-In-to-the-System/image64.png;content/bts_spark/Market/_index.md;content/bts_spark/Market/change_securities.png;content/bts_spark/Market/image11.png;content/bts_spark/Market/image14.png;content/bts_spark/Market/image20.png;content/bts_spark/Market/image21.png;content/bts_spark/Market/image23.png;content/bts_spark/Market/image24.png;content/bts_spark/Market/image34.png;content/bts_spark/Market/image49.png;content/bts_spark/Market/image53.png;content/bts_spark/Market/image66.png;content/bts_spark/Market/image69.png;content/bts_spark/Market/market_view.png;content/bts_spark/Market/settings_icon.png;content/bts_spark/Market/time_and_sales.png;content/bts_spark/My-Windows/_index.md;content/bts_spark/My-Windows/image15.png;content/bts_spark/My-Windows/image16.png;content/bts_spark/My-Windows/image37.png;content/bts_spark/Settings/_index.md;content/bts_spark/Settings/image51.png;content/bts_spark/Settings/image9.png;content/bts_spark/Spreader/_index.md;content/bts_spark/Spreader/image10.png;content/bts_spark/Spreader/image13.png;content/bts_spark/Spreader/image18.png;content/bts_spark/Spreader/image19.png;content/bts_spark/Spreader/image28.png;content/bts_spark/Spreader/image29.png;content/bts_spark/Spreader/image31.png;content/bts_spark/Spreader/image35.png;content/bts_spark/Spreader/image40.png;content/bts_spark/Spreader/image43.png;content/bts_spark/Spreader/image54.png;content/bts_spark/Spreader/image55.png;content/bts_spark/Spreader/image56.png;content/bts_spark/Spreader/image6.png;content/bts_spark/Spreader/image7.png;content/bts_spark/Spreader/image70.png;content/bts_spark/Spreader/image72.png;content/bts_spark/Spreader/image8.png;content/bts_spark/Trading/OrderTypes/index.md;content/bts_spark/Trading/_index.md;content/bts_spark/Trading/algo_studio.png;content/bts_spark/Trading/collapse_all_icon.png;content/bts_spark/Trading/cover_algo_control.png;content/bts_spark/Trading/expand_all_icon.png;content/bts_spark/Trading/image1.png;content/bts_spark/Trading/image17.png;content/bts_spark/Trading/image2.png;content/bts_spark/Trading/image25.png;content/bts_spark/Trading/image27.png;content/bts_spark/Trading/image33.png;content/bts_spark/Trading/image42.png;content/bts_spark/Trading/image44.png;content/bts_spark/Trading/image47.png;content/bts_spark/Trading/image48.png;content/bts_spark/Trading/image5.png;content/bts_spark/Trading/image50.png;content/bts_spark/Trading/image52.png;content/bts_spark/Trading/image57.png;content/bts_spark/Trading/image59.png;content/bts_spark/Trading/image60.png;content/bts_spark/Trading/image61.png;content/bts_spark/Trading/image62.png;content/bts_spark/Trading/image73.png;content/bts_spark/Trading/image74.png;content/bts_spark/Trading/join_algo_control.png;content/bts_spark/Trading/ladder.png;content/bts_spark/Trading/ladder_badges.png;content/bts_spark/Trading/ladder_main_part.png;content/bts_spark/Trading/lean_algo_control.png;content/bts_spark/Trading/mini_orderbook.png;content/bts_spark/Trading/oco_algo_control.png;content/bts_spark/Trading/offset_algo_control.png;content/bts_spark/Trading/pnl_calculation.png;content/bts_spark/Trading/pnl_window.png;content/bts_spark/Trading/recreate_icon.png;content/bts_spark/Trading/settings_icon.png;content/bts_spark/Trading/spark_menu_order_book.png;content/bts_spark/Trading/top_algo_control.png;content/bts_spark/Trading/trigger_algo_control.png;content/bts_spark/_index.md;content/release_notes/_index.md;content/system_requirements/_index.md;static/book.js;static/favicon.ico;static/image.js;templates/index.html;templates/page.html;templates/section.html;templates/shortcodes/back_button.html)
|
||||
set(sources /home/pfisher/bts/DJ_ICE/doc/user/build.sh;content/_index.md;content/bts_spark/Glossary/_index.md;content/bts_spark/Help/_index.md;content/bts_spark/Help/about_spark.png;content/bts_spark/Help/image39.png;content/bts_spark/Help/image58.png;content/bts_spark/Launcher/_index.md;content/bts_spark/Launcher/image38.png;content/bts_spark/Launcher/image68.png;content/bts_spark/Logging-In-to-the-System/_index.md;content/bts_spark/Logging-In-to-the-System/image3.png;content/bts_spark/Logging-In-to-the-System/image64.png;content/bts_spark/Market/_index.md;content/bts_spark/Market/change_securities.png;content/bts_spark/Market/image11.png;content/bts_spark/Market/image14.png;content/bts_spark/Market/image20.png;content/bts_spark/Market/image21.png;content/bts_spark/Market/image23.png;content/bts_spark/Market/image24.png;content/bts_spark/Market/image34.png;content/bts_spark/Market/image49.png;content/bts_spark/Market/image53.png;content/bts_spark/Market/image66.png;content/bts_spark/Market/image69.png;content/bts_spark/Market/market_view.png;content/bts_spark/Market/settings_icon.png;content/bts_spark/Market/time_and_sales.png;content/bts_spark/My-Windows/_index.md;content/bts_spark/My-Windows/image15.png;content/bts_spark/My-Windows/image16.png;content/bts_spark/My-Windows/image37.png;content/bts_spark/Settings/_index.md;content/bts_spark/Settings/image51.png;content/bts_spark/Settings/image9.png;content/bts_spark/Spreader/_index.md;content/bts_spark/Spreader/image10.png;content/bts_spark/Spreader/image13.png;content/bts_spark/Spreader/image18.png;content/bts_spark/Spreader/image19.png;content/bts_spark/Spreader/image28.png;content/bts_spark/Spreader/image29.png;content/bts_spark/Spreader/image31.png;content/bts_spark/Spreader/image35.png;content/bts_spark/Spreader/image40.png;content/bts_spark/Spreader/image43.png;content/bts_spark/Spreader/image54.png;content/bts_spark/Spreader/image55.png;content/bts_spark/Spreader/image56.png;content/bts_spark/Spreader/image6.png;content/bts_spark/Spreader/image7.png;content/bts_spark/Spreader/image70.png;content/bts_spark/Spreader/image72.png;content/bts_spark/Spreader/image8.png;content/bts_spark/Trading/OrderTypes/index.md;content/bts_spark/Trading/_index.md;content/bts_spark/Trading/algo_studio.png;content/bts_spark/Trading/collapse_all_icon.png;content/bts_spark/Trading/cover_algo_control.png;content/bts_spark/Trading/expand_all_icon.png;content/bts_spark/Trading/image1.png;content/bts_spark/Trading/image17.png;content/bts_spark/Trading/image2.png;content/bts_spark/Trading/image25.png;content/bts_spark/Trading/image27.png;content/bts_spark/Trading/image33.png;content/bts_spark/Trading/image42.png;content/bts_spark/Trading/image44.png;content/bts_spark/Trading/image47.png;content/bts_spark/Trading/image48.png;content/bts_spark/Trading/image5.png;content/bts_spark/Trading/image50.png;content/bts_spark/Trading/image52.png;content/bts_spark/Trading/image57.png;content/bts_spark/Trading/image59.png;content/bts_spark/Trading/image60.png;content/bts_spark/Trading/image61.png;content/bts_spark/Trading/image62.png;content/bts_spark/Trading/image73.png;content/bts_spark/Trading/image74.png;content/bts_spark/Trading/join_algo_control.png;content/bts_spark/Trading/ladder.png;content/bts_spark/Trading/ladder_badges.png;content/bts_spark/Trading/ladder_main_part.png;content/bts_spark/Trading/lean_algo_control.png;content/bts_spark/Trading/mini_orderbook.png;content/bts_spark/Trading/oco_algo_control.png;content/bts_spark/Trading/offset_algo_control.png;content/bts_spark/Trading/pnl_calculation.png;content/bts_spark/Trading/pnl_window.png;content/bts_spark/Trading/recreate_icon.png;content/bts_spark/Trading/settings_icon.png;content/bts_spark/Trading/spark_menu_order_book.png;content/bts_spark/Trading/top_algo_control.png;content/bts_spark/Trading/trigger_algo_control.png;content/bts_spark/_index.md;content/release_notes/_index.md;content/system_requirements/_index.md;static/book.js;static/favicon.ico;static/image.js;templates/index.html;templates/page.html;templates/section.html;templates/shortcodes/back_button.html)
|
||||
+1
-1
Submodule docker/linux updated: 6f0dd9324b...56c61231f3.
+1
-1
Submodule externals updated: 2ea5e355a6...768cfa0f9b.
@@ -0,0 +1,21 @@
|
||||
astroid==2.7.3
|
||||
autopep8==1.5.7
|
||||
cffi==1.14.6
|
||||
colorama==0.4.4
|
||||
isort==5.9.3
|
||||
lazy-object-proxy==1.6.0
|
||||
mccabe==0.6.1
|
||||
pkg_resources==0.0.0
|
||||
platformdirs==2.3.0
|
||||
protobuf==3.19.1
|
||||
pybars3==0.9.7
|
||||
pycodestyle==2.7.0
|
||||
pycparser==2.20
|
||||
pylint==2.10.2
|
||||
PyMeta3==0.5.1
|
||||
termcolor==1.1.0
|
||||
toml==0.10.2
|
||||
typed-ast==1.4.3
|
||||
typing_extensions==4.1.1
|
||||
wrapt==1.12.1
|
||||
yapf==0.31.0
|
||||
@@ -1,6 +1,7 @@
|
||||
using bts.api;
|
||||
using bts.co2;
|
||||
using bts.utils;
|
||||
using bts.utils.csv;
|
||||
using mbts;
|
||||
using mbts.spark;
|
||||
using mbts.ui.controls;
|
||||
@@ -49,6 +50,18 @@ namespace bts.shell.time_and_sales {
|
||||
public void raise_invalidated() =>
|
||||
invalidated?.Invoke();
|
||||
|
||||
public static System.Collections.Specialized.OrderedDictionary csv_ordered_properties =>
|
||||
CsvHelper.create_ordering_maintainer(
|
||||
typeof(TimeAndSalesRowVM),
|
||||
new string[] {
|
||||
nameof(security),
|
||||
nameof(time),
|
||||
nameof(price),
|
||||
nameof(size),
|
||||
nameof(aggressor_side),
|
||||
nameof(security_key),
|
||||
});
|
||||
|
||||
public bool Equals(TimeAndSalesRowVM other) =>
|
||||
other != null &&
|
||||
row_key == other.row_key;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using bts.shell.fills;
|
||||
using bts.spark;
|
||||
using bts.view;
|
||||
using bts.utils.csv;
|
||||
using mbts;
|
||||
using mbts.co2;
|
||||
using mbts.persist;
|
||||
@@ -124,6 +125,8 @@ namespace bts.shell.time_and_sales {
|
||||
show_in_context_menu = _can_pause_updates
|
||||
};
|
||||
_commands = new SparkCommand[] {
|
||||
// csv export
|
||||
new SparkCommandCommand("Export to csv", Icons.Export, FileDialogCommand.export_csv(() => _vm.rows.ToCsv(TimeAndSalesRowVM.csv_ordered_properties), "TaS")),
|
||||
// ladder
|
||||
SparkCommands.ShowLadderAutoLookup(SparkCommands.KeyGestures.ShowLadder)
|
||||
.complete(current_sec_key_src, sec_keys => sec_keys.Count > 0),
|
||||
|
||||
@@ -5,6 +5,7 @@ using bts.collections;
|
||||
using bts.shell.fills;
|
||||
using bts.spark;
|
||||
using bts.utils;
|
||||
using bts.utils.csv;
|
||||
using mbts.collections;
|
||||
using mbts.persist;
|
||||
using mbts.spark.filters;
|
||||
@@ -333,6 +334,27 @@ namespace mbts.spark {
|
||||
public override bool Equals(object obj) => Equals(obj as Row);
|
||||
public override int GetHashCode() => _fill.FillKey.GetHashCode() ^ _order.Key.GetHashCode();
|
||||
|
||||
public static System.Collections.Specialized.OrderedDictionary csv_ordered_properties =>
|
||||
CsvHelper.create_ordering_maintainer(typeof(Row),
|
||||
new string[] {
|
||||
nameof(security),
|
||||
nameof(order_type),
|
||||
nameof(root_algo_display_name),
|
||||
nameof(side),
|
||||
nameof(fill_time),
|
||||
nameof(user),
|
||||
nameof(account),
|
||||
nameof(exchange),
|
||||
nameof(time_in_force),
|
||||
nameof(size),
|
||||
nameof(price),
|
||||
nameof(fill_kind),
|
||||
nameof(fill_status),
|
||||
nameof(fill_key),
|
||||
nameof(order_key),
|
||||
nameof(security_key)
|
||||
});
|
||||
|
||||
public event Action invalidated;
|
||||
void IRowVM.raise_invalidated() => invalidated?.Invoke();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using bts.shell;
|
||||
using bts.shell.fills;
|
||||
using bts.spark;
|
||||
using bts.view;
|
||||
using bts.utils.csv;
|
||||
using mbts.persist;
|
||||
using mbts.ui;
|
||||
using mbts.ui.settings;
|
||||
@@ -61,6 +62,7 @@ namespace mbts.spark {
|
||||
_view = new FillsView { DataContext = _vm };
|
||||
|
||||
_commands = new List<SparkCommand> {
|
||||
new SparkCommandCommand("Export to csv", Icons.Export, FileDialogCommand.export_csv(() => _vm.rows.ToCsv(FillsVM.Row.csv_ordered_properties), "Fills")),
|
||||
// wrap the grid settings view factory in a dialogCommand here since the vm is destroyed/recreated when the security criteria changes
|
||||
SparkCommands.window_settings_command(new DialogCommand(() => {
|
||||
var vm = new ShellSettingsDialogVM<GridSettings, SimpleGridSettingsVM>(
|
||||
|
||||
@@ -203,6 +203,37 @@ namespace mbts.spark {
|
||||
_type_hash;
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
class FairValueLine : IEquatable<FairValueLine> {
|
||||
public enum PriceType {
|
||||
Bid,
|
||||
Ask,
|
||||
Mid
|
||||
}
|
||||
|
||||
[ProtoMember(1)]
|
||||
public uint security_key { get; set; }
|
||||
[ProtoMember(2)]
|
||||
public PriceType price_type { get; set; }
|
||||
[ProtoMember(3)]
|
||||
public LadderMarketBreakLine display { get; set; }
|
||||
|
||||
public bool Equals(FairValueLine other) {
|
||||
return other != null &&
|
||||
security_key == other.security_key &&
|
||||
price_type == other.price_type &&
|
||||
display.safe_equals(other.display);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
return Equals(obj as FairValueLine);
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
return (int)security_key;
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
enum LadderFavoriteAlgoFlags {
|
||||
Sticky = 1,
|
||||
@@ -328,7 +359,7 @@ namespace mbts.spark {
|
||||
|
||||
[ProtoContract]
|
||||
class LadderPanelPricePointSettings : IEquatable<LadderPanelPricePointSettings> {
|
||||
public static LadderPanelPricePointSettings Default =>
|
||||
public static LadderPanelPricePointSettings historic_default =>
|
||||
new LadderPanelPricePointSettings {
|
||||
day_change = new DaySettings {
|
||||
// (neutral)
|
||||
@@ -348,6 +379,18 @@ namespace mbts.spark {
|
||||
volume = _default_item
|
||||
};
|
||||
|
||||
public static LadderPanelPricePointSettings tt_default {
|
||||
get {
|
||||
var rv = historic_default;
|
||||
rv.day_change.background_color = Color.FromRgb(113, 201, 69).rgb_color();
|
||||
rv.day_change.font.font_color = Colors.Black.rgb_color();
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
public static LadderPanelPricePointSettings Default => LadderSettings.mimic_tt ?
|
||||
tt_default : historic_default;
|
||||
|
||||
[ProtoMember(1)]
|
||||
public DaySettings day_change { get; set; }
|
||||
[ProtoMember(2)]
|
||||
@@ -465,6 +508,12 @@ namespace mbts.spark {
|
||||
// so GetHashCode must return the same hash for every instance.
|
||||
static readonly int _type_hash = typeof(LadderSettings).GetHashCode();
|
||||
uint _ticks_per_row;
|
||||
List<FairValueLine> _fair_value_lines;
|
||||
|
||||
static LadderSettings() {
|
||||
var knobs = config.Configuration.get<bts.config.LadderKnobs>();
|
||||
mimic_tt = knobs.mimic_tt;
|
||||
}
|
||||
|
||||
// Default proto constructor
|
||||
// Added this so that when clients upgrade to a version with new settings,
|
||||
@@ -496,8 +545,10 @@ namespace mbts.spark {
|
||||
enforce_max_clip = _default_enforce_max_clip;
|
||||
status_message_visible = true;
|
||||
}
|
||||
|
||||
public static bool mimic_tt { get; }
|
||||
|
||||
public static LadderSettings Default {
|
||||
public static LadderSettings historic_default {
|
||||
get {
|
||||
LadderColumnSettings
|
||||
orders_column = LadderColumnSettings.DefaultOrderColumnSettings,
|
||||
@@ -507,12 +558,12 @@ namespace mbts.spark {
|
||||
last_column = LadderColumnSettings.Default,
|
||||
piq_column = LadderColumnSettings.DefaultPiqColumnSettings;
|
||||
orders_column.background = BTSColors.LadderSpecial.default_column_background;
|
||||
bid_column.foreground = 0xFFFFFF;
|
||||
bid_column.foreground = 0xFFFFFFFF;
|
||||
bid_column.background = BTSColors.MarketData.bid;
|
||||
ask_column.foreground = 0xFFFFFF;
|
||||
ask_column.foreground = 0xFFFFFFFF;
|
||||
ask_column.background = BTSColors.MarketData.ask;
|
||||
price_column.background = BTSColors.LadderSpecial.default_column_background;
|
||||
last_column.background = 0xFFFFFF;
|
||||
last_column.background = 0xFFFFFFFF;
|
||||
piq_column.background = BTSColors.LadderSpecial.default_column_background;
|
||||
var rv = new LadderSettings {
|
||||
row_height = 22,
|
||||
@@ -569,6 +620,28 @@ namespace mbts.spark {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
public static LadderSettings tt_default {
|
||||
get {
|
||||
var rv = historic_default;
|
||||
rv.orders_column.background = Color.FromRgb(223, 223, 223).rgb_color();
|
||||
// Since the price column sits atop the session range fill in tt
|
||||
// mode (normally it is the other way around), the former is made
|
||||
// partially translucent while the latter is fully opaque (obv the
|
||||
// top layer cannot be opaque, since it would completely hide the
|
||||
// layer beneath it).
|
||||
rv.session_range_fill.color = rv.session_range_fill.color.rgb_color().with(255).rgb_color();
|
||||
rv.price_column.background = Color.FromArgb(226, 166, 166, 166).rgb_color();
|
||||
rv.price_column.foreground = Colors.White.rgb_color();
|
||||
rv.bid_column.background = Color.FromRgb(0, 30, 160).rgb_color();
|
||||
rv.ask_column.background = Color.FromRgb(160, 0, 0).rgb_color();
|
||||
rv.ask_column.foreground = Colors.Black.rgb_color();
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
public static LadderSettings Default => mimic_tt ?
|
||||
tt_default : historic_default;
|
||||
|
||||
public enum BadgeStyle { Normal, Alternate }
|
||||
|
||||
@@ -745,6 +818,11 @@ namespace mbts.spark {
|
||||
public LadderOrderLimits ladder_order_limits { get; set; }
|
||||
[ProtoMember(901)]
|
||||
public LadderPanelPricePointSettings panel_price_point_settings { get; set; }
|
||||
[ProtoMember(902)]
|
||||
public List<FairValueLine> fair_value_lines {
|
||||
get => _fair_value_lines ?? (_fair_value_lines = new List<FairValueLine>());
|
||||
set => _fair_value_lines = value;
|
||||
}
|
||||
|
||||
public void sanitize() =>
|
||||
sanitize(this);
|
||||
@@ -781,6 +859,9 @@ namespace mbts.spark {
|
||||
s.row_height = LadderRender.measure_row_height(s);
|
||||
if (s.panel_price_point_settings is null)
|
||||
s.panel_price_point_settings = LadderPanelPricePointSettings.Default;
|
||||
if (s.fair_value_lines is null) {
|
||||
s.fair_value_lines = new List<FairValueLine>(0);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -856,7 +937,8 @@ namespace mbts.spark {
|
||||
a.status_message_visible == b.status_message_visible &&
|
||||
a.ladder_order_limits.safe_equals(b.ladder_order_limits) &&
|
||||
a.panel_price_point_settings.safe_equals(b.panel_price_point_settings) &&
|
||||
a._ticks_per_row == b._ticks_per_row;
|
||||
a._ticks_per_row == b._ticks_per_row &&
|
||||
EqualityComparer.safe_sequence_equals(a.fair_value_lines, b.fair_value_lines);
|
||||
|
||||
public bool Equals(LadderSettings other) =>
|
||||
profile_equals(this, other) &&
|
||||
|
||||
@@ -208,6 +208,10 @@ namespace bts.shell {
|
||||
s => {
|
||||
var svm = new LadderSettingsVM(model.order_gateway, vm.security);
|
||||
svm.load(s);
|
||||
svm.SubscribeDisposed(
|
||||
_bus.subscribe(SparkTags.SecuritiesTag)
|
||||
.OnDispatcher()
|
||||
.Subscribe(sec_map => svm.security_map = sec_map));
|
||||
return svm;
|
||||
},
|
||||
_ => _,
|
||||
@@ -331,4 +335,4 @@ namespace bts.shell {
|
||||
[ProtoMember(3)]
|
||||
public uint settings_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls.color_picker;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark {
|
||||
class FairValueLineSettingsVM : ui.shell.ViewModelBase {
|
||||
IReadOnlyDictionary<uint, SecurityMD> _security_map = DictionaryHelper.empty<uint, SecurityMD>();
|
||||
|
||||
public FairValueLineSettingsVM() {
|
||||
add_item_cmd = new DelegateCommand(() => items.Add(new FairValueLineItemSettingsVM()));
|
||||
remove_item_cmd = new DelegateCommand<FairValueLineItemSettingsVM>(item => items.Remove(item));
|
||||
}
|
||||
|
||||
public ObservableCollection<FairValueLineItemSettingsVM> items { get; } =
|
||||
new ObservableCollection<FairValueLineItemSettingsVM>();
|
||||
|
||||
public IReadOnlyDictionary<uint, SecurityMD> security_map {
|
||||
get => _security_map;
|
||||
set => Set(ref _security_map, value);
|
||||
}
|
||||
|
||||
public ICommand add_item_cmd { get; }
|
||||
public ICommand remove_item_cmd { get; }
|
||||
}
|
||||
|
||||
class FairValueLineItemSettingsVM : ui.shell.ViewModelBase {
|
||||
uint _selected_security_key;
|
||||
FairValueLine.PriceType _selected_price_type;
|
||||
Color _color;
|
||||
bool _show = true;
|
||||
bool _auto_refresh = true;
|
||||
|
||||
public FairValueLineItemSettingsVM() {
|
||||
palettes = new ObservableCollection<ColorPaletteVM>(ColorPalette.all_presets().Select(p => new ColorPaletteVM(p)));
|
||||
}
|
||||
|
||||
public uint selected_security_key {
|
||||
get => _selected_security_key;
|
||||
set => Set(ref _selected_security_key, value);
|
||||
}
|
||||
|
||||
public IEnumerable<FairValueLine.PriceType> price_types =>
|
||||
ui.utility.EnumHelper.get_values<FairValueLine.PriceType>();
|
||||
|
||||
public FairValueLine.PriceType selected_price_type {
|
||||
get => _selected_price_type;
|
||||
set => Set(ref _selected_price_type, value);
|
||||
}
|
||||
|
||||
public Color color { get => _color; set => Set(ref _color, value); }
|
||||
public bool show { get => _show; set => Set(ref _show, value); }
|
||||
public bool auto_refresh {
|
||||
get => _auto_refresh; set {
|
||||
if (Set(ref _auto_refresh, value)) {
|
||||
RaisePropertyChanged(nameof(refresh_mode));
|
||||
}
|
||||
}
|
||||
}
|
||||
public LadderMarketBreakLine.RefreshMode refresh_mode {
|
||||
get => _auto_refresh ? LadderMarketBreakLine.RefreshMode.Auto : LadderMarketBreakLine.RefreshMode.Manual;
|
||||
set => auto_refresh = value == LadderMarketBreakLine.RefreshMode.Auto;
|
||||
}
|
||||
public ObservableCollection<ColorPaletteVM> palettes { get; }
|
||||
|
||||
public void assign_from(FairValueLine settings) {
|
||||
if (settings is null) {
|
||||
settings = new FairValueLine();
|
||||
}
|
||||
selected_security_key = settings.security_key;
|
||||
selected_price_type = settings.price_type;
|
||||
var display = settings.display ?? new LadderMarketBreakLine();
|
||||
show = display.show;
|
||||
color = display.color.rgb_color();
|
||||
refresh_mode = display.refresh_mode;
|
||||
}
|
||||
|
||||
public FairValueLine create() {
|
||||
return new FairValueLine {
|
||||
security_key = selected_security_key,
|
||||
price_type = _selected_price_type,
|
||||
display = new LadderMarketBreakLine {
|
||||
color = color.rgb_color(),
|
||||
show = show,
|
||||
refresh_mode = refresh_mode
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
using mbts.co2;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark {
|
||||
class FairValueLineVM {
|
||||
NativePriceSize _bid;
|
||||
NativePriceSize _ask;
|
||||
double _settlement;
|
||||
double _frozen;
|
||||
ulong _last_update;
|
||||
|
||||
public FairValueLineVM(uint sec_id) {
|
||||
this.sec_id = sec_id;
|
||||
}
|
||||
|
||||
public FairValueLineVM(FairValueLine fvl, SecurityMD? sec_md = null) {
|
||||
sec_id = fvl.security_key;
|
||||
price_type = fvl.price_type;
|
||||
settings = fvl.display;
|
||||
this.sec_md = sec_md;
|
||||
}
|
||||
|
||||
public FairValueLine.PriceType price_type { get; private set; }
|
||||
public double price { get; private set; }
|
||||
public double price_view {
|
||||
get {
|
||||
if (!settings.show) {
|
||||
return double.NaN;
|
||||
}
|
||||
switch (settings.refresh_mode) {
|
||||
case LadderMarketBreakLine.RefreshMode.Auto:
|
||||
return price;
|
||||
case LadderMarketBreakLine.RefreshMode.Manual:
|
||||
return frozen;
|
||||
default: return double.NaN;
|
||||
}
|
||||
}
|
||||
}
|
||||
public double frozen {
|
||||
get {
|
||||
if (double.IsNaN(_frozen)) {
|
||||
_frozen = price;
|
||||
}
|
||||
return _frozen;
|
||||
}
|
||||
}
|
||||
public Color color { get; set; }
|
||||
public uint sec_id { get; }
|
||||
SecurityMD? _sec_md;
|
||||
public SecurityMD? sec_md {
|
||||
get => _sec_md;
|
||||
set {
|
||||
if (_sec_md == value) {
|
||||
return;
|
||||
}
|
||||
if (value.HasValue && value.Value.security.Id != sec_id) {
|
||||
throw new ArgumentException("'sec_md' security id must be equal to 'sec_id'", nameof(sec_md));
|
||||
}
|
||||
_sec_md = value;
|
||||
refresh(true);
|
||||
}
|
||||
}
|
||||
|
||||
public LadderMarketBreakLine settings { get; set; } = new LadderMarketBreakLine();
|
||||
|
||||
public void load(LadderMarketBreakLine settings, FairValueLine.PriceType price_type) {
|
||||
this.settings = settings;
|
||||
if (this.price_type != price_type) {
|
||||
this.price_type = price_type;
|
||||
refresh(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void refresh(bool update_frozen) {
|
||||
if (sec_md.HasValue) {
|
||||
var old_settlement = _settlement;
|
||||
_settlement = sec_md.Value.md.settlement_price;
|
||||
if (sec_md.Value.md.get_bbo(ref _last_update, out _bid, out _ask) || _settlement != old_settlement) {
|
||||
price = _read_price();
|
||||
}
|
||||
} else {
|
||||
price = double.NaN;
|
||||
}
|
||||
if (update_frozen) {
|
||||
_frozen = price;
|
||||
}
|
||||
}
|
||||
|
||||
double _read_price() {
|
||||
if (!_sec_md.HasValue) {
|
||||
return double.NaN;
|
||||
}
|
||||
var bid = _bid.price;
|
||||
var ask = _ask.price;
|
||||
switch (price_type) {
|
||||
case FairValueLine.PriceType.Bid:
|
||||
return LadderPriceLineViewAdapter.bid_line(
|
||||
_bid.price, _ask.price, _settlement, sec_md.Value.security.ContractSpec);
|
||||
case FairValueLine.PriceType.Ask:
|
||||
return _ask.is_nan ? double.NaN : _ask.price;
|
||||
case FairValueLine.PriceType.Mid:
|
||||
if (_bid.is_nan) {
|
||||
if (_ask.is_nan) {
|
||||
return double.NaN;
|
||||
}
|
||||
return _ask.price;
|
||||
}
|
||||
if (_ask.is_nan) {
|
||||
return _bid.price;
|
||||
}
|
||||
return (_bid.price + _ask.price) / 2;
|
||||
default: return double.NaN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,9 @@ namespace mbts.spark {
|
||||
readonly ObservableKeyedCollection<AlgoDefinitionVM, AlgoKey> _algo_definitions = new ObservableKeyedCollection<AlgoDefinitionVM, AlgoKey>(d => d.key);
|
||||
readonly OrdersModel _model;
|
||||
readonly SecurityImmutable _security;
|
||||
IReadOnlyDictionary<uint, SecurityMD> _security_map =
|
||||
DictionaryHelper.empty<uint, SecurityMD>();
|
||||
|
||||
uint? _desired_account;
|
||||
AlgoID? _desired_algo;
|
||||
TimeInForce _default_time_in_force;
|
||||
@@ -143,17 +146,22 @@ namespace mbts.spark {
|
||||
_accounts.SyncWithDictionary(MappedDictionary.create(acc_map, account_factory));
|
||||
_try_select_desired_account();
|
||||
}),
|
||||
ObservableAutoWrapper.connect_item_hooks(favorite_algos_vm.items, connect_favorite_algo),
|
||||
ObservableAutoWrapper.connect_item_hooks(favorite_algos_vm.items, observe_prop_changes),
|
||||
_model.algo_model.definitions.OnDispatcher().Subscribe(update => {
|
||||
AlgoCollectionHelper.update_persisted_definitions(_algo_definitions, update, algo_factory);
|
||||
_try_select_desired_algo();
|
||||
}),
|
||||
ObservableAutoWrapper.connect_item_hooks(fair_value_line_settings_vm.items, item => {
|
||||
_update.execute();
|
||||
var prop_changes_sub = observe_prop_changes(item);
|
||||
return Disposable.Create(_update.execute, prop_changes_sub.Dispose);
|
||||
})
|
||||
) { dispose_resources };
|
||||
// local methods
|
||||
void on_font_size_changed(double oldval, double newval) => _row_height.refresh();
|
||||
void on_prop_changed(object sender, PropertyChangedEventArgs e) => _update.execute();
|
||||
void on_favorite_algo_items_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) => _update.execute();
|
||||
IDisposable connect_favorite_algo(FavoriteAlgoItem item) {
|
||||
IDisposable observe_prop_changes(INotifyPropertyChanged item) {
|
||||
item.PropertyChanged += on_prop_changed;
|
||||
return Disposable.Create(() => item.PropertyChanged -= on_prop_changed);
|
||||
}
|
||||
@@ -253,6 +261,14 @@ namespace mbts.spark {
|
||||
public double row_height => _row_height.Value;
|
||||
public bool is_synthetic => _security.ContractCase == Security.ContractOneofCase.Synthetic;
|
||||
|
||||
public IReadOnlyDictionary<uint, SecurityMD> security_map {
|
||||
get => _security_map;
|
||||
set {
|
||||
Set(ref _security_map, value);
|
||||
fair_value_line_settings_vm.security_map = value;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<LadderColumnSettingsVM> column_items {
|
||||
get {
|
||||
yield return _orders;
|
||||
@@ -290,6 +306,9 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
public FairValueLineSettingsVM fair_value_line_settings_vm { get; } = new
|
||||
FairValueLineSettingsVM();
|
||||
|
||||
public IEnumerable order_entry_panel_items {
|
||||
get {
|
||||
yield return _zoom_slider_visbility;
|
||||
@@ -388,6 +407,14 @@ namespace mbts.spark {
|
||||
_session_low_mkt_line.assign_from(_current.session_low_line);
|
||||
_session_high_mkt_line.assign_from(_current.session_high_line);
|
||||
_session_range_fill.assign_from(_current.session_range_fill);
|
||||
// fair value lines
|
||||
fair_value_line_settings_vm.items.SetItems(
|
||||
_current.fair_value_lines.Select(fvl => {
|
||||
var fvl_vm = new FairValueLineItemSettingsVM();
|
||||
fvl_vm.assign_from(fvl);
|
||||
fvl_vm.selected_security_key = fvl.security_key;
|
||||
return fvl_vm;
|
||||
}));
|
||||
// left-panel (defaults)
|
||||
default_time_in_force = settings.default_time_in_force;
|
||||
// - account
|
||||
@@ -476,6 +503,11 @@ namespace mbts.spark {
|
||||
clone.session_low_line = _session_low_mkt_line.get_settings();
|
||||
clone.session_high_line = _session_high_mkt_line.get_settings();
|
||||
clone.session_range_fill = _session_range_fill.get_settings();
|
||||
// fair value lines
|
||||
clone.fair_value_lines = fair_value_line_settings_vm.items
|
||||
.Select(fvl => fvl.create())
|
||||
.Where(fvl => fvl.security_key != 0)
|
||||
.ToList();
|
||||
// left-panel price items
|
||||
clone.panel_price_point_settings = new LadderPanelPricePointSettings {
|
||||
day_change = _day_change.create(),
|
||||
@@ -628,8 +660,8 @@ namespace mbts.spark {
|
||||
font_size = settings.font_size;
|
||||
width = settings.width;
|
||||
show = settings.show;
|
||||
foreground = settings.foreground.rgb_color();
|
||||
background = settings.background.rgb_color();
|
||||
foreground = settings.foreground.argb_color();
|
||||
background = settings.background.argb_color();
|
||||
}
|
||||
|
||||
public LadderColumnSettings get_settings() {
|
||||
@@ -639,8 +671,8 @@ namespace mbts.spark {
|
||||
font_weight = font_weight.ToOpenTypeWeight(),
|
||||
width = width,
|
||||
show = show,
|
||||
foreground = new BTSColor(foreground).ToUint(),
|
||||
background = new BTSColor(background).ToUint()
|
||||
foreground = foreground.rgb_color(),
|
||||
background = background.rgb_color()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using bts.shell;
|
||||
using bts.spark;
|
||||
using bts.utils;
|
||||
using mbts.co2;
|
||||
using mbts.collections;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
@@ -34,10 +35,21 @@ namespace mbts.spark {
|
||||
readonly Property<uint> _orders_column_width, _bid_column_width, _price_column_width, _ask_column_width, _last_column_width, _volume_column_width, _piq_column_width;
|
||||
readonly Property<ulong> _volume;
|
||||
readonly Property<bool> _auto_clear;
|
||||
readonly PropertyAutoWrapper<LadderSettings, bool> _show_day, _show_high, _show_low, _show_open, _show_settlement, _show_volume, _show_account,
|
||||
_show_tif, _show_order_type, _show_size_preset, _show_auto_clear, _show_clear, _show_cancel_buys,
|
||||
_show_cancel_sells, _show_cancel_all, _show_zoom, _show_status_message;
|
||||
readonly PropertyAutoWrapper<LadderSettings, bool>
|
||||
_show_account,
|
||||
_show_tif,
|
||||
_show_order_type,
|
||||
_show_size_preset,
|
||||
_show_auto_clear,
|
||||
_show_clear,
|
||||
_show_cancel_buys,
|
||||
_show_cancel_sells,
|
||||
_show_cancel_all,
|
||||
_show_zoom,
|
||||
_show_status_message;
|
||||
readonly PropertyAutoWrapper<LadderSettings, Brush> _bid_background, _bid_foreground, _ask_background, _ask_foreground;
|
||||
readonly ObservableCollection<FairValueLine> _fair_value_line_inputs =
|
||||
new ObservableCollection<FairValueLine>();
|
||||
double
|
||||
_position,
|
||||
_day_position,
|
||||
@@ -53,6 +65,7 @@ namespace mbts.spark {
|
||||
Dictionary<double, LadderOrderVM> _slot_price_vs_orders;
|
||||
ImmutableSortedDictionary<double, LadderOrderVM> _order_price_index;
|
||||
IReadOnlyDictionary<uint, OrderSecurity> _cache = DictionaryHelper.empty<uint, OrderSecurity>();
|
||||
IReadOnlyDictionary<uint, SecurityMD> _security_map = DictionaryHelper.empty<uint, SecurityMD>();
|
||||
ImmutableDictionary<AlgoKey, LadderFavoriteAlgoItem> _favorite_algo_map = ImmutableDictionary<AlgoKey, LadderFavoriteAlgoItem>.Empty;
|
||||
ContractSpecificationImmutable? _spec;
|
||||
|
||||
@@ -109,12 +122,6 @@ namespace mbts.spark {
|
||||
(_ask_background = brush_prop(nameof(ask_background), s => s.ask_column.background)).set,
|
||||
(_ask_foreground = brush_prop(nameof(ask_foreground), s => s.ask_column.foreground)).set,
|
||||
// bool visibility props
|
||||
(_show_day = bool_prop(nameof(show_day), s => s.day_visible)).set,
|
||||
(_show_high = bool_prop(nameof(show_high), s => s.high_visible)).set,
|
||||
(_show_low = bool_prop(nameof(show_low), s => s.low_visible)).set,
|
||||
(_show_open = bool_prop(nameof(show_open), s => s.open_visible)).set,
|
||||
(_show_settlement = bool_prop(nameof(show_settlement), s => s.settle_visible)).set,
|
||||
(_show_volume = bool_prop(nameof(show_volume), s => s.volume_visible)).set,
|
||||
(_show_account = bool_prop(nameof(show_account), s => s.account_visible)).set,
|
||||
(_show_tif = bool_prop(nameof(show_tif), s => s.tif_visible)).set,
|
||||
(_show_order_type = bool_prop(nameof(show_order_type), s => s.order_type_visible)).set,
|
||||
@@ -147,14 +154,32 @@ namespace mbts.spark {
|
||||
_volume_column_width.set(s.volume_column.general.width);
|
||||
// left panel/zoom
|
||||
day_change_style.load_from(s.panel_price_point_settings.day_change);
|
||||
day_change_style.show = s.day_visible;
|
||||
// open
|
||||
open_style.load_from(s.panel_price_point_settings.open);
|
||||
open_style.show = s.open_visible;
|
||||
// session low
|
||||
session_low_style.load_from(s.panel_price_point_settings.session_low);
|
||||
session_low_style.show = s.low_visible;
|
||||
// session high
|
||||
session_high_style.load_from(s.panel_price_point_settings.session_high);
|
||||
session_high_style.show = s.high_visible;
|
||||
// settlement
|
||||
settlement_style.load_from(s.panel_price_point_settings.settlement);
|
||||
settlement_style.show = s.settle_visible;
|
||||
// volume
|
||||
volume_style.load_from(s.panel_price_point_settings.volume);
|
||||
volume_style.show = s.volume_visible;
|
||||
// left panel gen display
|
||||
_left_panel_width.set(s.order_entry_panel_initial_width);
|
||||
_zoom_factor.set(s.zoom_factor);
|
||||
RaisePropertyChanged(nameof(day_change_font_color), nameof(day_change_background_color));
|
||||
// fair value lines
|
||||
var new_fvls = s.fair_value_lines
|
||||
.DistinctOn(fvl => fvl.security_key)
|
||||
.OrderBy(fvl => fvl.security_key)
|
||||
.ToList();
|
||||
_fair_value_line_inputs.sync_with(new_fvls);
|
||||
}
|
||||
};
|
||||
PropertyAutoWrapper<LadderSettings, bool> bool_prop(string name, Func<LadderSettings, bool> get_bool) =>
|
||||
@@ -186,6 +211,11 @@ namespace mbts.spark {
|
||||
settings.OnDispatcher().Subscribe(settings_observer),
|
||||
get_order_properties_editor_hooks(),
|
||||
bus.subscribe(SparkTags.LogActivity).OnDispatcher().Subscribe(status_update),
|
||||
bus.subscribe(SparkTags.SecuritiesTag).OnDispatcher().Subscribe(on_security_map),
|
||||
ObservableAutoWrapper.connect(
|
||||
_fair_value_line_inputs,
|
||||
fair_value_lines,
|
||||
fvl => new FairValueLineVM(fvl, _find_sec_md(fvl.security_key))),
|
||||
orders_source.OnDispatcher().Subscribe(tup => {
|
||||
// Here we manage N orders to 1 price slot in the ladder
|
||||
Dictionary<double, HashSet<uint>> orders_used_in_this_update = new Dictionary<double, HashSet<uint>>(_equality);
|
||||
@@ -240,6 +270,15 @@ namespace mbts.spark {
|
||||
RaisePropertyChanged(nameof(position_display_text));
|
||||
}));
|
||||
}
|
||||
void on_security_map(IReadOnlyDictionary<uint, SecurityMD> security_map) {
|
||||
_security_map = security_map;
|
||||
foreach (var fvl_vm in fair_value_lines) {
|
||||
if (fvl_vm.sec_md.HasValue) {
|
||||
continue;
|
||||
}
|
||||
fvl_vm.sec_md = _find_sec_md(fvl_vm.sec_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IBus bus => _bus;
|
||||
@@ -325,12 +364,6 @@ namespace mbts.spark {
|
||||
public Brush bid_foreground => _bid_foreground.view;
|
||||
public Brush ask_background => _ask_background.view;
|
||||
public Brush ask_foreground => _ask_foreground.view;
|
||||
public bool show_day => _show_day.view;
|
||||
public bool show_high => _show_high.view;
|
||||
public bool show_low => _show_low.view;
|
||||
public bool show_open => _show_open.view;
|
||||
public bool show_settlement => _show_settlement.view;
|
||||
public bool show_volume => _show_volume.view;
|
||||
public bool show_account => _show_account.view;
|
||||
public bool show_tif => _show_tif.view;
|
||||
public bool show_order_type => _show_order_type.view;
|
||||
@@ -395,6 +428,10 @@ namespace mbts.spark {
|
||||
return rv ?? "";
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<FairValueLineVM> fair_value_lines { get; } =
|
||||
new ObservableCollection<FairValueLineVM>();
|
||||
|
||||
//public double window_height { get => _window_height.Value; set => _window_height.set(value); }
|
||||
//public double window_width { get => _window_width.Value; set => _window_width.set(value); }
|
||||
public uint orders_column_width { get => _orders_column_width.Value; set => _orders_column_width.set(value); }
|
||||
@@ -669,5 +706,12 @@ namespace mbts.spark {
|
||||
_update_header();
|
||||
on_tick?.Invoke();
|
||||
}
|
||||
|
||||
SecurityMD? _find_sec_md(uint sec_key) {
|
||||
if (_security_map.TryGetValue(sec_key, out var sec_md)) {
|
||||
return sec_md;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<UserControl
|
||||
x:Class="mbts.ui.spark.FairValueLineSettingsView"
|
||||
x:ClassModifier="internal"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mbts="clr-namespace:mbts"
|
||||
xmlns:sp="clr-namespace:mbts.spark"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:cv="clr-namespace:mbts.ui.converters"
|
||||
xmlns:stg="clr-namespace:mbts.ui.settings"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
>
|
||||
<UserControl.Resources>
|
||||
<Thickness x:Key="CellPadding">10,6</Thickness>
|
||||
<Style x:Key="DisabledColumnHeader" TargetType="GridViewColumnHeader">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="GridViewColumnHeader">
|
||||
<Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{x:Static u:BTSColors.header_brush}"/>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<c:DIYGrid
|
||||
Grid.Row="0"
|
||||
Grid.IsSharedSizeScope="True"
|
||||
BorderBrush="Black"
|
||||
BorderThickness="1"
|
||||
Rows="{Binding items}"
|
||||
RowsHorizontalScrollBarVisibility="Collapsed"
|
||||
SelectionMode="Single"
|
||||
>
|
||||
<c:DIYGrid.Columns>
|
||||
<c:DIYGridColumnCollection>
|
||||
<usp:FairValueLineSettingsColumn key="Delete" HeaderContainerStyle="{StaticResource DisabledColumnHeader}" Width="23" is_visible="True"/>
|
||||
<usp:FairValueLineSettingsColumn key="Security" Header="Security" Width="130" is_visible="True"/>
|
||||
<usp:FairValueLineSettingsColumn key="Show" Header="Show" Width="40" is_visible="True"/>
|
||||
<usp:FairValueLineSettingsColumn key="AutoRefresh" Header="Auto Refresh" Width="80" is_visible="True"/>
|
||||
<usp:FairValueLineSettingsColumn key="Color" Header="Color" Width="80" is_visible="True"/>
|
||||
<usp:FairValueLineSettingsColumn key="PriceType" Header="Type" Width="80" is_visible="True"/>
|
||||
</c:DIYGridColumnCollection>
|
||||
</c:DIYGrid.Columns>
|
||||
<c:DIYGrid.RowTemplate>
|
||||
<DataTemplate DataType="{x:Type sp:FairValueLineItemSettingsVM}">
|
||||
<Grid c:DIYGrid.SyncWithColumnGeometry="True">
|
||||
<!--Delete-->
|
||||
<Button
|
||||
c:DIYGrid.ColumnKey="Delete"
|
||||
HorizontalAlignment="Center"
|
||||
Command="{Binding DataContext.remove_item_cmd,
|
||||
RelativeSource={RelativeSource AncestorType=usp:FairValueLineSettingsView}}"
|
||||
CommandParameter="{Binding}"
|
||||
Style="{StaticResource RoundCloseButton}"
|
||||
ToolTip="Delete"
|
||||
/>
|
||||
<!--Security-->
|
||||
<c:ContractPickerPopup
|
||||
c:DIYGrid.ColumnKey="Security"
|
||||
Grid.Column="0"
|
||||
Margin="{StaticResource CellPadding}"
|
||||
CloseOnOK="True"
|
||||
CloseOnCancel="True"
|
||||
IsEditMode="False"
|
||||
MaxWidth="180"
|
||||
SecurityMap="{Binding DataContext.security_map,
|
||||
RelativeSource={RelativeSource AncestorType=usp:FairValueLineSettingsView}}"
|
||||
SelectedSecurityKey="{Binding selected_security_key}"
|
||||
Header="{Binding SelectedSecurity,
|
||||
RelativeSource={RelativeSource Self},
|
||||
Converter={StaticResource SelectedSecurityTextConverter}}"
|
||||
/>
|
||||
<!--Show-->
|
||||
<CheckBox
|
||||
c:DIYGrid.ColumnKey="Show"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
IsChecked="{Binding show}"
|
||||
/>
|
||||
<!--AutoRefresh-->
|
||||
<CheckBox
|
||||
c:DIYGrid.ColumnKey="AutoRefresh"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
IsChecked="{Binding auto_refresh}"
|
||||
/>
|
||||
<!--Color-->
|
||||
<c:ColorPickerPopup
|
||||
c:DIYGrid.ColumnKey="Color"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Center"
|
||||
Margin="{StaticResource CellPadding}"
|
||||
Palettes="{Binding color_palettes}"
|
||||
SelectedColor="{Binding color}"
|
||||
/>
|
||||
<!--PriceType-->
|
||||
<ComboBox
|
||||
c:DIYGrid.ColumnKey="PriceType"
|
||||
Margin="{StaticResource CellPadding}"
|
||||
ItemsSource="{Binding price_types}"
|
||||
SelectedItem="{Binding selected_price_type}"
|
||||
/>
|
||||
<Rectangle Grid.Column="0" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
<Rectangle Grid.Column="1" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
<Rectangle Grid.Column="2" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
<Rectangle Grid.Column="3" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
<Rectangle Grid.Column="4" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</c:DIYGrid.RowTemplate>
|
||||
</c:DIYGrid>
|
||||
<TextBlock Grid.Row="1" HorizontalAlignment="Left" Margin="4,8">
|
||||
<Hyperlink Command="{Binding add_item_cmd}">
|
||||
Click to Add Item
|
||||
</Hyperlink>
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,40 @@
|
||||
using mbts.ui.controls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace mbts.ui.spark {
|
||||
/// <summary>
|
||||
/// Interaction logic for FairValueLineSettingsView.xaml
|
||||
/// </summary>
|
||||
partial class FairValueLineSettingsView : UserControl {
|
||||
public FairValueLineSettingsView() =>
|
||||
InitializeComponent();
|
||||
|
||||
public enum Columns {
|
||||
None = 0,
|
||||
Delete,
|
||||
Security,
|
||||
Show,
|
||||
AutoRefresh,
|
||||
Color,
|
||||
PriceType
|
||||
}
|
||||
}
|
||||
|
||||
class FairValueLineSettingsColumn : DIYGrid.ColumnBase<FairValueLineSettingsView.Columns> {
|
||||
protected override void on_key_initialized(FairValueLineSettingsView.Columns key) =>
|
||||
id = key.ToString();
|
||||
}
|
||||
}
|
||||
@@ -29,8 +29,10 @@ using System.Windows.Media.Animation;
|
||||
namespace mbts.spark {
|
||||
partial class LadderGridHost : Control {
|
||||
const int _min_row_count = 501, _max_row_count = 2001;
|
||||
static readonly bool _show_scrollbar = config.Configuration.get<bts.config.LadderKnobs>().show_scrollbar;
|
||||
static readonly bool _lighten_market_cells = config.Configuration.get<bts.config.LadderKnobs>().lighten_market_cells;
|
||||
static readonly bool _show_scrollbar;
|
||||
static readonly bool _lighten_market_cells;
|
||||
static readonly Color? _bid_market_cell_background;
|
||||
static readonly Color? _ask_market_cell_background;
|
||||
|
||||
int _row_count = _min_row_count;
|
||||
|
||||
@@ -55,7 +57,7 @@ namespace mbts.spark {
|
||||
readonly RefValueContainer<IEnumerable<VolumeAtPriceLevelImmutable>> _volume_container =
|
||||
new RefValueContainer<IEnumerable<VolumeAtPriceLevelImmutable>>();
|
||||
|
||||
IDisposable _settings_sub, _volume_sub, _tick_sub, _vm_sub;
|
||||
IDisposable _settings_sub, _volume_sub, _tick_sub, _fair_value_lines_sub, _vm_sub;
|
||||
ScrollViewer _scrollViewer;
|
||||
LadderSettings _settings;
|
||||
LadderVM _vm;
|
||||
@@ -77,6 +79,19 @@ namespace mbts.spark {
|
||||
ToolTip tooltip_view = new ToolTip();
|
||||
IDisposable _parameterized_order_popup;
|
||||
|
||||
static LadderGridHost() {
|
||||
var knobs = config.Configuration.get<bts.config.LadderKnobs>();
|
||||
_show_scrollbar = knobs.show_scrollbar;
|
||||
_lighten_market_cells = knobs.lighten_market_cells;
|
||||
// For market cell backgrounds, 0 means null. Note that the full
|
||||
// range of colors can still be expressed, as zero is merely one of
|
||||
// 2^24 possible representations of 'transparent.'
|
||||
if (knobs.bid_market_cell_background != 0)
|
||||
_bid_market_cell_background = knobs.bid_market_cell_background.argb_color();
|
||||
if (knobs.ask_market_cell_background != 0)
|
||||
_ask_market_cell_background = knobs.ask_market_cell_background.argb_color();
|
||||
}
|
||||
|
||||
public LadderGridHost() {
|
||||
AllowDrop = true;
|
||||
UseLayoutRounding = true;
|
||||
@@ -638,7 +653,9 @@ namespace mbts.spark {
|
||||
if (_price_list != null) {
|
||||
switch (column.column_type) {
|
||||
case ColumnType.Order: _ordershost.set_col_width(column.settings.width); break;
|
||||
case ColumnType.Bid: render_market_col(_bids); break;
|
||||
case ColumnType.Bid:
|
||||
render_market_col(_bids, _bid_market_cell_background);
|
||||
break;
|
||||
case ColumnType.Price:
|
||||
if (_settings.net_change != LadderSettings.NetChangeTerms.None) {
|
||||
LadderRender.render_prices(
|
||||
@@ -663,7 +680,9 @@ namespace mbts.spark {
|
||||
_settings.price_display_format);
|
||||
}
|
||||
break;
|
||||
case ColumnType.Ask: render_market_col(_asks); break;
|
||||
case ColumnType.Ask:
|
||||
render_market_col(_asks, _ask_market_cell_background);
|
||||
break;
|
||||
case ColumnType.Volume:
|
||||
_volume_container.mark_dirty();
|
||||
_refresh_volume_at_price();
|
||||
@@ -675,9 +694,9 @@ namespace mbts.spark {
|
||||
if (_mkt_break_lines.high_render_index.HasValue)
|
||||
_render_session_line(_session_high_vis, _mkt_break_lines.high_render_index.Value, _settings.session_high_line.color);
|
||||
}
|
||||
void render_market_col(NativePriceSize[] depth) {
|
||||
void render_market_col(NativePriceSize[] depth, Color? market_cell_background) {
|
||||
var mid = LadderRender.index_of(_price_list, _last_origin_price, _price_comparer);
|
||||
LadderRender.render_sizes(column.visual_tup.visual, column.visual_tup.glyph_context, mid, _price_list, depth, _settings.row_height, _spec, column.settings, _fmt_mkt_depth_item, _lighten_market_cells);
|
||||
LadderRender.render_sizes(column.visual_tup.visual, column.visual_tup.glyph_context, mid, _price_list, depth, _settings.row_height, _spec, column.settings, _fmt_mkt_depth_item, _lighten_market_cells, market_cell_background);
|
||||
}
|
||||
}
|
||||
_apply_column_visual_offset();
|
||||
@@ -813,6 +832,7 @@ namespace mbts.spark {
|
||||
_refresh_bid_mkt_break();
|
||||
_refresh_ask_mkt_break();
|
||||
_refresh_mid_mkt_break();
|
||||
_refresh_fair_value_lines(true);
|
||||
}
|
||||
|
||||
void _on_vm_disposed(bool obj) =>
|
||||
@@ -822,6 +842,7 @@ namespace mbts.spark {
|
||||
Disposable.dispose(ref _settings_sub);
|
||||
Disposable.dispose(ref _volume_sub);
|
||||
Disposable.dispose(ref _tick_sub);
|
||||
Disposable.dispose(ref _fair_value_lines_sub);
|
||||
if (_vm != null)
|
||||
_vm.OnDisposed -= _on_vm_disposed;
|
||||
}
|
||||
@@ -878,6 +899,7 @@ namespace mbts.spark {
|
||||
_refresh_bid_mkt_break();
|
||||
_refresh_ask_mkt_break();
|
||||
_refresh_mid_mkt_break();
|
||||
_refresh_fair_value_lines(true);
|
||||
_refresh_session_low_line();
|
||||
_refresh_session_high_line();
|
||||
_refresh_session_range();
|
||||
@@ -890,6 +912,7 @@ namespace mbts.spark {
|
||||
_refresh_ask_mkt_break();
|
||||
if (_mkt_break_lines.mid_dirty)
|
||||
_refresh_mid_mkt_break();
|
||||
_refresh_fair_value_lines(false);
|
||||
if (_mkt_break_lines.session_low_dirty)
|
||||
_refresh_session_low_line();
|
||||
if (_mkt_break_lines.session_high_dirty)
|
||||
@@ -943,6 +966,14 @@ namespace mbts.spark {
|
||||
_mkt_break_lines.mid,
|
||||
_settings.mid_break_line.color);
|
||||
|
||||
void _refresh_fair_value_lines(bool force) {
|
||||
foreach (var fvl in _mkt_break_lines.fair_value_line_views) {
|
||||
if (force || fvl.is_dirty) {
|
||||
_render_mkt_break(fvl.vis, fvl.price_view, fvl.color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _refresh_session_low_line() {
|
||||
if (_settings.session_low_line.show && _mkt_break_lines.low_render_index.HasValue)
|
||||
_render_session_line(_session_low_vis, _mkt_break_lines.low_render_index.Value, _settings.session_low_line.color);
|
||||
@@ -969,8 +1000,8 @@ namespace mbts.spark {
|
||||
void _refresh_sizes() {
|
||||
Log.assert_d(_price_list != null);
|
||||
int origin_index = LadderRender.index_of(_price_list, _mkt_break_lines.origin, _price_comparer);
|
||||
LadderRender.render_sizes(_bid_vis_tup.visual, _bid_vis_tup.glyph_context, origin_index, _price_list, _bids, _settings.row_height, _spec, _settings.bid_column, _fmt_mkt_depth_item, _lighten_market_cells);
|
||||
LadderRender.render_sizes(_ask_vis_tup.visual, _ask_vis_tup.glyph_context, origin_index, _price_list, _asks, _settings.row_height, _spec, _settings.ask_column, _fmt_mkt_depth_item, _lighten_market_cells);
|
||||
LadderRender.render_sizes(_bid_vis_tup.visual, _bid_vis_tup.glyph_context, origin_index, _price_list, _bids, _settings.row_height, _spec, _settings.bid_column, _fmt_mkt_depth_item, _lighten_market_cells, _bid_market_cell_background);
|
||||
LadderRender.render_sizes(_ask_vis_tup.visual, _ask_vis_tup.glyph_context, origin_index, _price_list, _asks, _settings.row_height, _spec, _settings.ask_column, _fmt_mkt_depth_item, _lighten_market_cells, _ask_market_cell_background);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1114,6 +1145,7 @@ namespace mbts.spark {
|
||||
_refresh_bid_mkt_break();
|
||||
_refresh_ask_mkt_break();
|
||||
_refresh_mid_mkt_break();
|
||||
_refresh_fair_value_lines(true);
|
||||
_refresh_session_low_line();
|
||||
_refresh_session_high_line();
|
||||
_refresh_session_range();
|
||||
@@ -1127,39 +1159,24 @@ namespace mbts.spark {
|
||||
prices != null && prices.Length > 0 ? prices[0].price : double.NaN;
|
||||
|
||||
double _get_bid_market_break() {
|
||||
var raw_bid_break = _get_bid_market_break_raw();
|
||||
return _normalize_price(raw_bid_break);
|
||||
double best_bid = _get_top_price(_bids);
|
||||
double best_ask = _get_top_price(_asks);
|
||||
return LadderPriceLineViewAdapter.bid_line(best_bid, best_ask, _vm.settlement, _spec);
|
||||
}
|
||||
|
||||
double _normalize_price(double price) =>
|
||||
TickUtils.normalize_price(_spec, price);
|
||||
|
||||
double _get_bid_market_break_raw() {
|
||||
double best_bid = _get_top_price(_bids);
|
||||
double best_ask = _get_top_price(_asks);
|
||||
return double.IsNaN(best_bid) ?
|
||||
double.IsNaN(best_ask) ? _vm.settlement : _spec.tickdown(best_ask) :
|
||||
best_bid;
|
||||
}
|
||||
|
||||
double _get_ask_market_break() {
|
||||
var raw_ask_break = _get_ask_market_break_raw();
|
||||
return _normalize_price(raw_ask_break);
|
||||
}
|
||||
double _get_ask_market_break_raw() {
|
||||
double best_bid = _get_top_price(_bids);
|
||||
double best_ask = _get_top_price(_asks);
|
||||
return double.IsNaN(best_ask) ?
|
||||
double.IsNaN(best_bid) ? _vm.settlement : best_bid :
|
||||
_spec.tickdown(best_ask);
|
||||
return LadderPriceLineViewAdapter.ask_line(best_bid, best_ask, _vm.settlement, _spec);
|
||||
}
|
||||
|
||||
double _get_mid_market_break() {
|
||||
double best_bid = _get_top_price(_bids);
|
||||
double best_ask = _get_top_price(_asks);
|
||||
return double.IsNaN(best_bid) ?
|
||||
double.IsNaN(best_ask) ? _vm.settlement : _spec.tickdown(best_ask) :
|
||||
double.IsNaN(best_ask) ? best_bid : TickUtils.mid_tick(_spec, best_bid, best_ask);
|
||||
return LadderPriceLineViewAdapter.mid_line(best_bid, best_ask, _vm.settlement, _spec);
|
||||
}
|
||||
|
||||
double _get_session_low() => _normalize_price(_get_session_low_raw());
|
||||
@@ -1210,8 +1227,22 @@ namespace mbts.spark {
|
||||
if (prev_row_height != _settings.row_height)
|
||||
_reset_height();
|
||||
_price_dirty = _settings.price_column.show;
|
||||
Disposable.dispose(ref _fair_value_lines_sub);
|
||||
_mkt_break_lines.fair_value_line_views.Clear();
|
||||
// Clear and re-add the columns to the viewer to ensure offset/visibility is correct
|
||||
_visualHost.Clear();
|
||||
if (LadderSettings.mimic_tt) {
|
||||
// The session_range_vis sits beneath the grid backgrounds (on the
|
||||
// z-axis) to avoid obfuscating the font color (dj wants it to be
|
||||
// pure white). Historically, it sat atop the price column, with a
|
||||
// low opacity to slightly darken the range of prices inside of the
|
||||
// session range (i.e., the price-band of the day's trades). In
|
||||
// conjuction with this change, the price column's background
|
||||
// opacity is made slightly less than 1 (in the default settings),
|
||||
// while the font color remains fully opaque, so this layer will
|
||||
// darken the background without affecting the font color.
|
||||
_visualHost.AddVisualChild(_session_range_vis);
|
||||
}
|
||||
// Renders the grid lines and column backgrounds
|
||||
_visualHost.AddVisualChild(_gridvis);
|
||||
// Orders column
|
||||
@@ -1240,9 +1271,19 @@ namespace mbts.spark {
|
||||
_visualHost.AddVisualChild(_mid_mkt_break_vis);
|
||||
_visualHost.AddVisualChild(_ask_mkt_break_vis);
|
||||
_visualHost.AddVisualChild(_bid_mkt_break_vis);
|
||||
_fair_value_lines_sub = ui.utility.ObservableAutoWrapper.connect(
|
||||
_vm.fair_value_lines,
|
||||
_mkt_break_lines.fair_value_line_views,
|
||||
vm => {
|
||||
var with_vis = new FairValueLineWithVis(vm);
|
||||
_visualHost.AddVisualChild(with_vis.vis);
|
||||
return with_vis;
|
||||
},
|
||||
with_vis => _visualHost.RemoveVisualChild(with_vis.vis));
|
||||
_visualHost.AddVisualChild(_session_low_vis);
|
||||
_visualHost.AddVisualChild(_session_high_vis);
|
||||
_visualHost.AddVisualChild(_session_range_vis);
|
||||
if (!LadderSettings.mimic_tt)
|
||||
_visualHost.AddVisualChild(_session_range_vis);
|
||||
_render_grid_background();
|
||||
_init_tactile_adorner();
|
||||
// this effectively sets the background of the "Last" column
|
||||
@@ -1328,6 +1369,24 @@ namespace mbts.spark {
|
||||
!(x == y);
|
||||
}
|
||||
|
||||
class FairValueLineWithVis {
|
||||
readonly FairValueLineVM _vm;
|
||||
double _price_view = double.NaN;
|
||||
|
||||
public FairValueLineWithVis(FairValueLineVM vm) =>
|
||||
_vm = vm ?? throw new ArgumentNullException(nameof(vm));
|
||||
|
||||
public DrawingVisual vis { get; } = new DrawingVisual();
|
||||
public double price_view => _price_view;
|
||||
public uint color => _vm.settings.color;
|
||||
public bool is_dirty { get; private set; }
|
||||
|
||||
public void refresh(bool update_frozen) {
|
||||
_vm.refresh(update_frozen);
|
||||
is_dirty = ConvertUtils.update_value_type(ref _price_view, _vm.price_view);
|
||||
}
|
||||
}
|
||||
|
||||
// This class represents interesting price points as they should be rendered on the LadderGridHost
|
||||
// Note: The values contained here do NOT necessarily represent true data, as they will be NaN/null if their respective visual is hidden in LadderSettings
|
||||
class MarketBreakLines {
|
||||
@@ -1390,6 +1449,9 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<FairValueLineWithVis> fair_value_line_views { get; } =
|
||||
new ObservableCollection<FairValueLineWithVis>();
|
||||
|
||||
int _get_session_range_size() =>
|
||||
_owner._spec.tickdiff(_session_high, _session_low) ?? 0;
|
||||
|
||||
@@ -1408,6 +1470,9 @@ namespace mbts.spark {
|
||||
mid_dirty = ConvertUtils.update_value_type(ref _mid, _settings.mid_break_line.show ? _owner._get_mid_market_break() : double.NaN);
|
||||
session_low_dirty = ConvertUtils.update_value_type(ref _session_low, (_settings.session_low_line.show || _settings.session_range_fill.show) ? _owner._get_session_low() : double.NaN);
|
||||
session_high_dirty = ConvertUtils.update_value_type(ref _session_high, (_settings.session_high_line.show || _settings.session_range_fill.show) ? _owner._get_session_high() : double.NaN);
|
||||
foreach (var fvlv in fair_value_line_views) {
|
||||
fvlv.refresh(update_frozen);
|
||||
}
|
||||
if (session_low_dirty)
|
||||
_low_index = null;
|
||||
if (session_high_dirty)
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
using bts.api;
|
||||
|
||||
namespace mbts.spark {
|
||||
class LadderPriceLineViewAdapter {
|
||||
public static double bid_line(
|
||||
double bid, double ask, double settlement, ContractSpecificationImmutable? spec) {
|
||||
return TickUtils.normalize_price(spec, impl());
|
||||
double impl() {
|
||||
if (!double.IsNaN(bid)) {
|
||||
return bid;
|
||||
}
|
||||
if (!double.IsNaN(ask)) {
|
||||
return _try_tick_down(spec, ask);
|
||||
}
|
||||
return settlement;
|
||||
}
|
||||
}
|
||||
|
||||
public static double ask_line(
|
||||
double bid, double ask, double settlement, ContractSpecificationImmutable? spec) {
|
||||
return TickUtils.normalize_price(spec, impl());
|
||||
double impl() {
|
||||
if (!double.IsNaN(ask)) {
|
||||
return _try_tick_down(spec, ask);
|
||||
}
|
||||
if (!double.IsNaN(bid)) {
|
||||
return bid;
|
||||
}
|
||||
return settlement;
|
||||
}
|
||||
}
|
||||
|
||||
public static double mid_line(
|
||||
double bid, double ask, double settlement, ContractSpecificationImmutable? spec) {
|
||||
return TickUtils.normalize_price(spec, impl());
|
||||
double impl() {
|
||||
if (double.IsNaN(bid)) {
|
||||
if (double.IsNaN(ask)) {
|
||||
return settlement;
|
||||
}
|
||||
return _try_tick_down(spec, ask);
|
||||
}
|
||||
if (double.IsNaN(ask)) {
|
||||
return bid;
|
||||
}
|
||||
if (spec.HasValue) {
|
||||
return TickUtils.mid_tick(spec.Value, bid, ask);
|
||||
}
|
||||
return bid;
|
||||
}
|
||||
}
|
||||
|
||||
static double _try_tick_down(ContractSpecificationImmutable? spec, double value) {
|
||||
if (spec.HasValue) {
|
||||
return spec.Value.tickdown(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,9 @@ namespace mbts.spark {
|
||||
static class LadderRender {
|
||||
// Note: the orders-column has a separate "row_padding" value: Badge.DefaultMargin
|
||||
// (see how it is incorporated in measure_row_height() below)
|
||||
public static readonly Thickness row_padding = new Thickness(6);
|
||||
public static Thickness row_padding => LadderSettings.mimic_tt ?
|
||||
new Thickness(4, 2, 4, 2) : new Thickness(6);
|
||||
|
||||
const string tick_separator_period = ".";
|
||||
const string tick_separator_dash = "-";
|
||||
const int GRID_LINE_HEIGHT = 1;
|
||||
@@ -59,11 +61,20 @@ namespace mbts.spark {
|
||||
public static int index_of(double[] prices, double price, IComparer<double> comparer) =>
|
||||
Array.BinarySearch(prices, price, comparer);
|
||||
|
||||
public static GlyphRun format_text(string text, int row, double row_height, LadderColumnSettings settings, GlyphContext glyph_context, LadderSettings.PriceDisplayFormat price_display_format = LadderSettings.PriceDisplayFormat.Default) =>
|
||||
public static GlyphRun format_text(
|
||||
string text,
|
||||
int row,
|
||||
double row_height,
|
||||
LadderColumnSettings settings,
|
||||
GlyphContext glyph_context,
|
||||
LadderSettings.PriceDisplayFormat price_display_format = LadderSettings.PriceDisplayFormat.Default) =>
|
||||
glyph_context.get_glyph_run(
|
||||
// long term there is probably a better way to get rid of the separator, such as in the TickExtensions._format_tick
|
||||
price_display_format == LadderSettings.PriceDisplayFormat.Integer ? text.Replace(tick_separator_period, string.Empty).Replace(tick_separator_dash, string.Empty) : text,
|
||||
settings.font_size, settings.width, row_height, HorizontalAlignment.Center, 0, VerticalAlignment.Center, row * row_height, true);
|
||||
price_display_format == LadderSettings.PriceDisplayFormat.Integer ?
|
||||
text.Replace(tick_separator_period, string.Empty).Replace(tick_separator_dash, string.Empty) :
|
||||
text,
|
||||
settings.font_size, settings.width, row_height, HorizontalAlignment.Right,
|
||||
-4, VerticalAlignment.Center, row * row_height, true);
|
||||
|
||||
public static double[] gen_prices(double mid, int row_count, ContractSpecificationImmutable spec) {
|
||||
// require odd number
|
||||
@@ -150,8 +161,7 @@ namespace mbts.spark {
|
||||
using (var dc = dv.RenderOpen()) {
|
||||
// draw column backgrounds
|
||||
foreach (var col in columns) {
|
||||
var background = col.settings.background.rgb_brush();
|
||||
background.Freeze();
|
||||
var background = col.settings.background.argb_brush();
|
||||
dc.DrawRectangle(background, null, new Rect(col.x_left, 0, col.settings.width, rowcount * row_height));
|
||||
}
|
||||
// draw grid lines
|
||||
@@ -172,10 +182,17 @@ namespace mbts.spark {
|
||||
ContractSpecificationImmutable spec,
|
||||
LadderColumnSettings settings,
|
||||
Func<NativePriceSize, string> fmt,
|
||||
bool lighten_market_cells) {
|
||||
bool lighten_market_cells,
|
||||
Color? market_cell_background) {
|
||||
//var background = new SolidColorBrush(settings.background.rgb_color());
|
||||
var mkt_background = lighten_market_cells ?
|
||||
settings.background.rgb_color().blend_with(Colors.White).to_brush() : null;
|
||||
Brush market_cell_background_brush;
|
||||
if (market_cell_background.HasValue) {
|
||||
market_cell_background_brush = new SolidColorBrush(market_cell_background.Value);
|
||||
} else if (lighten_market_cells) {
|
||||
market_cell_background_brush = settings.background.rgb_color().blend_with(Colors.White).to_brush();
|
||||
} else {
|
||||
market_cell_background_brush = null;
|
||||
}
|
||||
using (var dc = dv.RenderOpen())
|
||||
using (_draw_with_clip(dc, settings, row_height, prices.Length)) {
|
||||
//dc.DrawRectangle(background, null, new Rect(0, 0, settings.width, prices.Length * row_height));
|
||||
@@ -205,8 +222,8 @@ namespace mbts.spark {
|
||||
curr_index += tick_diff;
|
||||
curr_price = price;
|
||||
if (curr_index >= 0 && curr_index < prices.Length) {
|
||||
if (mkt_background != null)
|
||||
dc.DrawRectangle(mkt_background, null,
|
||||
if (market_cell_background_brush != null)
|
||||
dc.DrawRectangle(market_cell_background_brush, null,
|
||||
new Rect(0, curr_index * row_height + GRID_LINE_HEIGHT,
|
||||
settings.width, row_height - GRID_LINE_HEIGHT));
|
||||
var gr = format_text(fmt(rung), curr_index, row_height, settings, glyph_context);
|
||||
@@ -394,7 +411,7 @@ namespace mbts.spark {
|
||||
public static void render_session_range(DrawingVisual dv, uint color, LadderColumnSettings settings, int low_index, int high_index, double[] prices, double row_height) {
|
||||
using (var dc = dv.RenderOpen())
|
||||
using (_draw_with_clip(dc, settings, row_height, prices.Length))
|
||||
dc.DrawRectangle(new SolidColorBrush(color.rgb_color()) { Opacity = 0.2 }, null, new Rect(0, high_index * row_height, settings.width, (low_index - high_index) * row_height));
|
||||
dc.DrawRectangle(new SolidColorBrush(color.argb_color()), null, new Rect(0, high_index * row_height, settings.width, (low_index - high_index) * row_height));
|
||||
}
|
||||
|
||||
static GlyphRun[] _format_empty_prices(int row_count, double row_height, LadderColumnSettings settings, GlyphContext glyph_context) {
|
||||
|
||||
@@ -899,6 +899,9 @@
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<TabItem Header="Fair Value Lines" VerticalAlignment="Stretch">
|
||||
<usp:FairValueLineSettingsView HorizontalAlignment="Left" MaxHeight="300" DataContext="{Binding fair_value_line_settings_vm}"/>
|
||||
</TabItem>
|
||||
<!-- Market Price & Size Tab -->
|
||||
<TabItem Header="Market Price and Size Display">
|
||||
<Grid Margin="6" Grid.IsSharedSizeScope="True">
|
||||
|
||||
@@ -126,9 +126,12 @@ namespace mbts.spark {
|
||||
return Cursors.Arrow;
|
||||
switch (column.column_type) {
|
||||
case ColumnType.Bid:
|
||||
case ColumnType.Ask: return _can_send_orders ? Cursors.Hand : Cursors.No;
|
||||
default: return Cursors.Arrow;
|
||||
case ColumnType.Ask:
|
||||
if (!_can_send_orders)
|
||||
return Cursors.No;
|
||||
break;
|
||||
}
|
||||
return Cursors.Arrow;
|
||||
}
|
||||
|
||||
#region UI Event Handlers
|
||||
|
||||
@@ -141,7 +141,61 @@
|
||||
<Setter Property="Margin" Value="2,0,2,5"/>
|
||||
<Setter Property="Padding" Value="2"/>
|
||||
</Style>
|
||||
<Style x:Key="CancelAll" TargetType="Button" BasedOn="{StaticResource LadderMenuButton}">
|
||||
<Setter Property="Grid.Row" Value="2" />
|
||||
<Setter Property="Content">
|
||||
<Setter.Value>
|
||||
<TextBlock VerticalAlignment="Center">Cancel All</TextBlock>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border
|
||||
x:Name="Border"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
BorderBrush="{mbts:BTSColor UI.Button.normal_border}"
|
||||
Background="{mbts:BTSColor UI.Button.normal_background}"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
SnapsToDevicePixels="True">
|
||||
<ContentPresenter
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
RecognizesAccessKey="True"
|
||||
Name="button_content"
|
||||
/>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="Border" Property="Background" Value="{mbts:BTSColor UI.Button.mouseover_background}" />
|
||||
<Setter TargetName="Border" Property="BorderBrush" Value="{mbts:BTSColor UI.Button.mouseover_border}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<Style x:Key="TT_CancelAll" TargetType="Button" BasedOn="{StaticResource CancelAll}">
|
||||
<Setter Property="Grid.Row" Value="0"/>
|
||||
</Style>
|
||||
<Style x:Key="TT_CancelBuys" TargetType="Button" BasedOn="{StaticResource CancelAll}">
|
||||
<Setter Property="Grid.Row" Value="1" />
|
||||
<Setter Property="Content">
|
||||
<Setter.Value>
|
||||
<TextBlock VerticalAlignment="Center">Cancel Buys</TextBlock>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<Style x:Key="TT_CancelSells" TargetType="Button" BasedOn="{StaticResource CancelAll}">
|
||||
<Setter Property="Grid.Row" Value="2" />
|
||||
<Setter Property="Content">
|
||||
<Setter.Value>
|
||||
<TextBlock VerticalAlignment="Center">Cancel Sells</TextBlock>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<Style x:Key="CancelBuys" TargetType="Button" BasedOn="{StaticResource LadderMenuButton}">
|
||||
<Setter Property="Grid.Row" Value="0" />
|
||||
<Setter Property="Content">
|
||||
<Setter.Value>
|
||||
<TextBlock VerticalAlignment="Center" Foreground="{Binding bid_foreground}">Cancel Buys</TextBlock>
|
||||
@@ -177,6 +231,7 @@
|
||||
</Style>
|
||||
<Style x:Key="CancelSells" TargetType="Button" BasedOn="{StaticResource LadderMenuButton}">
|
||||
<Setter Property="Background" Value="{mbts:BTSColor MarketData.ask}" />
|
||||
<Setter Property="Grid.Row" Value="1" />
|
||||
<Setter Property="Content">
|
||||
<Setter.Value>
|
||||
<TextBlock VerticalAlignment="Center" Foreground="{Binding ask_foreground}">Cancel Sells</TextBlock>
|
||||
@@ -210,39 +265,6 @@
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<Style x:Key="CancelAll" TargetType="Button" BasedOn="{StaticResource LadderMenuButton}">
|
||||
<Setter Property="Content">
|
||||
<Setter.Value>
|
||||
<TextBlock VerticalAlignment="Center">Cancel All</TextBlock>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border
|
||||
x:Name="Border"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
BorderBrush="{mbts:BTSColor UI.Button.normal_border}"
|
||||
Background="{mbts:BTSColor UI.Button.normal_background}"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
SnapsToDevicePixels="True">
|
||||
<ContentPresenter
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
RecognizesAccessKey="True"
|
||||
Name="button_content"
|
||||
/>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="Border" Property="Background" Value="{mbts:BTSColor UI.Button.mouseover_background}" />
|
||||
<Setter TargetName="Border" Property="BorderBrush" Value="{mbts:BTSColor UI.Button.mouseover_border}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<Style x:Key="SettingsButton" TargetType="Button" BasedOn="{StaticResource LadderMenuButton}">
|
||||
<Setter Property="Content">
|
||||
<Setter.Value>
|
||||
@@ -372,7 +394,7 @@
|
||||
<Border
|
||||
Grid.Row="0"
|
||||
Background="{Binding day_change_background_color, Converter={x:Static converters:ColorToBrushConverter.Instance}}"
|
||||
Visibility="{Binding show_day_change, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
Visibility="{Binding day_change_style.show, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
ToolTip="Day Change"
|
||||
Style="{StaticResource LeftPanelPricePointBorder}"
|
||||
>
|
||||
@@ -403,7 +425,7 @@
|
||||
<Border
|
||||
Grid.Row="1"
|
||||
Background="{Binding volume_style.background_color, Converter={x:Static converters:ColorToBrushConverter.Instance}}"
|
||||
Visibility="{Binding show_volume, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
Visibility="{Binding volume_style.show, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
ToolTip="Volume"
|
||||
Style="{StaticResource LeftPanelPricePointBorder}"
|
||||
>
|
||||
@@ -438,7 +460,7 @@
|
||||
<Border
|
||||
Grid.Row="2"
|
||||
Background="{Binding session_high_style.background_color, Converter={x:Static converters:ColorToBrushConverter.Instance}}"
|
||||
Visibility="{Binding show_session_high, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
Visibility="{Binding session_high_style.show, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
ToolTip="Session High"
|
||||
Style="{StaticResource LeftPanelPricePointBorder}"
|
||||
>
|
||||
@@ -467,7 +489,7 @@
|
||||
<Border
|
||||
Grid.Row="3"
|
||||
Background="{Binding session_low_style.background_color, Converter={x:Static converters:ColorToBrushConverter.Instance}}"
|
||||
Visibility="{Binding show_session_low, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
Visibility="{Binding session_low_style.show, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
ToolTip="Session Low"
|
||||
Style="{StaticResource LeftPanelPricePointBorder}"
|
||||
>
|
||||
@@ -496,7 +518,7 @@
|
||||
<Border
|
||||
Grid.Row="4"
|
||||
Background="{Binding open_style.background_color, Converter={x:Static converters:ColorToBrushConverter.Instance}}"
|
||||
Visibility="{Binding show_open, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
Visibility="{Binding open_style.show, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
ToolTip="Open"
|
||||
Style="{StaticResource LeftPanelPricePointBorder}"
|
||||
>
|
||||
@@ -525,7 +547,7 @@
|
||||
<Border
|
||||
Grid.Row="5"
|
||||
Background="{Binding settlement_style.background_color, Converter={x:Static converters:ColorToBrushConverter.Instance}}"
|
||||
Visibility="{Binding show_settlement, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
Visibility="{Binding settlement_style.show, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
ToolTip="Settlement"
|
||||
Style="{StaticResource LeftPanelPricePointBorder}"
|
||||
>
|
||||
@@ -669,15 +691,20 @@
|
||||
</ItemsPanelTemplate>
|
||||
</uag:AlgoTemplateFavoriteButtonsView.ItemsPanel>
|
||||
</uag:AlgoTemplateFavoriteButtonsView>
|
||||
<StackPanel Margin="0,17,0,0" VerticalAlignment="Top">
|
||||
<Grid Margin="0,17,0,0" VerticalAlignment="Top">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<!-- Cancel Buttons -->
|
||||
<Button Command="{Binding cancel_command}" CommandParameter="Bids" Style="{StaticResource CancelBuys}"
|
||||
<Button Command="{Binding cancel_command}" CommandParameter="Bids" Style="{StaticResource {x:Static spark:LadderView.CancelBuysButtonStyleKey}}"
|
||||
Visibility="{Binding show_cancel_buys, Converter={StaticResource BooleanToVisibilityConverter}}"/>
|
||||
<Button Command="{Binding cancel_command}" CommandParameter="Asks" Style="{StaticResource CancelSells}"
|
||||
<Button Command="{Binding cancel_command}" CommandParameter="Asks" Style="{StaticResource {x:Static spark:LadderView.CancelSellsButtonStyleKey}}"
|
||||
Visibility="{Binding show_cancel_sells, Converter={StaticResource BooleanToVisibilityConverter}}"/>
|
||||
<Button Command="{Binding cancel_command}" CommandParameter="All" Style="{StaticResource CancelAll}"
|
||||
<Button Command="{Binding cancel_command}" CommandParameter="All" Style="{StaticResource {x:Static spark:LadderView.CancelAllButtonStyleKey}}"
|
||||
Visibility="{Binding show_cancel_all, Converter={StaticResource BooleanToVisibilityConverter}}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<StackPanel Grid.Row="1" Margin="0,17,0,0" VerticalAlignment="Bottom">
|
||||
<!-- Settings Button -->
|
||||
<Button Command="{Binding settings_command}" Style="{StaticResource SettingsButton}"/>
|
||||
|
||||
@@ -22,6 +22,22 @@ namespace mbts.spark {
|
||||
MaxLeftPanelWidth = 150,
|
||||
MinZoomFactor = 0.5,
|
||||
MaxZoomFactor = 1.5;
|
||||
|
||||
static LadderView() {
|
||||
var knobs = config.Configuration.get<bts.config.LadderKnobs>();
|
||||
MimicTT = knobs.mimic_tt;
|
||||
}
|
||||
|
||||
public static bool MimicTT { get; }
|
||||
|
||||
public static string CancelBuysButtonStyleKey =>
|
||||
MimicTT ? "TT_CancelBuys" : "CancelBuys";
|
||||
|
||||
public static string CancelSellsButtonStyleKey =>
|
||||
MimicTT ? "TT_CancelSells" : "CancelSells";
|
||||
|
||||
public static string CancelAllButtonStyleKey =>
|
||||
MimicTT ? "TT_CancelAll" : "CancelAll";
|
||||
|
||||
public static IMultiValueConverter PositionToolTipConverter =
|
||||
ValueConverter.create<AccountTuple?, bool, bool, bool, string>((account, show_day_pos, show_raw_day_pos, show_total_pos) => {
|
||||
@@ -253,4 +269,4 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using bts.api.orderman;
|
||||
using bts.collections;
|
||||
using bts.spark;
|
||||
using bts.utils;
|
||||
using bts.utils.csv;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using System;
|
||||
@@ -11,6 +12,7 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Reactive.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Linq;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using Columns = mbts.spark.OrderBookGridView.ColumnKeys;
|
||||
@@ -60,6 +62,35 @@ namespace mbts.spark {
|
||||
public event Action<(OrderSecurityRootPair oldval, OrderSecurityRootPair newval)> updated;
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public static System.Collections.Specialized.OrderedDictionary csv_ordered_properties =>
|
||||
CsvHelper.create_ordering_maintainer(
|
||||
typeof(OrderBookRowVM),
|
||||
new string[] {
|
||||
nameof(security_text),
|
||||
nameof(symbol),
|
||||
nameof(time_created),
|
||||
nameof(last_change),
|
||||
nameof(user),
|
||||
nameof(account),
|
||||
nameof(exchange),
|
||||
nameof(time_in_force),
|
||||
nameof(order_type),
|
||||
nameof(root_algo_display_name),
|
||||
nameof(order_sub_type),
|
||||
nameof(side),
|
||||
nameof(quantity),
|
||||
nameof(filled_quantity),
|
||||
nameof(price),
|
||||
nameof(avg_price),
|
||||
nameof(last_price),
|
||||
nameof(piq),
|
||||
nameof(status),
|
||||
// last message (could contains commas, so skipping)
|
||||
nameof(security_key),
|
||||
nameof(order_key),
|
||||
nameof(parent_order_key),
|
||||
});
|
||||
|
||||
// Core
|
||||
public OrderSecurityRootPair order_tuple { get; private set; }
|
||||
public OrderRecordImmutable order => order_tuple.order.order;
|
||||
|
||||
@@ -6,6 +6,7 @@ using bts.shell.fills;
|
||||
using bts.shell.orderbook;
|
||||
using bts.spark;
|
||||
using bts.view;
|
||||
using bts.utils.csv;
|
||||
using mbts.persist;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui;
|
||||
@@ -231,6 +232,7 @@ namespace mbts.spark {
|
||||
toggle_collapse_all_command,
|
||||
toggle_expand_all_command,
|
||||
show_grid_settings_command,
|
||||
new SparkCommandCommand("Export to csv", Icons.Export, FileDialogCommand.export_csv(() => _vm.rows.ToCsv(OrderBookRowVM.csv_ordered_properties), "OrderBook")),
|
||||
// hidden cmds (i.e., keyboard shortcuts at window level)
|
||||
hidden_cmd(new SparkCommandCommand(OrderBookView.CommandDescriptions.ModifyOrders, null, _vm.modify_selected_orders_cmd, OrderBookView.KeyboardShortcuts.ModifyOrders)),
|
||||
hidden_cmd(new SparkCommandCommand(OrderBookView.CommandDescriptions.RevertOrders, null, _vm.revert_selected_orders_cmd, OrderBookView.KeyboardShortcuts.RevertOrders)),
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace mbts.ui {
|
||||
|
||||
public static BTSColor session_low { get; } = new BTSColor(89, 89, 107);
|
||||
public static BTSColor session_high { get; } = new BTSColor(35, 155, 0);
|
||||
public static BTSColor session_range_fill { get; } = Colors.Black;
|
||||
public static BTSColor session_range_fill { get; } = Color.FromArgb(26, 0, 0, 0);
|
||||
|
||||
// Alerts
|
||||
[DisplayInfo(name = "Trade Alert")]
|
||||
@@ -731,4 +731,4 @@ namespace mbts.ui {
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,12 @@ using System.Windows.Data;
|
||||
namespace mbts.ui.converters {
|
||||
[ValueConversion(typeof(SecurityTuple), typeof(string))]
|
||||
public class SecurityDisplayTextConverter : IValueConverter {
|
||||
public string TextForNull { get; set; } = "Unknown";
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value is Security s)
|
||||
return SecurityFormatter.format(s);
|
||||
return value?.ToString() ?? "Unknown";
|
||||
return value?.ToString() ?? TextForNull;
|
||||
}
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -64,6 +64,25 @@ namespace mbts.ui {
|
||||
}
|
||||
}, can_execute == null ? null : new Func<object, bool>(_ => can_execute()));
|
||||
|
||||
public static IDialogCommand export_csv(
|
||||
Func<string> get_file_content,
|
||||
string source_window_name) =>
|
||||
new AnonymousFileDialogCommand<object>(_ =>
|
||||
_create_save_file_dialog(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
|
||||
$"BTS_Spark_{source_window_name}_{DateTime.Now.ToString("yyyyMMdd_HHmm")}.csv",
|
||||
new[] { ("CSV (comma delimited)", new string[] { "csv" }) }
|
||||
),
|
||||
(_, file) => {
|
||||
try {
|
||||
File.WriteAllText(file, get_file_content.Invoke());
|
||||
} catch (Exception ex) {
|
||||
BTSMessageBox.Show($"Error exporting data to csv: {ex}.", "CSV Export Error", BTSMessageBoxButtons.OK, System.Windows.MessageBoxImage.Error, true, false, true);
|
||||
}
|
||||
},
|
||||
// we are always able to perform an export, even when no rows (it will just be a header)
|
||||
(_) => true);
|
||||
|
||||
static TDialog _create_file_dialog<TDialog>(string initial_dir = null, IReadOnlyList<(string name, string[] extensions)> filter_items = null) where TDialog : FileDialog, new() {
|
||||
var rv = new TDialog();
|
||||
if (!string.IsNullOrEmpty(initial_dir))
|
||||
|
||||
@@ -97,6 +97,12 @@ namespace mbts.ui {
|
||||
return brush;
|
||||
}
|
||||
|
||||
public static Brush argb_brush(this uint color) {
|
||||
var brush = new SolidColorBrush(argb_color(color));
|
||||
brush.Freeze();
|
||||
return brush;
|
||||
}
|
||||
|
||||
public static SolidColorBrush rgb_solid_brush(this uint color) =>
|
||||
new SolidColorBrush(rgb_color(color));
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
<cv:CellPathConverter x:Key="CellPathConverter" />
|
||||
<cv:CellKeyConverter x:Key="CellKeyConverter" />
|
||||
<cv:SecurityDisplayTextConverter x:Key="SecurityTextConverter"/>
|
||||
<cv:SecurityDisplayTextConverter x:Key="SelectedSecurityTextConverter" TextForNull="(None)"/>
|
||||
<cv:NumericSignBrushConverter x:Key="NumericSignBrushConverter" />
|
||||
<cv:TickDisplayTextConverter x:Key="TickTextConverter" />
|
||||
<cv:DoubleTextConverter x:Key="DoubleTextConverter" />
|
||||
|
||||
@@ -23,11 +23,13 @@ namespace mbts.ui.controls {
|
||||
readonly PropertyUpdateGate _selection_sync_gate = new PropertyUpdateGate();
|
||||
|
||||
IReadOnlyDictionary<uint, SecurityMD> _cached_security_map = DictionaryHelper.empty<uint, SecurityMD>();
|
||||
// The security key of the most recently changed property among
|
||||
// SelectedSecurity, SelectedSecurityMD, and SelectedSecurityKey
|
||||
uint? _last_selected_sec_key = null;
|
||||
ContractPickerPopupController _controller;
|
||||
bool _allow_empty, _is_lazy;
|
||||
|
||||
public ContractPickerPopup() {
|
||||
SetCurrentValue(SecurityMapProperty, new Dictionary<uint, SecurityMD>(0));
|
||||
var sec_map_source = Observable.Create<IReadOnlyDictionary<uint, SecurityMD>>(o => {
|
||||
try_notify();
|
||||
_security_map_changed += on_security_map_changed;
|
||||
@@ -50,6 +52,9 @@ namespace mbts.ui.controls {
|
||||
}
|
||||
});
|
||||
_controller = new ContractPickerPopupController(this, new ContractPickerModel(sec_map_source, true, null));
|
||||
// This has to be set after _controller is initialized (because it causes a call to the IsEditMode getter,
|
||||
// which assumes _controller is non-null)
|
||||
SetCurrentValue(SecurityMapProperty, new Dictionary<uint, SecurityMD>(0));
|
||||
InitializeComponent();
|
||||
DataContextChanged += (s, e) => {
|
||||
// - unhooking from oldval must co-incide with hooking to newval.
|
||||
@@ -91,6 +96,8 @@ namespace mbts.ui.controls {
|
||||
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
||||
(o, v) => {
|
||||
o._cached_security_map = v;
|
||||
o._selection_sync_gate.try_update(() => o._sync_selection_props(
|
||||
o.SelectedSecurityMD, o.SelectedSecurity, o.SelectedSecurityKey, o._last_selected_sec_key));
|
||||
o._security_map_changed?.Invoke(v);
|
||||
},
|
||||
(o, v) => v ?? new Dictionary<uint, SecurityMD>());
|
||||
@@ -125,6 +132,7 @@ namespace mbts.ui.controls {
|
||||
}
|
||||
|
||||
void _sync_selection_props(SecurityMD? curr_sec_md, SecurityImmutable? curr_sec, uint? curr_sec_key, uint? target_sec_key) {
|
||||
_last_selected_sec_key = target_sec_key;
|
||||
if (curr_sec_key != target_sec_key) {
|
||||
SetCurrentValue(SelectedSecurityKeyProperty, target_sec_key);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace bts {
|
||||
Plugin,
|
||||
Sdk,
|
||||
Http,
|
||||
iLink3
|
||||
// Please keep this list in sync with logging.h/logging.cpp
|
||||
}
|
||||
|
||||
|
||||
@@ -245,6 +245,10 @@ namespace mbts.spark {
|
||||
return ticks.HasValue ? spec.tickup(0, ticks.Value) : price;
|
||||
}
|
||||
|
||||
public static double normalize_price(ContractSpecificationImmutable? spec, double price) {
|
||||
return spec.HasValue ? normalize_price(spec.Value, price) : price;
|
||||
}
|
||||
|
||||
public static uint fit_ticks_per_row_to_dollars(ContractSpecificationImmutable spec, uint ticks_per_row) =>
|
||||
_fit_ticks_per_row_to_dollars(spec, ticks_per_row) ?? 1;
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace bts.utils.csv {
|
||||
public static class CsvHelper {
|
||||
|
||||
public static string ToCsv<T>(this IEnumerable<T> items, OrderedDictionary properties = null) where T : class {
|
||||
var output = "";
|
||||
var delimiter = ",";
|
||||
if (properties == null) {
|
||||
properties = new OrderedDictionary();
|
||||
foreach (var pi in typeof(T).GetProperties()) {
|
||||
properties.Add(pi.Name, pi);
|
||||
}
|
||||
}
|
||||
|
||||
using (var sw = new StringWriter()) {
|
||||
var dict_values = properties.Values.OfType<PropertyInfo>();
|
||||
var header = dict_values.Select(n => n.Name).Aggregate((first, second) => first + delimiter + second);
|
||||
sw.WriteLine(header);
|
||||
foreach (var i in items) {
|
||||
var row = dict_values.Select(x => x.GetValue(i, null))
|
||||
.Select(x => x == null ? "null" : x.ToString())
|
||||
.Aggregate((first, second) => first + delimiter + second);
|
||||
sw.WriteLine(row);
|
||||
}
|
||||
output = sw.ToString();
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public static OrderedDictionary create_ordering_maintainer(Type t, string[] property_names_in_order) {
|
||||
OrderedDictionary od = new OrderedDictionary();
|
||||
var props = t.GetProperties();
|
||||
foreach (var n in property_names_in_order) {
|
||||
var query = props.Where(pi => pi.Name == n);
|
||||
if (query.Any()) {
|
||||
var property_info = query.First();
|
||||
if (!od.Contains(property_info)) {
|
||||
od.Add(n, property_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
return od;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
set(sources files/cert_secure_logon.txt;files/futures.coconut.xz;files/onixs_ice/ConnectivityConfiguration.APITest.xml;files/onixs_ice/ConnectivityConfiguration.APITest.xml.orig;files/onixs_ice/ConnectivityConfiguration.PerfTest.xml;files/onixs_ice/ConnectivityConfiguration.Production.xml;files/perf_trace/compiled.css;files/perf_trace/index.html;files/perf_trace/jquery-3.3.1.min.js;files/perf_trace/main.js;files/perf_trace/perf_log.sql;files/perf_trace/perf_trace_analysis.sql;files/perf_trace/plotly-latest.min.js)
|
||||
set(sources files/audit_ilink3.py;files/audit_upload.sh;files/audit_uploader.py;files/cert_secure_logon.txt;files/example.conf;files/futures.coconut.xz;files/onixs_ice/ConnectivityConfiguration.APITest.xml;files/onixs_ice/ConnectivityConfiguration.PerfTest.xml;files/onixs_ice/ConnectivityConfiguration.Production.xml;files/perf_trace/compiled.css;files/perf_trace/index.html;files/perf_trace/jquery-3.3.1.min.js;files/perf_trace/main.js;files/perf_trace/perf_log.sql;files/perf_trace/perf_trace_analysis.sql;files/perf_trace/plotly-latest.min.js)
|
||||
Executable
+211
@@ -0,0 +1,211 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import os
|
||||
import re
|
||||
import fileinput
|
||||
import sys
|
||||
import collections
|
||||
import csv
|
||||
import time, datetime
|
||||
import copy
|
||||
import itertools
|
||||
import argparse
|
||||
|
||||
# region fix record processing
|
||||
|
||||
valid_message_types = {
|
||||
'D': 'NEW ORDER',
|
||||
'G': 'MODIFY',
|
||||
'F': 'CANCEL',
|
||||
'8': 'EXECUTION',
|
||||
'i': 'MASS QUOTE',
|
||||
'R': 'QUOTE REQUEST',
|
||||
'b': 'QUOTE ACK',
|
||||
'Z': 'MASS QUOTE CANCEL',
|
||||
# 'c': 'SECURITY DEFINITION REQUEST',
|
||||
'3': 'SESSION LEVEL REJECT',
|
||||
'j': 'BUSINESS LEVEL REJECT',
|
||||
'9': 'CANCEL REJECT',
|
||||
'CA': 'ORDER MASS ACTION REQUEST',
|
||||
'BZ': 'ORDER MASS ACTION REPORT'
|
||||
}
|
||||
|
||||
def print_headers():
|
||||
# From https://www.theice.com/publicdocs/futures_us/exchange_notices/ICE_Advisory_0113_009.pdf
|
||||
line_to_write = ",11,37,60,55,55,167,202,201,54,38,210,40,44,99,440,439,9175,9195,9208,9139,115 (left),115 (right),116 (right),116 (left),144 (left),59"
|
||||
|
||||
with open (args.output_file, 'w') as the_file:
|
||||
the_file.write(line_to_write)
|
||||
the_file.write("\n")
|
||||
|
||||
line_to_write = "Active Date,Cl Ord ID,OrderID,Transact Time,Symbol,Symbol,SecurityType,Stk Prc,P/C,Side,OrderQty,Max Show,OrdType,\
|
||||
Price,StopPx,Clearing Account,Clearing Firm,Order State,AccountCode,CTI Code,Originator User ID,OnBehalfOfCompID,\
|
||||
OnBehalfOfCompID,On Behalf Of Sub ID,On Behalf Of Sub ID,On Behalf Of Location ID,Time In Force"
|
||||
|
||||
with open (args.output_file, 'a') as the_file:
|
||||
the_file.write(line_to_write)
|
||||
the_file.write("\n")
|
||||
|
||||
line_to_write = "Activity Date,Client Order ID,Original Order ID,Order Entry/Modification Time,Commodity,Contract Month,Future/Option Indicator,\
|
||||
Strike Price,,Put or Call,Buy/Sell Indicator,Quantity,Reserve Quantity,Order Type,Price,Stop Price,Account #,CM#,\
|
||||
Order Status,Clearing Account Code,CTI,ETS Login ID,Routing Member ID,Authorized Trader ID,Authorized Trdr ID,\
|
||||
Routing Trdr,Routing Grp,Time In Force"
|
||||
|
||||
with open (args.output_file, 'a') as the_file:
|
||||
the_file.write(line_to_write)
|
||||
the_file.write("\n")
|
||||
|
||||
def getter(field_name):
|
||||
def result(parsed_fix_record):
|
||||
if field_name in parsed_fix_record:
|
||||
return parsed_fix_record[field_name]
|
||||
else:
|
||||
return None
|
||||
return result
|
||||
|
||||
def parse_fix_line(line):
|
||||
ts = line[:21]
|
||||
fix_line = line[24:].split('\1')
|
||||
result = {}
|
||||
result['timestamp'] = ts
|
||||
for fix_field in fix_line:
|
||||
rx = r"(?P<tag>\d+)?=(?P<value>.*)"
|
||||
match = re.match(rx,fix_field)
|
||||
if match:
|
||||
result[match.group('tag')] = match.group('value')
|
||||
return result
|
||||
|
||||
def tagged_field(line,number):
|
||||
if number in line:
|
||||
return line[number]
|
||||
else:
|
||||
return ""
|
||||
|
||||
def formatted_tagged_field(line,number):
|
||||
if number in line:
|
||||
return line[number].lstrip("0")
|
||||
else:
|
||||
return ""
|
||||
|
||||
def lr_tagged_field(line,number):
|
||||
if number in line:
|
||||
return line[number].rsplit('|',1)
|
||||
else:
|
||||
return "",""
|
||||
|
||||
def lr_contract_month(line,number):
|
||||
try:
|
||||
ice_line="ICE_SECURITY_ID_TO_SYMBOL_MAPPING: " + line[number]
|
||||
with open('/sparkdata/data/md_dump.txt') as f:
|
||||
datafile = f.readlines()
|
||||
for data in datafile:
|
||||
if data.find(str(ice_line)) != -1:
|
||||
placeholder=data.find('> ')+1
|
||||
get_ending=data[placeholder:]
|
||||
get_ending=get_ending.strip()
|
||||
return get_ending.split(" ")
|
||||
except KeyError:
|
||||
print("Can not find key 55")
|
||||
return "",""
|
||||
|
||||
|
||||
def valid_file(f):
|
||||
if not os.path.exists(f):
|
||||
# Argparse uses the ArgumentTypeError to give a rejection message like:
|
||||
# error: argument input: x does not exist
|
||||
raise argparse.ArgumentTypeError("{0} does not exist".format(f))
|
||||
return f
|
||||
|
||||
def valid_date(s):
|
||||
try:
|
||||
return datetime.datetime.strptime(s, "%Y%m%d")
|
||||
except ValueError:
|
||||
raise argparse.ArgumentTypeError("Not a valid date: '{0}'.".format(s))
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("quickfix_log", help="the quickfix log[.gz] you wish to process", type=valid_file)
|
||||
parser.add_argument("output_file", help="the destination csv file you wish to write")
|
||||
parser.add_argument("-d", "--date", help="the date you wish to parse from the log, specified as YYYYmmdd",
|
||||
default=datetime.datetime.today().strftime("%Y%m%d"), type=valid_date)
|
||||
#quickfix_log="/home/pfisher/temp/audit/fix"
|
||||
#output_file="/home/pfisher/temp/audit/fix.csv"
|
||||
args = parser.parse_args()
|
||||
|
||||
# Note that the timedeltas specificed in trade_day_start and trade_day_end
|
||||
# are based on Chicago times; as such, this script should run on a machine
|
||||
# set to a Chicago timezone. A future impromovement would be to determine
|
||||
# the current machine's timezone and determine the appropriate offset
|
||||
# versus Chicago time, but for now we assume this will run on a Chicago
|
||||
# tz machine.
|
||||
input_as_datetime = args.date
|
||||
trade_day_start = input_as_datetime - datetime.timedelta(days=1) + datetime.timedelta(hours=17, minutes=30)
|
||||
trade_day_utc_start = time.gmtime((time.mktime(trade_day_start.timetuple())))
|
||||
trade_day_end = input_as_datetime + datetime.timedelta(hours=17)
|
||||
trade_day_utc_end = time.gmtime((time.mktime(trade_day_end.timetuple())))
|
||||
|
||||
#file_opener = open
|
||||
file_opener = None
|
||||
if args.quickfix_log.endswith(".gz"):
|
||||
import gzip
|
||||
file_opener = gzip.open
|
||||
else:
|
||||
file_opener = open
|
||||
|
||||
audit_entries = []
|
||||
line_number = 0
|
||||
print_headers()
|
||||
with file_opener(args.quickfix_log) as input_file:
|
||||
#with file_opener(quickfix_log) as input_file:
|
||||
for line in input_file:
|
||||
try:
|
||||
line_timestamp = time.strptime(line[:21], "%Y%m%d-%H:%M:%S.%f")
|
||||
except:
|
||||
continue
|
||||
if trade_day_utc_start <= line_timestamp <= trade_day_utc_end:
|
||||
parsed_fix_record = parse_fix_line(line)
|
||||
if parsed_fix_record['35'] in valid_message_types:
|
||||
line_number = line_number + 1
|
||||
# Static fields
|
||||
tt = datetime.datetime.strptime(line[:21], "%Y%m%d-%H:%M:%S.%f")
|
||||
transacttime = tt.strftime('%Y%m%d-%H:%M:%S.%f')
|
||||
activedate = time.strftime('%Y%m%d',time.strptime(line[:8], "%Y%m%d"))
|
||||
securitytype = "FUT"
|
||||
stkprc = ""
|
||||
putcall = ""
|
||||
#symbol = "HNG"
|
||||
#contractmonth = "U20"
|
||||
# No formatting fields
|
||||
ciorderid = tagged_field(parsed_fix_record, '11')
|
||||
orderid = tagged_field(parsed_fix_record,'37')
|
||||
side = tagged_field(parsed_fix_record,'54')
|
||||
orderquanity = tagged_field(parsed_fix_record,'38')
|
||||
maxshow = tagged_field(parsed_fix_record,'201')
|
||||
ordertype = tagged_field(parsed_fix_record,'40')
|
||||
stoppx = tagged_field(parsed_fix_record,'99')
|
||||
clearingaccount = tagged_field(parsed_fix_record,'440')
|
||||
clearingfirm = tagged_field(parsed_fix_record,'439')
|
||||
orderstate = tagged_field(parsed_fix_record,'9175')
|
||||
accountcode = tagged_field(parsed_fix_record,'9195')
|
||||
cticode = tagged_field(parsed_fix_record,'9208')
|
||||
originatoruserid = tagged_field(parsed_fix_record,'9139')
|
||||
timeinforce = tagged_field(parsed_fix_record,'59')
|
||||
# Needs Formatting
|
||||
price = formatted_tagged_field(parsed_fix_record,'44')
|
||||
# Left Right
|
||||
OnBehalfOfCompID_Left,OnBehalfOfCompID_Right = lr_tagged_field(parsed_fix_record,'115')
|
||||
OnBehalfOfSubID_Left,OnBehalfOfSubID_Right = lr_tagged_field(parsed_fix_record,'116')
|
||||
OnBehalfOfLocationID_Left,OnBehalfOfLocationID_Right = lr_tagged_field(parsed_fix_record,'144')
|
||||
if parsed_fix_record['35'] == "9":
|
||||
symbol = ""
|
||||
contractmonth = ""
|
||||
else:
|
||||
symbol,contractmonth = lr_contract_month(parsed_fix_record,'55')
|
||||
line_to_write = activedate + "," + ciorderid + "," + orderid + "," + transacttime + "," + symbol + "," + contractmonth + "," + securitytype + "," + \
|
||||
stkprc + "," + putcall + "," + side + "," + orderquanity + "," + maxshow + "," + ordertype + "," + price + "," + stoppx + "," + \
|
||||
clearingaccount + "," + clearingfirm + "," + orderstate + "," + accountcode + "," + cticode + "," + originatoruserid + "," + OnBehalfOfCompID_Left + "," + \
|
||||
OnBehalfOfCompID_Right + "," + OnBehalfOfSubID_Left + "," + OnBehalfOfSubID_Right + "," + OnBehalfOfLocationID_Left + "," + timeinforce
|
||||
with open (args.output_file, 'a') as the_file:
|
||||
the_file.write(line_to_write)
|
||||
the_file.write("\n")
|
||||
# except Exception:
|
||||
# pass
|
||||
@@ -0,0 +1,405 @@
|
||||
import json
|
||||
import csv
|
||||
import datetime, time
|
||||
import argparse, os
|
||||
|
||||
|
||||
def valid_file(f):
|
||||
if not os.path.exists(f):
|
||||
# Argparse uses the ArgumentTypeError to give a rejection message like:
|
||||
# error: argument input: x does not exist
|
||||
raise argparse.ArgumentTypeError("{0} does not exist".format(f))
|
||||
return f
|
||||
|
||||
def valid_date(s):
|
||||
try:
|
||||
return datetime.datetime.strptime(s, "%Y%m%d")
|
||||
except ValueError:
|
||||
raise argparse.ArgumentTypeError("Not a valid date: '{0}'.".format(s))
|
||||
|
||||
def print_headers():
|
||||
# From https://www.cmegroup.com/confluence/display/EPICSANDBOX/iLink+3+-+Minimum+Acceptable+Audit+Trail+Elements+-+Data+Definitions+and+Validation+Rules
|
||||
line_to_write = "Sending Timestamps,Message Direction,Operator ID,Session ID,Manual Order Indicator,Message Type,Instrument,Order Flow ID,\
|
||||
CME Globex Order ID,Client Order ID,Order Request ID,Buy/Sell Indicator,Quantity,Limit Price,Stop Price,Order Type,Order Qualifier,IFM Flag,\
|
||||
Display Quantity,Minimum Quantity,Country of Origin,Fill Price,Fill Quantity,Cumulative Quantity,Remaining Quantity,Aggressor Flag,Source of Cancellation,\
|
||||
Reject Reason,CME Globex Message ID,Cross ID,Quote Request ID,Message Quote ID,Quote Set ID,Quote Entry ID,Bid Price,Bid Size,Offer Price,Offer Size,\
|
||||
Processed Entries,Party Details List Request ID,ListUpdateAction,Self-Matching Prevention ID,Self-Match Prevention Instr,Customer Type Indicator,\
|
||||
AvgPxGroupID,Average Px Ind,CmtaGiveUpCD,Origin,Clearing Trade Price Type,Customer Handling Instr,Executing Firm ID,Account Number,Take Up Firm,Take up Account"
|
||||
|
||||
with open (args.output_file, 'w') as the_file:
|
||||
the_file.write(line_to_write)
|
||||
the_file.write("\n")
|
||||
|
||||
def set_blanks():
|
||||
return ""
|
||||
|
||||
def get_value(json_key):
|
||||
prices = ["Price", "LastPx", "StopPx"]
|
||||
if json_key in json_data:
|
||||
if json_key in prices:
|
||||
x = json_data[json_key]
|
||||
return x['mantissa']/100000000000
|
||||
else:
|
||||
return json_data[json_key]
|
||||
else:
|
||||
return ""
|
||||
|
||||
|
||||
# Column 1 - Sending Timestamps
|
||||
def SendingTimeEpoch(epochtime): #1
|
||||
#TIME = time.strftime('%Y%m%d-%H:%M:%S.{}'.format(epochtime/1000000000), time.gmtime(epochtime/1000000000))
|
||||
TIME = datetime.datetime.fromtimestamp(int(epochtime) / 1e9).strftime('%Y%m%d-%H:%M:%S.%f')
|
||||
return TIME
|
||||
|
||||
# Column 2 - Message Direction
|
||||
def direction(whichway):
|
||||
if whichway == '<':
|
||||
DIRECTION = "FROM CME"
|
||||
else:
|
||||
DIRECTION = "TO CME"
|
||||
return DIRECTION
|
||||
|
||||
# Column 3 - Operator ID
|
||||
def SenderID(sender):
|
||||
if "SenderID" in json_data:
|
||||
SENDER = json_data["SenderID"]
|
||||
return SENDER
|
||||
else:
|
||||
return SESSIONID
|
||||
|
||||
|
||||
# Column 4 - Session ID
|
||||
|
||||
# Column 5 - Manual Order Indicator
|
||||
def ManualOrderIndicator(manual):
|
||||
if "ManualOrderIndicator" in json_data:
|
||||
if manual == "Manual":
|
||||
return "1"
|
||||
else:
|
||||
return "0"
|
||||
|
||||
# Column 6 - Message Type
|
||||
def MessageType(msg_type,orderstatus):
|
||||
if msg_type == "NewOrderSingle514":
|
||||
return "D"
|
||||
elif msg_type == "ExecutionReportNew522":
|
||||
return "8--0"
|
||||
if "ExecutionReportTrade" in msg_type:
|
||||
if orderstatus == "PartiallyFilled":
|
||||
return "8--1"
|
||||
else:
|
||||
return "8--2"
|
||||
elif msg_type == "ExecutionReportCancel534":
|
||||
return "8--4"
|
||||
elif msg_type == "ExecutionReportModify531":
|
||||
return "8--5"
|
||||
elif msg_type == "ExecutionReportCancel534":
|
||||
return "8--H"
|
||||
elif msg_type == "ExecutionReportReject523":
|
||||
return "8--8"
|
||||
elif msg_type == "OrderCancelReplaceReject536":
|
||||
return "9--2"
|
||||
elif msg_type == "OrderCancelReject535":
|
||||
return "9--1"
|
||||
elif msg_type == "PartyDetailsDefinitionRequest518":
|
||||
return "CX"
|
||||
elif msg_type == "PartyDetailsDefinitionRequestAck519":
|
||||
return "CY"
|
||||
elif msg_type == "OrderCancelRequest516":
|
||||
return "F"
|
||||
elif msg_type == "OrderCancelReplaceRequest515":
|
||||
return "G"
|
||||
|
||||
|
||||
|
||||
# Column 12 - Buy-Sell Indicator/Side
|
||||
def Side(indicator):
|
||||
if "Side" in json_data:
|
||||
if indicator == "Buy":
|
||||
return "1"
|
||||
else:
|
||||
return "2"
|
||||
|
||||
# Column 16 - Order Type/OrdType
|
||||
def OrdType(ordertype):
|
||||
if "OrdType" in json_data:
|
||||
if ordertype == "MarketWithProtection" or ordertype == "MarketwithProtection":
|
||||
return "1"
|
||||
elif ordertype == "Limit":
|
||||
return "2"
|
||||
elif ordertype == "StopWithProtection" or ordertype == "StopwithProtection":
|
||||
return "3"
|
||||
elif ordertype == "StopLimit":
|
||||
return "4"
|
||||
elif ordertype == "MarketLimit":
|
||||
return "K"
|
||||
else:
|
||||
return ""
|
||||
|
||||
# Column 17 - Order Qualifier/TimeInForce
|
||||
def TimeInForce(orderqual):
|
||||
if "TimeInForce" in json_data:
|
||||
if orderqual == "Day":
|
||||
return "0"
|
||||
elif orderqual == "GTC":
|
||||
return "1"
|
||||
elif orderqual == "FAK":
|
||||
return "3"
|
||||
elif orderqual == "GTD":
|
||||
return "6"
|
||||
else:
|
||||
return ""
|
||||
|
||||
# Column 18 IFM Flag/OFMOverride
|
||||
def OFMOverride(imfflag):
|
||||
if "OFMOverride" in json_data:
|
||||
if imfflag == "Enabled":
|
||||
return "1"
|
||||
else:
|
||||
return "0"
|
||||
|
||||
# Column 19 Display Quantity/DisplayQty
|
||||
def DisplayQty(qty):
|
||||
if "DisplayQty" in json_data:
|
||||
if str(qty) == "0":
|
||||
return ""
|
||||
elif str(qty) == "4294967295":
|
||||
return ""
|
||||
else:
|
||||
return qty
|
||||
|
||||
|
||||
# Column 26 - Aggressor Flag/AggressorIndicator
|
||||
def AggressorIndicator(aggressor):
|
||||
if "AggressorIndicator" in json_data:
|
||||
if aggressor == "True":
|
||||
return "1"
|
||||
else:
|
||||
return "0"
|
||||
|
||||
# Column 27 - Source of Cancellation/ExecRestatementReason
|
||||
def ExecRestatementReason(sourcecancel):
|
||||
if "ExecRestatementReason" in json_data:
|
||||
if sourcecancel == "Exchange":
|
||||
return "8"
|
||||
elif sourcecancel == "CancelledNotBest":
|
||||
return "9"
|
||||
elif sourcecancel == "CancelOnDisconnect":
|
||||
return "100"
|
||||
elif sourcecancel == "CancelRestingDueToSelfMatchPrevention":
|
||||
return "103"
|
||||
elif sourcecancel == "CancelFromCMEGlobexCreditControlsViolation":
|
||||
return "104"
|
||||
elif sourcecancel == "CancelFromCMEOne":
|
||||
return "105"
|
||||
elif sourcecancel == "CancelFromRiskManagementAPI":
|
||||
return "106"
|
||||
elif sourcecancel == "CancelAggressingDueToSelfMatchPrevention":
|
||||
return "107"
|
||||
elif sourcecancel == "CancelDueToVolatilityQuoteOptionLessThanMinOrderSize":
|
||||
return "108"
|
||||
else:
|
||||
return ""
|
||||
|
||||
# Column 43 - Self-Match Prevention Instr/SelfMatchPreventionInstruction
|
||||
def SelfMatchPreventionInstruction(instr):
|
||||
if "SelfMatchPreventionInstruction" in json_data:
|
||||
if instr == "CancelOldest":
|
||||
return "O"
|
||||
elif instr == "CancelNewest":
|
||||
return "N"
|
||||
else:
|
||||
return ""
|
||||
|
||||
# Column 44 - Customer Type Indicator/CustOrderCapacity
|
||||
def CustOrderCapacity(custord):
|
||||
if "CustOrderCapacity" in json_data:
|
||||
if custord == "NULL_VALUE":
|
||||
return ""
|
||||
elif custord == "Membertradingfortheirownaccount":
|
||||
return "1"
|
||||
elif custord == "ClearingFirmtradingforitsproprietaryaccount":
|
||||
return "2"
|
||||
elif custord == "Membertradingforanothermember":
|
||||
return "3"
|
||||
else:
|
||||
return "4"
|
||||
|
||||
# Column 46 - Average Px Ind/AvgPxInd
|
||||
def AvgPxInd(avgpxindicator):
|
||||
if "AvgPxInd" in json_data:
|
||||
if avgpxindicator == "NULL_VALUE":
|
||||
return ""
|
||||
else:
|
||||
return avgpxindicator
|
||||
|
||||
# Column 48 - Origin/ClearingAccountType
|
||||
def ClearingAccountType(accounttype):
|
||||
if "ClearingAccountType" in json_data:
|
||||
if accounttype == "Customer":
|
||||
return "0"
|
||||
elif accounttype == "Firm":
|
||||
return "1"
|
||||
else:
|
||||
return ""
|
||||
|
||||
# Column 49 - Clearing Trade Price Type/ClearingTradePriceType
|
||||
def ClearingTradePriceType(clrtrdprice):
|
||||
if "ClearingTradePriceType" in json_data:
|
||||
if clrtrdprice == "NULL_VALUE":
|
||||
return "0"
|
||||
else:
|
||||
return "3"
|
||||
|
||||
# Column 50 - Customer Handling Instr/CustOrderHandlingInst
|
||||
def CustOrderHandlingInst(custorderinst):
|
||||
if "CustOrderHandlingInst" in json_data:
|
||||
if custorderinst == "ClientElectronic":
|
||||
return "C"
|
||||
elif custorderinst == "TEST":
|
||||
return "D"
|
||||
else:
|
||||
return ""
|
||||
|
||||
# Column 51 and 52 - Getting the Firm and Account Number
|
||||
def partyid(partydetailid,column):
|
||||
for x in partydetailid:
|
||||
role = x['PartyDetailRole']
|
||||
id = x['PartyDetailID']
|
||||
if column == "51" and role == "ExecutingFirm":
|
||||
return id
|
||||
if column == "52" and role == "CustomerAccount":
|
||||
return id
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("json_log", help="the json log[.gz] you wish to process", type=valid_file)
|
||||
parser.add_argument("output_file", help="the destination csv file you wish to write")
|
||||
parser.add_argument("-d", "--date", help="the date you wish to parse from the log, specified as YYYYmmdd",
|
||||
default=datetime.datetime.today().strftime("%Y%m%d"), type=valid_date)
|
||||
args = parser.parse_args()
|
||||
|
||||
print_headers()
|
||||
|
||||
list_types = ['NewOrderSingle514', 'OrderCancelReplaceRequest515', 'OrderCancelRequest516', 'PartyDetailsDefinitionRequest518', 'PartyDetailsDefinitionRequestAck519', \
|
||||
'ExecutionReportNew522', 'ExecutionReportReject523', 'ExecutionReportTradeOutright525', 'ExecutionReportTradeSpread526', 'ExecutionReportTradeSpreadLeg527', \
|
||||
'ExecutionReportModify531', 'ExecutionReportCancel534', 'OrderCancelReject535', 'OrderCancelReplaceReject536', ]
|
||||
|
||||
# Note that the timedeltas specificed in trade_day_start and trade_day_end
|
||||
# are based on Chicago times; as such, this script should run on a machine
|
||||
# set to a Chicago timezone. A future impromovement would be to determine
|
||||
# the current machine's timezone and determine the appropriate offset
|
||||
# versus Chicago time, but for now we assume this will run on a Chicago
|
||||
# tz machine.
|
||||
input_as_datetime = args.date
|
||||
trade_day_start = input_as_datetime - datetime.timedelta(days=1) + datetime.timedelta(hours=16, minutes=30)
|
||||
trade_day_utc_start = time.gmtime((time.mktime(trade_day_start.timetuple())))
|
||||
trade_day_end = input_as_datetime + datetime.timedelta(hours=16)
|
||||
trade_day_utc_end = time.gmtime((time.mktime(trade_day_end.timetuple())))
|
||||
|
||||
file_opener = None
|
||||
if args.json_log.endswith(".gz"):
|
||||
import gzip
|
||||
file_opener = gzip.open
|
||||
else:
|
||||
file_opener = open
|
||||
|
||||
|
||||
#inputFile = open(fileInput) #open json file
|
||||
#outputFile = open(fileOutput, 'w') #load csv file
|
||||
# Get Session
|
||||
with file_opener(args.json_log) as json_file:
|
||||
for line in json_file:
|
||||
data = json.loads(line)
|
||||
json_data = data['msg_json']
|
||||
if "Session" in json_data:
|
||||
SESSIONID = json_data["Session"]
|
||||
|
||||
#inputFile = open(fileInput) #open json file
|
||||
#outputFile = open(fileOutput, 'w') #load csv file
|
||||
with file_opener(args.json_log) as json_file:
|
||||
for line in json_file:
|
||||
data = json.loads(line)
|
||||
line_timestamp = time.strptime(data['time'], "%Y%m%d-%H:%M:%S.%f")
|
||||
if trade_day_utc_start <= line_timestamp <= trade_day_utc_end:
|
||||
json_data = data['msg_json']
|
||||
NAME = json_data["Name"]
|
||||
if NAME in list_types:
|
||||
EXECUTING_FIRM_ID = ""
|
||||
ACCOUNT_NUMBER = ""
|
||||
DIRECTION = direction(data['direction'])
|
||||
# Set Blanks
|
||||
blank_json = {'QuoteReqID': '', 'QuoteID': '', 'QuoteSetID': '', 'QuoteEntryID': '', 'BidPx': '', 'BidSize': '', 'OfferPx': '', \
|
||||
'OfferSize': '', 'NoProcessedEntries': '', 'ListUpdateAction': '', 'MinQty': '', 'AvgPxGroupID': '', \
|
||||
'CmtaGiveUpCD': '', 'TAKE_UP_FIRM': '', 'TAKE_UP_ACCOUNT': '',}
|
||||
|
||||
# No Data Processing
|
||||
straight_json = {'SecurityID': '', 'ClOrdID': '', 'OrderID': '', 'OrderRequestID': '', 'OrderQty': '', \
|
||||
'Location': '', 'LastQty': '', 'CumQty': '', 'LeavesQty': '', 'Text': '', 'SideTradeID': '', 'CrossID': '', 'SelfMatchPreventionID': '', \
|
||||
'Price': '', 'StopPx': '', 'LastPx': '', 'PartyDetailsListReqID': '', 'OrdStatus': ''}
|
||||
|
||||
# Processing Data
|
||||
process_json = {'SendingTimeEpoch': '', 'ManualOrderIndicator': '', 'SenderID': '', 'Side': '', 'OrdType': '', 'TimeInForce': '', \
|
||||
'OFMOverride': '', 'AggressorIndicator': '', 'ExecRestatementReason': '', 'SelfMatchPreventionInstruction': '', 'CustOrderCapacity': '', \
|
||||
'AvgPxInd': '', 'ClearingAccountType': '', 'ClearingTradePriceType': '', 'CustOrderHandlingInst': '', 'DisplayQty': ''}
|
||||
|
||||
for d in straight_json:
|
||||
test = get_value(d)
|
||||
if test != "None" or test != "":
|
||||
if "," in str(test):
|
||||
test = test.replace(",",";")
|
||||
if "4294967295" in str(test):
|
||||
test = ""
|
||||
if "us;" in str(test):
|
||||
test = test.upper()
|
||||
if d == "SelfMatchPreventionID" and len(str(test)) > 8:
|
||||
test = ""
|
||||
straight_json[d] = test
|
||||
else:
|
||||
straight_json[d] = ''
|
||||
|
||||
for d in process_json:
|
||||
if d in json_data:
|
||||
function = locals()[d]
|
||||
test = function(json_data[d])
|
||||
if test != "None":
|
||||
process_json[d] = test
|
||||
else:
|
||||
process_json[d] = ''
|
||||
elif d == "SenderID":
|
||||
function = locals()[d]
|
||||
test = function(SenderID)
|
||||
if test != "None":
|
||||
process_json[d] = test
|
||||
|
||||
# Party Message Fields
|
||||
# Column 51 - Executing Firm ID
|
||||
if "NoPartyDetails" in json_data:
|
||||
EXECUTING_FIRM_ID = partyid(json_data['NoPartyDetails'], "51")
|
||||
# Column 52 - Party Account Number
|
||||
ACCOUNT_NUMBER = partyid(json_data['NoPartyDetails'], "52")
|
||||
|
||||
line_to_write = process_json['SendingTimeEpoch'] + "," + DIRECTION + "," + process_json['SenderID'] + "," + SESSIONID + "," + process_json['ManualOrderIndicator'] + "," + \
|
||||
MessageType(NAME,straight_json['OrdStatus']) + "," + str(straight_json['SecurityID']) + "," + str(straight_json['ClOrdID']) + "," + str(straight_json['OrderID']) + "," + str(straight_json['ClOrdID']) + "," + \
|
||||
str(straight_json['OrderRequestID']) + "," + process_json['Side'] + "," + str(straight_json['OrderQty']) + "," + str(straight_json['Price']) + "," + \
|
||||
str(straight_json['StopPx']) + "," + process_json['OrdType'] + "," + process_json['TimeInForce'] + "," + process_json['OFMOverride'] + "," + str(process_json['DisplayQty']) + "," + \
|
||||
blank_json['MinQty'] + "," + straight_json['Location'] + "," + str(straight_json['LastPx']) + "," + str(straight_json['LastQty']) + "," + str(straight_json['CumQty']) + "," + \
|
||||
str(straight_json['LeavesQty']) + "," + process_json['AggressorIndicator'] + "," + process_json['ExecRestatementReason'] + "," + str(straight_json['Text']) + "," + \
|
||||
str(straight_json['SideTradeID']) + "," + str(straight_json['CrossID']) + "," + blank_json['QuoteReqID'] + "," + blank_json['QuoteID'] + "," + blank_json['QuoteSetID'] + "," + \
|
||||
blank_json['QuoteEntryID'] + "," + blank_json['BidPx'] + "," + blank_json['BidSize'] + "," + blank_json['OfferPx'] + "," + blank_json['OfferSize'] + "," + \
|
||||
blank_json['NoProcessedEntries'] + "," + str(straight_json['PartyDetailsListReqID']) + "," + blank_json['ListUpdateAction'] + "," + str(straight_json['SelfMatchPreventionID']) + "," + \
|
||||
process_json['SelfMatchPreventionInstruction'] + "," + process_json['CustOrderCapacity'] + "," + blank_json['AvgPxGroupID'] + "," + process_json['AvgPxInd'] + "," + \
|
||||
blank_json['CmtaGiveUpCD'] + "," + str(process_json['ClearingAccountType']) + "," + process_json['ClearingTradePriceType'] + "," + process_json['CustOrderHandlingInst'] + "," + \
|
||||
EXECUTING_FIRM_ID + "," + str(ACCOUNT_NUMBER) + "," + blank_json['TAKE_UP_FIRM'] + "," + blank_json['TAKE_UP_ACCOUNT']
|
||||
|
||||
|
||||
#print(line_to_write)
|
||||
|
||||
with open (args.output_file, 'a') as the_file:
|
||||
the_file.write(line_to_write)
|
||||
the_file.write("\n")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Executable
+84
@@ -0,0 +1,84 @@
|
||||
#/bin/bash
|
||||
|
||||
function help_and_exit()
|
||||
{
|
||||
echo
|
||||
echo Usage: $0 [option]... config_file
|
||||
echo
|
||||
echo Can also be used in cron like the following
|
||||
echo 40 16 * * 1-5 /usr/bin/docker exec spark_10000 bash /sparkbin/data_files/audit_upload.sh /sparkdata/data/audit_uploads/example.conf
|
||||
echo example.conf included. The location of the conf file should be relative to the docker container, not the host
|
||||
echo
|
||||
echo Options are as follows:
|
||||
echo " -d|--date YYYYMMDD Example is 20180731"
|
||||
echo " Help: "
|
||||
echo " -h|--help Display this message."
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
DATE=$(date +%Y%m%d)
|
||||
ORIG_DIR=$(pwd)
|
||||
ERROR_LEVEL="0"
|
||||
|
||||
while getopts "d:h" option; do
|
||||
case $option in
|
||||
d) DATE=$OPTARG ;;
|
||||
h) help_and_exit;;
|
||||
\?) echo "Invalid option: -$OPTARG" >&2;
|
||||
exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1))
|
||||
|
||||
CONFIG_FILE=$1
|
||||
|
||||
declare -A conf_vars; while read line; do conf_vars[${line%=*}]=${line#*=}; done <$CONFIG_FILE
|
||||
|
||||
SESSION_ID=${conf_vars[session_id]}
|
||||
FCM=${conf_vars[fcm]}
|
||||
CLIENT=${conf_vars[client]}
|
||||
|
||||
# Create MD dump
|
||||
cd /sparkbin
|
||||
./sparkd md dumpsecurity all > /sparkdata/data/md_dump.txt
|
||||
|
||||
cd /sparkbin/data_files
|
||||
|
||||
for SESSION in $(ls /sparkdata/data/{ilink3,jetfix}/); do
|
||||
if [[ $SESSION == *$SESSION_ID* ]]; then
|
||||
echo "Session is $SESSION"
|
||||
SESSION_DAY=$(date -d $DATE +%Y-%m-%d)
|
||||
if [[ $SESSION == "cme_"* ]]; then
|
||||
SESSION_DAY=$(date -d "$DATE -$(date -d $DATE +%u) days" +"%Y-%m-%d")
|
||||
AUDIT_SCRIPT="audit_ilink3.py"
|
||||
ILINK_TYPE="ilink3"
|
||||
LOG_NAME="log"
|
||||
elif [[ $SESSION == "ice_"* ]]; then
|
||||
SESSION_DAY=$(date -d "$DATE 1 days ago" +%Y-%m-%d)
|
||||
AUDIT_SCRIPT="audit_ice.py"
|
||||
ILINK_TYPE="jetfix"
|
||||
LOG_NAME="fix"
|
||||
fi
|
||||
echo $SESSION_DAY
|
||||
if [[ ! -d /sparkdata/data/$ILINK_TYPE/$SESSION/audit_logs ]]; then
|
||||
mkdir -p /sparkdata/data/$ILINK_TYPE/$SESSION/audit_logs
|
||||
fi
|
||||
if [[ -d /sparkdata/data/$ILINK_TYPE/$SESSION/$SESSION_DAY ]]; then
|
||||
echo "Starting the creation of the audit log"
|
||||
python3 $AUDIT_SCRIPT -d $DATE /sparkdata/data/$ILINK_TYPE/$SESSION/$SESSION_DAY/$LOG_NAME /sparkdata/data/$ILINK_TYPE/$SESSION/audit_logs/"$FCM"_audit_"$SESSION"_"$DATE".csv
|
||||
fi
|
||||
if [[ ! -d /sparkdata/data/md_audit ]]; then
|
||||
mkdir /sparkdata/data/md_audit
|
||||
fi
|
||||
if [[ -d /sparkdata/data/md_audit ]]; then
|
||||
# Running the MD Audit csv generation
|
||||
cd /sparkbin
|
||||
./sparkd adminreport md > /sparkdata/data/md_audit/"$FCM"_md_"$CLIENT"_"$DATE".csv
|
||||
cd /sparkbin/data_files
|
||||
fi
|
||||
echo "Uploading to the (s)FTP Server"
|
||||
python3 audit_uploader.py --config_file="$CONFIG_FILE" --datestamp $DATE --session="$SESSION" --client="$CLIENT" --fcm="$FCM"
|
||||
fi
|
||||
done
|
||||
Executable
+164
@@ -0,0 +1,164 @@
|
||||
import getopt, sys, datetime
|
||||
import paramiko, ftplib
|
||||
|
||||
#########################################################
|
||||
# Commandline Args #
|
||||
#########################################################
|
||||
|
||||
def usage():
|
||||
print ("-------------------------------------------------------")
|
||||
print ("-Usage: -")
|
||||
print ("-------------------------------------------------------")
|
||||
print ("- --config_file= : Path to upload config file -")
|
||||
print ("- -if no path is specified look -")
|
||||
print ("- in the working directory. -")
|
||||
print ("- -")
|
||||
print ("- --help : Print this message -")
|
||||
print ("- -")
|
||||
print ("- --datestamp= : Optional, defaults to today -")
|
||||
print ("- -replaces *datestamp in the -")
|
||||
print ("- the upload config file -")
|
||||
print ("- -")
|
||||
print ("- --fcm : Optional, spark input -")
|
||||
print ("- -")
|
||||
print ("- --session : Optional, spark jf session -")
|
||||
print ("-------------------------------------------------------")
|
||||
|
||||
fcm = ''
|
||||
session = ''
|
||||
|
||||
try:
|
||||
options, arguments = getopt.getopt(sys.argv[1:],"h",['config_file=', 'datestamp=', 'help', 'fcm=', 'client=', 'session='])
|
||||
except getopt.GetoptError as err:
|
||||
print(err)
|
||||
usage()
|
||||
sys.exit(2)
|
||||
|
||||
for option, value in options:
|
||||
if option in ("-h","--h","-help","--help"):
|
||||
usage()
|
||||
sys.exit()
|
||||
elif option in ("-config_file","--config_file"):
|
||||
config_file = value
|
||||
elif option in ("-datestamp","--datestamp"):
|
||||
datestamp = value
|
||||
elif option in ("-fcm","--fcm"):
|
||||
fcm = value
|
||||
elif option in ("-client","--client"):
|
||||
client = value
|
||||
elif option in ("-session","--session"):
|
||||
session = value
|
||||
|
||||
for argument in arguments:
|
||||
if argument in ("h", "help"):
|
||||
usage()
|
||||
sys.exit()
|
||||
else:
|
||||
print ("Unrecognized commandline argument. Type help for usage.")
|
||||
sys.exit()
|
||||
|
||||
if len(options) <= 0:
|
||||
print("Requires a config file to run.")
|
||||
usage()
|
||||
sys.exit()
|
||||
|
||||
|
||||
#########################################################
|
||||
# Read Config Function #
|
||||
#########################################################
|
||||
|
||||
def read_config_file(config_file, datestamp=datetime.datetime.today().strftime('%Y%m%d'), fcm=fcm, session=session):
|
||||
'''
|
||||
Parse our config file that gets passed in as a commandline parameter.
|
||||
All config keys must be of the form key=value. White space is ignored.
|
||||
All config keys must be seperated by a newline character.
|
||||
Called during initialization.
|
||||
'''
|
||||
upload_config = {}
|
||||
config_file = open(config_file, 'r')
|
||||
config_file = config_file.read()
|
||||
for config in config_file.split("\n"):
|
||||
if '=' in config:
|
||||
cleaned_key = config.split('=')[0].strip().upper()
|
||||
cleaned_value = config.split('=')[1].strip()
|
||||
if '*datestamp*' in cleaned_value:
|
||||
cleaned_value = cleaned_value.replace('*datestamp*',datestamp)
|
||||
if '*fcm*' in cleaned_value:
|
||||
cleaned_value = cleaned_value.replace('*fcm*',fcm)
|
||||
if '*client*' in cleaned_value:
|
||||
cleaned_value = cleaned_value.replace('*client*',client)
|
||||
if '*session*' in cleaned_value:
|
||||
cleaned_value = cleaned_value.replace('*session*',session)
|
||||
upload_config[cleaned_key] = cleaned_value
|
||||
else:
|
||||
pass
|
||||
return upload_config
|
||||
|
||||
#########################################################
|
||||
# FTP File Transfer Function #
|
||||
#########################################################
|
||||
def putfile_ftp(file, put_path, site, user, password, port=21, verbose=True):
|
||||
if verbose: print("Uploading", file)
|
||||
local = open(file, 'rb')
|
||||
remote = ftplib.FTP(site)
|
||||
remote.login(user, password)
|
||||
remote.storbinary(put_path, local, 1024)
|
||||
remote.quit()
|
||||
local.close()
|
||||
if verbose: print("Upload done.")
|
||||
|
||||
#########################################################
|
||||
# SFTP File Transfer Function #
|
||||
#########################################################
|
||||
def putfile_sftp(file, put_path, site, username, password, port=22, verbose=True):
|
||||
transport = paramiko.Transport((site, port))
|
||||
transport.connect(username = username, password = password)
|
||||
sftp = paramiko.SFTPClient.from_transport(transport)
|
||||
sftp.put(file, put_path)
|
||||
sftp.close()
|
||||
transport.close()
|
||||
|
||||
|
||||
#########################################################
|
||||
# Main #
|
||||
#########################################################
|
||||
#if datestamp != None:
|
||||
# upload_config = read_config_file(config_file, datestamp)
|
||||
#else:
|
||||
# upload_config = read_config_file(config_file)
|
||||
|
||||
try:
|
||||
datestamp
|
||||
except NameError:
|
||||
upload_config = read_config_file(config_file)
|
||||
else:
|
||||
upload_config = read_config_file(config_file, datestamp)
|
||||
|
||||
|
||||
|
||||
print(upload_config)
|
||||
|
||||
if upload_config["PROTOCOL_PUT"] in ['FTP','ftp']:
|
||||
print("Protocol = FTP")
|
||||
try:
|
||||
putfile_ftp(upload_config["GET_ILINK3_FILE_PATH"] + upload_config["GET_ILINK3_FILE_NAME"], upload_config["PUT_ILINK3_FILE_PATH"] + upload_config["PUT_ILINK3_FILE_NAME"], upload_config["PUT_HOST"], upload_config["USERNAME_PUT"], upload_config["PASSWORD_PUT"], upload_config["PORT_PUT"] )
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
putfile_ftp(upload_config["GET_JETFIX_FILE_PATH"] + upload_config["GET_JETFIX_FILE_NAME"], upload_config["PUT_JETFIX_FILE_PATH"] + upload_config["PUT_JETFIX_FILE_NAME"], upload_config["PUT_HOST"], upload_config["USERNAME_PUT"], upload_config["PASSWORD_PUT"], upload_config["PORT_PUT"] )
|
||||
except KeyError:
|
||||
pass
|
||||
putfile_ftp(upload_config["GET_MD_FILE_PATH"] + upload_config["GET_MD_FILE_NAME"], upload_config["PUT_MD_FILE_PATH"] + upload_config["PUT_MD_FILE_NAME"], upload_config["PUT_HOST"], upload_config["USERNAME_PUT"], upload_config["PASSWORD_PUT"], upload_config["PORT_PUT"] )
|
||||
elif upload_config["PROTOCOL_PUT"] in ['SFTP','sftp']:
|
||||
print("Protocol = SFTP")
|
||||
try:
|
||||
putfile_sftp(upload_config["GET_ILINK3_FILE_PATH"] + upload_config["GET_ILINK3_FILE_NAME"], upload_config["PUT_ILINK3_FILE_PATH"] + upload_config["PUT_ILINK3_FILE_NAME"], upload_config["PUT_HOST"], upload_config["USERNAME_PUT"], upload_config["PASSWORD_PUT"], int(upload_config["PORT_PUT"]) )
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
putfile_sftp(upload_config["GET_JETFIX_FILE_PATH"] + upload_config["GET_JETFIX_FILE_NAME"], upload_config["PUT_JETFIX_FILE_PATH"] + upload_config["PUT_JETFIX_FILE_NAME"], upload_config["PUT_HOST"], upload_config["USERNAME_PUT"], upload_config["PASSWORD_PUT"], int(upload_config["PORT_PUT"]) )
|
||||
except KeyError:
|
||||
pass
|
||||
putfile_sftp(upload_config["GET_MD_FILE_PATH"] + upload_config["GET_MD_FILE_NAME"], upload_config["PUT_MD_FILE_PATH"] + upload_config["PUT_MD_FILE_NAME"], upload_config["PUT_HOST"], upload_config["USERNAME_PUT"], upload_config["PASSWORD_PUT"], int(upload_config["PORT_PUT"]) )
|
||||
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
Session ID Access ID Secret Key Creation Date Expiration Date Environment
|
||||
|
||||
M4D lLtjH74y1Kh5XUJTLyH2 f1K_tROQp2lTIplVp34WxKa7xDUgfFnIteolfik061o 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC1 VEMlkDuLz74OVHSuacQB IuHyYT3b-9KUo3WsuXykt-fXsjzp7L-JOrdCSQZLNl0 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC5 77lzSUwPLlM9obaXh2mK z6aA9qfASDKfZkYTVKFqJd-78i0HZ2Q9ec3CKCYIqHg 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC7 RphzI3rn71oGUEiYnX9e y6OvvPPyoyj2S8YAnE1gFduXT8v29HIMjO5EngYxSNg 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC8 PYBIm2TI9gFPIxmHbuYl 6o-ZolGH2DdeQOlGtJ5Zqoh_kg7VdbxkmjeOHmigKwU 2019-09-03 2020-09-03 CERT
|
||||
|
||||
Session ID Access ID Secret Key Creation Date Expiration Date Environment
|
||||
|
||||
M4D lLtjH74y1Kh5XUJTLyH2 f1K_tROQp2lTIplVp34WxKa7xDUgfFnIteolfik061o 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC1 VEMlkDuLz74OVHSuacQB IuHyYT3b-9KUo3WsuXykt-fXsjzp7L-JOrdCSQZLNl0 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC5 77lzSUwPLlM9obaXh2mK z6aA9qfASDKfZkYTVKFqJd-78i0HZ2Q9ec3CKCYIqHg 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC7 RphzI3rn71oGUEiYnX9e y6OvvPPyoyj2S8YAnE1gFduXT8v29HIMjO5EngYxSNg 2019-09-03 2020-09-03 CERT
|
||||
|
||||
MC8 PYBIm2TI9gFPIxmHbuYl 6o-ZolGH2DdeQOlGtJ5Zqoh_kg7VdbxkmjeOHmigKwU 2019-09-03 2020-09-03 CERT
|
||||
|
||||
NGG RYcigz3bSLIIBBF2A2Hq qB1dm9VkTKeXcdQpFzla8B3_jwTgya_-Fk5iyEJvr2E 2020-06-15 2021-06-15 NEWRELEASE
|
||||
|
||||
NGF o4OTmmTLQ7Lv4g6bCm26 HbD3FneMyb9Fu-FkCDLscCczHqFcFE2PyWv978RXGyA 2019-12-20 2020-12-20 NEWRELEASE
|
||||
|
||||
UZE EeFdZ1FPepk6U4k3xBZA 2LjEtdLvBLLB1QuDJ4KiJW6M4dF6IHWd_UKmo7p3_Us 2020-06-24 2021-06-24 NEWRELEASE
|
||||
|
||||
VAE Y8iqatTewuoHX16gghw8 FNcCB3Ks1qleS56quYzH4V7zAu78YY2bCdLRi9tmU9E 2020-06-24 2021-06-24 NEWRELEASE
|
||||
@@ -0,0 +1,16 @@
|
||||
fcm=FCM
|
||||
client=NAME
|
||||
session_id=ses
|
||||
put_host=ftpc.example.com
|
||||
port_put=2222
|
||||
username_put=user
|
||||
password_put=password
|
||||
protocol_put=sftp
|
||||
get_ilink3_file_path=/sparkdata/data/ilink3/*session*/audit_logs/
|
||||
put_ilink3_file_path=/
|
||||
get_ilink3_file_name=*fcm*_audit_*session*_*datestamp*.csv
|
||||
put_ilink3_file_name=*fcm*_audit_*session*_*datestamp*.csv
|
||||
get_md_file_path=/sparkdata/data/md_audit/
|
||||
put_md_file_path=/
|
||||
get_md_file_name=*fcm*_md_*client*_*datestamp*.csv
|
||||
put_md_file_name=*fcm*_md_*client*_*datestamp*.csv
|
||||
@@ -1 +1 @@
|
||||
set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/service_helpers/AlgoServiceUtils.cpp;api/service_helpers/PositionUtilities.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/BasePositionService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MBOService.proto;api/services/MarginService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/MarketDataService.proto;api/services/MoneyFileService.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/keycode.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/position_cfg.conf;config/defaults/span.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/AlgoTypes.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/keycode.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/position_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/span.proto;config/protos/spreader.proto;config/protos/subprocess.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/sod.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;jetfix/codec/FIXArray.cpp;jetfix/common/OutFIX.cpp;jetfix/connection/AsyncReader.cpp;jetfix/connection/IConnection.cpp;jetfix/connection/SocketConnection.cpp;jetfix/gateway/CoreGateway.cpp;jetfix/gateway/JetFIXGateway.cpp;jetfix/gateway/Session.cpp;jetfix/store/FIXFileStore.cpp;jetfix/store/session_name.cpp;jetfix/tests/async_reader_tests.cpp;jetfix/tests/decoding_tests.cpp;jetfix/tests/fix_encoding_stream_tests.cpp;jetfix/tests/fix_fragment_tests.cpp;jetfix/tests/jetfix_performance_tests.cpp;jetfix/tests/sample_fix.cpp;jetfix/tests/store_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MBOProcessor.cpp;md/MBOServiceServer.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/Product.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityMapper.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/ice/ICEUtils.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/service/MarketDataServiceServer.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/mbo_tests.cpp;md/test/md2_tests.cpp;md/test/md_test_utils.cpp;md/test/synthetic_book_merge_tests.cpp;md/vendor/OnixsUtils.cpp;mercury/actors/IPollableActor.cpp;mercury/broker/Broker.cpp;mercury/broker/BrokerProxy.cpp;mercury/broker/ILocalBroker.cpp;mercury/broker/IRemoteBroker.cpp;mercury/common/mercury_common.cpp;mercury/events/TimerEvent.cpp;mercury/executor/Executor.cpp;mercury/topics/Topic.cLine truncated
|
||||
set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/service_helpers/AlgoServiceUtils.cpp;api/service_helpers/PositionUtilities.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/BasePositionService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MBOService.proto;api/services/MarginService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/MarketDataService.proto;api/services/MoneyFileService.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/keycode.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/position_cfg.conf;config/defaults/span.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/AlgoTypes.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/keycode.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/position_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/span.proto;config/protos/spreader.proto;config/protos/subprocess.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/sod.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;jetfix/codec/FIXArray.cpp;jetfix/common/OutFIX.cpp;jetfix/connection/AsyncReader.cpp;jetfix/connection/IConnection.cpp;jetfix/connection/SocketConnection.cpp;jetfix/gateway/CoreGateway.cpp;jetfix/gateway/JetFIXGateway.cpp;jetfix/gateway/Session.cpp;jetfix/store/FIXFileStore.cpp;jetfix/store/session_name.cpp;jetfix/tests/async_reader_tests.cpp;jetfix/tests/decoding_tests.cpp;jetfix/tests/fix_encoding_stream_tests.cpp;jetfix/tests/fix_fragment_tests.cpp;jetfix/tests/jetfix_performance_tests.cpp;jetfix/tests/sample_fix.cpp;jetfix/tests/store_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MBOProcessor.cpp;md/MBOServiceServer.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/Product.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityMapper.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/ice/ICEUtils.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/service/MarketDataServiceServer.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/mbo_tests.cpp;md/test/md2_tests.cpp;md/test/md_test_utils.cpp;md/test/synthetic_book_merge_tests.cpp;md/vendor/OnixsUtils.cpp;mercury/actors/IPollableActor.cpp;mercury/broker/Broker.cpp;mercury/broker/BrokerProxy.cpp;mercury/broker/ILocalBroker.cpp;mercury/broker/IRemoteBroker.cpp;mercury/common/mercury_common.cpp;mercury/events/TimerEvent.cpp;mercury/executor/Executor.cpp;mercury/topics/Topic.cLine truncated
|
||||
@@ -135,7 +135,9 @@ else ()
|
||||
-ldl
|
||||
-static-libgcc
|
||||
-static-libstdc++
|
||||
-pthread)
|
||||
-pthread)
|
||||
|
||||
install(TARGETS libspark DESTINATION bin)
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
|
||||
@@ -319,7 +319,7 @@ if __name__ == "__main__":
|
||||
|
||||
if DEBUG:
|
||||
for f in response.file:
|
||||
print f.content
|
||||
print (f.content)
|
||||
else:
|
||||
output = response.SerializeToString()
|
||||
sys.stdout.write(output)
|
||||
|
||||
@@ -596,7 +596,9 @@ bts::api::orderman::RoutingRecord AdminServiceUtils::get_routing_record(const bt
|
||||
rv.set_session(conn_ptr->name());
|
||||
rv.set_operator_id(cme_user_data->operator_id());
|
||||
rv.set_location(cme_user_data->location());
|
||||
|
||||
rv.set_smp_id(cme_user_data->smp_id());
|
||||
|
||||
if (cme_user_data->smp_instruction()== "O")
|
||||
rv.set_smp_instruction(api::orderman::SelfMatchPreventionInstruction::SELF_MATCH_PREVENTION_INSTRUCTION_CANCEL_RESTING);
|
||||
else if (cme_user_data->smp_instruction()== "N")
|
||||
|
||||
@@ -386,7 +386,9 @@ message NativeOrderState {
|
||||
RoutingRecord routing_record = 5;
|
||||
NativeOrderType native_type = 6;
|
||||
string last_transact_time = 7;
|
||||
uint64 last_transact_time_unix_ns = 9;
|
||||
double stop_px = 8;
|
||||
uint64 exchange_order_id_u64 = 10;
|
||||
}
|
||||
|
||||
// Custom order states
|
||||
@@ -455,7 +457,8 @@ enum TimeInForce {
|
||||
TIME_IN_FORCE_UNDEFINED = 0;
|
||||
TIME_IN_FORCE_DAY = 48;
|
||||
TIME_IN_FORCE_GTC = 49;
|
||||
TIME_IN_FORCE_IOC = 51;
|
||||
TIME_IN_FORCE_IOC = 51; // FAK
|
||||
TIME_IN_FORCE_DATE = 52;
|
||||
}
|
||||
|
||||
enum ManualOrderIndicator {
|
||||
|
||||
@@ -46,6 +46,12 @@ CMEOptions {
|
||||
}
|
||||
}
|
||||
|
||||
ICEPublisherOptions {
|
||||
value {
|
||||
network_interface: "eth1"
|
||||
}
|
||||
}
|
||||
|
||||
#to make this work in dev clone the operations repo
|
||||
#go here: c:\\code\\bts\\operations\\ice\\ICE_iMpactMulticastFeed_GettingStarted-1_1_36\\bin\\easyTunnel>
|
||||
#modify the easyTunnelProxy.properties file to replace
|
||||
|
||||
+1091
-13
File diff suppressed because it is too large.
Load diff
@@ -76,6 +76,23 @@ message LadderKnobs {
|
||||
// DJ wants bid/ask cells with markets (i.e., size > 0) to have a
|
||||
// lighter background than those without markets.
|
||||
optional bool lighten_market_cells = 10 [default = true];
|
||||
|
||||
// For market cell backgrounds, 0 means 'ignore this color setting'
|
||||
// (i.e., employ the ladder's default behavior instead).
|
||||
//
|
||||
// Note that despite reserving the value 0 as a flag, the full range of
|
||||
// colors can still be expressed. Zero is one of 2^24 representations
|
||||
// of 'transparent.'
|
||||
//
|
||||
// The channels alpha, red, green, and blue are stored in the
|
||||
// 1-4th bytes respectively. For example:
|
||||
// Transparent: 0x00XXXXXX (any value with the first byte set to 0)
|
||||
// Pure Red : 0xFFFF0000
|
||||
// Pure Blue : 0xFF00FF00
|
||||
// Pure Green : 0xFF0000FF
|
||||
optional uint32 bid_market_cell_background = 11;
|
||||
optional uint32 ask_market_cell_background = 12;
|
||||
optional bool mimic_tt = 13 [default = true];
|
||||
}
|
||||
|
||||
message OrderBookOptions {
|
||||
@@ -182,4 +199,4 @@ message SymbolUIConfigurationItem {
|
||||
|
||||
message SymbolUIConfiguration {
|
||||
repeated SymbolUIConfigurationItem items = 1;
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,9 @@ message JetFIX {
|
||||
enum JetFIXPlatform {
|
||||
GLBX = 1;
|
||||
CBOE = 6;
|
||||
SIM = 2;
|
||||
ICE = 3;
|
||||
SIMICE = 4;
|
||||
SIM = 2;
|
||||
ICE = 3;
|
||||
SIMICE = 4;
|
||||
}
|
||||
optional JetFIXPlatform platform = 15 [default = GLBX];
|
||||
|
||||
@@ -87,6 +87,7 @@ message JetFIX {
|
||||
|
||||
optional uint32 max_connection_attempts = 346 [default=10];
|
||||
optional bool auto_fix_seq_num = 347 [default=false];
|
||||
optional bool use_ilink3 = 348 [default=false] ;
|
||||
}
|
||||
|
||||
repeated Connection connection = 10;
|
||||
@@ -116,4 +117,4 @@ message CMECannedSecureLogon {
|
||||
"MC8 AbEEtBn63WIAuItPDz1c n3ndjYb03Hx6wBO3me35HoONyDgO5TZKWk0tDSaX9KA 2018-04-05 2019-04-05 CERT \n"
|
||||
"T39 UWggBgHWAe07aqW3ps2I tbb3it0rUQSSTa0TC9QcRwkrHEMDLWhaJH4VQ0FqGB4 2018-04-05 2019-04-05 NEWRELEASE \n"
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -9,33 +9,28 @@ namespace config {
|
||||
namespace internal {
|
||||
|
||||
HTTPServer::HTTPServer()
|
||||
: _io_service(),
|
||||
_acceptor(_io_service, tcp::endpoint(boost::asio::ip::address_v4::loopback(), 0)),
|
||||
_cur_socket(),
|
||||
_request_response_pairs(),
|
||||
_thread(),
|
||||
_done(false)
|
||||
{
|
||||
|
||||
}
|
||||
: _io_service(),
|
||||
_acceptor(
|
||||
_io_service,
|
||||
tcp::endpoint(boost::asio::ip::address_v4::loopback(), 0)),
|
||||
_cur_socket(), _request_response_pairs(), _thread(), _done(false) {}
|
||||
|
||||
unsigned int HTTPServer::port() const
|
||||
{
|
||||
unsigned int HTTPServer::port() const {
|
||||
return _acceptor.local_endpoint().port();
|
||||
}
|
||||
|
||||
void HTTPServer::add_response(const std::string& path, const std::string& response, const std::string& content)
|
||||
{
|
||||
void HTTPServer::add_response(
|
||||
const std::string &path,
|
||||
const std::string &response,
|
||||
const std::string &content) {
|
||||
_request_response_pairs[path] = response + content;
|
||||
}
|
||||
|
||||
void HTTPServer::start()
|
||||
{
|
||||
void HTTPServer::start() {
|
||||
_thread.reset(new boost::thread(boost::bind(&HTTPServer::worker, this)));
|
||||
}
|
||||
|
||||
void HTTPServer::stop()
|
||||
{
|
||||
void HTTPServer::stop() {
|
||||
_done = true;
|
||||
_io_service.stop();
|
||||
|
||||
@@ -45,55 +40,52 @@ void HTTPServer::stop()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPServer::worker()
|
||||
{
|
||||
void HTTPServer::worker() {
|
||||
start_accept();
|
||||
|
||||
|
||||
_io_service.run();
|
||||
}
|
||||
|
||||
void HTTPServer::start_accept()
|
||||
{
|
||||
void HTTPServer::start_accept() {
|
||||
_cur_socket.reset(new boost::asio::ip::tcp::socket(_io_service));
|
||||
_acceptor.async_accept(*_cur_socket.get(), boost::bind(&HTTPServer::handle_accept, this, _cur_socket.get(), boost::asio::placeholders::error));
|
||||
_acceptor.async_accept(
|
||||
*_cur_socket.get(),
|
||||
boost::bind(
|
||||
&HTTPServer::handle_accept, this, _cur_socket.get(),
|
||||
boost::asio::placeholders::error));
|
||||
}
|
||||
|
||||
void HTTPServer::handle_accept(boost::asio::ip::tcp::socket* socket, const boost::system::error_code& error)
|
||||
{
|
||||
if (!error)
|
||||
{
|
||||
void HTTPServer::handle_accept(
|
||||
boost::asio::ip::tcp::socket *socket,
|
||||
const boost::system::error_code &error) {
|
||||
if (!error) {
|
||||
handle_connect(socket);
|
||||
}
|
||||
start_accept();
|
||||
}
|
||||
|
||||
void HTTPServer::handle_connect(boost::asio::ip::tcp::socket* socket)
|
||||
{
|
||||
void HTTPServer::handle_connect(boost::asio::ip::tcp::socket *socket) {
|
||||
boost::asio::streambuf buffer;
|
||||
size_t size = boost::asio::read_until(*socket, buffer, "\r\n\r\n");
|
||||
std::string request(size, 0);
|
||||
buffer.sgetn(&request[0], size);
|
||||
|
||||
|
||||
size_t start = request.find("GET ") + 4;
|
||||
size_t end = request.find(" HTTP/1.1\r\n");
|
||||
size_t url_args = request.find("?");
|
||||
if (url_args != std::string::npos)
|
||||
end = std::min(end, url_args);
|
||||
std::string request_path = request.substr(start, end-start);
|
||||
std::string request_path = request.substr(start, end - start);
|
||||
|
||||
std::map<std::string, std::string>::iterator request_match =
|
||||
_request_response_pairs.find(request_path);
|
||||
|
||||
if (request_match == _request_response_pairs.end())
|
||||
{
|
||||
std::map<std::string, std::string>::iterator request_match =
|
||||
_request_response_pairs.find(request_path);
|
||||
|
||||
if (request_match == _request_response_pairs.end()) {
|
||||
std::string response = "HTTP/1.0 404 NOT FOUND\r\n"
|
||||
"Content-Type: text/plain\r\n\r\n"
|
||||
"not found\r\n";
|
||||
boost::asio::write(*socket, boost::asio::buffer(response));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
boost::asio::write(*socket, boost::asio::buffer(request_match->second));
|
||||
}
|
||||
|
||||
@@ -102,4 +94,6 @@ void HTTPServer::handle_connect(boost::asio::ip::tcp::socket* socket)
|
||||
socket->close(ec);
|
||||
}
|
||||
|
||||
}}}
|
||||
} // namespace internal
|
||||
} // namespace config
|
||||
} // namespace bts
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <boost/asio/read_until.hpp>
|
||||
#include <boost/asio/streambuf.hpp>
|
||||
#include <boost/asio/write.hpp>
|
||||
#define BOOST_BIND_GLOBAL_PLACEHOLDERS
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
@@ -17,28 +18,31 @@
|
||||
#include <boost/asio/connect.hpp>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace bts {
|
||||
namespace config {
|
||||
namespace internal {
|
||||
|
||||
class HTTPServer
|
||||
{
|
||||
public:
|
||||
class HTTPServer {
|
||||
public:
|
||||
HTTPServer();
|
||||
unsigned int port() const;
|
||||
|
||||
void start();
|
||||
void add_response(const std::string& path, const std::string& response, const std::string& content);
|
||||
void add_response(
|
||||
const std::string &path,
|
||||
const std::string &response,
|
||||
const std::string &content);
|
||||
void stop();
|
||||
|
||||
private:
|
||||
private:
|
||||
void worker();
|
||||
void start_accept();
|
||||
void handle_accept(boost::asio::ip::tcp::socket*, const boost::system::error_code& error);
|
||||
void handle_connect(boost::asio::ip::tcp::socket*);
|
||||
void handle_accept(
|
||||
boost::asio::ip::tcp::socket *, const boost::system::error_code &error);
|
||||
void handle_connect(boost::asio::ip::tcp::socket *);
|
||||
|
||||
boost::asio::io_service _io_service;
|
||||
boost::asio::ip::tcp::acceptor _acceptor;
|
||||
@@ -46,8 +50,9 @@ private:
|
||||
std::map<std::string, std::string> _request_response_pairs;
|
||||
boost::scoped_ptr<boost::thread> _thread;
|
||||
bool _done;
|
||||
|
||||
};
|
||||
|
||||
}}} // end namespace
|
||||
} // namespace internal
|
||||
} // namespace config
|
||||
} // namespace bts
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,8 +1,8 @@
|
||||
#include "lib/utils/TempFile.h"
|
||||
|
||||
#include "../config.h"
|
||||
#include "../ConfigurationState.h"
|
||||
#include "../ConfigurationException.h"
|
||||
#include "../ConfigurationState.h"
|
||||
#include "../config.h"
|
||||
#include "lib/expression/ParserExceptions.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
#include "lib/utils/is_unittest_environment.h"
|
||||
@@ -19,9 +19,9 @@
|
||||
|
||||
#define URDL_HEADER_ONLY 1
|
||||
#define URDL_DISALE_SSL 1
|
||||
#include <urdl/url.hpp>
|
||||
#include <urdl/test/http_server.hpp>
|
||||
#include <catch/catch.hpp>
|
||||
#include <urdl/test/http_server.hpp>
|
||||
#include <urdl/url.hpp>
|
||||
|
||||
using namespace bts::config;
|
||||
using namespace bts::config::internal;
|
||||
@@ -31,124 +31,107 @@ using bts::config::test::Foo;
|
||||
using bts::config::test::FooGroup;
|
||||
using bts::config::test::StringTable;
|
||||
|
||||
|
||||
|
||||
namespace bts {
|
||||
int config_tests = 0;
|
||||
|
||||
TEST_CASE("Configuration Tests","[config]") {
|
||||
TEST_CASE("Configuration Tests", "[config]") {
|
||||
|
||||
bts::utils::internal::force_unittest_environment();
|
||||
|
||||
SECTION("basic_get_value_test")
|
||||
{
|
||||
initialize_for_test(
|
||||
"Foo { \n"
|
||||
" rule: \"true\"\n"
|
||||
" value {\n"
|
||||
" name: \"Name A\"\n"
|
||||
" id: 65\n"
|
||||
" email: \"test@example.com\"\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
SECTION("basic_get_value_test") {
|
||||
initialize_for_test("Foo { \n"
|
||||
" rule: \"true\"\n"
|
||||
" value {\n"
|
||||
" name: \"Name A\"\n"
|
||||
" id: 65\n"
|
||||
" email: \"test@example.com\"\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
|
||||
const Foo& foo = get<Foo>();
|
||||
const Foo &foo = get<Foo>();
|
||||
|
||||
REQUIRE(foo.name() == "Name A");
|
||||
REQUIRE(foo.id() == 65);
|
||||
REQUIRE(foo.email().Get(0) == "test@example.com");
|
||||
}
|
||||
|
||||
SECTION("default_value_test")
|
||||
{
|
||||
SECTION("default_value_test") {
|
||||
initialize_for_test(""); // Only loads defaults.conf
|
||||
|
||||
// Should load a Foo from testkeys.conf
|
||||
const Foo& foo = get<Foo>();
|
||||
const Foo &foo = get<Foo>();
|
||||
REQUIRE(foo.name() == "Blue Foo"); // from testkeys.proto
|
||||
REQUIRE(foo.id() == 1234); // from testkeys.proto
|
||||
REQUIRE(foo.id() == 1234); // from testkeys.proto
|
||||
REQUIRE(foo.email().size() > 0);
|
||||
REQUIRE(foo.email().Get(0) == "default@example.com"); // from testkeys.conf
|
||||
REQUIRE(
|
||||
foo.email().Get(0) == "default@example.com"); // from testkeys.conf
|
||||
}
|
||||
|
||||
SECTION("default_include_test")
|
||||
{
|
||||
SECTION("default_include_test") {
|
||||
// test defaults.conf with an include
|
||||
}
|
||||
|
||||
SECTION("invalid_key_type_test")
|
||||
{
|
||||
SECTION("invalid_key_type_test") {
|
||||
// Load an initialize with no files - OK all values default
|
||||
|
||||
const Foo& foo = get<Foo>(); // OK
|
||||
const Foo &foo = get<Foo>(); // OK
|
||||
REQUIRE(foo.name() == "Blue Foo");
|
||||
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
try {
|
||||
get<config::test::InvalidMessageType>(); // BAD
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
} catch (...) {
|
||||
error = true;
|
||||
}
|
||||
REQUIRE(error == true);
|
||||
}
|
||||
|
||||
SECTION("invalid_config_test2")
|
||||
{
|
||||
SECTION("invalid_config_test2") {
|
||||
utils::TempFile config_b;
|
||||
|
||||
*config_b.out() <<
|
||||
"Foo {\n"
|
||||
" value { \n"
|
||||
" name: \"bob\"\n"
|
||||
" id: 7319 \n"
|
||||
" }";
|
||||
*config_b.out() << "Foo {\n"
|
||||
" value { \n"
|
||||
" name: \"bob\"\n"
|
||||
" id: 7319 \n"
|
||||
" }";
|
||||
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
try {
|
||||
initialize_for_test("include: \"" + config_b.path() + "\"", false);
|
||||
}
|
||||
catch(const ConfigurationException& err)
|
||||
{
|
||||
} catch (const ConfigurationException &err) {
|
||||
std::string what = err.what();
|
||||
bts_assert(what.find("Expected identifier.") != std::string::npos);
|
||||
error = true;
|
||||
}
|
||||
REQUIRE(error == true);
|
||||
|
||||
}
|
||||
|
||||
// Tests that we can load using a File:/// url
|
||||
// Tests complex value load
|
||||
SECTION("file_url_test")
|
||||
{
|
||||
SECTION("file_url_test") {
|
||||
utils::TempFile config_a;
|
||||
utils::TempFile config_b;
|
||||
|
||||
*config_a.out() << "include: \"" << config_b.path() << "\"" << std::endl <<
|
||||
"Foo { \n"
|
||||
" rule: \"false\"\n"
|
||||
" value {\n"
|
||||
" name: \"Name A\"\n"
|
||||
" id: 65\n"
|
||||
" email: \"A@bluecg.com\"\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
*config_a.out() << "include: \"" << config_b.path() << "\"" << std::endl
|
||||
<< "Foo { \n"
|
||||
" rule: \"false\"\n"
|
||||
" value {\n"
|
||||
" name: \"Name A\"\n"
|
||||
" id: 65\n"
|
||||
" email: \"A@bluecg.com\"\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
|
||||
*config_b.out() <<
|
||||
"Foo {\n"
|
||||
" rule: \"true\"\n"
|
||||
" value {\n"
|
||||
" name: \"Name B\"\n"
|
||||
" id: 66 "
|
||||
" email: \"A@bluecg.com\" \n"
|
||||
" }}";
|
||||
*config_b.out() << "Foo {\n"
|
||||
" rule: \"true\"\n"
|
||||
" value {\n"
|
||||
" name: \"Name B\"\n"
|
||||
" id: 66 "
|
||||
" email: \"A@bluecg.com\" \n"
|
||||
" }}";
|
||||
|
||||
|
||||
// Get key Foo without loading any config files - this will show the default value
|
||||
// Get key Foo without loading any config files - this will show the
|
||||
// default value
|
||||
Foo foo = bts::config::get<Foo>();
|
||||
|
||||
REQUIRE(foo.name() == "Blue Foo");
|
||||
@@ -163,23 +146,20 @@ TEST_CASE("Configuration Tests","[config]") {
|
||||
REQUIRE(foo.id() == 66);
|
||||
}
|
||||
|
||||
SECTION("http_test")
|
||||
{
|
||||
SECTION("http_test") {
|
||||
HTTPServer server;
|
||||
std::string port = boost::lexical_cast<std::string>(server.port());
|
||||
std::string path = "/spark.conf";
|
||||
std::string response =
|
||||
"HTTP/1.0 200 OK\r\n"
|
||||
"Content-Type: text/plain\r\n\r\n";
|
||||
std::string content =
|
||||
"FooGroup {\n"
|
||||
" rule: \"true\"\n"
|
||||
" value {\n"
|
||||
" group: \"http_group\"\n"
|
||||
" foo {\n"
|
||||
" name: \"http\"\n"
|
||||
" id: 80\n"
|
||||
"}}}\n";
|
||||
std::string response = "HTTP/1.0 200 OK\r\n"
|
||||
"Content-Type: text/plain\r\n\r\n";
|
||||
std::string content = "FooGroup {\n"
|
||||
" rule: \"true\"\n"
|
||||
" value {\n"
|
||||
" group: \"http_group\"\n"
|
||||
" foo {\n"
|
||||
" name: \"http\"\n"
|
||||
" id: 80\n"
|
||||
"}}}\n";
|
||||
|
||||
server.add_response(path, response, content);
|
||||
server.start();
|
||||
@@ -190,7 +170,7 @@ TEST_CASE("Configuration Tests","[config]") {
|
||||
|
||||
server.stop();
|
||||
|
||||
const FooGroup& foogrp = get<FooGroup>();
|
||||
const FooGroup &foogrp = get<FooGroup>();
|
||||
|
||||
REQUIRE(foogrp.group() == "http_group");
|
||||
REQUIRE(foogrp.foo().name() == "http");
|
||||
@@ -198,41 +178,41 @@ TEST_CASE("Configuration Tests","[config]") {
|
||||
REQUIRE(get<System>().config_host() == "127.0.0.1");
|
||||
}
|
||||
|
||||
SECTION("http_folder_test")
|
||||
{
|
||||
SECTION("http_folder_test") {
|
||||
HTTPServer server;
|
||||
std::string port = boost::lexical_cast<std::string>(server.port());
|
||||
std::string config_url = "http://localhost:" + port + "/";
|
||||
std::string response =
|
||||
"HTTP/1.0 200 OK\r\n"
|
||||
"Content-Type: text/plain\r\n\r\n";
|
||||
std::string response = "HTTP/1.0 200 OK\r\n"
|
||||
"Content-Type: text/plain\r\n\r\n";
|
||||
|
||||
server.add_response("/spark.conf", response, "include: \"" + config_url + "other/\"");
|
||||
server.add_response("/testkeys.conf", response,
|
||||
"FooGroup {\n"
|
||||
" rule: \"true\"\n"
|
||||
" value {\n"
|
||||
" group: \"http_group\"\n"
|
||||
" foo {\n"
|
||||
" name: \"http\"\n"
|
||||
" id: 80\n"
|
||||
"}}}\n");
|
||||
|
||||
server.add_response("/other/spark.conf", response,
|
||||
"Foo {\n"
|
||||
" rule: \"true\"\n"
|
||||
" value: {\n"
|
||||
" name: \"included_value\"\n"
|
||||
" id: 4096\n"
|
||||
" }}\n");
|
||||
server.add_response(
|
||||
"/spark.conf", response, "include: \"" + config_url + "other/\"");
|
||||
server.add_response(
|
||||
"/testkeys.conf", response,
|
||||
"FooGroup {\n"
|
||||
" rule: \"true\"\n"
|
||||
" value {\n"
|
||||
" group: \"http_group\"\n"
|
||||
" foo {\n"
|
||||
" name: \"http\"\n"
|
||||
" id: 80\n"
|
||||
"}}}\n");
|
||||
|
||||
server.add_response(
|
||||
"/other/spark.conf", response,
|
||||
"Foo {\n"
|
||||
" rule: \"true\"\n"
|
||||
" value: {\n"
|
||||
" name: \"included_value\"\n"
|
||||
" id: 4096\n"
|
||||
" }}\n");
|
||||
|
||||
server.start();
|
||||
initialize_for_test("include: \"" + config_url + "\"");
|
||||
|
||||
server.stop();
|
||||
|
||||
const FooGroup& foogrp = get<FooGroup>();
|
||||
const FooGroup &foogrp = get<FooGroup>();
|
||||
|
||||
REQUIRE(foogrp.group() == "http_group");
|
||||
REQUIRE(foogrp.foo().name() == "http");
|
||||
@@ -242,44 +222,39 @@ TEST_CASE("Configuration Tests","[config]") {
|
||||
REQUIRE(get<Foo>().id() == 4096);
|
||||
}
|
||||
|
||||
|
||||
SECTION("test_rules")
|
||||
{
|
||||
initialize_for_test(
|
||||
"StringTable {\n"
|
||||
" value { \n"
|
||||
" entries: [\"foo\", \"bar\", \"baz\"] \n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"RuleRef { \n"
|
||||
" # use this rule of StringTable has a cow \n"
|
||||
" rule: \"'cow' in StringTable.entries\" \n"
|
||||
" value { \n"
|
||||
" a_string: \"AAA\"\n"
|
||||
" a_int: -1\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"RuleRef { \n"
|
||||
" rule: \"'baz' in StringTable.entries\" \n"
|
||||
" value { \n"
|
||||
" a_string: \"BBB\"\n"
|
||||
" a_int: 99\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"Foo { \n"
|
||||
" rule: \"RuleRef.a_int == 789\"\n"
|
||||
" value {\n"
|
||||
" name: \"A\"\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"Foo { \n"
|
||||
" rule: \"RuleRef.a_string == 'BBB'\"\n"
|
||||
" value {\n"
|
||||
" name: \"B\"\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
SECTION("test_rules") {
|
||||
initialize_for_test("StringTable {\n"
|
||||
" value { \n"
|
||||
" entries: [\"foo\", \"bar\", \"baz\"] \n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"RuleRef { \n"
|
||||
" # use this rule of StringTable has a cow \n"
|
||||
" rule: \"'cow' in StringTable.entries\" \n"
|
||||
" value { \n"
|
||||
" a_string: \"AAA\"\n"
|
||||
" a_int: -1\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"RuleRef { \n"
|
||||
" rule: \"'baz' in StringTable.entries\" \n"
|
||||
" value { \n"
|
||||
" a_string: \"BBB\"\n"
|
||||
" a_int: 99\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"Foo { \n"
|
||||
" rule: \"RuleRef.a_int == 789\"\n"
|
||||
" value {\n"
|
||||
" name: \"A\"\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"Foo { \n"
|
||||
" rule: \"RuleRef.a_string == 'BBB'\"\n"
|
||||
" value {\n"
|
||||
" name: \"B\"\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
|
||||
// What should happen:
|
||||
// Foo A
|
||||
@@ -297,286 +272,262 @@ TEST_CASE("Configuration Tests","[config]") {
|
||||
// success a_string == 'BBB'
|
||||
// return Foo B
|
||||
|
||||
const Foo& foo = get<Foo>();
|
||||
const Foo &foo = get<Foo>();
|
||||
REQUIRE(foo.name() == "B");
|
||||
}
|
||||
|
||||
SECTION("test_recursive_rules") {
|
||||
initialize_for_test("StringTable {\n"
|
||||
" rule: \"Foo.name == 'foo'\"\n"
|
||||
" value { \n"
|
||||
" entries: [\"foo\", \"bar\", \"baz\"] \n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"RuleRef { \n"
|
||||
" rule: \"'foo' in StringTable.entries\" \n"
|
||||
" value { \n"
|
||||
" a_string: \"AAA\"\n"
|
||||
" a_int: -1\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"Foo { \n"
|
||||
" rule: \"RuleRef.a_string == 'BBB'\"\n"
|
||||
" value {\n"
|
||||
" name: \"foo\"\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
|
||||
|
||||
SECTION("test_recursive_rules")
|
||||
{
|
||||
initialize_for_test(
|
||||
"StringTable {\n"
|
||||
" rule: \"Foo.name == 'foo'\"\n"
|
||||
" value { \n"
|
||||
" entries: [\"foo\", \"bar\", \"baz\"] \n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"RuleRef { \n"
|
||||
" rule: \"'foo' in StringTable.entries\" \n"
|
||||
" value { \n"
|
||||
" a_string: \"AAA\"\n"
|
||||
" a_int: -1\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"Foo { \n"
|
||||
" rule: \"RuleRef.a_string == 'BBB'\"\n"
|
||||
" value {\n"
|
||||
" name: \"foo\"\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
// Foo cannot be queried because RuleRef's rule requests StringTable which requests RuleRef
|
||||
// Foo cannot be queried because RuleRef's rule requests StringTable which
|
||||
// requests RuleRef
|
||||
bool error = false;
|
||||
try
|
||||
{
|
||||
try {
|
||||
get<Foo>();
|
||||
}
|
||||
catch(const expression::RecursivePropertyGetException&)
|
||||
{
|
||||
} catch (const expression::RecursivePropertyGetException &) {
|
||||
error = true;
|
||||
}
|
||||
REQUIRE(error);
|
||||
}
|
||||
|
||||
SECTION("test_nested_properties")
|
||||
{
|
||||
initialize_for_test(
|
||||
"RuleRef { \n"
|
||||
" value { \n"
|
||||
" nested {\n"
|
||||
" list_int: [7,8,9] \n"
|
||||
" nested {\n"
|
||||
" a_string: 'ABC' \n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"Foo { \n"
|
||||
" rule: \"RuleRef.nested.nested.a_string == 'ABC' and 9 in RuleRef.nested.list_int\"\n"
|
||||
" value {\n"
|
||||
" name: \"foo\"\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
SECTION("test_nested_properties") {
|
||||
initialize_for_test("RuleRef { \n"
|
||||
" value { \n"
|
||||
" nested {\n"
|
||||
" list_int: [7,8,9] \n"
|
||||
" nested {\n"
|
||||
" a_string: 'ABC' \n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"Foo { \n"
|
||||
" rule: \"RuleRef.nested.nested.a_string == 'ABC' "
|
||||
"and 9 in RuleRef.nested.list_int\"\n"
|
||||
" value {\n"
|
||||
" name: \"foo\"\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
|
||||
REQUIRE(get<Foo>().name() == "foo");
|
||||
}
|
||||
|
||||
SECTION("built_in_properties_test")
|
||||
{
|
||||
initialize_for_test(
|
||||
"Foo { \n"
|
||||
" rule: \"System.unittest_environment == true \"\n"
|
||||
" value {\n"
|
||||
" name: \"unit tests\"\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
);
|
||||
SECTION("built_in_properties_test") {
|
||||
initialize_for_test("Foo { \n"
|
||||
" rule: \"System.unittest_environment == true \"\n"
|
||||
" value {\n"
|
||||
" name: \"unit tests\"\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
|
||||
REQUIRE(get<Foo>().name() == "unit tests");
|
||||
}
|
||||
|
||||
SECTION("nonbreaking_space_test")
|
||||
{
|
||||
SECTION("nonbreaking_space_test") {
|
||||
bool parse_error = false;
|
||||
try
|
||||
{
|
||||
try {
|
||||
initialize_for_test(
|
||||
"Foo { "
|
||||
" value {\xA0\xA0 "
|
||||
" name: \"valid name\""
|
||||
" \xA0 }"
|
||||
"} ", false);
|
||||
}
|
||||
catch(const bts::config::ConfigurationException)
|
||||
{
|
||||
"Foo { "
|
||||
" value {\xA0\xA0 "
|
||||
" name: \"valid name\""
|
||||
" \xA0 }"
|
||||
"} ",
|
||||
false);
|
||||
} catch (const bts::config::ConfigurationException &) {
|
||||
parse_error = true;
|
||||
}
|
||||
REQUIRE(parse_error);
|
||||
}
|
||||
|
||||
SECTION("macro_bool_test")
|
||||
{
|
||||
initialize_for_test(
|
||||
"macro"
|
||||
"{"
|
||||
" name: \"bool\""
|
||||
" expression: \"'c' in ['a', 'b', 'c', 'd']\""
|
||||
"}"
|
||||
""
|
||||
"Foo"
|
||||
"{"
|
||||
" rule: \"$bool\""
|
||||
" value {"
|
||||
" name: 'good'"
|
||||
" }"
|
||||
"}"
|
||||
""
|
||||
"Foo"
|
||||
"{"
|
||||
" value {"
|
||||
" name: 'bad'"
|
||||
" }"
|
||||
"}"
|
||||
);
|
||||
SECTION("macro_bool_test") {
|
||||
initialize_for_test("macro"
|
||||
"{"
|
||||
" name: \"bool\""
|
||||
" expression: \"'c' in ['a', 'b', 'c', 'd']\""
|
||||
"}"
|
||||
""
|
||||
"Foo"
|
||||
"{"
|
||||
" rule: \"$bool\""
|
||||
" value {"
|
||||
" name: 'good'"
|
||||
" }"
|
||||
"}"
|
||||
""
|
||||
"Foo"
|
||||
"{"
|
||||
" value {"
|
||||
" name: 'bad'"
|
||||
" }"
|
||||
"}");
|
||||
|
||||
REQUIRE(config::get<Foo>().name() == "good");
|
||||
|
||||
}
|
||||
|
||||
SECTION("macro_list_test")
|
||||
{
|
||||
initialize_for_test(
|
||||
"macro"
|
||||
"{"
|
||||
" name: \"list\""
|
||||
" expression: \"['a', 'b', 'c', 'd']\""
|
||||
"}"
|
||||
""
|
||||
"Foo"
|
||||
"{"
|
||||
" rule: \"'a' in $list\""
|
||||
" value {"
|
||||
" name: 'good'"
|
||||
" }"
|
||||
"}"
|
||||
""
|
||||
"Foo"
|
||||
"{"
|
||||
" value {"
|
||||
" name: 'bad'"
|
||||
" }"
|
||||
"}"
|
||||
);
|
||||
SECTION("macro_list_test") {
|
||||
initialize_for_test("macro"
|
||||
"{"
|
||||
" name: \"list\""
|
||||
" expression: \"['a', 'b', 'c', 'd']\""
|
||||
"}"
|
||||
""
|
||||
"Foo"
|
||||
"{"
|
||||
" rule: \"'a' in $list\""
|
||||
" value {"
|
||||
" name: 'good'"
|
||||
" }"
|
||||
"}"
|
||||
""
|
||||
"Foo"
|
||||
"{"
|
||||
" value {"
|
||||
" name: 'bad'"
|
||||
" }"
|
||||
"}");
|
||||
|
||||
REQUIRE(config::get<Foo>().name() == "good");
|
||||
}
|
||||
|
||||
SECTION("fallback_test") {
|
||||
//HTTPServer main;
|
||||
// HTTPServer main;
|
||||
HTTPServer fallback;
|
||||
//std::string main_url = "http://localhost:" + boost::lexical_cast<std::string>(main.port()) + "/";
|
||||
// std::string main_url = "http://localhost:" +
|
||||
// boost::lexical_cast<std::string>(main.port()) + "/";
|
||||
std::string main_url = "http://does_not_exist:12345/";
|
||||
//main.stop();
|
||||
std::string fallback_url = "http://127.0.0.1:" + boost::lexical_cast<std::string>(fallback.port()) + "/";
|
||||
std::string response =
|
||||
"HTTP/1.0 200 OK\r\n"
|
||||
"Content-Type: text/plain\r\n\r\n";
|
||||
// main.stop();
|
||||
std::string fallback_url =
|
||||
"http://127.0.0.1:" +
|
||||
boost::lexical_cast<std::string>(fallback.port()) + "/";
|
||||
std::string response = "HTTP/1.0 200 OK\r\n"
|
||||
"Content-Type: text/plain\r\n\r\n";
|
||||
|
||||
std::string content =
|
||||
"FooGroup {\n"
|
||||
" value {\n"
|
||||
" group: \"http_group\"\n"
|
||||
" foo {\n"
|
||||
" name: \"http\"\n"
|
||||
" id: 80\n"
|
||||
"}}}\n";
|
||||
std::string content = "FooGroup {\n"
|
||||
" value {\n"
|
||||
" group: \"http_group\"\n"
|
||||
" foo {\n"
|
||||
" name: \"http\"\n"
|
||||
" id: 80\n"
|
||||
"}}}\n";
|
||||
|
||||
fallback.add_response("/spark.conf", response, content);
|
||||
|
||||
|
||||
fallback.start();
|
||||
initialize_for_test(
|
||||
"include: '" + main_url + "'\n"
|
||||
"fallback: '" + fallback_url + "'\n",false
|
||||
);
|
||||
"include: '" + main_url +
|
||||
"'\n"
|
||||
"fallback: '" +
|
||||
fallback_url + "'\n",
|
||||
false);
|
||||
fallback.stop();
|
||||
|
||||
|
||||
REQUIRE(get<FooGroup>().foo().name() == "http");
|
||||
REQUIRE(get<FooGroup>().foo().id() == 80);
|
||||
|
||||
}
|
||||
|
||||
SECTION("macro_definition_order_test") {
|
||||
// The $is_crusible test
|
||||
// o2_cme_enabled depends on Foo which has a rule which depends on is_crucible.
|
||||
// Eager evaluation caused a bug which would cause loading o2_cme_enabled to set is_crucible false. Case 3993
|
||||
initialize_for_test(
|
||||
"Foo {"
|
||||
" rule: '$is_crucible'"
|
||||
" value { name: 'cme_1u7_cert' }"
|
||||
"}"
|
||||
""
|
||||
"Foo {"
|
||||
" value { name: '' }"
|
||||
"}"
|
||||
""
|
||||
"macro {"
|
||||
" name: 'o2_cme_enabled'"
|
||||
" expression: \"Foo.name != ''\" "
|
||||
"}"
|
||||
""
|
||||
"macro {"
|
||||
" name: 'is_crucible'"
|
||||
" expression: 'true'"
|
||||
"}"
|
||||
);
|
||||
// o2_cme_enabled depends on Foo which has a rule which depends on
|
||||
// is_crucible. Eager evaluation caused a bug which would cause loading
|
||||
// o2_cme_enabled to set is_crucible false. Case 3993
|
||||
initialize_for_test("Foo {"
|
||||
" rule: '$is_crucible'"
|
||||
" value { name: 'cme_1u7_cert' }"
|
||||
"}"
|
||||
""
|
||||
"Foo {"
|
||||
" value { name: '' }"
|
||||
"}"
|
||||
""
|
||||
"macro {"
|
||||
" name: 'o2_cme_enabled'"
|
||||
" expression: \"Foo.name != ''\" "
|
||||
"}"
|
||||
""
|
||||
"macro {"
|
||||
" name: 'is_crucible'"
|
||||
" expression: 'true'"
|
||||
"}");
|
||||
|
||||
REQUIRE(get<Foo>().name() == "cme_1u7_cert");
|
||||
}
|
||||
|
||||
SECTION("repeated_value_order_preserved") {
|
||||
initialize_for_test(
|
||||
"Foo {"
|
||||
" value { name: 'edge-eharding' id: 80 }"
|
||||
"}"
|
||||
"StringTable {"
|
||||
" value {"
|
||||
" entries: 'http://'"
|
||||
" entries: @Foo.name"
|
||||
" entries: ':'"
|
||||
" entries: @Foo.id"
|
||||
" entries: '/risk'"
|
||||
" }"
|
||||
"}");
|
||||
initialize_for_test("Foo {"
|
||||
" value { name: 'edge-eharding' id: 80 }"
|
||||
"}"
|
||||
"StringTable {"
|
||||
" value {"
|
||||
" entries: 'http://'"
|
||||
" entries: @Foo.name"
|
||||
" entries: ':'"
|
||||
" entries: @Foo.id"
|
||||
" entries: '/risk'"
|
||||
" }"
|
||||
"}");
|
||||
std::string result;
|
||||
for (const auto& part : get<StringTable>().entries()) {
|
||||
for (const auto &part : get<StringTable>().entries()) {
|
||||
result += part;
|
||||
}
|
||||
REQUIRE(result == "http://edge-eharding:80/risk");
|
||||
}
|
||||
|
||||
SECTION("string_concat_test") {
|
||||
initialize_for_test(
|
||||
"Ports {\n"
|
||||
" value { \n"
|
||||
" config_port: 80 \n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"RuleRef { \n"
|
||||
" value { \n"
|
||||
" a_string: \"localhost\"\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"macro{\n"
|
||||
" name: 'list'\n"
|
||||
" expression: \"['http://', RuleRef.a_string, ':', Ports.config_port, '/risk']\"\n"
|
||||
"}"
|
||||
"StringTable {\n"
|
||||
"value {\n"
|
||||
" entries: 'http://'\n"
|
||||
" entries: @RuleRef.a_string\n"
|
||||
" entries: ':'\n"
|
||||
" entries: @Ports.config_port\n"
|
||||
" entries: '/risk'\n"
|
||||
"}}\n"
|
||||
"Foo { \n"
|
||||
" value {\n"
|
||||
" name: $list\n"
|
||||
" url: @StringTable.entries \n"
|
||||
" }\n"
|
||||
"}"
|
||||
);
|
||||
initialize_for_test("Ports {\n"
|
||||
" value { \n"
|
||||
" config_port: 80 \n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"RuleRef { \n"
|
||||
" value { \n"
|
||||
" a_string: \"localhost\"\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"macro{\n"
|
||||
" name: 'list'\n"
|
||||
" expression: \"['http://', RuleRef.a_string, ':', "
|
||||
"Ports.config_port, '/risk']\"\n"
|
||||
"}"
|
||||
"StringTable {\n"
|
||||
"value {\n"
|
||||
" entries: 'http://'\n"
|
||||
" entries: @RuleRef.a_string\n"
|
||||
" entries: ':'\n"
|
||||
" entries: @Ports.config_port\n"
|
||||
" entries: '/risk'\n"
|
||||
"}}\n"
|
||||
"Foo { \n"
|
||||
" value {\n"
|
||||
" name: $list\n"
|
||||
" url: @StringTable.entries \n"
|
||||
" }\n"
|
||||
"}");
|
||||
|
||||
auto foo = config::get<Foo>();
|
||||
auto expected = "http://localhost:80/risk";
|
||||
REQUIRE(foo.name() == expected);
|
||||
REQUIRE(foo.url() == expected);
|
||||
}
|
||||
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace bts
|
||||
@@ -52,7 +52,7 @@ class FIXEncodingStream {
|
||||
auto msg_offset = _buffer.size();
|
||||
|
||||
_current_msg = FIXFragment(_buffer);
|
||||
_begin_string_bm = _current_msg.add<fix::BeginString>("FIX.4.2");
|
||||
_begin_string_bm = _current_msg.add<fix::BeginString>(std::string_view {"FIX.4.2"});
|
||||
_body_length_bm = _current_msg.add<fix::BodyLength>(0, 6);
|
||||
|
||||
char mt_encoding[4];
|
||||
|
||||
@@ -85,6 +85,7 @@ typedef StringField<307> UnderlyingSecurityDesc;
|
||||
typedef StringField<336> TradingSessionID;
|
||||
typedef StringField<35> MsgType;
|
||||
typedef StringField<37> OrderID;
|
||||
typedef BigIntField<37> OrderIDu64;
|
||||
typedef StringField<41> OrigClOrdID;
|
||||
typedef StringField<440> ClearingAccount;
|
||||
typedef StringField<48> SecurityID;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <memory>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <string_view>
|
||||
|
||||
#include "lib/jetfix/codec/ReaderCursor.h"
|
||||
#include "lib/utils/meta_programming.h"
|
||||
#include "lib/utils/datetime.h"
|
||||
@@ -203,6 +205,13 @@ public:
|
||||
static std::pair<uint32_t,uint32_t> write (char*buffer,std::string const &str)
|
||||
{return write (buffer,str.data (),str.size ());}
|
||||
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
static uint32_t max_value_size (std::string_view const&str) {return str.size ();}
|
||||
static std::pair<uint32_t,uint32_t> write (char*buffer,std::string_view const &str)
|
||||
{return write (buffer,str.data (),str.size ());}
|
||||
#endif
|
||||
|
||||
static std::pair<uint32_t,uint32_t> write (char*buffer,const char*str,uint32_t sz)
|
||||
{
|
||||
memcpy (buffer,str,sz);
|
||||
|
||||
@@ -23,9 +23,9 @@ SocketConnection::SocketConnection(bts::config::JetFIX::Connection const &cfg,
|
||||
: _fd(-1), _cfg(cfg), _log(cfg.log_fix_stream()), _in_log(), _out_log(),
|
||||
_perf_log(perf_log) {
|
||||
if (_log) {
|
||||
_in_log.open(std::string("/tmp/fix_raw_read_log_") + session_name(cfg),
|
||||
_in_log.open(std::string("/tmp/fix_raw_read_log_") + session_name(cfg).as_string,
|
||||
std::ios_base::app);
|
||||
_out_log.open(std::string("/tmp/fix_raw_write_log_") + session_name(cfg),
|
||||
_out_log.open(std::string("/tmp/fix_raw_write_log_") + session_name(cfg).as_string,
|
||||
std::ios_base::app);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -788,7 +788,7 @@ OutFIXPtr make_logon(uint32_t seq_num, uint32_t last_seq_num_processed,
|
||||
{
|
||||
std::string sender_comp_id = session_cfg.sender_subid();
|
||||
buffer.add<ICEApplicationSystemName>(sender_comp_id);
|
||||
buffer.add<ICEApplicationSystemVersion>("1.0");
|
||||
buffer.add<ICEApplicationSystemVersion>(std::string_view{"1.0"});
|
||||
buffer.add<ICEApplicationSystemVendor>(sender_comp_id);
|
||||
|
||||
buffer.add<UserName>(session_cfg.user_name());
|
||||
@@ -797,19 +797,18 @@ OutFIXPtr make_logon(uint32_t seq_num, uint32_t last_seq_num_processed,
|
||||
buffer.add<EncryptMethod>(0);
|
||||
buffer.add<ICEStrategyPreference>(1);
|
||||
buffer.add<ICETimeStampPreference>(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.add<ApplicationSystemName>(application);
|
||||
buffer.add<ApplicationSystemVersion>("1.0");
|
||||
buffer.add<ApplicationSystemVendor>("BTS");
|
||||
} else {
|
||||
buffer.add<ApplicationSystemName>(std::string_view{application});
|
||||
buffer.add<ApplicationSystemVersion>(std::string_view{"1.0"});
|
||||
buffer.add<ApplicationSystemVendor>(std::string_view{"BTS"});
|
||||
|
||||
if (session_cfg.has_trading_session_id()) {
|
||||
buffer.add<fix::NoTradingSessions>(1);
|
||||
buffer.add<fix::TradingSessionID>(session_cfg.trading_session_id());
|
||||
}
|
||||
if (session_cfg.has_udf_support_indicator())
|
||||
buffer.add<fix::UDFSupportIndicator>(session_cfg.udf_support_indicator());
|
||||
buffer.add<fix::UDFSupportIndicator>(
|
||||
session_cfg.udf_support_indicator());
|
||||
|
||||
if (session_cfg.use_cme_secure_logon()) {
|
||||
bts_assert(session_cfg.sender_compid().size() >= 3);
|
||||
@@ -820,25 +819,24 @@ OutFIXPtr make_logon(uint32_t seq_num, uint32_t last_seq_num_processed,
|
||||
std::string last_seq_num_str(9, ' ');
|
||||
i32_toa(last_seq_num_processed, &last_seq_num_str[0], 9);
|
||||
auto ld = glbx::calculate_hmac(
|
||||
session_id, seq_num_str, session_cfg.sender_compid(),
|
||||
session_cfg.sender_subid(), time_str, session_cfg.target_subid(),
|
||||
std::to_string(session_cfg.seconds_between_hbs()),
|
||||
session_cfg.sender_locationid(), last_seq_num_str, application, "1.0",
|
||||
"BTS");
|
||||
#ifndef BTS_EDGE
|
||||
LOG(Jetfix, Info, "Canonical string for secure logon: {}", ld.canonical);
|
||||
#endif
|
||||
session_id, seq_num_str, session_cfg.sender_compid(),
|
||||
session_cfg.sender_subid(), time_str, session_cfg.target_subid(),
|
||||
std::to_string(session_cfg.seconds_between_hbs()),
|
||||
session_cfg.sender_locationid(), last_seq_num_str, application,
|
||||
"1.0", "BTS");
|
||||
#ifndef BTS_EDGE
|
||||
LOG(Jetfix, Info, "Canonical string for secure logon: {}",
|
||||
ld.canonical);
|
||||
#endif
|
||||
buffer.add<EncodedTextLen>(ld.access_key.size());
|
||||
buffer.add<EncodedText>(ld.access_key);
|
||||
buffer.add<EncryptedPasswordMethod>("CME-1-SHA-256");
|
||||
buffer.add<EncryptedPasswordMethod>(std::string_view{"CME-1-SHA-256"});
|
||||
buffer.add<EncryptedPasswordLen>(ld.signature.size());
|
||||
buffer.add<EncryptedPassword>(ld.signature);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
buffer.add<RawDataLength>(session_cfg.raw_data().size());
|
||||
buffer.add<RawData>(session_cfg.raw_data());
|
||||
if(session_cfg.user_name() != "")
|
||||
if (session_cfg.user_name() != "")
|
||||
buffer.add<UserName>(session_cfg.user_name());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ void load_seq_nums(std::string const &path, uint32_t *last_seq_num,
|
||||
FIXFileStore::FIXFileStore(config::JetFIX::Connection const &cfg,
|
||||
std::string base_path)
|
||||
: me(new PImpl(cfg)) {
|
||||
auto sn = session_name(cfg);
|
||||
auto sn = session_name(cfg).as_string;
|
||||
me->active = sn.size() > 0;
|
||||
if (me->active) {
|
||||
|
||||
|
||||
@@ -75,49 +75,55 @@ bool in_session (datetime::PTime const &ref_date,
|
||||
return closest_earlier_end<closest_earlier_start;
|
||||
}
|
||||
|
||||
std::string session_name_from_ptime (datetime::PTime t,
|
||||
SessionName session_name_from_ptime (datetime::PTime t,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end)
|
||||
{
|
||||
std::string result (10,' ');
|
||||
SessionName result;
|
||||
result.as_string = std::string(10,' ');
|
||||
auto start_of_session = t;
|
||||
|
||||
if (time_of_day_start > time_of_day_end &&
|
||||
start_of_session.time_of_day () <= time_of_day_end)
|
||||
start_of_session -= boost::gregorian::date_duration (1);
|
||||
|
||||
sprintf (&result[0], "%04d-%02d-%02d",
|
||||
|
||||
using namespace boost::posix_time;
|
||||
ptime epoch(boost::gregorian::date(1970,1,1));
|
||||
ptime session_start_date(start_of_session.date());
|
||||
result.as_uint64_t = (session_start_date - epoch).total_milliseconds();
|
||||
|
||||
sprintf (&(result.as_string[0]), "%04d-%02d-%02d",
|
||||
(unsigned short) start_of_session.date ().year (),
|
||||
start_of_session.date ().month ().as_number (),
|
||||
start_of_session.date ().day ().as_number ());
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string session_name (datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday_start,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::gregorian::greg_weekday weekday_end,
|
||||
boost::posix_time::time_duration time_of_day_end)
|
||||
SessionName session_name (datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday_start,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::gregorian::greg_weekday weekday_end,
|
||||
boost::posix_time::time_duration time_of_day_end)
|
||||
{
|
||||
if (in_session (ref_date,weekday_start,time_of_day_start,weekday_end,time_of_day_end))
|
||||
return session_name_from_ptime (closest_before (ref_date,weekday_start,time_of_day_start),
|
||||
boost::posix_time::time_duration(0, 0, 0),
|
||||
boost::posix_time::time_duration(0, 0, 1));
|
||||
else
|
||||
return std::string ();
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string session_name (datetime::PTime const &ref_date,
|
||||
SessionName session_name (datetime::PTime const &ref_date,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end)
|
||||
{
|
||||
if (in_session (ref_date,time_of_day_start,time_of_day_end))
|
||||
return session_name_from_ptime (ref_date, time_of_day_start, time_of_day_end);
|
||||
else
|
||||
return "";
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string session_name (config::JetFIX::Connection const &session_cfg)
|
||||
SessionName session_name (config::JetFIX::Connection const &session_cfg)
|
||||
{
|
||||
auto now = datetime::local_now ();
|
||||
|
||||
@@ -134,7 +140,6 @@ std::string session_name (config::JetFIX::Connection const &session_cfg)
|
||||
parse_time (session_cfg.end_time ()));
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/config/protos/jetfix.pb.h"
|
||||
#include "lib/utils/datetime.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "lib/utils/datetime.h"
|
||||
#include "lib/config/protos/jetfix.pb.h"
|
||||
|
||||
namespace boost {
|
||||
namespace gregorian {
|
||||
@@ -11,39 +11,45 @@ class greg_weekday;
|
||||
}
|
||||
namespace posix_time {
|
||||
class time_duration;
|
||||
}}
|
||||
|
||||
}
|
||||
} // namespace boost
|
||||
|
||||
namespace bts {
|
||||
namespace jetfix {
|
||||
|
||||
boost::gregorian::greg_weekday parse_weekday (std::string weekday_str);
|
||||
bool parse_time (std::string const &time_str,boost::posix_time::time_duration *out);
|
||||
boost::gregorian::greg_weekday parse_weekday(std::string weekday_str);
|
||||
bool parse_time(std::string const &time_str,
|
||||
boost::posix_time::time_duration *out);
|
||||
|
||||
datetime::PTime closest_before (datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday,
|
||||
boost::posix_time::time_duration time_of_day);
|
||||
datetime::PTime closest_before(datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday,
|
||||
boost::posix_time::time_duration time_of_day);
|
||||
|
||||
bool in_session (datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday_start,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::gregorian::greg_weekday weekday_end,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
bool in_session(datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday_start,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::gregorian::greg_weekday weekday_end,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
|
||||
bool in_session (datetime::PTime const &ref_date,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
bool in_session(datetime::PTime const &ref_date,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
|
||||
std::string session_name (datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday_start,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::gregorian::greg_weekday weekday_end,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
struct SessionName {
|
||||
std::string as_string;
|
||||
uint64_t as_uint64_t;
|
||||
bool empty() const {return as_string.empty();};
|
||||
};
|
||||
|
||||
std::string session_name (datetime::PTime const &ref_date,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
SessionName session_name(datetime::PTime const &ref_date,
|
||||
boost::gregorian::greg_weekday weekday_start,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::gregorian::greg_weekday weekday_end,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
SessionName session_name(datetime::PTime const &ref_date,
|
||||
boost::posix_time::time_duration time_of_day_start,
|
||||
boost::posix_time::time_duration time_of_day_end);
|
||||
SessionName session_name(config::JetFIX::Connection const &session_cfg);
|
||||
|
||||
std::string session_name (config::JetFIX::Connection const &session_cfg);
|
||||
|
||||
}}
|
||||
} // namespace jetfix
|
||||
} // namespace bts
|
||||
@@ -81,9 +81,9 @@ TEST_CASE ("JetFIX Field2Tests", "[jetfix]")
|
||||
std::string out (20, ' ');
|
||||
typedef StringField<123> Field;
|
||||
|
||||
REQUIRE(Field::max_value_size ("hello")==5);
|
||||
REQUIRE(Field::max_value_size (std::string_view{"hello"})==5);
|
||||
|
||||
auto result = Field::write (&out[0],"hello");
|
||||
auto result = Field::write (&out[0],std::string_view{"hello"});
|
||||
REQUIRE (result.first==5);
|
||||
REQUIRE (result.second=='h'+'e'+'l'+'l'+'o');
|
||||
REQUIRE (out.compare (0,5,"hello") == 0);
|
||||
@@ -112,7 +112,7 @@ TEST_CASE ("JetFIX FIXFragmentTests" , "[jetfix]")
|
||||
FIXFragment g (0);
|
||||
g.add<CharField<1>> ('a');
|
||||
g.add<FloatField<2>> (1.2,-1,6);
|
||||
g.add<StringField<3>> ("hello");
|
||||
g.add<StringField<3>> (std::string_view{"hello"});
|
||||
g.add<IntField<4>> (123,3);
|
||||
const char*t_s = "20150427-19:05:18.922";
|
||||
g.add<TimeField<5>> (datetime::parse_FIX_timestamp (t_s));
|
||||
@@ -141,14 +141,14 @@ TEST_CASE ("JetFIX FIXFragmentTests" , "[jetfix]")
|
||||
FIXFragment g;
|
||||
auto c_bm = g.add<CharField<1>> ('a');
|
||||
auto f_bm = g.add<FloatField<2>> (1.2,-1,6);
|
||||
auto s_bm = g.add<StringField<3>> ("hello");
|
||||
auto s_bm = g.add<StringField<3>> (std::string_view{"hello"});
|
||||
auto i_bm = g.add<IntField<4>> (123,3);
|
||||
auto t_bm = g.add<TimeField<5>> (datetime::parse_FIX_timestamp (t_s1));
|
||||
auto b_bm = g.add<BoolField<6>> (true);
|
||||
|
||||
g.overwrite (c_bm,'b');
|
||||
g.overwrite (f_bm,1.3,-1,6);
|
||||
g.overwrite (s_bm,"olleh");
|
||||
g.overwrite (s_bm,std::string_view {"olleh"});
|
||||
g.overwrite (i_bm,321,3);
|
||||
g.overwrite (t_bm,(datetime::parse_FIX_timestamp (t_s2)));
|
||||
g.overwrite (b_bm,false);
|
||||
@@ -172,11 +172,11 @@ TEST_CASE ("JetFIX FIXFragmentTests" , "[jetfix]")
|
||||
FIXFragment g1;;
|
||||
g1.add<CharField<1>> ('a');
|
||||
g1.add<FloatField<2>> (1.2,-1,6);
|
||||
g1.add<StringField<3>> ("hello");
|
||||
g1.add<StringField<3>> (std::string_view{"hello"});
|
||||
auto chk1 = g1.checksum ();
|
||||
|
||||
FIXFragment g2;
|
||||
g2.add<StringField<4>> ("goodbye");
|
||||
g2.add<StringField<4>> (std::string_view{"goodbye"});
|
||||
g2.add<IntField<5>> (321,3);
|
||||
auto chk2 = g2.checksum ();
|
||||
|
||||
|
||||
@@ -6,279 +6,270 @@
|
||||
#include "lib/jetfix/common/OutFIXPtr.h"
|
||||
#include "lib/jetfix/store/FIXFileStore.h"
|
||||
#include "lib/jetfix/store/session_name.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/utils/TempDir.h"
|
||||
#include "lib/utils/TimeStamp.h"
|
||||
#include "lib/utils/datetime.h"
|
||||
#include "lib/logging/logging.h"
|
||||
|
||||
#include <boost/date_time.hpp>
|
||||
#include <boost/date_time/gregorian/gregorian.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/date_time.hpp>
|
||||
|
||||
namespace bts {
|
||||
namespace jetfix {
|
||||
|
||||
TEST_CASE ("JetFIX SessionNameTests", "[jetfix]")
|
||||
{
|
||||
SECTION("greg_weekday_works")
|
||||
{
|
||||
const char*days [] = {"sun","Monday","tuesday","Wedn","Thursday","Friday","sat"};
|
||||
TEST_CASE("JetFIX SessionNameTests", "[jetfix]") {
|
||||
SECTION("greg_weekday_works") {
|
||||
const char *days[] = {"sun", "Monday", "tuesday", "Wedn",
|
||||
"Thursday", "Friday", "sat"};
|
||||
|
||||
int i =0;
|
||||
int i = 0;
|
||||
for (auto d : days)
|
||||
REQUIRE (parse_weekday (d)==boost::gregorian::greg_weekday (i++));
|
||||
}
|
||||
|
||||
SECTION("closest_before_works")
|
||||
{
|
||||
auto same_day_before = closest_before (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(16, 59, 59));
|
||||
REQUIRE (datetime::FIX_date_time_string (same_day_before)=="20150717-16:59:59");
|
||||
|
||||
auto same_day_after = closest_before (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(17,0,1));
|
||||
REQUIRE (datetime::FIX_date_time_string (same_day_after)=="20150710-17:00:01");
|
||||
|
||||
auto another_day_same_week = closest_before (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::gregorian::Thursday,
|
||||
boost::posix_time::time_duration(16, 59, 59));
|
||||
REQUIRE (datetime::FIX_date_time_string (another_day_same_week)=="20150716-16:59:59");
|
||||
|
||||
auto another_day_previous_week = closest_before (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::gregorian::Saturday,
|
||||
boost::posix_time::time_duration(16, 59, 59));
|
||||
REQUIRE (datetime::FIX_date_time_string (another_day_previous_week)=="20150711-16:59:59");
|
||||
|
||||
REQUIRE(parse_weekday(d) == boost::gregorian::greg_weekday(i++));
|
||||
}
|
||||
|
||||
SECTION("in_session_works")
|
||||
{
|
||||
REQUIRE (in_session (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::gregorian::Sunday,
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(17, 0, 1)));
|
||||
SECTION("closest_before_works") {
|
||||
auto same_day_before =
|
||||
closest_before(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(16, 59, 59));
|
||||
REQUIRE(datetime::FIX_date_time_string(same_day_before) ==
|
||||
"20150717-16:59:59");
|
||||
|
||||
REQUIRE (!in_session (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::gregorian::Sunday,
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(16, 59, 59)));
|
||||
auto same_day_after = closest_before(
|
||||
datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::gregorian::Friday, boost::posix_time::time_duration(17, 0, 1));
|
||||
REQUIRE(datetime::FIX_date_time_string(same_day_after) ==
|
||||
"20150710-17:00:01");
|
||||
|
||||
REQUIRE (in_session (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
boost::posix_time::time_duration(17, 59, 59)));
|
||||
auto another_day_same_week =
|
||||
closest_before(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::gregorian::Thursday,
|
||||
boost::posix_time::time_duration(16, 59, 59));
|
||||
REQUIRE(datetime::FIX_date_time_string(another_day_same_week) ==
|
||||
"20150716-16:59:59");
|
||||
|
||||
REQUIRE (!in_session (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::posix_time::time_duration(0,0,0),
|
||||
boost::posix_time::time_duration(16, 0,0)));
|
||||
|
||||
REQUIRE (in_session (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)));
|
||||
|
||||
REQUIRE (!in_session (datetime::make_ptime (2015,7,17,17,47,0,0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)));
|
||||
auto another_day_previous_week =
|
||||
closest_before(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::gregorian::Saturday,
|
||||
boost::posix_time::time_duration(16, 59, 59));
|
||||
REQUIRE(datetime::FIX_date_time_string(another_day_previous_week) ==
|
||||
"20150711-16:59:59");
|
||||
}
|
||||
|
||||
SECTION("session_name_works")
|
||||
{
|
||||
REQUIRE (session_name (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::gregorian::Sunday,
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(17, 0, 1)) ==
|
||||
"2015-07-12");
|
||||
SECTION("in_session_works") {
|
||||
REQUIRE(in_session(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::gregorian::Sunday,
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(17, 0, 1)));
|
||||
|
||||
REQUIRE (session_name (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::gregorian::Sunday,
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(16, 59, 59)) == "");
|
||||
REQUIRE(!in_session(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::gregorian::Sunday,
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
|
||||
REQUIRE (session_name (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
boost::posix_time::time_duration(17, 59, 59)) ==
|
||||
"2015-07-17");
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(16, 59, 59)));
|
||||
|
||||
REQUIRE (session_name (datetime::make_ptime (2015,7,17,18,0,0,0),
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
boost::posix_time::time_duration(17, 59, 59)) ==
|
||||
"");
|
||||
REQUIRE(in_session(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
boost::posix_time::time_duration(17, 59, 59)));
|
||||
|
||||
REQUIRE (session_name (datetime::make_ptime (2015,7,17,17,0,0,0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)) ==
|
||||
"2015-07-16");
|
||||
REQUIRE(!in_session(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::posix_time::time_duration(0, 0, 0),
|
||||
boost::posix_time::time_duration(16, 0, 0)));
|
||||
|
||||
REQUIRE (session_name (datetime::make_ptime (2015,7,17,17,51,0,0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)) ==
|
||||
"2015-07-17");
|
||||
|
||||
REQUIRE (session_name (datetime::make_ptime (2015,7,17,17,47,0,0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)) ==
|
||||
"");
|
||||
REQUIRE(in_session(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)));
|
||||
|
||||
REQUIRE(!in_session(datetime::make_ptime(2015, 7, 17, 17, 47, 0, 0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)));
|
||||
}
|
||||
|
||||
SECTION("session_name_works") {
|
||||
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::gregorian::Sunday,
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(17, 0, 1)).as_string ==
|
||||
"2015-07-12");
|
||||
|
||||
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::gregorian::Sunday,
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
|
||||
boost::gregorian::Friday,
|
||||
boost::posix_time::time_duration(16, 59, 59)).as_string == "");
|
||||
|
||||
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
boost::posix_time::time_duration(17, 59, 59)).as_string ==
|
||||
"2015-07-17");
|
||||
|
||||
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 18, 0, 0, 0),
|
||||
boost::posix_time::time_duration(16, 59, 59),
|
||||
boost::posix_time::time_duration(17, 59, 59)).as_string == "");
|
||||
|
||||
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)).as_string ==
|
||||
"2015-07-16");
|
||||
|
||||
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 17, 51, 0, 0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)).as_string ==
|
||||
"2015-07-17");
|
||||
|
||||
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 17, 47, 0, 0),
|
||||
boost::posix_time::time_duration(17, 50, 59),
|
||||
boost::posix_time::time_duration(17, 45, 59)).as_string == "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE ("JetFIX FileStoreTests", "[jetfix]")
|
||||
{
|
||||
SECTION("empty_store_works")
|
||||
{
|
||||
TEST_CASE("JetFIX FileStoreTests", "[jetfix]") {
|
||||
SECTION("empty_store_works") {
|
||||
config::JetFIX::Connection c;
|
||||
c.set_name ("test");
|
||||
c.set_sender_compid ("CME");
|
||||
c.set_sender_subid ("G");
|
||||
c.set_target_compid ("1U7001N");
|
||||
c.set_target_subid ("BLUESTREAM");
|
||||
c.set_name("test");
|
||||
c.set_sender_compid("CME");
|
||||
c.set_sender_subid("G");
|
||||
c.set_target_compid("1U7001N");
|
||||
c.set_target_subid("BLUESTREAM");
|
||||
|
||||
c.set_start_time ("00:00:00");
|
||||
c.set_end_time ("23:59:59");
|
||||
c.set_start_time("00:00:00");
|
||||
c.set_end_time("23:59:59");
|
||||
|
||||
utils::TempDir td;
|
||||
|
||||
FIXFileStore fs (c,td.name ());
|
||||
REQUIRE (fs.session_active ());
|
||||
REQUIRE (fs.replay ().size ()==0);
|
||||
REQUIRE (fs.last_seq_num ()==0);
|
||||
REQUIRE (fs.last_seq_num_processed ()==0);
|
||||
|
||||
FIXFileStore fs(c, td.name());
|
||||
REQUIRE(fs.session_active());
|
||||
REQUIRE(fs.replay().size() == 0);
|
||||
REQUIRE(fs.last_seq_num() == 0);
|
||||
REQUIRE(fs.last_seq_num_processed() == 0);
|
||||
}
|
||||
|
||||
SECTION("in_msg_is_stored")
|
||||
{
|
||||
auto td = std::make_shared<utils::TempDir> ();
|
||||
SECTION("in_msg_is_stored") {
|
||||
auto td = std::make_shared<utils::TempDir>();
|
||||
config::JetFIX::Connection c;
|
||||
c.set_name ("test");
|
||||
c.set_sender_compid ("CME");
|
||||
c.set_sender_subid ("G");
|
||||
c.set_target_compid ("1U7001N");
|
||||
c.set_target_subid ("BLUESTREAM");
|
||||
c.set_name("test");
|
||||
c.set_sender_compid("CME");
|
||||
c.set_sender_subid("G");
|
||||
c.set_target_compid("1U7001N");
|
||||
c.set_target_subid("BLUESTREAM");
|
||||
|
||||
c.set_start_time ("00:00:00");
|
||||
c.set_end_time ("23:59:59");
|
||||
c.set_start_time("00:00:00");
|
||||
c.set_end_time("23:59:59");
|
||||
|
||||
FIXEncodingStream stream (c);
|
||||
auto &buf = stream.new_msg (MessageTypes::Logon);
|
||||
buf.add<fix::TargetLocationID> ("US,NC");
|
||||
buf.add<fix::EncryptMethod> (0);
|
||||
FIXEncodingStream stream(c);
|
||||
auto &buf = stream.new_msg(MessageTypes::Logon);
|
||||
buf.add<fix::TargetLocationID>(std::string_view{"US,NC"});
|
||||
buf.add<fix::EncryptMethod>(0);
|
||||
buf.add<fix::HeartBtInt>(30);
|
||||
buf.add<fix::ApplicationSystemName> ("O2");
|
||||
buf.add<fix::ApplicationSystemVersion> ("1.0");
|
||||
buf.add<fix::ApplicationSystemVendor> ("BTS");
|
||||
stream.close ();
|
||||
stream.stamp (2,3,datetime::FIX_timestamp (datetime::now ()));
|
||||
auto fix = stream.to_str ();
|
||||
|
||||
buf.add<fix::ApplicationSystemName>(std::string_view{"O2"});
|
||||
buf.add<fix::ApplicationSystemVersion>(std::string_view{"1.0"});
|
||||
buf.add<fix::ApplicationSystemVendor>(std::string_view{"BTS"});
|
||||
stream.close();
|
||||
stream.stamp(2, 3, datetime::FIX_timestamp(datetime::now()));
|
||||
auto fix = stream.to_str();
|
||||
|
||||
{
|
||||
FIXFileStore fs (c,td->name ());
|
||||
fs.store (InMsgBuffer (fix));
|
||||
fs.set_last_msg_processed (3);
|
||||
FIXFileStore fs(c, td->name());
|
||||
fs.store(InMsgBuffer(fix));
|
||||
fs.set_last_msg_processed(3);
|
||||
}
|
||||
|
||||
FIXFileStore fs (c,td->name ());
|
||||
auto replay = fs.replay ();
|
||||
REQUIRE (replay.size ()==1);
|
||||
REQUIRE (replay[0].type ()==MessageTypes::Logon);
|
||||
REQUIRE (replay[0].to_str ()==fix);
|
||||
REQUIRE (fs.last_seq_num ()==0);
|
||||
REQUIRE (fs.last_seq_num_processed ()==3);
|
||||
FIXFileStore fs(c, td->name());
|
||||
auto replay = fs.replay();
|
||||
REQUIRE(replay.size() == 1);
|
||||
REQUIRE(replay[0].type() == MessageTypes::Logon);
|
||||
REQUIRE(replay[0].to_str() == fix);
|
||||
REQUIRE(fs.last_seq_num() == 0);
|
||||
REQUIRE(fs.last_seq_num_processed() == 3);
|
||||
}
|
||||
|
||||
SECTION("out_msg_is_stored")
|
||||
{
|
||||
auto td = std::make_shared<utils::TempDir> ();
|
||||
SECTION("out_msg_is_stored") {
|
||||
auto td = std::make_shared<utils::TempDir>();
|
||||
config::JetFIX::Connection c;
|
||||
c.set_name ("test");
|
||||
c.set_sender_compid ("CME");
|
||||
c.set_sender_subid ("G");
|
||||
c.set_target_compid ("1U7001N");
|
||||
c.set_target_subid ("BLUESTREAM");
|
||||
c.set_name("test");
|
||||
c.set_sender_compid("CME");
|
||||
c.set_sender_subid("G");
|
||||
c.set_target_compid("1U7001N");
|
||||
c.set_target_subid("BLUESTREAM");
|
||||
|
||||
c.set_start_time ("00:00:00");
|
||||
c.set_end_time ("23:59:59");
|
||||
c.set_start_time("00:00:00");
|
||||
c.set_end_time("23:59:59");
|
||||
|
||||
auto msg_vec = std::make_shared<OutFIX>(c);
|
||||
auto &stream = msg_vec->fix.back ();
|
||||
auto &buf = stream.new_msg (MessageTypes::Logon);
|
||||
buf.add<fix::TargetLocationID> ("US,NC");
|
||||
buf.add<fix::EncryptMethod> (0);
|
||||
auto &stream = msg_vec->fix.back();
|
||||
auto &buf = stream.new_msg(MessageTypes::Logon);
|
||||
buf.add<fix::TargetLocationID>(std::string_view{"US,NC"});
|
||||
buf.add<fix::EncryptMethod>(0);
|
||||
buf.add<fix::HeartBtInt>(30);
|
||||
buf.add<fix::ApplicationSystemName> ("O2");
|
||||
buf.add<fix::ApplicationSystemVersion> ("1.0");
|
||||
buf.add<fix::ApplicationSystemVendor> ("BTS");
|
||||
stream.close ();
|
||||
stream.stamp (2,3,datetime::FIX_timestamp (datetime::now ()));
|
||||
|
||||
buf.add<fix::ApplicationSystemName>(std::string_view{"O2"});
|
||||
buf.add<fix::ApplicationSystemVersion>(std::string_view{"1.0"});
|
||||
buf.add<fix::ApplicationSystemVendor>(std::string_view{"BTS"});
|
||||
stream.close();
|
||||
stream.stamp(2, 3, datetime::FIX_timestamp(datetime::now()));
|
||||
|
||||
{
|
||||
FIXFileStore fs (c,td->name ());
|
||||
fs.store (msg_vec);
|
||||
FIXFileStore fs(c, td->name());
|
||||
fs.store(msg_vec);
|
||||
}
|
||||
|
||||
FIXFileStore fs (c,td->name ());
|
||||
auto replay = fs.replay ();
|
||||
REQUIRE (replay.size ()==0);
|
||||
REQUIRE (fs.last_seq_num ()==3);
|
||||
REQUIRE (fs.last_seq_num_processed ()==0);
|
||||
FIXFileStore fs(c, td->name());
|
||||
auto replay = fs.replay();
|
||||
REQUIRE(replay.size() == 0);
|
||||
REQUIRE(fs.last_seq_num() == 3);
|
||||
REQUIRE(fs.last_seq_num_processed() == 0);
|
||||
}
|
||||
|
||||
SECTION("test_performance")
|
||||
{
|
||||
auto td = std::make_shared<utils::TempDir> ();
|
||||
SECTION("test_performance") {
|
||||
auto td = std::make_shared<utils::TempDir>();
|
||||
config::JetFIX::Connection c;
|
||||
c.set_name ("test");
|
||||
c.set_sender_compid ("CME");
|
||||
c.set_sender_subid ("G");
|
||||
c.set_target_compid ("1U7001N");
|
||||
c.set_target_subid ("BLUESTREAM");
|
||||
c.set_name("test");
|
||||
c.set_sender_compid("CME");
|
||||
c.set_sender_subid("G");
|
||||
c.set_target_compid("1U7001N");
|
||||
c.set_target_subid("BLUESTREAM");
|
||||
|
||||
c.set_start_time ("00:00:00");
|
||||
c.set_end_time ("23:59:59");
|
||||
c.set_start_time("00:00:00");
|
||||
c.set_end_time("23:59:59");
|
||||
|
||||
auto start = utils::TimeStamp::now ();
|
||||
auto start = utils::TimeStamp::now();
|
||||
{
|
||||
FIXFileStore fs (c,td->name ());
|
||||
for (int i = 0; i < 10000;i++) {
|
||||
FIXFileStore fs(c, td->name());
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
auto msg_vec = std::make_shared<std::vector<FIXEncodingStream>>();
|
||||
msg_vec->emplace_back (c);
|
||||
auto &stream = msg_vec->back ();
|
||||
auto &buf = stream.new_msg (MessageTypes::Logon);
|
||||
buf.add<fix::TargetLocationID> ("US,NC");
|
||||
buf.add<fix::EncryptMethod> (0);
|
||||
msg_vec->emplace_back(c);
|
||||
auto &stream = msg_vec->back();
|
||||
auto &buf = stream.new_msg(MessageTypes::Logon);
|
||||
buf.add<fix::TargetLocationID>(std::string_view{"US,NC"});
|
||||
buf.add<fix::EncryptMethod>(0);
|
||||
buf.add<fix::HeartBtInt>(30);
|
||||
buf.add<fix::ApplicationSystemName> ("O2");
|
||||
buf.add<fix::ApplicationSystemVersion> ("1.0");
|
||||
buf.add<fix::ApplicationSystemVendor> ("BTS");
|
||||
stream.close ();
|
||||
stream.stamp (i,3,datetime::FIX_timestamp (datetime::now () - boost::gregorian::days (1)));
|
||||
fs.store (InMsgBuffer (stream.to_str ()));
|
||||
buf.add<fix::ApplicationSystemName>(std::string_view{"O2"});
|
||||
buf.add<fix::ApplicationSystemVersion>(std::string_view{"1.0"});
|
||||
buf.add<fix::ApplicationSystemVendor>(std::string_view{"BTS"});
|
||||
stream.close();
|
||||
stream.stamp(i, 3,
|
||||
datetime::FIX_timestamp(datetime::now() -
|
||||
boost::gregorian::days(1)));
|
||||
fs.store(InMsgBuffer(stream.to_str()));
|
||||
}
|
||||
}
|
||||
auto stop = utils::TimeStamp::now ();
|
||||
LOG(Testing,Info,"jetfix store gen: {} ms", (stop-start).milliseconds () );
|
||||
|
||||
start = utils::TimeStamp::now ();
|
||||
FIXFileStore fs (c,td->name ());
|
||||
stop = utils::TimeStamp::now ();
|
||||
LOG(Testing,Info,"jetfix store load: {} ms", (stop-start).milliseconds () );
|
||||
auto stop = utils::TimeStamp::now();
|
||||
LOG(Testing, Info, "jetfix store gen: {} ms",
|
||||
(stop - start).milliseconds());
|
||||
|
||||
start = utils::TimeStamp::now();
|
||||
FIXFileStore fs(c, td->name());
|
||||
stop = utils::TimeStamp::now();
|
||||
LOG(Testing, Info, "jetfix store load: {} ms",
|
||||
(stop - start).milliseconds());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace jetfix
|
||||
} // namespace bts
|
||||
@@ -120,6 +120,7 @@ void configure_logging(bts::config::Logging const&cfg, bts::config::ThreadGroupC
|
||||
{log::Plugin,"Plugin"},
|
||||
{log::Sdk,"Sdk"},
|
||||
{log::Http,"Http"},
|
||||
{log::iLink3,"iLink3"},
|
||||
};
|
||||
|
||||
real_cfg.sinks["console"] =
|
||||
|
||||
@@ -46,6 +46,7 @@ constexpr log::Subsystem DataFlow {Latency.ordinal+1 };
|
||||
constexpr log::Subsystem Plugin {DataFlow.ordinal+1 };
|
||||
constexpr log::Subsystem Sdk {Plugin.ordinal+1 };
|
||||
constexpr log::Subsystem Http {Sdk.ordinal+1 };
|
||||
constexpr log::Subsystem iLink3 {Http.ordinal+1 };
|
||||
|
||||
struct LoggerHandle {
|
||||
LoggerHandle(LoggerHandle const&) = delete;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
#include "lib/utils/ValueWrapper.h"
|
||||
namespace bts {
|
||||
using ExchangeSecurityKey = utils::ValueWrapper<struct ExchangeSecurityKeyTag,uint64_t>;
|
||||
}
|
||||
+172
-166
@@ -1,71 +1,72 @@
|
||||
#ifndef _WIN32
|
||||
#include "MBOServiceServer.h"
|
||||
#include "MBOServiceServer.h"
|
||||
|
||||
#include "lib/api/services/OrderService.client.pb.h"
|
||||
#include "lib/utils/Dispatcher.h"
|
||||
#include "lib/utils/TimeStamp.h"
|
||||
#include "lib/domain_model/Security.h"
|
||||
#include "MDClient.h"
|
||||
#include "ExchangeOrderKey.h"
|
||||
#include "MBOProcessor.h"
|
||||
#include "MDClient.h"
|
||||
#include "lib/api/services/OrderService.client.pb.h"
|
||||
#include "lib/domain_model/Security.h"
|
||||
#include "lib/orderman/orderman_utils/orderman_common.h"
|
||||
#include "lib/utils/Dispatcher.h"
|
||||
#include "lib/utils/TimeStamp.h"
|
||||
|
||||
#include "lib/utils/LockBox.h"
|
||||
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace bts::api::orderman;
|
||||
|
||||
namespace bts {
|
||||
namespace md {
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
//
|
||||
// Simple class to handle MD recovery and maintain an index of SecurityKey=>MDConsumerHandle
|
||||
// Simple class to handle MD recovery and maintain an index of
|
||||
// SecurityKey=>MDConsumerHandle
|
||||
|
||||
class HandleIndex {
|
||||
MDClient& _client;
|
||||
MDClient &_client;
|
||||
int _sub;
|
||||
std::optional<MDConsumer> _consumer;
|
||||
|
||||
public:
|
||||
utils::LockBox<std::unordered_map<SecurityKey,MDConsumerHandle>> index;
|
||||
public:
|
||||
utils::LockBox<std::unordered_map<SecurityKey, MDConsumerHandle>> index;
|
||||
|
||||
HandleIndex(md::MDClient& client):
|
||||
_client(client),
|
||||
_sub(0),
|
||||
_consumer(std::nullopt),
|
||||
index() {
|
||||
_sub = _client.on_consumer().subscribe([=](const MDConsumer& c) { on_consumer(c); });
|
||||
on_consumer(_client.current_consumer());
|
||||
}
|
||||
HandleIndex(md::MDClient &client)
|
||||
: _client(client), _sub(0), _consumer(std::nullopt), index() {
|
||||
_sub = _client.on_consumer().subscribe(
|
||||
[=](const MDConsumer &c) { on_consumer(c); });
|
||||
on_consumer(_client.current_consumer());
|
||||
}
|
||||
|
||||
~HandleIndex() { _client.on_consumer().unsubscribe(_sub); }
|
||||
|
||||
|
||||
private:
|
||||
void on_consumer(const MDConsumer& c) {
|
||||
private:
|
||||
void on_consumer(const MDConsumer &c) {
|
||||
MDConsumer temp(c);
|
||||
if (temp.all_heartbeats_ok()) {
|
||||
auto existing = _consumer ? _consumer->id() : 0;
|
||||
LOG(md,Info, "Updateing MBOService MDConsumer. Old {} new {}", existing, temp.id());
|
||||
LOG(md, Info, "Updateing MBOService MDConsumer. Old {} new {}",
|
||||
existing, temp.id());
|
||||
// clear the index
|
||||
index.lock([](auto& index) { index.clear(); });
|
||||
index.lock([](auto &index) { index.clear(); });
|
||||
// Swap to new consumer
|
||||
if (_consumer) {
|
||||
_consumer->swap(temp);
|
||||
} else {
|
||||
_consumer = temp;
|
||||
}
|
||||
else { _consumer = temp; }
|
||||
// Subscribe to on_security
|
||||
auto id = _consumer->id();
|
||||
_consumer->on_security([this,id](const SecurityPtr&, MDConsumerHandle handle) {
|
||||
if (_consumer->id() == id) {
|
||||
index.lock([handle](auto& index) {
|
||||
index[SecurityKey(handle.key())] = handle;
|
||||
});
|
||||
}
|
||||
});
|
||||
_consumer->on_security(
|
||||
[this, id](const SecurityPtr &, MDConsumerHandle handle) {
|
||||
if (_consumer->id() == id) {
|
||||
index.lock([handle](auto &index) {
|
||||
index[SecurityKey(handle.key())] = handle;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -73,21 +74,20 @@ private:
|
||||
class ActiveOrder {
|
||||
SecurityKey _security;
|
||||
SparkOrderKey _id;
|
||||
ExchangeOrderKey _ex_id;
|
||||
ExchangeOrderKey _ex_id;
|
||||
int32_t _position;
|
||||
|
||||
public:
|
||||
public:
|
||||
// empty constructor needed for unordered map operator[]
|
||||
// ActiveOrder(): _security(), _id(), _ex_id(), _position(-1) { bts_assert(false); }
|
||||
ActiveOrder(SecurityKey sec, SparkOrderKey s, ExchangeOrderKey ex): _security(sec), _id(s), _ex_id(ex), _position(-1) {}
|
||||
ActiveOrder(SecurityKey sec, SparkOrderKey s, const std::string& ex): _security(sec), _id(s), _ex_id(), _position(-1) {
|
||||
_ex_id = ExchangeOrderKey(std::stoul(ex));
|
||||
}
|
||||
// ActiveOrder(): _security(), _id(), _ex_id(), _position(-1) {
|
||||
// bts_assert(false); }
|
||||
ActiveOrder(SecurityKey sec, SparkOrderKey s, ExchangeOrderKey ex)
|
||||
: _security(sec), _id(s), _ex_id(ex), _position(-1) {}
|
||||
|
||||
SecurityKey security_id() const { return _security; }
|
||||
SparkOrderKey id() const { return _id; }
|
||||
ExchangeOrderKey exchange_id() const { return _ex_id; }
|
||||
int32_t& position() { return _position; };
|
||||
int32_t &position() { return _position; };
|
||||
int32_t position() const { return _position; };
|
||||
bool set_position(int32_t pos) {
|
||||
if (pos != _position) {
|
||||
@@ -108,23 +108,14 @@ public:
|
||||
// MBOService
|
||||
|
||||
struct MBOServiceImpl {
|
||||
MBOServiceImpl(
|
||||
api::ServiceContext& ctx,
|
||||
utils::Dispatcher& d,
|
||||
md::MDClient& c,
|
||||
MBOServiceBase::PiqPublisher&& pub
|
||||
):
|
||||
dispatcher(d),
|
||||
client(c),
|
||||
orders(ctx.locate<api::orderman::OrderService>()),
|
||||
handle_index(c),
|
||||
publish(pub),
|
||||
timer(d, 200, [&]() {timer_tick();}),
|
||||
orders_sub()
|
||||
{}
|
||||
MBOServiceImpl(api::ServiceContext &ctx, utils::Dispatcher &d,
|
||||
md::MDClient &c, MBOServiceBase::PiqPublisher &&pub)
|
||||
: dispatcher(d), client(c),
|
||||
orders(ctx.locate<api::orderman::OrderService>()), handle_index(c),
|
||||
publish(pub), timer(d, 200, [&]() { timer_tick(); }), orders_sub() {}
|
||||
|
||||
utils::Dispatcher& dispatcher;
|
||||
md::MDClient& client;
|
||||
utils::Dispatcher &dispatcher;
|
||||
md::MDClient &client;
|
||||
OrderService orders;
|
||||
|
||||
HandleIndex handle_index;
|
||||
@@ -138,23 +129,23 @@ struct MBOServiceImpl {
|
||||
void flush();
|
||||
};
|
||||
|
||||
|
||||
|
||||
///////////////////////
|
||||
|
||||
std::optional<uint32_t> search_orders(const ExchangeOrderKey oid, const std::vector<SnapshotOrder>& orders) {
|
||||
std::optional<uint32_t>
|
||||
search_orders(const ExchangeOrderKey oid,
|
||||
const std::vector<SnapshotOrder> &orders) {
|
||||
IntPrice price = {};
|
||||
size_t position = 0;
|
||||
for (size_t x = 0; x < orders.size(); ++x) {
|
||||
const auto& oo = orders[x];
|
||||
const auto &oo = orders[x];
|
||||
if (oo.id == oid) {
|
||||
if (oo.price == price) return { position };
|
||||
else return 0;
|
||||
}
|
||||
else if (price == oo.price) {
|
||||
if (oo.price == price)
|
||||
return {position};
|
||||
else
|
||||
return 0;
|
||||
} else if (price == oo.price) {
|
||||
position += oo.size;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
price = oo.price;
|
||||
position = oo.size;
|
||||
}
|
||||
@@ -162,11 +153,11 @@ std::optional<uint32_t> search_orders(const ExchangeOrderKey oid, const std::vec
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
bool update_position(const HandleIndex& handles, ActiveOrder& order) {
|
||||
const auto& index = handles.index;
|
||||
auto handle = index.lock([id=order.security_id()](const auto& index) {
|
||||
bool update_position(const HandleIndex &handles, ActiveOrder &order) {
|
||||
const auto &index = handles.index;
|
||||
auto handle = index.lock([id = order.security_id()](const auto &index) {
|
||||
auto iter = index.find(id);
|
||||
return iter != index.end() ? iter->second : MDConsumerHandle {};
|
||||
return iter != index.end() ? iter->second : MDConsumerHandle{};
|
||||
});
|
||||
|
||||
if (handle.is_initialized()) {
|
||||
@@ -185,9 +176,9 @@ bool update_position(const HandleIndex& handles, ActiveOrder& order) {
|
||||
}
|
||||
|
||||
void MBOServiceImpl::timer_tick() {
|
||||
//Dispatcher thread
|
||||
// Dispatcher thread
|
||||
std::vector<OrderPIQ> rows;
|
||||
for (auto& pair : active) {
|
||||
for (auto &pair : active) {
|
||||
if (update_position(handle_index, pair.second)) {
|
||||
rows.push_back(pair.second.to_piq());
|
||||
}
|
||||
@@ -197,29 +188,30 @@ void MBOServiceImpl::timer_tick() {
|
||||
}
|
||||
}
|
||||
|
||||
const NativeOrderState* native_order_state(const OrderRecord& record) {
|
||||
switch(record.state().custom_case()) {
|
||||
case OrderState::kMarket:
|
||||
return &record.state().market().native_state();
|
||||
case OrderState::kLimit:
|
||||
return &record.state().limit().native_state();
|
||||
case OrderState::kStop:
|
||||
return &record.state().stop().native_state();
|
||||
case OrderState::kStopLimit:
|
||||
return &record.state().stop_limit().native_state();
|
||||
case OrderState::kGlbxIceberg:
|
||||
return &record.state().glbx_iceberg().native_state();
|
||||
default:
|
||||
const NativeOrderState *native_order_state(const OrderRecord &record) {
|
||||
switch (record.state().custom_case()) {
|
||||
case OrderState::kMarket:
|
||||
return &record.state().market().native_state();
|
||||
case OrderState::kLimit:
|
||||
return &record.state().limit().native_state();
|
||||
case OrderState::kStop:
|
||||
return &record.state().stop().native_state();
|
||||
case OrderState::kStopLimit:
|
||||
return &record.state().stop_limit().native_state();
|
||||
case OrderState::kGlbxIceberg:
|
||||
return &record.state().glbx_iceberg().native_state();
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool is_active_exchange_order(const OrderRecord& record) {
|
||||
bool is_active_exchange_order(const OrderRecord &record) {
|
||||
return record.state().status() == ORDER_STATUS_WORKING &&
|
||||
native_order_state(record) != nullptr;
|
||||
}
|
||||
|
||||
void try_remove(MBOServiceImpl& me, std::set<uint32_t>& to_remove, const OrderRecord& record) {
|
||||
void try_remove(MBOServiceImpl &me, std::set<uint32_t> &to_remove,
|
||||
const OrderRecord &record) {
|
||||
auto key = SparkOrderKey(record.key());
|
||||
auto iter = me.active.find(key);
|
||||
if (iter != me.active.end()) {
|
||||
@@ -227,103 +219,113 @@ void try_remove(MBOServiceImpl& me, std::set<uint32_t>& to_remove, const OrderRe
|
||||
to_remove.insert(key.value());
|
||||
}
|
||||
}
|
||||
void try_add(MBOServiceImpl& me, std::vector<OrderPIQ>& to_add, const OrderRecord& record) {
|
||||
void try_add(MBOServiceImpl &me, std::vector<OrderPIQ> &to_add,
|
||||
const OrderRecord &record) {
|
||||
if (is_active_exchange_order(record)) {
|
||||
auto native = native_order_state(record);
|
||||
|
||||
auto ex_key = orderman::get_exchange_order_id(*native);
|
||||
auto u64_key =
|
||||
std::visit(overloaded{[](orderman::ExchangeOrderID const &str) {
|
||||
return std::stoul(str.value().data());
|
||||
},
|
||||
[](orderman::ExchangeOrderID64 oid) {
|
||||
return oid.value();
|
||||
}},
|
||||
ex_key);
|
||||
bts_assert(native);
|
||||
ActiveOrder order(
|
||||
SecurityKey(record.def().security_key()),
|
||||
SparkOrderKey(record.key()),
|
||||
native->exchange_order_id());
|
||||
ActiveOrder order(SecurityKey(record.def().security_key()),
|
||||
SparkOrderKey(record.key()), ExchangeOrderKey{u64_key});
|
||||
update_position(me.handle_index, order);
|
||||
to_add.push_back(order.to_piq());
|
||||
me.active.insert(std::make_pair(order.id(), order));
|
||||
}
|
||||
}
|
||||
|
||||
MBOServiceServer::MBOServiceServer(
|
||||
api::ServiceContext& ctx,
|
||||
utils::Dispatcher& d,
|
||||
md::MDClient& c
|
||||
) :
|
||||
MBOServiceBase(ctx),
|
||||
_me(new MBOServiceImpl(ctx,d,c,make_piq_publisher()))
|
||||
{
|
||||
// subscribe to mdclient ✔
|
||||
// make publishers ✔
|
||||
// subscribe to orders => stash active orders dict
|
||||
_me->orders_sub =
|
||||
_me->orders.subscribe_orders().subscribe([=](const auto& update) {
|
||||
// api thread
|
||||
const auto& added = update.added();
|
||||
const auto& changed = update.changed();
|
||||
const auto& removed = update.removed();
|
||||
_me->dispatcher.post([this,added,changed,removed]() {
|
||||
// dispatcher thread
|
||||
std::vector<OrderPIQ> to_add, to_change;
|
||||
std::set<uint32_t> to_remove;
|
||||
MBOServiceServer::MBOServiceServer(api::ServiceContext &ctx,
|
||||
utils::Dispatcher &d, md::MDClient &c)
|
||||
: MBOServiceBase(ctx),
|
||||
_me(new MBOServiceImpl(ctx, d, c, make_piq_publisher())) {
|
||||
// subscribe to mdclient ✔
|
||||
// make publishers ✔
|
||||
// subscribe to orders => stash active orders dict
|
||||
_me->orders_sub =
|
||||
_me->orders.subscribe_orders().subscribe([=](const auto &update) {
|
||||
// api thread
|
||||
const auto &added = update.added();
|
||||
const auto &changed = update.changed();
|
||||
const auto &removed = update.removed();
|
||||
_me->dispatcher.post([this, added, changed, removed]() {
|
||||
// dispatcher thread
|
||||
std::vector<OrderPIQ> to_add, to_change;
|
||||
std::set<uint32_t> to_remove;
|
||||
|
||||
// Remove
|
||||
for(const auto& r : removed) {
|
||||
// If it was active remove it and add to to_remove
|
||||
try_remove(*_me, to_remove, *r);
|
||||
}
|
||||
// Added
|
||||
for(const auto& add : added) {
|
||||
// If active add look up the position and add to the state
|
||||
try_add(*_me, to_add, *add);
|
||||
}
|
||||
// Changed
|
||||
for(const auto& ch : changed) {
|
||||
// new order is active and old is not look up piq and add to state
|
||||
bool is_active = is_active_exchange_order(*ch.current());
|
||||
bool was_active = is_active_exchange_order(*ch.previous());
|
||||
if (is_active && !was_active) {
|
||||
try_add(*_me, to_add, *ch.current());
|
||||
}
|
||||
else if (was_active && !is_active) {
|
||||
try_remove(*_me, to_remove, *ch.current());
|
||||
}
|
||||
// is_active && was_active => don't care
|
||||
// !is_active && !was_active => don't care
|
||||
}
|
||||
// Remove
|
||||
for (const auto &r : removed) {
|
||||
// If it was active remove it and add to to_remove
|
||||
try_remove(*_me, to_remove, *r);
|
||||
}
|
||||
// Added
|
||||
for (const auto &add : added) {
|
||||
// If active add look up the position and add to the state
|
||||
try_add(*_me, to_add, *add);
|
||||
}
|
||||
// Changed
|
||||
for (const auto &ch : changed) {
|
||||
// new order is active and old is not look up piq and add to
|
||||
// state
|
||||
bool is_active = is_active_exchange_order(*ch.current());
|
||||
bool was_active = is_active_exchange_order(*ch.previous());
|
||||
if (is_active && !was_active) {
|
||||
try_add(*_me, to_add, *ch.current());
|
||||
} else if (was_active && !is_active) {
|
||||
try_remove(*_me, to_remove, *ch.current());
|
||||
}
|
||||
// is_active && was_active => don't care
|
||||
// !is_active && !was_active => don't care
|
||||
}
|
||||
|
||||
_me->publish(&to_add, &to_change, &to_remove);
|
||||
if (!_me->timer.running()) _me->timer.start();
|
||||
});
|
||||
});
|
||||
}
|
||||
_me->publish(&to_add, &to_change, &to_remove);
|
||||
if (!_me->timer.running())
|
||||
_me->timer.start();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
MBOServiceServer::~MBOServiceServer() { }
|
||||
MBOServiceServer::~MBOServiceServer() {}
|
||||
|
||||
|
||||
void MBOServiceServer::get_orders_for_security(const MBOSecurityQuery& request, const api::Response<PositionData>& reply) {
|
||||
void MBOServiceServer::get_orders_for_security(
|
||||
const MBOSecurityQuery &request, const api::Response<PositionData> &reply) {
|
||||
PositionData response;
|
||||
response.set_security_id(request.security_id());
|
||||
auto handle = _me->handle_index.index.lock([id=request.security_id()](const auto& index) {
|
||||
auto iter = index.find(SecurityKey(id));
|
||||
return iter != index.end() ? iter->second : MDConsumerHandle {};
|
||||
});
|
||||
auto handle = _me->handle_index.index.lock(
|
||||
[id = request.security_id()](const auto &index) {
|
||||
auto iter = index.find(SecurityKey(id));
|
||||
return iter != index.end() ? iter->second : MDConsumerHandle{};
|
||||
});
|
||||
|
||||
std::unordered_map<ExchangeOrderKey, SparkOrderKey> reverse;
|
||||
for (const auto& pair : _me->active) {
|
||||
for (const auto &pair : _me->active) {
|
||||
reverse.insert(std::make_pair(pair.second.exchange_id(), pair.first));
|
||||
}
|
||||
|
||||
size_t count = 0;
|
||||
auto tick = handle.get_minimum_tick();
|
||||
if(handle.is_initialized()) {
|
||||
if (handle.is_initialized()) {
|
||||
auto mbo = handle.get_mbo();
|
||||
if (mbo) {
|
||||
for (const auto& o : mbo->bids) {
|
||||
for (const auto &o : mbo->bids) {
|
||||
double price = o.price.price();
|
||||
bool isnan = os::is_nan(request.price_level());
|
||||
if (isnan || securities::test_price_equality(request.price_level(), price, tick)) {
|
||||
if (isnan || securities::test_price_equality(request.price_level(),
|
||||
price, tick)) {
|
||||
++count;
|
||||
if (request.limit() && count > request.limit()) break;
|
||||
auto* entry = response.add_bid();
|
||||
if (request.limit() && count > request.limit())
|
||||
break;
|
||||
auto *entry = response.add_bid();
|
||||
entry->set_exchange_id(o.id.value());
|
||||
if (isnan) entry->set_price(price);
|
||||
if (isnan)
|
||||
entry->set_price(price);
|
||||
entry->set_size(o.size);
|
||||
auto iter = reverse.find(o.id);
|
||||
if (iter != reverse.end()) {
|
||||
@@ -331,15 +333,18 @@ void MBOServiceServer::get_orders_for_security(const MBOSecurityQuery& request,
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto& o : mbo->asks) {
|
||||
for (const auto &o : mbo->asks) {
|
||||
double price = o.price.price();
|
||||
bool isnan = os::is_nan(request.price_level());
|
||||
if (isnan || securities::test_price_equality(request.price_level(), price, tick)) {
|
||||
if (isnan || securities::test_price_equality(request.price_level(),
|
||||
price, tick)) {
|
||||
++count;
|
||||
if (request.limit() && count > request.limit()) break;
|
||||
auto* entry = response.add_ask();
|
||||
if (request.limit() && count > request.limit())
|
||||
break;
|
||||
auto *entry = response.add_ask();
|
||||
entry->set_exchange_id(o.id.value());
|
||||
if (isnan) entry->set_price(price);
|
||||
if (isnan)
|
||||
entry->set_price(price);
|
||||
entry->set_size(o.size);
|
||||
auto iter = reverse.find(o.id);
|
||||
if (iter != reverse.end()) {
|
||||
@@ -349,9 +354,10 @@ void MBOServiceServer::get_orders_for_security(const MBOSecurityQuery& request,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
reply(response);
|
||||
}
|
||||
|
||||
}} //namespace
|
||||
} // namespace md
|
||||
} // namespace bts
|
||||
#endif
|
||||
@@ -92,7 +92,7 @@ MDConsumer& MDClient::current_consumer() const {
|
||||
return _self->_consumer;
|
||||
}
|
||||
SecurityOracle MDClient::oracle() const {
|
||||
return SecurityOracle(*this);
|
||||
return SecurityOracle(_self->_cache);
|
||||
}
|
||||
std::set<UserSymbol> MDClient::symbols() const {
|
||||
return _self->_symbols;
|
||||
|
||||
@@ -897,7 +897,7 @@ public:
|
||||
scan_securities(resolve_legs);
|
||||
}
|
||||
|
||||
SecurityPtr get_security(SecurityKey key) const {
|
||||
const Security* get_security(SecurityKey key) const {
|
||||
return _cache.get_security(key);
|
||||
}
|
||||
|
||||
@@ -979,7 +979,7 @@ size_t MDConsumer::walk_security_list(SecurityCallback cb, const string& symbol,
|
||||
|
||||
size_t MDConsumer::scan_securities(bool resolve_legs) { return _pimpl->scan_securities(resolve_legs); }
|
||||
void MDConsumer::on_security(SecurityCallback cb, bool resolve_legs) { _pimpl->on_security(cb, resolve_legs); }
|
||||
const api::Security* MDConsumer::get_security(SecurityKey key) const { return _pimpl->get_security(key).get(); }
|
||||
const api::Security* MDConsumer::get_security(SecurityKey key) const { return _pimpl->get_security(key); }
|
||||
std::vector<api::Security const*> MDConsumer::get_securities() const {return _pimpl->get_securities();}
|
||||
|
||||
MDConsumerChannel MDConsumer::get_channel(const std::string& symbol, SecurityType type, Venue exchange) const {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include "SecurityCache.h"
|
||||
#include "SecurityDB.h"
|
||||
#include "lib/utils/Dispatcher.h"
|
||||
#include "lib/utils/LockBox.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <google/btree/btree_map.h>
|
||||
#include <tbb/concurrent_queue.h>
|
||||
#include <mutex>
|
||||
|
||||
@@ -10,8 +12,8 @@ namespace bts {
|
||||
namespace md {
|
||||
|
||||
struct SecurityCacheImpl {
|
||||
std::mutex cache_mutex;
|
||||
std::unordered_map<SecurityKey, SecurityPtr> cache;
|
||||
utils::LockBox<btree::btree_map<SecurityKey, SecurityPtr>> cache;
|
||||
utils::LockBox<btree::btree_map<ExchangeSecurityKey, SecurityPtr>> ex_cache;
|
||||
tbb::concurrent_queue<SecurityPtr> update_queue;
|
||||
void enqueue_update_db(const SecurityPtr&);
|
||||
void flush();
|
||||
@@ -42,61 +44,83 @@ void SecurityCacheImpl::flush() {
|
||||
SecurityCache::SecurityCache() : _me(std::make_shared<SecurityCacheImpl>()) {}
|
||||
SecurityCache::~SecurityCache() {}
|
||||
|
||||
SecurityPtr SecurityCache::try_get_security(SecurityKey key) const {
|
||||
std::lock_guard<std::mutex> lock(_me->cache_mutex);
|
||||
auto iter = _me->cache.find(key);
|
||||
if (iter != _me->cache.end()) {
|
||||
return iter->second;
|
||||
}
|
||||
return nullptr;
|
||||
const Security* SecurityCache::try_get_security(SecurityKey key) const {
|
||||
return _me->cache.lock([key](btree::btree_map<SecurityKey, SecurityPtr>& t) {
|
||||
auto iter = t.find(key);
|
||||
if (iter != t.end()) {
|
||||
return iter->second.get();
|
||||
}
|
||||
return (const api::Security*)nullptr;
|
||||
});
|
||||
}
|
||||
const Security* SecurityCache::try_get_security(ExchangeSecurityKey key) const {
|
||||
return _me->ex_cache.lock([key](btree::btree_map<ExchangeSecurityKey,SecurityPtr>& t) {
|
||||
auto iter = t.find(key);
|
||||
if (iter != t.end()) {
|
||||
return iter->second.get();
|
||||
}
|
||||
return (const api::Security*)nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
SecurityPtr SecurityCache::get_security(SecurityKey key) {
|
||||
std::unique_lock<std::mutex> lock(_me->cache_mutex);
|
||||
auto iter = _me->cache.find(key);
|
||||
if (iter != _me->cache.end()) {
|
||||
return iter->second;
|
||||
}
|
||||
else {
|
||||
// unlock for db read
|
||||
lock.unlock();
|
||||
|
||||
const Security* SecurityCache::get_security(SecurityKey key) {
|
||||
const Security* result = try_get_security(key);
|
||||
if (result == nullptr) {
|
||||
// outside lock
|
||||
auto security = db::find_security(key);
|
||||
if (security) {
|
||||
LOG(md,Info, "Loaded security from database: {} {}", security->symbol(), security->id());
|
||||
return add_db_security(security);
|
||||
}
|
||||
return security;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<api::Security const*> SecurityCache::get_securities()
|
||||
{
|
||||
std::vector<api::Security const*> result;
|
||||
result.reserve(100000);
|
||||
|
||||
std::unique_lock<std::mutex> lock(_me->cache_mutex);
|
||||
for (auto const&p : _me->cache)
|
||||
result.push_back(p.second.get());
|
||||
return result;
|
||||
}
|
||||
|
||||
SecurityPtr SecurityCache::add_db_security(const SecurityPtr& security) {
|
||||
std::vector<api::Security const*> SecurityCache::get_securities() {
|
||||
std::vector<api::Security const*> result;
|
||||
result.reserve(100000);
|
||||
|
||||
_me->cache.lock([&result](auto& cache) {
|
||||
for (auto const&p : cache) {
|
||||
result.push_back(p.second.get());
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
const Security* SecurityCache::add_db_security(const SecurityPtr& security) {
|
||||
bts_assert(security);
|
||||
std::lock_guard<std::mutex> lock(_me->cache_mutex);
|
||||
SecurityKey key(security->id());
|
||||
auto result = _me->cache.insert(std::make_pair(SecurityKey(security->id()), security));
|
||||
// If result was inserted result.first->second is equal to security
|
||||
// If the value was already present it must be a recently inserted 'live' security and we should use it
|
||||
return result.first->second;
|
||||
if (security->has_glbx()) {
|
||||
_me->ex_cache.lock([&security](auto& cache) {
|
||||
ExchangeSecurityKey key(security->id());
|
||||
cache.insert(std::make_pair(key, security));
|
||||
});
|
||||
}
|
||||
return _me->cache.lock([&security](auto& cache) {
|
||||
SecurityKey key(security->id());
|
||||
auto result = cache.insert(std::make_pair(key, security));
|
||||
// If result was inserted result.first->second is equal to security
|
||||
// If the value was already present it must be a recently inserted 'live' security and we should use it
|
||||
return result.first->second.get();
|
||||
});
|
||||
}
|
||||
bool SecurityCache::add_live_security(const SecurityPtr& security) {
|
||||
bts_assert(security);
|
||||
std::lock_guard<std::mutex> lock(_me->cache_mutex);
|
||||
SecurityKey key(security->id());
|
||||
// Insert but don't overwrite existing
|
||||
auto result = _me->cache.insert(std::make_pair(SecurityKey(security->id()), security));
|
||||
_me->enqueue_update_db(security);
|
||||
return result.second;
|
||||
if (security->has_glbx()) {
|
||||
_me->ex_cache.lock([&security](auto& cache) {
|
||||
ExchangeSecurityKey key(security->id());
|
||||
cache.insert(std::make_pair(key, security));
|
||||
});
|
||||
}
|
||||
return _me->cache.lock([&](auto& cache) {
|
||||
SecurityKey key(security->id());
|
||||
// Insert but don't overwrite existing
|
||||
auto result = cache.insert(std::make_pair(SecurityKey(security->id()), security));
|
||||
_me->enqueue_update_db(security);
|
||||
return result.second;
|
||||
});
|
||||
}
|
||||
|
||||
void SecurityCache::flush_to_disk() { _me->flush(); }
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "lib/domain_model/Security.pb.h"
|
||||
#include "MDConsumerHandle.h"
|
||||
#include "lib/domain_model/SecurityKey.h"
|
||||
#include "lib/md/ExchangeSecurityKey.h"
|
||||
#include "SecurityPtr.h"
|
||||
#include <memory>
|
||||
|
||||
@@ -20,17 +21,18 @@ public:
|
||||
~SecurityCache();
|
||||
|
||||
//Load security from cache with fallback to database
|
||||
SecurityPtr get_security(SecurityKey key);
|
||||
const Security* get_security(SecurityKey key);
|
||||
|
||||
// Load all securities from cache, no fallback to database
|
||||
std::vector<api::Security const*> get_securities();
|
||||
|
||||
// Get the security if it's in the cache otherwise return nullptr. Does not query security database.
|
||||
SecurityPtr try_get_security(SecurityKey key) const;
|
||||
const Security* try_get_security(SecurityKey key) const;
|
||||
const Security* try_get_security(ExchangeSecurityKey key) const;
|
||||
|
||||
// returns true if the cache was updated
|
||||
bool add_live_security(const SecurityPtr& security);
|
||||
SecurityPtr add_db_security(const SecurityPtr& security);
|
||||
const Security* add_db_security(const SecurityPtr& security);
|
||||
|
||||
void flush_to_disk();
|
||||
|
||||
|
||||
@@ -4,14 +4,18 @@
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
SecurityOracle::SecurityOracle(const MDClient& client): _client(client) {}
|
||||
SecurityOracle::SecurityOracle(SecurityCache& cache): _cache(cache) {}
|
||||
SecurityOracle::~SecurityOracle() { }
|
||||
const api::Security* SecurityOracle::get_security(SecurityKey key) const {
|
||||
return _client.current_consumer().get_security(key);
|
||||
return _cache.get_security(key);
|
||||
}
|
||||
|
||||
const api::Security* SecurityOracle::get_security(ExchangeSecurityKey key) const {
|
||||
return _cache.try_get_security(key);
|
||||
}
|
||||
|
||||
std::vector<api::Security const*> SecurityOracle::get_securities() const {
|
||||
return _client.current_consumer().get_securities();
|
||||
return _cache.get_securities();
|
||||
}
|
||||
|
||||
}}//namespace
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/domain_model/SecurityKey.h"
|
||||
#include "lib/md/ExchangeSecurityKey.h"
|
||||
#include "lib/md/SecurityCache.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@@ -9,11 +11,12 @@ namespace api {class Security;}
|
||||
namespace md {
|
||||
class MDClient;
|
||||
class SecurityOracle {
|
||||
const MDClient& _client;
|
||||
SecurityCache& _cache;
|
||||
public:
|
||||
SecurityOracle(const MDClient&);
|
||||
SecurityOracle(SecurityCache&);
|
||||
~SecurityOracle();
|
||||
const api::Security* get_security(SecurityKey key) const;
|
||||
const api::Security* get_security(ExchangeSecurityKey key) const;
|
||||
std::vector<api::Security const*> get_securities() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "lib/persistence/SqliteStore.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
#include "lib/orderman/actors/SODPosition.h"
|
||||
#include "lib/utils/overloaded.h"
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <sys/time.h>
|
||||
@@ -164,8 +165,21 @@ void FillStore::on_execution_report(
|
||||
fill.set_fill_status(api::orderman::Fill::FILL_STATUS_CORRECTED);
|
||||
fill.set_fill_key(fk);
|
||||
|
||||
auto exchange_ts = utils::pb::to_timestamp(
|
||||
datetime::parse_FIX_timestamp(to_str(er.transact_time)));
|
||||
auto exchange_ts =
|
||||
std::visit(overloaded {
|
||||
[](const orderman::ExchangeTimeStampStr& ts) {
|
||||
return utils::pb::to_timestamp(
|
||||
datetime::parse_FIX_timestamp(to_str(ts)));
|
||||
},
|
||||
[](ExchangeTimeStamp64 ts) {
|
||||
google::protobuf::Timestamp gts;
|
||||
auto seconds = ts.value() / 1E9;
|
||||
gts.set_seconds(seconds);
|
||||
gts.set_nanos(ts.value() - (seconds * 1E9));
|
||||
return gts;
|
||||
}
|
||||
}, er.transact_time);
|
||||
|
||||
*fill.mutable_timestamp() = exchange_ts;
|
||||
|
||||
auto it = me->known_orders.find(er.order_key);
|
||||
|
||||
@@ -222,7 +222,9 @@ void GLBXExecutionGateway::on_exe_report(
|
||||
msg.get<fix::ManualOrderIndicator>()
|
||||
? api::orderman::MANUAL_ORDER_INDICATOR_YES
|
||||
: api::orderman::MANUAL_ORDER_INDICATOR_YES;
|
||||
str_to(msg.get<fix::OrderID>(), &data->exchange_order_id);
|
||||
str_to(msg.get<fix::OrderID>(),
|
||||
& std::get<ExchangeOrderID>(
|
||||
data->exchange_order_id));
|
||||
|
||||
if (msg.has<fix::Price>())
|
||||
data->price = securities::decode_exchange_price(
|
||||
@@ -261,7 +263,9 @@ void GLBXExecutionGateway::on_exe_report(
|
||||
: Price(0);
|
||||
if (msg.has<fix::ExecID>())
|
||||
str_to(msg.get<fix::ExecID>(), &data->exchange_fill_id);
|
||||
str_to(msg.get<fix::TransactTimeStr>(), &data->transact_time);
|
||||
orderman::ExchangeTimeStampStr t;
|
||||
str_to(msg.get<fix::TransactTimeStr>(), &t);
|
||||
data->transact_time = t;
|
||||
|
||||
if (msg.has<fix::CustOrderHandlingInst>())
|
||||
data->cust_order_handling_inst = msg.get<fix::CustOrderHandlingInst>();
|
||||
@@ -280,12 +284,16 @@ void GLBXExecutionGateway::on_cancel_reject(
|
||||
decode_clorid(msg.get<fix::ClOrdID>(), &ok, &sk);
|
||||
|
||||
std::string reject_msg;
|
||||
CancelRejectReason reason = CancelRejectReason::Other;
|
||||
if (msg.has<fix::Text>())
|
||||
reject_msg = msg.get<fix::Text>();
|
||||
else if (msg.has<fix::CXlRejReason>())
|
||||
else if (msg.has<fix::CXlRejReason>()) {
|
||||
if (msg.get<fix::CXlRejReason>() == 2045)
|
||||
reason = CancelRejectReason::UnknownOrder;
|
||||
reject_msg = fmt::format("Order cancel was rejected with error code {}",
|
||||
msg.get<fix::CXlRejReason>());
|
||||
me->on_cancel_reject(ok, reject_msg);
|
||||
}
|
||||
me->on_cancel_reject({ok, reason,reject_msg});
|
||||
}
|
||||
|
||||
void GLBXExecutionGateway::on_connection_status_change(bool is_connected) {
|
||||
|
||||
@@ -18,6 +18,7 @@ class GLBXExecutionGateway : public IExecutionGateway {
|
||||
void on_securities(const mercury::Update<NewSecuritiesEvent> &) override;
|
||||
void on_admin_data(const mercury::Update<NewAdminDataEvent> &) override;
|
||||
void send_fix(jetfix::OutFIXPtr const &fix, trace::CorID trace) override;
|
||||
void send_msgs(std::vector<OrderMsg> const&, trace::CorID) override {bts_assert(false);}
|
||||
|
||||
OnExeReport& on_exe_report() override;
|
||||
OnGwStatusChange& on_gw_status_change() override;
|
||||
|
||||
@@ -0,0 +1,300 @@
|
||||
#include "lib/orderman/actors/GLBXiLink3ExecutionGateway.h"
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/orderman_cfg.pb.h"
|
||||
#include "lib/domain_model/Security.h"
|
||||
#include "lib/jetfix/common/OutFIX.h"
|
||||
#include "lib/jetfix/store/session_name.h"
|
||||
#include "lib/orderman/actors/GLBXExecutionGateway.h"
|
||||
#include "lib/orderman/actors/ilink3/IL3GW.h"
|
||||
#include "lib/orderman/actors/ilink3/IL3MessageFramer.h"
|
||||
#include "lib/orderman/actors/ilink3/IL3Reactor.h"
|
||||
#include "lib/orderman/actors/ilink3/IL3SecDB.h"
|
||||
#include "lib/orderman/actors/ilink3/SessionStore.h"
|
||||
#include "lib/orderman/events/NewSecuritiesEvent.h"
|
||||
#include "lib/orderman/orderman_utils/fix_order_codec.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
namespace ilink3 {
|
||||
|
||||
enum class GLBXiLink3ExecutionGateway::State {
|
||||
|
||||
WAITING_FOR_SECURITIES,
|
||||
PAUSED,
|
||||
CONNECTING,
|
||||
READY
|
||||
};
|
||||
|
||||
struct GLBXiLink3ExecutionGateway::PImpl {
|
||||
PImpl(config::JetFIX::Connection const &cfg, trace::PerfLog &log,
|
||||
md::SecurityOracle o)
|
||||
: state(), cfg(cfg), reactor(), start_of_pause(), on_exe_report(),
|
||||
on_gw_status_change(), on_cancel_reject(), perf_log(log), db(o),
|
||||
gw_name(cfg.name()), session_store(), gw(), connection(nullptr),
|
||||
connection_failures(0), started(false), replay_messages(),
|
||||
has_replayed(false) {
|
||||
TCPEndpoint endpoint{cfg.socket_connect_host_ip(),
|
||||
(ushort)cfg.socket_connect_port()};
|
||||
connection = &reactor.register_connection({endpoint});
|
||||
}
|
||||
|
||||
State state;
|
||||
config::JetFIX::Connection const cfg;
|
||||
IL3Reactor reactor;
|
||||
IL3MessageFramer framer;
|
||||
TimeStamp start_of_pause;
|
||||
|
||||
OnExeReport on_exe_report;
|
||||
OnGwStatusChange on_gw_status_change;
|
||||
orderman::OnCancelReject on_cancel_reject;
|
||||
trace::PerfLog &perf_log;
|
||||
IL3SecDB db;
|
||||
GatewayName gw_name;
|
||||
std::optional<SessionStore> session_store;
|
||||
std::optional<IL3GW> gw;
|
||||
IL3Connection *connection;
|
||||
size_t connection_failures;
|
||||
bool started;
|
||||
|
||||
// We need to keep this collection alive for the duration of the
|
||||
// program because we will be passing pointers to ExecutionReport
|
||||
// to other threads
|
||||
std::vector<ExecutionReport> replay_messages;
|
||||
bool has_replayed;
|
||||
};
|
||||
|
||||
GLBXiLink3ExecutionGateway::GLBXiLink3ExecutionGateway(
|
||||
config::JetFIX::Connection const &cfg, trace::PerfLog &log,
|
||||
md::SecurityOracle o)
|
||||
: me(new PImpl(cfg, log, o)) {
|
||||
me->state = State::WAITING_FOR_SECURITIES;
|
||||
}
|
||||
|
||||
GLBXiLink3ExecutionGateway::~GLBXiLink3ExecutionGateway() {}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::start() {
|
||||
bts_assert(!me->started);
|
||||
me->started = true;
|
||||
}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::dispatch_incoming_fix_messages() {
|
||||
if (me->started) {
|
||||
switch (me->state) {
|
||||
case State::WAITING_FOR_SECURITIES:
|
||||
break;
|
||||
case State::PAUSED:
|
||||
on_time();
|
||||
break;
|
||||
case State::READY:
|
||||
case State::CONNECTING:
|
||||
me->reactor.do_work();
|
||||
me->gw->on_time();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::on_time() {
|
||||
bts_assert(me->state == State::PAUSED);
|
||||
|
||||
// If we are still paused bail early, this avoids logging too much
|
||||
// or spending too much CPU
|
||||
if (pause_in_effect())
|
||||
return;
|
||||
|
||||
me->start_of_pause = Timer::now();
|
||||
|
||||
// If we alread exceed the maximum number of failures per run
|
||||
// bail. This is a safety measure to avoid overwhelming the
|
||||
// exchange in the event of a bug or operational problem that
|
||||
// results in repeated connection failures.
|
||||
if (max_failures_reached()) {
|
||||
LOG(iLink3, Warn,
|
||||
"Maximum number of connection failures reached for {}. Reboot to try "
|
||||
"again",
|
||||
me->gw_name.value());
|
||||
return;
|
||||
}
|
||||
|
||||
// If we reach this point we are no longer in the pause window and
|
||||
// we have not exceed our connection failure limit. The only thing
|
||||
// to check now is wheter we are inside the exchange's active
|
||||
// hours.
|
||||
auto current_session = jetfix::session_name(me->cfg);
|
||||
if (current_session.empty()) {
|
||||
LOG(iLink3, Info, "Outside of session in ", me->gw_name.value());
|
||||
return;
|
||||
}
|
||||
// Yep, the stars are all aligned, lets try to connect
|
||||
connect(current_session);
|
||||
}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::connect(jetfix::SessionName const &sn) {
|
||||
bts_assert(me->state == State::PAUSED);
|
||||
transition(State::CONNECTING);
|
||||
Config c;
|
||||
c.cme_session = me->cfg.sender_compid().substr(0, 3);
|
||||
c.firm = me->cfg.sender_compid().substr(3);
|
||||
c.failover_on_disconnect = false;
|
||||
|
||||
me->session_store.emplace(me->db, sn, &me->cfg);
|
||||
if (!me->has_replayed) {
|
||||
me->has_replayed = true;
|
||||
me->replay_messages = me->session_store.value().replay();
|
||||
for (auto const &er : me->replay_messages)
|
||||
me->on_exe_report(er, {});
|
||||
}
|
||||
|
||||
c.raw_message_logger =
|
||||
[store = &me->session_store.value()](auto d, auto sn, auto const &msg) {
|
||||
store->async_store_raw_msg(d, sn, msg);
|
||||
};
|
||||
|
||||
me->gw.emplace(*me->connection, me->framer, &me->db,
|
||||
me->session_store->starting_session_descriptor(), c,
|
||||
&me->cfg);
|
||||
|
||||
me->gw->subscribe_cancel_reject([this](auto &cr) {
|
||||
bts_assert(me->state == State::READY || me->state == State::CONNECTING);
|
||||
me->on_cancel_reject(cr);
|
||||
});
|
||||
|
||||
me->gw->subscribe_execution_reports([this](auto er) {
|
||||
bts_assert(me->state == State::READY || me->state == State::CONNECTING);
|
||||
me->on_exe_report(*er, {});
|
||||
});
|
||||
|
||||
me->gw->subscribe_session(
|
||||
[this](auto const &s) { me->session_store->async_update_session(s); });
|
||||
|
||||
me->gw->subscribe_state([this](auto gw_state) {
|
||||
LOG(iLink3, Info, "Internal gateway state change in {}. State is now {}",
|
||||
me->gw_name.value(),
|
||||
log::CharPtrWrapper{ilink3::state_string(gw_state)});
|
||||
switch (me->state) {
|
||||
case State::CONNECTING:
|
||||
if (gw_state == ilink3::State::READY) {
|
||||
transition(State::READY);
|
||||
me->on_gw_status_change(true);
|
||||
} else if (gw_state == ilink3::State::ERROR) {
|
||||
me->connection_failures++;
|
||||
pause();
|
||||
}
|
||||
break;
|
||||
case State::READY:
|
||||
if (gw_state == ilink3::State::ERROR) {
|
||||
me->connection_failures++;
|
||||
pause();
|
||||
me->on_gw_status_change(false);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
});
|
||||
me->gw->connect();
|
||||
}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::pause() {
|
||||
me->start_of_pause = Timer::now();
|
||||
me->gw.reset();
|
||||
transition(State::PAUSED);
|
||||
}
|
||||
|
||||
bool GLBXiLink3ExecutionGateway::pause_in_effect() const {
|
||||
return sec_diff(Timer::now(), me->start_of_pause) <=
|
||||
me->cfg.seconds_to_pause();
|
||||
}
|
||||
|
||||
bool GLBXiLink3ExecutionGateway::max_failures_reached() const {
|
||||
return me->connection_failures > me->cfg.max_connection_attempts();
|
||||
}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::on_securities(
|
||||
const mercury::Update<NewSecuritiesEvent> &update) {
|
||||
if (update.events) {
|
||||
|
||||
for (auto const &ev : *(update.events)) {
|
||||
auto sec_ptr = ev.security;
|
||||
me->db.add_security(*sec_ptr);
|
||||
}
|
||||
|
||||
if (me->state == State::WAITING_FOR_SECURITIES) {
|
||||
LOG(iLink3, Warn,
|
||||
"Received first set of {} securities. Proceeding "
|
||||
"with initialization of execution gateway {}",
|
||||
update.events->size(), me->gw_name.value());
|
||||
// got our security synopsis, ready to start the GW
|
||||
transition(State::PAUSED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::on_admin_data(
|
||||
const mercury::Update<NewAdminDataEvent> &) {}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::send_msgs(std::vector<OrderMsg> const &msgs,
|
||||
trace::CorID) {
|
||||
|
||||
if (me->state == State::READY) {
|
||||
for (auto &m : msgs) {
|
||||
// NewOrderSingle
|
||||
auto create_ptr = std::get_if<CreateOrderMsg>(&m);
|
||||
if (create_ptr) {
|
||||
me->gw->send_order(*create_ptr);
|
||||
continue;
|
||||
}
|
||||
// CancelReplace
|
||||
auto cancel_replace_ptr = std::get_if<CancelReplaceOrderMsg>(&m);
|
||||
if (cancel_replace_ptr) {
|
||||
me->gw->send_cancel_replace(*cancel_replace_ptr);
|
||||
continue;
|
||||
}
|
||||
// Cancel
|
||||
auto cancel_ptr = std::get_if<CancelOrderMsg>(&m);
|
||||
if (cancel_ptr) {
|
||||
me->gw->send_cancel(*cancel_ptr);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
me->gw->flush();
|
||||
}
|
||||
}
|
||||
|
||||
OnExeReport &GLBXiLink3ExecutionGateway::on_exe_report() {
|
||||
return me->on_exe_report;
|
||||
}
|
||||
|
||||
OnGwStatusChange &GLBXiLink3ExecutionGateway::on_gw_status_change() {
|
||||
return me->on_gw_status_change;
|
||||
}
|
||||
|
||||
orderman::OnCancelReject &GLBXiLink3ExecutionGateway::on_cancel_reject() {
|
||||
return me->on_cancel_reject;
|
||||
}
|
||||
|
||||
log::CharPtrWrapper GLBXiLink3ExecutionGateway::state_name(State st) {
|
||||
switch (st) {
|
||||
case State::WAITING_FOR_SECURITIES:
|
||||
return {"WAITING_FOR_SECURITIES"};
|
||||
case State::PAUSED:
|
||||
return {"PAUSED"};
|
||||
case State::CONNECTING:
|
||||
return {"CONNECTING"};
|
||||
case State::READY:
|
||||
return {"READY"};
|
||||
}
|
||||
bts_assert(false);
|
||||
return {""};
|
||||
}
|
||||
|
||||
void GLBXiLink3ExecutionGateway::transition(State new_state) {
|
||||
LOG(iLink3, Info, "Transitioning {} from {} to {}", me->gw_name.value(),
|
||||
state_name(me->state), state_name(new_state));
|
||||
me->state = new_state;
|
||||
}
|
||||
|
||||
} // namespace ilink3
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "IExecutionGateway.h"
|
||||
#include "lib/logging/logging.h"
|
||||
|
||||
namespace bts {
|
||||
namespace jetfix {struct SessionName;}
|
||||
namespace orderman {
|
||||
namespace ilink3 {
|
||||
|
||||
struct Session;
|
||||
|
||||
class GLBXiLink3ExecutionGateway : public IExecutionGateway {
|
||||
public:
|
||||
GLBXiLink3ExecutionGateway(config::JetFIX::Connection const &, trace::PerfLog &,
|
||||
md::SecurityOracle);
|
||||
virtual ~GLBXiLink3ExecutionGateway();
|
||||
|
||||
void start() override;
|
||||
void dispatch_incoming_fix_messages() override;
|
||||
void on_securities(const mercury::Update<NewSecuritiesEvent> &) override;
|
||||
void on_admin_data(const mercury::Update<NewAdminDataEvent> &) override;
|
||||
void send_fix(jetfix::OutFIXPtr const &, trace::CorID ) override {bts_assert(false);}
|
||||
void send_msgs(std::vector<OrderMsg> const&, trace::CorID) override;
|
||||
|
||||
OnExeReport& on_exe_report() override;
|
||||
OnGwStatusChange& on_gw_status_change() override;
|
||||
OnCancelReject &on_cancel_reject() override;
|
||||
|
||||
private:
|
||||
enum class State;
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me;
|
||||
|
||||
// Time passing
|
||||
void on_time();
|
||||
bool pause_in_effect() const;
|
||||
bool max_failures_reached()const;
|
||||
static log::CharPtrWrapper state_name(State);
|
||||
void transition(State);
|
||||
|
||||
void pause();
|
||||
void connect(jetfix::SessionName const&);
|
||||
};
|
||||
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
}
|
||||
@@ -417,7 +417,9 @@ void ICEExecutionGateway::on_exe_report(const jetfix::fix::ICEExecutionReportMsg
|
||||
data->manual_order_indicator = api::orderman::MANUAL_ORDER_INDICATOR_NO;
|
||||
|
||||
std::string oid_string = get_ice_order_id_string(msg);
|
||||
str_to(oid_string, &data->exchange_order_id);
|
||||
str_to(oid_string,
|
||||
& std::get<ExchangeOrderID>(
|
||||
data->exchange_order_id));
|
||||
data->ice_cl_ord_id = 0;
|
||||
if(msg.has<fix::Int_ClOrdID>())
|
||||
data->ice_cl_ord_id = msg.get<fix::Int_ClOrdID>();
|
||||
@@ -465,8 +467,10 @@ void ICEExecutionGateway::on_exe_report(const jetfix::fix::ICEExecutionReportMsg
|
||||
if (msg.has<fix::TransactTimeStr>())
|
||||
{
|
||||
std::string stamp = msg.get<fix::TransactTimeStr>();
|
||||
stamp.resize(sizeof(mercury::TimeStampStr));
|
||||
str_to(stamp, &data->transact_time);
|
||||
stamp.resize(sizeof(orderman::ExchangeTimeStampStr));
|
||||
orderman::ExchangeTimeStampStr t;
|
||||
str_to(stamp, &t);
|
||||
data->transact_time = t;
|
||||
}
|
||||
data->cfg = &me->cfg;
|
||||
data->msg = text_msg;
|
||||
@@ -486,7 +490,7 @@ void ICEExecutionGateway::on_cancel_reject(const jetfix::fix::ICECancelRejectMsg
|
||||
else if (msg.has<fix::CXlRejReason>())
|
||||
reject_msg = fmt::format("Order cancel was rejected with error code {}",
|
||||
msg.get<fix::CXlRejReason>());
|
||||
me->on_cancel_reject(ok, reject_msg);
|
||||
me->on_cancel_reject(CancelReject {ok, CancelRejectReason::Other,reject_msg});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ class ICEExecutionGateway : public IExecutionGateway {
|
||||
void on_securities(const mercury::Update<NewSecuritiesEvent> &) override;
|
||||
void on_admin_data(const mercury::Update<NewAdminDataEvent> &) override;
|
||||
void send_fix(const jetfix::OutFIXPtr& fix, trace::CorID trace) override;
|
||||
void send_msgs(std::vector<OrderMsg> const&, trace::CorID) override {bts_assert(false);}
|
||||
|
||||
OnExeReport& on_exe_report() override;
|
||||
OnGwStatusChange& on_gw_status_change() override;
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
|
||||
#include "IExecutionGateway.h"
|
||||
#include "ICEExecutionGateway.h"
|
||||
#include "GLBXExecutionGateway.h"
|
||||
#include "ICEExecutionGateway.h"
|
||||
#include "lib/utils/ValueWrapper.h"
|
||||
#include "lib/orderman/actors/GLBXiLink3ExecutionGateway.h"
|
||||
|
||||
#include <variant>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
std::unique_ptr<IExecutionGateway>
|
||||
ExecutionGatewayFactory::create_gateway(const config::JetFIX::Connection& conn, trace::PerfLog& pl, md::SecurityOracle o)
|
||||
{
|
||||
if(conn.platform() == bts::config::JetFIX_Connection_JetFIXPlatform_ICE ||
|
||||
conn.platform() == bts::config::JetFIX_Connection_JetFIXPlatform_SIMICE)
|
||||
ExecutionGatewayFactory::create_gateway(const config::JetFIX::Connection &conn,
|
||||
trace::PerfLog &pl,
|
||||
md::SecurityOracle o) {
|
||||
if (conn.platform() == bts::config::JetFIX_Connection_JetFIXPlatform_ICE ||
|
||||
conn.platform() == bts::config::JetFIX_Connection_JetFIXPlatform_SIMICE)
|
||||
return std::make_unique<ICEExecutionGateway>(conn, pl, o);
|
||||
else if (conn.use_ilink3())
|
||||
return std::make_unique<ilink3::GLBXiLink3ExecutionGateway>(conn, pl, o);
|
||||
else
|
||||
return std::make_unique<GLBXExecutionGateway>(conn, pl, o);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "lib/utils/bts_no_copy.h"
|
||||
|
||||
#include <memory>
|
||||
#include <variant>
|
||||
|
||||
namespace bts {
|
||||
namespace trace {struct CorID;class PerfLog;}
|
||||
@@ -16,11 +17,42 @@ namespace orderman {
|
||||
class NewSecuritiesEvent;
|
||||
class NewAdminDataEvent;
|
||||
class ExecutionReport;
|
||||
class CancelReject;
|
||||
|
||||
struct CreateOrderMsg {
|
||||
OrderKey key;
|
||||
Price price;
|
||||
Quantity quantity;
|
||||
api::Security const *security;
|
||||
api::Side side;
|
||||
Price stop_px;
|
||||
Quantity display_quantity;
|
||||
api::orderman::NativeOrderType order_type;
|
||||
api::orderman::TimeInForce time_in_force;
|
||||
api::orderman::ManualOrderIndicator manual_order_indicator;
|
||||
api::orderman::RoutingRecord const *routing_record;
|
||||
};
|
||||
|
||||
struct CancelReplaceOrderMsg {
|
||||
CreateOrderMsg create_fields;
|
||||
ExchangeOrderID64 exchange_order_id;
|
||||
};
|
||||
|
||||
struct CancelOrderMsg {
|
||||
OrderKey key;
|
||||
ExchangeOrderID64 exchange_order_id;
|
||||
api::orderman::ManualOrderIndicator manual_order_indicator;
|
||||
api::Security const *security;
|
||||
api::orderman::RoutingRecord const *routing_record;
|
||||
api::Side side;
|
||||
};
|
||||
|
||||
using OrderMsg =
|
||||
std::variant<CreateOrderMsg, CancelReplaceOrderMsg, CancelOrderMsg>;
|
||||
|
||||
using OnGwStatusChange = std::function<void(bool)>;
|
||||
using OnExeReport = std::function<void(ExecutionReport const &, trace::CorID const &)>;
|
||||
using OnCancelReject = std::function<void(OrderKey, std::string const &)>;
|
||||
using OnCancelReject = std::function<void(CancelReject const&)>;
|
||||
|
||||
// fix execution gateway for a single FIX session
|
||||
class IExecutionGateway {
|
||||
@@ -33,7 +65,7 @@ class IExecutionGateway {
|
||||
virtual void on_securities(const mercury::Update<NewSecuritiesEvent> &) = 0;
|
||||
virtual void on_admin_data(const mercury::Update<NewAdminDataEvent> &) = 0;
|
||||
virtual void send_fix(const jetfix::OutFIXPtr&, trace::CorID) = 0;
|
||||
|
||||
virtual void send_msgs(std::vector<OrderMsg> const&, trace::CorID) = 0;
|
||||
virtual OnExeReport& on_exe_report() = 0;
|
||||
virtual OnGwStatusChange& on_gw_status_change() = 0;
|
||||
virtual OnCancelReject &on_cancel_reject() = 0;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/domain_model/Security.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/md/IntPrice.h"
|
||||
#include "lib/md/MDConsumer.h"
|
||||
@@ -10,12 +11,11 @@
|
||||
#include "lib/mercury/events/TimerEvent.h"
|
||||
#include "lib/orderman/events/BookUpdateEvent.h"
|
||||
#include "lib/orderman/events/MDRequestEvent.h"
|
||||
#include "lib/orderman/events/TickerUpdateEvent.h"
|
||||
#include "lib/orderman/events/StatusUpdateEvent.h"
|
||||
#include "lib/orderman/events/TickerUpdateEvent.h"
|
||||
#include "lib/tracing/PerfLog.h"
|
||||
#include "lib/tracing/bts_trace.h"
|
||||
#include "lib/utils/TimeStamp.h"
|
||||
#include "lib/domain_model/Security.h"
|
||||
|
||||
#include <date/date.h>
|
||||
|
||||
@@ -31,9 +31,9 @@ class MDSource : public mercury::Actor, public mercury::IPollableActor {
|
||||
public:
|
||||
MDSource(md::MDConsumer &consumer, metrics::MetricsContainer &stats,
|
||||
trace::PerfLog &log)
|
||||
: _handles(), _pending_handles(), _status_subs(), _md_consumer(consumer),
|
||||
_book_update(), _ticker_update(), _status_update(),
|
||||
_perf_log(log), _stats(stats), _loop_timer(), _counter(0) {
|
||||
: _handles(), _pending_handles(), _status_subs(), _md_consumer(consumer),
|
||||
_book_update(), _ticker_update(), _status_update(), _perf_log(log),
|
||||
_stats(stats), _loop_timer(), _counter(0) {
|
||||
|
||||
_trades_buffer.Reserve(1000);
|
||||
auto cme_channels = md::get_configured_cme_channels();
|
||||
@@ -67,9 +67,8 @@ class MDSource : public mercury::Actor, public mercury::IPollableActor {
|
||||
auto ticker_channel_cout_metric =
|
||||
std::make_shared<metrics::CounterMetric<int>>(
|
||||
"spark_mdsource_ticker_channel_count");
|
||||
auto status_count_metric =
|
||||
std::make_shared<metrics::CounterMetric<int>>(
|
||||
"spark_mdsource_status_count");
|
||||
auto status_count_metric = std::make_shared<metrics::CounterMetric<int>>(
|
||||
"spark_mdsource_status_count");
|
||||
_stats.publish(security_count_metric);
|
||||
_stats.publish(synthetic_count_metric);
|
||||
_stats.publish(ticker_channel_cout_metric);
|
||||
@@ -78,37 +77,40 @@ class MDSource : public mercury::Actor, public mercury::IPollableActor {
|
||||
_book_update = make_stream<BookUpdateEvent>();
|
||||
_ticker_update = make_stream<TickerUpdateEvent>();
|
||||
_status_update = make_stream<StatusUpdateEvent>();
|
||||
subscribe<MDRequestEvent>(
|
||||
[this, security_count_metric, synthetic_count_metric,
|
||||
ticker_channel_cout_metric, status_count_metric](auto const &update) {
|
||||
if (update.events) {
|
||||
for (auto const &ev : *update.events) {
|
||||
auto k = ev.security_key;
|
||||
subscribe<MDRequestEvent>([this, security_count_metric,
|
||||
synthetic_count_metric,
|
||||
ticker_channel_cout_metric,
|
||||
status_count_metric](auto const &update) {
|
||||
if (update.events) {
|
||||
for (auto const &ev : *update.events) {
|
||||
auto k = ev.security_key;
|
||||
|
||||
switch (ev.md_type) {
|
||||
case MDRequestType::BOOK:
|
||||
on_book_sub(k, *synthetic_count_metric);
|
||||
security_count_metric->set(_handles.size());
|
||||
break;
|
||||
case MDRequestType::TICKER:
|
||||
on_ticker_sub(k, *ticker_channel_cout_metric);
|
||||
break;
|
||||
case MDRequestType::STATUS:
|
||||
on_status_sub(k);
|
||||
status_count_metric->set(_status_subs.size());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
switch (ev.md_type) {
|
||||
case MDRequestType::BOOK:
|
||||
on_book_sub(k, *synthetic_count_metric);
|
||||
security_count_metric->set(_handles.size());
|
||||
break;
|
||||
case MDRequestType::TICKER:
|
||||
on_ticker_sub(k, *ticker_channel_cout_metric);
|
||||
break;
|
||||
case MDRequestType::STATUS:
|
||||
on_status_sub(k);
|
||||
status_count_metric->set(_status_subs.size());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
security_count_metric->set(_handles.size());
|
||||
}
|
||||
|
||||
private:
|
||||
void on_poll(trace::PerfLog& log) override {
|
||||
void on_poll(trace::PerfLog &log) override {
|
||||
|
||||
auto scoped_do_work = trace::log_scope(log, {}, "MDSource::on_poll", utils::TimeStamp::Interval::from_microseconds(2));
|
||||
auto scoped_do_work =
|
||||
trace::log_scope(log, {}, "MDSource::on_poll",
|
||||
utils::TimeStamp::Interval::from_microseconds(2));
|
||||
|
||||
// Book Updates
|
||||
Book book;
|
||||
@@ -158,11 +160,11 @@ class MDSource : public mercury::Actor, public mercury::IPollableActor {
|
||||
}
|
||||
|
||||
// Status updates
|
||||
for (auto& s : _status_subs) {
|
||||
for (auto &s : _status_subs) {
|
||||
auto status = s.handle.trading_status();
|
||||
if (status != s.status) {
|
||||
s.status = status;
|
||||
publish(_status_update, SecurityKey { s.handle.key() }, status);
|
||||
publish(_status_update, SecurityKey{s.handle.key()}, status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +173,7 @@ class MDSource : public mercury::Actor, public mercury::IPollableActor {
|
||||
_loop_timer->observe((start - stop).nanoseconds());
|
||||
|
||||
_counter += 1;
|
||||
if (_counter % (2<<20) == 0) {
|
||||
if (_counter % (2 << 20) == 0) {
|
||||
// Invoke periodic work every 2M calls on on_poll
|
||||
// This is approximately 20-30 seconds
|
||||
do_periodic_work();
|
||||
@@ -180,35 +182,39 @@ class MDSource : public mercury::Actor, public mercury::IPollableActor {
|
||||
|
||||
void do_periodic_work() {
|
||||
if (!_pending_handles.empty()) {
|
||||
for (auto iter = _pending_handles.begin(); iter != _pending_handles.end(); ++iter) {
|
||||
for (auto iter = _pending_handles.begin();
|
||||
iter != _pending_handles.end(); ++iter) {
|
||||
if (iter->handle->is_initialized()) {
|
||||
auto handle = *(iter->handle);
|
||||
LOG(OrderMan, Info, "Found md for {}. Pending handle removed.", handle.key());
|
||||
switch(iter->type) {
|
||||
case MDRequestType::BOOK:
|
||||
_handles.push_back({utils::TimeStamp(), handle,
|
||||
get_external_event_channel(handle.get_usersymbol()),
|
||||
std::make_unique<std::string>(securities::descriptor(
|
||||
handle.get_normalized_security()))});
|
||||
break;
|
||||
case MDRequestType::STATUS:
|
||||
for (auto& h : _status_subs) {
|
||||
// no need to reset status
|
||||
if (h.handle.key() == handle.key()) break;
|
||||
}
|
||||
_status_subs.push_back(
|
||||
StatusRecord{ handle, co2::TRADINGSTATUS_UNKNOWN });
|
||||
case MDRequestType::TICKER:
|
||||
LOG(OrderMan, Info, "Found md for {}. Pending handle removed.",
|
||||
handle.key());
|
||||
switch (iter->type) {
|
||||
case MDRequestType::BOOK:
|
||||
_handles.push_back(
|
||||
{utils::TimeStamp(), handle,
|
||||
get_external_event_channel(handle.get_usersymbol()),
|
||||
std::make_unique<std::string>(securities::descriptor(
|
||||
handle.get_normalized_security()))});
|
||||
break;
|
||||
case MDRequestType::STATUS:
|
||||
for (auto &h : _status_subs) {
|
||||
// no need to reset status
|
||||
if (h.handle.key() == handle.key())
|
||||
break;
|
||||
}
|
||||
_status_subs.push_back(
|
||||
StatusRecord{handle, co2::TRADINGSTATUS_UNKNOWN});
|
||||
case MDRequestType::TICKER:
|
||||
// We aren't currently monitoring for pending ticker requests
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
_pending_handles.erase(
|
||||
std::remove_if(_pending_handles.begin(),
|
||||
_pending_handles.end(),
|
||||
[](const auto& h) { return h.handle->is_initialized(); }),
|
||||
_pending_handles.end());
|
||||
std::remove_if(
|
||||
_pending_handles.begin(), _pending_handles.end(),
|
||||
[](const auto &h) { return h.handle->is_initialized(); }),
|
||||
_pending_handles.end());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,18 +235,18 @@ class MDSource : public mercury::Actor, public mercury::IPollableActor {
|
||||
auto mhandle = _md_consumer.get_managed_handle(k);
|
||||
if (mhandle->is_initialized()) {
|
||||
auto handle = *mhandle;
|
||||
_handles.push_back({utils::TimeStamp(), handle,
|
||||
get_external_event_channel(handle.get_usersymbol()),
|
||||
std::make_unique<std::string>(securities::descriptor(
|
||||
handle.get_normalized_security()))});
|
||||
_handles.push_back(
|
||||
{utils::TimeStamp(), handle,
|
||||
get_external_event_channel(handle.get_usersymbol()),
|
||||
std::make_unique<std::string>(
|
||||
securities::descriptor(handle.get_normalized_security()))});
|
||||
if (handle.is_synthetic())
|
||||
synthetic_count_metric.increment();
|
||||
}
|
||||
else {
|
||||
// A pending handle is a handle for security we are reasonbly sure exists
|
||||
// but we haven't yet found live market data for.
|
||||
} else {
|
||||
// A pending handle is a handle for security we are reasonbly sure
|
||||
// exists but we haven't yet found live market data for.
|
||||
LOG(OrderMan, Warn, "No market data for {}. Pending handle added.", k);
|
||||
_pending_handles.push_back({ mhandle, MDRequestType::BOOK });
|
||||
_pending_handles.push_back({mhandle, MDRequestType::BOOK});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,8 +259,17 @@ class MDSource : public mercury::Actor, public mercury::IPollableActor {
|
||||
|
||||
void on_ticker_sub(SecurityKey sk,
|
||||
metrics::CounterMetric<int> &channel_count_metric) {
|
||||
auto handle = _md_consumer.get_managed_handle(sk.value());
|
||||
|
||||
auto user_symbol = _md_consumer.get_handle(sk.value()).get_usersymbol();
|
||||
if (!handle->is_initialized()) {
|
||||
LOG(OrderMan, Warn,
|
||||
"Received ticker subscription for security {} which does not have "
|
||||
"valid market data. Ignoring",
|
||||
sk.value());
|
||||
return;
|
||||
}
|
||||
|
||||
auto user_symbol = handle->get_usersymbol();
|
||||
for (auto &ch : _channels) {
|
||||
if (ch.user_symbol == user_symbol) {
|
||||
auto it =
|
||||
@@ -262,7 +277,7 @@ class MDSource : public mercury::Actor, public mercury::IPollableActor {
|
||||
[sk](auto const &ev) { return ev.key() == sk; });
|
||||
if (it == ch.securities.end()) {
|
||||
// first time we are asked for this security, we will
|
||||
// publish the trades for it next time next round
|
||||
// publish the trades for it next time around
|
||||
LOG(OrderMan, Warn,
|
||||
"Starting to publish ticker updates on user symbol {} for "
|
||||
"security key: {} (sec count for the symbol: {} )",
|
||||
@@ -294,7 +309,7 @@ class MDSource : public mercury::Actor, public mercury::IPollableActor {
|
||||
|
||||
void on_status_sub(SecurityKey sk) {
|
||||
auto k = sk.value();
|
||||
for (auto& h : _status_subs) {
|
||||
for (auto &h : _status_subs) {
|
||||
if (h.handle.key() == k) {
|
||||
// reset status so it get resent next on_poll
|
||||
h.status = co2::TRADINGSTATUS_UNKNOWN;
|
||||
@@ -303,11 +318,11 @@ class MDSource : public mercury::Actor, public mercury::IPollableActor {
|
||||
}
|
||||
auto handle = _md_consumer.get_managed_handle(k);
|
||||
if (handle->is_initialized()) {
|
||||
_status_subs.push_back(StatusRecord{ *handle, co2::TRADINGSTATUS_UNKNOWN });
|
||||
}
|
||||
else {
|
||||
_status_subs.push_back(
|
||||
StatusRecord{*handle, co2::TRADINGSTATUS_UNKNOWN});
|
||||
} else {
|
||||
LOG(OrderMan, Warn, "No market data for {}. Pending handle added.", k);
|
||||
_pending_handles.push_back({ handle, MDRequestType::STATUS });
|
||||
_pending_handles.push_back({handle, MDRequestType::STATUS});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,7 +352,7 @@ class MDSource : public mercury::Actor, public mercury::IPollableActor {
|
||||
md::MDConsumerHandle handle;
|
||||
co2::TradingStatus status;
|
||||
};
|
||||
boost::container::small_vector<StatusRecord,20> _status_subs;
|
||||
boost::container::small_vector<StatusRecord, 20> _status_subs;
|
||||
|
||||
md::MDConsumer _md_consumer;
|
||||
mercury::Stream<BookUpdateEvent> _book_update;
|
||||
|
||||
@@ -101,6 +101,8 @@ void OrderStore::on_order_state_update(
|
||||
for (auto const &ev : *u.events) {
|
||||
|
||||
auto &rec_info = me->known_orders[ev.key];
|
||||
LOG(iLink3,Info, "Received order state update for {}",
|
||||
ev.key.value());
|
||||
auto &rec = rec_info.rec;
|
||||
bts_assert(rec.has_def());
|
||||
rec.set_key(ev.key.value());
|
||||
@@ -123,6 +125,8 @@ void OrderStore::on_order_definition_update(
|
||||
std::set<OrderKey> modified_orders;
|
||||
if (u.events)
|
||||
for (auto const &ev : *u.events) {
|
||||
LOG(iLink3,Info, "Received order definition update for {}",
|
||||
ev.key.value());
|
||||
auto &rec_info = me->known_orders[ev.key];
|
||||
auto &rec = rec_info.rec;
|
||||
rec.set_key(ev.key.value());
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "IL3ConnectionHandler.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
namespace ilink3 {
|
||||
|
||||
struct IL3Connection {
|
||||
virtual ~IL3Connection() = default;
|
||||
virtual void connect(IL3ConnectionHandler&) = 0;
|
||||
virtual void disconnect() = 0;
|
||||
// Switch connection but do not connect()
|
||||
virtual void failover() = 0;
|
||||
virtual void send(const std::string_view) = 0;
|
||||
virtual void send(const std::vector<std::string_view>&) = 0;
|
||||
};
|
||||
|
||||
}}}//namespace
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "IL3ConnectionHandler.h"
|
||||
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
namespace ilink3 {
|
||||
|
||||
IL3ConnectionHandler::~IL3ConnectionHandler() = default;
|
||||
|
||||
}}}
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
namespace ilink3 {
|
||||
|
||||
struct IL3ConnectionHandler {
|
||||
virtual ~IL3ConnectionHandler() ;
|
||||
virtual void on_connect_success() = 0;
|
||||
virtual void on_disconnect() = 0;
|
||||
// Send available data and length. Handler will return what it consumed
|
||||
virtual size_t on_data(const std::string_view&) = 0;
|
||||
};
|
||||
|
||||
}}}//namespace
|
||||
@@ -0,0 +1,140 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include "IL3GeneratedFull.h"
|
||||
#include "IL3MessageFramer.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
namespace ilink3 {
|
||||
|
||||
template <class Handler, class T>
|
||||
void handle(Handler& h, const char* data, uint16_t len) {
|
||||
const FramingHeader* fheader = reinterpret_cast<const FramingHeader*>(data);
|
||||
iLinkBinary::MessageHeader mheader {
|
||||
(char*)data, sizeof(FramingHeader), fheader->message_size,
|
||||
iLinkBinary::MessageHeader::sbeSchemaVersion() };
|
||||
|
||||
T t {
|
||||
const_cast<char*>(data),
|
||||
sizeof(FramingHeader) + iLinkBinary::MessageHeader::encodedLength(),
|
||||
len,
|
||||
mheader.blockLength(),
|
||||
mheader.version()};
|
||||
h.handle(t);
|
||||
}
|
||||
|
||||
|
||||
template <class H>
|
||||
void dispatch_message(H& handler, const FramingHeader* header, const char* data) {
|
||||
using namespace iLinkBinary;
|
||||
bts_assert_d(header->encoding_type == 0XCAFE);
|
||||
MessageHeader mheader {
|
||||
(char*)data, sizeof(FramingHeader), header->message_size,
|
||||
MessageHeader::sbeSchemaVersion() };
|
||||
|
||||
switch(mheader.templateId()) {
|
||||
case 501: handle<H, NegotiationResponse501>(handler, data, header->message_size); break;
|
||||
case 502: handle<H, NegotiationReject502>(handler, data, header->message_size); break;
|
||||
case 504: handle<H, EstablishmentAck504>(handler, data, header->message_size); break;
|
||||
case 505: handle<H, EstablishmentReject505>(handler, data, header->message_size); break;
|
||||
case 506: handle<H, Sequence506>(handler, data, header->message_size); break;
|
||||
case 507: handle<H, Terminate507>(handler, data, header->message_size); break;
|
||||
case 509: handle<H, Retransmission509>(handler, data, header->message_size); break;
|
||||
case 510: handle<H, RetransmitReject510>(handler, data, header->message_size); break;
|
||||
case 513: handle<H, NotApplied513>(handler, data, header->message_size); break;
|
||||
case 519: handle<H, PartyDetailsDefinitionRequestAck519>(handler, data, header->message_size); break;
|
||||
case 521: handle<H, BusinessReject521>(handler, data, header->message_size); break;
|
||||
case 522: handle<H, ExecutionReportNew522>(handler, data, header->message_size); break;
|
||||
case 523: handle<H, ExecutionReportReject523>(handler, data, header->message_size); break;
|
||||
case 524: handle<H, ExecutionReportElimination524>(handler, data, header->message_size); break;
|
||||
case 525: handle<H, ExecutionReportTradeOutright525>(handler, data, header->message_size); break;
|
||||
case 526: handle<H, ExecutionReportTradeSpread526>(handler, data, header->message_size); break;
|
||||
case 527: handle<H, ExecutionReportTradeSpreadLeg527>(handler, data, header->message_size); break;
|
||||
case 531: handle<H, ExecutionReportModify531>(handler, data, header->message_size); break;
|
||||
case 532: handle<H, ExecutionReportStatus532>(handler, data, header->message_size); break;
|
||||
case 534: handle<H, ExecutionReportCancel534>(handler, data, header->message_size); break;
|
||||
case 535: handle<H, OrderCancelReject535>(handler, data, header->message_size); break;
|
||||
case 536: handle<H, OrderCancelReplaceReject536>(handler, data, header->message_size); break;
|
||||
// case 538: handle<H, PartyDetailsListReport538>(handler, data, header->message_size); break;
|
||||
// The Execution Acknowledgment message notifies CME that a given fill has either been accepted or rejected by a counterparty for EU bilateral trades.
|
||||
// case 539: handle<H, ExecutionAck539>(handler, data, header->message_size); break;
|
||||
// case 544: handle<H, NewOrderCross544>(handler, data, header->message_size); break;
|
||||
// case 545: handle<H, MassQuoteAck545>(handler, data, header->message_size); break;
|
||||
// case 546: handle<H, RequestForQuoteAck546>(handler, data, header->message_size); break;
|
||||
// case 547: handle<H, QuoteCancelAck547>(handler, data, header->message_size); break;
|
||||
case 548: handle<H, ExecutionReportTradeAddendumOutright548>(handler, data, header->message_size); break;
|
||||
case 549: handle<H, ExecutionReportTradeAddendumSpread549>(handler, data, header->message_size); break;
|
||||
case 550: handle<H, ExecutionReportTradeAddendumSpreadLeg550>(handler, data, header->message_size); break;
|
||||
// case 558: handle<H, iLinkBinary::OrderMassActionReport558>(handler, data, header->message_size); break;
|
||||
// case 561: handle<H, iLinkBinary::SecurityDefinitionResponse561>(handler, data, header->message_size); break;
|
||||
}
|
||||
}
|
||||
|
||||
template <class H>
|
||||
void dispatch_execution_reports(H& handler, const FramingHeader* header, const char* data) {
|
||||
using namespace iLinkBinary;
|
||||
bts_assert_d(header->encoding_type == 0XCAFE);
|
||||
MessageHeader mheader {
|
||||
(char*)data, sizeof(FramingHeader), header->message_size,
|
||||
MessageHeader::sbeSchemaVersion() };
|
||||
|
||||
switch(mheader.templateId()) {
|
||||
case 522: handle<H, ExecutionReportNew522>(handler, data, header->message_size); break;
|
||||
case 523: handle<H, ExecutionReportReject523>(handler, data, header->message_size); break;
|
||||
case 524: handle<H, ExecutionReportElimination524>(handler, data, header->message_size); break;
|
||||
case 525: handle<H, ExecutionReportTradeOutright525>(handler, data, header->message_size); break;
|
||||
case 526: handle<H, ExecutionReportTradeSpread526>(handler, data, header->message_size); break;
|
||||
case 527: handle<H, ExecutionReportTradeSpreadLeg527>(handler, data, header->message_size); break;
|
||||
case 531: handle<H, ExecutionReportModify531>(handler, data, header->message_size); break;
|
||||
case 532: handle<H, ExecutionReportStatus532>(handler, data, header->message_size); break;
|
||||
case 534: handle<H, ExecutionReportCancel534>(handler, data, header->message_size); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// This handler handles exchange messages for testing
|
||||
template <class H>
|
||||
void dispatch_exchange_message(H& handler, const FramingHeader* header, const char* data) {
|
||||
using namespace iLinkBinary;
|
||||
bts_assert_d(header->encoding_type == 0XCAFE);
|
||||
MessageHeader mheader {
|
||||
(char*)data, sizeof(FramingHeader), header->message_size,
|
||||
MessageHeader::sbeSchemaVersion() };
|
||||
// Rather than trying to be exhaustive like the client
|
||||
// we will only add handlers for the messages we use for testing
|
||||
switch(mheader.templateId()) {
|
||||
case 500: handle<H, Negotiate500>(handler, data, header->message_size); break;
|
||||
case 503: handle<H, Establish503>(handler, data, header->message_size); break;
|
||||
case 506: handle<H, Sequence506>(handler, data, header->message_size); break;
|
||||
case 508: handle<H, RetransmitRequest508>(handler, data, header->message_size); break;
|
||||
case 518: handle<H, PartyDetailsDefinitionRequest518>(handler, data, header->message_size); break;
|
||||
case 514: handle<H, NewOrderSingle514>(handler, data, header->message_size); break;
|
||||
case 515: handle<H, OrderCancelReplaceRequest515>(handler, data, header->message_size); break;
|
||||
case 516: handle<H, OrderCancelRequest516>(handler, data, header->message_size); break;
|
||||
}
|
||||
}
|
||||
|
||||
template <class Handler, class Dispatcher>
|
||||
size_t consume_messages(
|
||||
Handler& handler, const char* data, size_t len, Dispatcher dispatch) {
|
||||
// void(*dispatch)(Handler&, const FramingHeader*, const char*)) {
|
||||
size_t read = 0;
|
||||
while(len > sizeof(FramingHeader)) {
|
||||
// read the FramingHeader
|
||||
const FramingHeader* header = reinterpret_cast<const FramingHeader*>(data);
|
||||
// Check if we can consume the message
|
||||
auto msize = header->message_size;
|
||||
if (msize <= len) {
|
||||
read += msize;
|
||||
dispatch(handler, header, data);
|
||||
data += msize;
|
||||
len -= msize;
|
||||
}
|
||||
else {
|
||||
return read;
|
||||
}
|
||||
}
|
||||
return read;
|
||||
}
|
||||
|
||||
}}}//namespace
|
||||
@@ -0,0 +1,662 @@
|
||||
#include "IL3GW.h"
|
||||
#include "IL3Dispatcher.h"
|
||||
#include "IL3GeneratedFull.h"
|
||||
#include "IL3MessageFramer.h"
|
||||
#include "ILink3Utils.h"
|
||||
#include "lib/orderman/orderman_utils/fix_order_codec.h"
|
||||
#include "lib/utils/SecureLogon.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
#include "lib/utils/datetime.h"
|
||||
|
||||
/*
|
||||
# Some notes about session binding and initialization: #
|
||||
|
||||
## Official documentation:
|
||||
https://www.cmegroup.com/confluence/display/EPICSANDBOX/iLink+3+Binary+Order+Entry+-+Session+Layer#iLink3BinaryOrderEntry-SessionLayer-WeeklyReset
|
||||
|
||||
## Begining of week (new session?)
|
||||
- config.session = X
|
||||
- config.outgoing_sequence = 1
|
||||
-> Negotiate session=X
|
||||
<- NegotiateResponse session=X, oldsession=Y, oldSeq=N
|
||||
if oldSeq > 0 -> ReplayRequest
|
||||
-> Establish seq=1
|
||||
<- EstablishAck oldsession=Y, oldSeq=N
|
||||
|
||||
## Middle of week (same session)
|
||||
- config.session = X
|
||||
- config.outgoing_sequence > 1
|
||||
-> Establish seq=N
|
||||
*/
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
namespace ilink3 {
|
||||
|
||||
log::CharPtrWrapper wrap(const char *str) { return log::CharPtrWrapper{str}; }
|
||||
|
||||
IL3GW::IL3GW(IL3Connection &con, IL3MessageFramer &buffer, IL3SecDB *db,
|
||||
const Session &session, const Config &conf,
|
||||
config::JetFIX::Connection const *cfg)
|
||||
: _config(conf), _x_state(State::INIT), _buffer(buffer),
|
||||
_on_state_change([](auto) {}), _on_exe_report([](auto *) {}),
|
||||
_on_session_change([](auto) {}), _connection(con), _session(session),
|
||||
_msg_count(0), _time(), _pool(), _exe_parser(cfg, db), _retransmit() {
|
||||
_clorid_buffer.resize(clordid_sz());
|
||||
}
|
||||
|
||||
void IL3GW::connect() {
|
||||
bts_assert(state() == State::INIT || state() == State::ERROR);
|
||||
set_state(State::CONNECTING);
|
||||
_connection.connect(*this); // -> on_connect_success
|
||||
}
|
||||
|
||||
// This determines the session uuid
|
||||
void IL3GW::send_negotiate() {
|
||||
// add 2 bytes for the empty 'credentials' (39008) length which must be
|
||||
// present
|
||||
auto msg = _buffer.frame<iLinkBinary::Negotiate500>(
|
||||
iLinkBinary::Negotiate500::credentialsHeaderLength());
|
||||
msg.uUID(_session.uuid);
|
||||
msg.requestTimestamp(_time.now());
|
||||
msg.putSession(_config.cme_session);
|
||||
// We need this call to set the length of the credential block to 0
|
||||
// This behavior is specific to "data" in the xml template
|
||||
msg.putCredentials("", 0);
|
||||
msg.putFirm(_config.firm);
|
||||
|
||||
const auto ld = glbx::calculate_hmac(
|
||||
_config.cme_session, std::to_string(msg.requestTimestamp()),
|
||||
std::to_string(msg.uUID()), _config.cme_session, _config.firm);
|
||||
msg.putAccessKeyID(ld.access_key);
|
||||
msg.putHMACSignature(ld.hmac);
|
||||
|
||||
std::string temp = ld.canonical;
|
||||
for (size_t x = 0; x < temp.size(); ++x) {
|
||||
if (temp[x] == '\n')
|
||||
temp[x] = '$';
|
||||
}
|
||||
|
||||
flush(false);
|
||||
// clear HMAC for json logging
|
||||
msg.putHMACSignature(std::string_view{nullptr, 0});
|
||||
log_out(msg, 0);
|
||||
// expect -> NegotiationResponse501 or NegotiationReject502
|
||||
}
|
||||
|
||||
void IL3GW::send_establish() {
|
||||
// add 2 bytes for the empty 'credentials' (39008) length which must be
|
||||
// present
|
||||
auto msg = _buffer.frame<iLinkBinary::Establish503>(2);
|
||||
msg.uUID(_session.uuid);
|
||||
msg.requestTimestamp(_time.now());
|
||||
msg.putSession(_config.cme_session);
|
||||
msg.putCredentials("", 0);
|
||||
msg.putFirm(_config.firm);
|
||||
|
||||
msg.putTradingSystemName(std::string_view("Katallage Trading System"));
|
||||
msg.putTradingSystemVersion(std::string_view("1"));
|
||||
msg.putTradingSystemVendor(std::string_view("BTS"));
|
||||
// On primary connection, the expected message sequence number of the next
|
||||
// business message from customer to CME
|
||||
msg.nextSeqNo(_session.to_cme);
|
||||
msg.keepAliveInterval(30000);
|
||||
|
||||
const auto ld =
|
||||
glbx::calculate_hmac(_config.cme_session,
|
||||
// RequestTimestamp
|
||||
std::to_string(msg.requestTimestamp()),
|
||||
std::to_string(msg.uUID()), _config.cme_session,
|
||||
// Firm ID
|
||||
_config.firm,
|
||||
// TradingSystemName
|
||||
msg.getTradingSystemNameAsString(),
|
||||
// TradingSystemVersion
|
||||
msg.getTradingSystemVersionAsString(),
|
||||
// TradingSystemVendor
|
||||
msg.getTradingSystemVendorAsString(),
|
||||
// NextSeqNo
|
||||
std::to_string(msg.nextSeqNo()),
|
||||
// KeepAliveInterval
|
||||
std::to_string(msg.keepAliveInterval()));
|
||||
|
||||
msg.putAccessKeyID(ld.access_key);
|
||||
msg.putHMACSignature(ld.hmac);
|
||||
|
||||
flush(false);
|
||||
// clear HMAC for json logging
|
||||
msg.putHMACSignature(std::string_view{nullptr, 0});
|
||||
log_out(msg, 0);
|
||||
// expect -> EstablishmentAck504 or EstablishmentReject505
|
||||
}
|
||||
|
||||
void IL3GW::send_sequence(bool lapsed) {
|
||||
auto msg = _buffer.frame<iLinkBinary::Sequence506>();
|
||||
msg.uUID(_session.uuid);
|
||||
msg.nextSeqNo(_session.to_cme);
|
||||
msg.faultToleranceIndicator(iLinkBinary::FTI::NULL_VALUE);
|
||||
msg.keepAliveIntervalLapsed(lapsed
|
||||
? iLinkBinary::KeepAliveLapsed::Lapsed
|
||||
: iLinkBinary::KeepAliveLapsed::NotLapsed);
|
||||
log_out(msg, 0);
|
||||
}
|
||||
|
||||
void IL3GW::send_retransmit_request(uint64_t uuid, uint32_t from,
|
||||
size_t count) {
|
||||
bts_assert(from > 0);
|
||||
using namespace iLinkBinary;
|
||||
auto msg = _buffer.frame<RetransmitRequest508>();
|
||||
msg.uUID(_session.uuid);
|
||||
msg.lastUUID(uuid);
|
||||
msg.requestTimestamp(_time.now());
|
||||
msg.fromSeqNo(from);
|
||||
msg.msgCount(count);
|
||||
log_out(msg, 0);
|
||||
}
|
||||
|
||||
uint64_t IL3GW::send_party_details(const api::orderman::RoutingRecord &route) {
|
||||
using namespace iLinkBinary;
|
||||
|
||||
auto msg = _buffer.frame<PartyDetailsDefinitionRequest518>(
|
||||
// 2 repeating group header.
|
||||
// 1 for party details and 1 for trade reg
|
||||
// This seems unsafe but the api doesn't seem to want you to know how to
|
||||
// size buffers ahead of time
|
||||
2 * PartyDetailsDefinitionRequest518::NoPartyDetails::sbeHeaderSize() +
|
||||
// N * size of each block
|
||||
3 * PartyDetailsDefinitionRequest518::NoPartyDetails::sbeBlockLength() +
|
||||
0 * PartyDetailsDefinitionRequest518::NoTrdRegPublications::
|
||||
sbeBlockLength());
|
||||
msg.partyDetailsListReqID(0);
|
||||
msg.sendingTimeEpoch(_time.now());
|
||||
msg.listUpdateAction(ListUpdAct::Add);
|
||||
msg.seqNum(next_seq());
|
||||
// msg.putMemo("") -- not supported
|
||||
if (route.smp_id().empty()) {
|
||||
msg.selfMatchPreventionID(
|
||||
PartyDetailsDefinitionRequest518::selfMatchPreventionIDNullValue());
|
||||
} else {
|
||||
auto smp_id = std::atoi(route.smp_id().c_str());
|
||||
msg.selfMatchPreventionID(smp_id);
|
||||
}
|
||||
msg.cmtaGiveupCD(CmtaGiveUpCD::NULL_VALUE);
|
||||
msg.custOrderCapacity(map_cust_cti(route.cti_code()));
|
||||
msg.clearingAccountType(map_customer_or_firm(route.customer_or_firm()));
|
||||
msg.selfMatchPreventionInstruction(
|
||||
map_smp_instruction(route.smp_instruction()));
|
||||
msg.avgPxIndicator(AvgPxInd::NULL_VALUE);
|
||||
msg.clearingTradePriceType(SLEDS::NULL_VALUE);
|
||||
msg.custOrderHandlingInst(static_cast<iLinkBinary::CustOrdHandlInst::Value>(
|
||||
route.cust_order_handing_inst()[0]));
|
||||
msg.executor(PartyDetailsDefinitionRequest518::executorNullValue());
|
||||
msg.iDMShortCode(PartyDetailsDefinitionRequest518::iDMShortCodeNullValue());
|
||||
|
||||
auto details = msg.noPartyDetailsCount(3);
|
||||
details.next();
|
||||
details.partyDetailRole(PartyDetailRole::CustomerAccount);
|
||||
details.putPartyDetailID(route.account());
|
||||
details.next();
|
||||
details.partyDetailRole(PartyDetailRole::ExecutingFirm);
|
||||
// 004 in cert
|
||||
details.putPartyDetailID(
|
||||
std::string_view(route.sender_compid().c_str() + 3, 3));
|
||||
details.next();
|
||||
details.partyDetailRole(PartyDetailRole::Operator);
|
||||
details.putPartyDetailID(std::string_view(route.sender_compid().c_str(), 3));
|
||||
msg.noTrdRegPublicationsCount(0);
|
||||
// In the future we may check for existing party details definitions and
|
||||
// return that id
|
||||
log_out(msg, msg.seqNum());
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool needs_stop_px(api::orderman::NativeOrderType order_type) {
|
||||
return order_type ==
|
||||
api::orderman::NativeOrderType::NATIVE_ORDER_TYPE_STOP ||
|
||||
order_type ==
|
||||
api::orderman::NativeOrderType::NATIVE_ORDER_TYPE_STOP_LIMIT;
|
||||
}
|
||||
bool need_px(api::orderman::NativeOrderType order_type) {
|
||||
return order_type !=
|
||||
api::orderman::NativeOrderType::NATIVE_ORDER_TYPE_MARKET &&
|
||||
order_type !=
|
||||
api::orderman::NativeOrderType::NATIVE_ORDER_TYPE_MARKET_LIMIT &&
|
||||
order_type != api::orderman::NativeOrderType::NATIVE_ORDER_TYPE_STOP;
|
||||
}
|
||||
|
||||
void IL3GW::send_order(const CreateOrderMsg &create) {
|
||||
bts_assert_d(create.routing_record);
|
||||
bts_assert_d(create.security);
|
||||
bts_assert_d(create.security->has_glbx());
|
||||
|
||||
auto party = send_party_details(*create.routing_record);
|
||||
auto msg = _buffer.frame<iLinkBinary::NewOrderSingle514>();
|
||||
|
||||
if (need_px(create.order_type)) {
|
||||
msg.price().mantissa(to_price9(create.price));
|
||||
} else {
|
||||
msg.price().mantissa(iLinkBinary::PRICENULL9::mantissaNullValue());
|
||||
}
|
||||
msg.orderQty(create.quantity.value());
|
||||
msg.securityID(create.security->glbx().exchange_id());
|
||||
msg.side(map_side(create.side));
|
||||
msg.seqNum(next_seq());
|
||||
msg.putSenderID(create.routing_record->operator_id());
|
||||
encode_clorid(create.key, SecurityKey(create.security->id()),
|
||||
&_clorid_buffer);
|
||||
msg.putClOrdID(_clorid_buffer);
|
||||
msg.partyDetailsListReqID(party);
|
||||
msg.orderRequestID(++_msg_count);
|
||||
msg.sendingTimeEpoch(_time.now());
|
||||
if (needs_stop_px(create.order_type)) {
|
||||
msg.stopPx().mantissa(to_price9(create.stop_px));
|
||||
} else {
|
||||
msg.stopPx().mantissa(iLinkBinary::PRICENULL9::mantissaNullValue());
|
||||
}
|
||||
msg.putLocation(create.routing_record->location());
|
||||
msg.minQty(iLinkBinary::NewOrderSingle514::minQtyNullValue());
|
||||
if (create.time_in_force != api::orderman::TimeInForce::TIME_IN_FORCE_IOC) {
|
||||
msg.displayQty(create.display_quantity.value());
|
||||
} else {
|
||||
msg.displayQty(iLinkBinary::NewOrderSingle514::displayQtyNullValue());
|
||||
}
|
||||
if (create.time_in_force == api::orderman::TimeInForce::TIME_IN_FORCE_DATE) {
|
||||
// TODO: # of days since jan 1 1970
|
||||
msg.expireDate(18424);
|
||||
} else {
|
||||
msg.expireDate(iLinkBinary::NewOrderSingle514::expireDateNullValue());
|
||||
}
|
||||
msg.ordType(map_order_type(create.order_type));
|
||||
msg.timeInForce(map_time_in_force(create.time_in_force));
|
||||
msg.manualOrderIndicator(
|
||||
map_manual_order_indicator(create.manual_order_indicator));
|
||||
msg.execInst().clear();
|
||||
msg.executionMode(iLinkBinary::ExecMode::NULL_VALUE);
|
||||
msg.liquidityFlag(iLinkBinary::BooleanNULL::NULL_VALUE);
|
||||
msg.managedOrder(iLinkBinary::BooleanNULL::NULL_VALUE);
|
||||
msg.shortSaleType(iLinkBinary::ShortSaleType::NULL_VALUE);
|
||||
log_out(msg, msg.seqNum());
|
||||
}
|
||||
|
||||
void IL3GW::send_cancel_replace(const CancelReplaceOrderMsg &replace) {
|
||||
const auto &create = replace.create_fields;
|
||||
bts_assert_d(create.routing_record);
|
||||
bts_assert_d(create.security);
|
||||
bts_assert_d(create.security->has_glbx());
|
||||
|
||||
auto party = send_party_details(*create.routing_record);
|
||||
auto msg = _buffer.frame<iLinkBinary::OrderCancelReplaceRequest515>();
|
||||
|
||||
msg.orderID(replace.exchange_order_id.value());
|
||||
|
||||
if (need_px(create.order_type)) {
|
||||
msg.price().mantissa(to_price9(create.price));
|
||||
} else {
|
||||
msg.price().mantissa(iLinkBinary::PRICENULL9::mantissaNullValue());
|
||||
}
|
||||
msg.orderQty(create.quantity.value());
|
||||
msg.securityID(create.security->glbx().exchange_id());
|
||||
msg.side(map_side(create.side));
|
||||
msg.seqNum(next_seq());
|
||||
msg.putSenderID(create.routing_record->operator_id());
|
||||
encode_clorid(create.key, SecurityKey(create.security->id()),
|
||||
&_clorid_buffer);
|
||||
msg.putClOrdID(_clorid_buffer);
|
||||
msg.partyDetailsListReqID(party);
|
||||
msg.orderRequestID(++_msg_count);
|
||||
msg.sendingTimeEpoch(_time.now());
|
||||
if (needs_stop_px(create.order_type)) {
|
||||
msg.stopPx().mantissa(to_price9(create.stop_px));
|
||||
} else {
|
||||
msg.stopPx().mantissa(iLinkBinary::PRICENULL9::mantissaNullValue());
|
||||
}
|
||||
msg.putLocation(create.routing_record->location());
|
||||
msg.minQty(iLinkBinary::NewOrderSingle514::minQtyNullValue());
|
||||
msg.displayQty(create.display_quantity.value());
|
||||
msg.expireDate(iLinkBinary::NewOrderSingle514::expireDateNullValue());
|
||||
msg.ordType(map_order_type(create.order_type));
|
||||
msg.timeInForce(map_time_in_force(create.time_in_force));
|
||||
msg.manualOrderIndicator(
|
||||
map_manual_order_indicator(create.manual_order_indicator));
|
||||
msg.oFMOverride(iLinkBinary::OFMOverrideReq::Enabled);
|
||||
msg.execInst().clear();
|
||||
msg.executionMode(iLinkBinary::ExecMode::NULL_VALUE);
|
||||
msg.liquidityFlag(iLinkBinary::BooleanNULL::NULL_VALUE);
|
||||
msg.managedOrder(iLinkBinary::BooleanNULL::NULL_VALUE);
|
||||
msg.shortSaleType(iLinkBinary::ShortSaleType::NULL_VALUE);
|
||||
log_out(msg, msg.seqNum());
|
||||
}
|
||||
|
||||
void IL3GW::send_cancel(const CancelOrderMsg &cancel) {
|
||||
bts_assert_d(cancel.routing_record);
|
||||
bts_assert_d(cancel.security);
|
||||
bts_assert_d(cancel.security->has_glbx());
|
||||
|
||||
auto party = send_party_details(*cancel.routing_record);
|
||||
auto msg = _buffer.frame<iLinkBinary::OrderCancelRequest516>();
|
||||
|
||||
msg.orderID(cancel.exchange_order_id.value());
|
||||
msg.partyDetailsListReqID(party);
|
||||
msg.manualOrderIndicator(
|
||||
map_manual_order_indicator(cancel.manual_order_indicator));
|
||||
msg.seqNum(next_seq());
|
||||
msg.putSenderID(cancel.routing_record->operator_id());
|
||||
encode_clorid(cancel.key, SecurityKey(cancel.security->id()),
|
||||
&_clorid_buffer);
|
||||
msg.putClOrdID(_clorid_buffer);
|
||||
msg.orderRequestID(++_msg_count);
|
||||
msg.sendingTimeEpoch(_time.now());
|
||||
msg.putLocation(cancel.routing_record->location());
|
||||
msg.securityID(cancel.security->glbx().exchange_id());
|
||||
msg.side(map_side(cancel.side));
|
||||
msg.liquidityFlag(iLinkBinary::BooleanNULL::NULL_VALUE);
|
||||
log_out(msg, msg.seqNum());
|
||||
}
|
||||
|
||||
void IL3GW::send_terminate(uint16_t code) {
|
||||
LOG(iLink3, Info, "Terminate");
|
||||
auto msg = _buffer.frame<iLinkBinary::Terminate507>();
|
||||
msg.uUID(_session.uuid);
|
||||
msg.requestTimestamp(_time.now());
|
||||
msg.errorCodes(code);
|
||||
log_out(msg, 0);
|
||||
}
|
||||
|
||||
void IL3GW::flush(bool publish) {
|
||||
_buffer.flush(_connection);
|
||||
if (publish)
|
||||
publish_session_update();
|
||||
}
|
||||
|
||||
const char *state_string(State s) {
|
||||
switch (s) {
|
||||
case State::INIT:
|
||||
return "INIT";
|
||||
case State::CONNECTING:
|
||||
return "CONNECTING";
|
||||
case State::NEGOTIATING:
|
||||
return "NEGOTIATING";
|
||||
case State::ESTABLISHING:
|
||||
return "ESTABLISHING";
|
||||
case State::RETRANSMITTING:
|
||||
return "RETRANSMITTING";
|
||||
case State::READY:
|
||||
return "READY";
|
||||
case State::ERROR:
|
||||
return "ERROR";
|
||||
}
|
||||
return "UNKNOWN";
|
||||
}
|
||||
log::CharPtrWrapper wstate_string(State s) { return wrap(state_string(s)); }
|
||||
|
||||
void IL3GW::set_state(State s) {
|
||||
if (s != _x_state) {
|
||||
LOG(iLink3, Info, "ILinkGW {}: {}->{}", _session.uuid,
|
||||
wstate_string(_x_state), wstate_string(s));
|
||||
_x_state = s;
|
||||
if (_on_state_change)
|
||||
_on_state_change(s);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// IConnectionHandler
|
||||
|
||||
void IL3GW::on_connect_success() {
|
||||
if (!_session) {
|
||||
// If we have a 0 cme_seq this is a new session and we need to negotiate
|
||||
// it
|
||||
LOG(iLink3, Info, "Negotiating new iLink session. {}", _session.uuid);
|
||||
set_state(State::NEGOTIATING);
|
||||
send_negotiate();
|
||||
} else {
|
||||
// We only need to establish the current sequence number
|
||||
LOG(iLink3, Info, "re-establishing existing iLink session. {}",
|
||||
_session.uuid);
|
||||
_session.to_cme = std::max(_session.to_cme, 1u);
|
||||
set_state(State::ESTABLISHING);
|
||||
send_establish();
|
||||
}
|
||||
}
|
||||
|
||||
void IL3GW::on_disconnect() {
|
||||
LOG(iLink3, Error, "Disconnected.");
|
||||
if (_config.failover_on_disconnect) {
|
||||
LOG(iLink3, Error, "Attempting failover");
|
||||
_connection.failover();
|
||||
connect();
|
||||
} else {
|
||||
set_state(State::ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
void IL3GW::enqueue_retransmit(uint32_t from, uint32_t to, uint64_t uuid) {
|
||||
LOG(iLink3, Warn, "Prepare retransmit from: {} to: {}", from, to);
|
||||
bts_assert(to >= from);
|
||||
do {
|
||||
// +1 because to/from are using an inclusive range
|
||||
auto count = std::min(to - from + 1, Retransmit::MAX_RECOVERY);
|
||||
_retransmit.push(Retransmit{uuid, from, from + count - 1});
|
||||
from += count;
|
||||
} while (from < to);
|
||||
}
|
||||
|
||||
void IL3GW::begin_retransmit() {
|
||||
if (_retransmit.empty())
|
||||
return;
|
||||
auto &working = _retransmit.front();
|
||||
// Don't pop the queue because we need to know when we're done
|
||||
auto count = working.to - working.from + 1;
|
||||
LOG(iLink3, Warn,
|
||||
"Sending retransmit for missing packets: from: {} to: {} count: {}",
|
||||
working.from, working.to, count);
|
||||
bts_assert_d(count <= Retransmit::MAX_RECOVERY);
|
||||
send_retransmit_request(working.uuid, working.from, count);
|
||||
}
|
||||
|
||||
void IL3GW::on_retransmit_complete() {
|
||||
// Replay is complete. Advance to go. Collect $200
|
||||
_retransmit.pop();
|
||||
LOG(iLink3, Warn, "Retransmit complete");
|
||||
if (!_retransmit.empty()) {
|
||||
// More replay to do...
|
||||
begin_retransmit();
|
||||
flush();
|
||||
} else {
|
||||
// Replay is finished, transition to ready state.
|
||||
// Since we're already established we dont' need to send anything
|
||||
set_state(State::READY);
|
||||
}
|
||||
}
|
||||
|
||||
size_t IL3GW::on_data(const std::string_view &data) {
|
||||
return consume_messages(*this, data.data(), data.size(),
|
||||
dispatch_message<IL3GW>);
|
||||
}
|
||||
|
||||
void IL3GW::handle(const iLinkBinary::NegotiationResponse501 &msg) {
|
||||
// If we're receiving a NegotiateResponse we just created a session
|
||||
log_in(msg, 0);
|
||||
|
||||
// NegotiationResponse indicates the session was created. CME sequence will
|
||||
// be 1
|
||||
_session.from_cme = 1;
|
||||
publish_session_update();
|
||||
|
||||
// Even though the CME sends a previous uuid+sequence we can't act on
|
||||
// that data right now since we aren't established. We don't have to remember
|
||||
// it, though, because exactly the same data comes on the EstablishmentAck
|
||||
// msg.previousUUID(), msg.previousSeqNo();
|
||||
|
||||
set_state(State::ESTABLISHING);
|
||||
send_establish();
|
||||
}
|
||||
|
||||
void IL3GW::handle(const iLinkBinary::NegotiationReject502 &msg) {
|
||||
LOG(iLink3, Error, "Negotiate Reject: {} '{}'.", msg.errorCodes(),
|
||||
std::string(translate_negotiation_reject(msg.errorCodes())));
|
||||
log_in(msg, 0);
|
||||
_connection.disconnect();
|
||||
set_state(State::ERROR);
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::EstablishmentAck504 &msg) {
|
||||
// previous uuid+sequence
|
||||
auto cme_prev_uuid = msg.previousUUID();
|
||||
auto cme_prev_seq = msg.previousSeqNo();
|
||||
if (cme_prev_seq != 0 && cme_prev_uuid != _session.uuid) {
|
||||
// There was a previous session and we need to replay messages from it
|
||||
|
||||
// We *intend* to only have a single session each week except
|
||||
// in the case of catastrophic failure. So If we log in and
|
||||
// there is a previous UUID we can just replay it entirely.
|
||||
// The other possibility is a session was created automatically
|
||||
// to handle a fill from a GTC order from the previous week
|
||||
enqueue_retransmit(1, cme_prev_seq, cme_prev_uuid);
|
||||
}
|
||||
|
||||
// next sequence number from the current session may also be ahead
|
||||
auto cme_current_seq = msg.nextSeqNo() - 1;
|
||||
if (_session.from_cme < cme_current_seq) {
|
||||
// If we're behind it indicates we missed messages while disconnected
|
||||
enqueue_retransmit(_session.from_cme + 1, cme_current_seq, msg.uUID());
|
||||
}
|
||||
|
||||
_session.from_cme = cme_current_seq;
|
||||
log_in(msg, 0);
|
||||
|
||||
if (!_retransmit.empty()) {
|
||||
send_sequence();
|
||||
begin_retransmit();
|
||||
flush();
|
||||
set_state(State::RETRANSMITTING);
|
||||
} else {
|
||||
send_sequence();
|
||||
flush();
|
||||
set_state(State::READY);
|
||||
}
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::EstablishmentReject505 &msg) {
|
||||
LOG(iLink3, Error, "Establishment Reject: {} '{}'. NextSeq: {}.",
|
||||
msg.errorCodes(),
|
||||
std::string(translate_establish_reject(msg.errorCodes())),
|
||||
msg.nextSeqNo());
|
||||
_connection.disconnect();
|
||||
log_in(msg, 0);
|
||||
set_state(State::ERROR);
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::Sequence506 &msg) {
|
||||
log_in(msg, 0);
|
||||
_session.from_cme = msg.nextSeqNo() - 1;
|
||||
publish_session_update();
|
||||
send_sequence();
|
||||
flush();
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::Terminate507 &msg) {
|
||||
// https://www.cmegroup.com/confluence/display/EPICSANDBOX/Terminate
|
||||
LOG(iLink3, Error, "Terminated by exchange. Code: {} Reason: {} Text: {}",
|
||||
msg.errorCodes(), wrap(msg.reason()),
|
||||
wrap(translate_terminate(msg.errorCodes())));
|
||||
if (msg.errorCodes() == 11 || msg.errorCodes() == 10) {
|
||||
// This indicates our sequence number is too low. We will jump
|
||||
// forward one at a time. That should eventually fix it.
|
||||
LOG(iLink3, Error,
|
||||
"Will attempt to recover by advancing our sequence number");
|
||||
_session.to_cme++;
|
||||
publish_session_update();
|
||||
}
|
||||
log_in(msg, 0);
|
||||
_connection.disconnect();
|
||||
set_state(State::ERROR);
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::Retransmission509 &msg) {
|
||||
// Accepted Retransmit
|
||||
log_in(msg, 0);
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::RetransmitReject510 &msg) {
|
||||
LOG(iLink3, Error, "Retransmit requeste rejected. {}",
|
||||
msg.getReasonAsString());
|
||||
log_in(msg, 0);
|
||||
set_state(State::ERROR);
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::NotApplied513 &msg) {
|
||||
log_in(msg, 0);
|
||||
send_sequence();
|
||||
}
|
||||
void IL3GW::handle(
|
||||
const iLinkBinary::PartyDetailsDefinitionRequestAck519 &msg) {
|
||||
_exe_parser.set_account(msg);
|
||||
handle_common(msg);
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::BusinessReject521 &msg) {
|
||||
LOG(iLink3, Error, "Business Reject: {} '{}'.", msg.businessRejectReason(),
|
||||
wrap(translate_business_reject_reason(msg.businessRejectReason())));
|
||||
handle_common(msg);
|
||||
// A business reject can de-sync the sequence number because it rejects
|
||||
// the sequence number of the rejected message. Send a sequence message
|
||||
// to tell the cme to advance.
|
||||
send_sequence();
|
||||
flush();
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::ExecutionReportNew522 &msg) {
|
||||
handle_exe_report(msg);
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::ExecutionReportReject523 &msg) {
|
||||
LOG(iLink3, Error, "Execution report reject: {}", wrap(msg.text()));
|
||||
handle_exe_report(msg);
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::ExecutionReportElimination524 &msg) {
|
||||
handle_exe_report(msg);
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::ExecutionReportTradeOutright525 &msg) {
|
||||
handle_exe_report(msg);
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::ExecutionReportTradeSpread526 &msg) {
|
||||
handle_exe_report(msg);
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::ExecutionReportTradeSpreadLeg527 &msg) {
|
||||
handle_exe_report(msg);
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::ExecutionReportModify531 &msg) {
|
||||
handle_exe_report(msg);
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::ExecutionReportStatus532 &msg) {
|
||||
handle_exe_report(msg);
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::ExecutionReportCancel534 &msg) {
|
||||
handle_exe_report(msg);
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::OrderCancelReject535 &msg) {
|
||||
CancelReject cr;
|
||||
bool result = _exe_parser.parse(msg, &cr);
|
||||
if (result) {
|
||||
_on_cancel_reject(cr);
|
||||
} else {
|
||||
LOG(iLink3, Error, "Failed to parse cancel reject.");
|
||||
}
|
||||
handle_common(msg);
|
||||
}
|
||||
void IL3GW::handle(const iLinkBinary::OrderCancelReplaceReject536 &msg) {
|
||||
handle_common(msg);
|
||||
}
|
||||
void IL3GW::handle(
|
||||
const iLinkBinary::ExecutionReportTradeAddendumOutright548 &msg) {
|
||||
// Ignore trade correction/addendum messages for now.
|
||||
// See GLBXExecutionGateway.cpp:139 for further details
|
||||
handle_common(msg);
|
||||
}
|
||||
void IL3GW::handle(
|
||||
const iLinkBinary::ExecutionReportTradeAddendumSpread549 &msg) {
|
||||
// Ignore trade correction/addendum messages for now.
|
||||
// See GLBXExecutionGateway.cpp:139 for further details
|
||||
handle_common(msg);
|
||||
}
|
||||
void IL3GW::handle(
|
||||
const iLinkBinary::ExecutionReportTradeAddendumSpreadLeg550 &msg) {
|
||||
// Ignore trade correction/addendum messages for now.
|
||||
// See GLBXExecutionGateway.cpp:139 for further details
|
||||
handle_common(msg);
|
||||
}
|
||||
|
||||
} // namespace ilink3
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -0,0 +1,235 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../IExecutionGateway.h"
|
||||
#include "IL3Connection.h"
|
||||
#include "IL3ConnectionHandler.h"
|
||||
#include "TimeKeeper.h"
|
||||
|
||||
#include "IL3GeneratedFwd.h"
|
||||
#include "IL3Parser.h"
|
||||
#include "generated/MessageHeader.h"
|
||||
#include "lib/config/protos/jetfix.pb.h"
|
||||
#include "lib/orderman/actors/ilink3/RawMsg.h"
|
||||
#include "lib/orderman/orderman_utils/CancelReject.h"
|
||||
|
||||
#define MID_SESSION_REPLAY
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
class ExecutionReport;
|
||||
namespace ilink3 {
|
||||
|
||||
class IL3SecDB;
|
||||
|
||||
struct Session {
|
||||
uint64_t uuid;
|
||||
// bts->cme
|
||||
uint32_t to_cme;
|
||||
// cme->bts
|
||||
uint32_t from_cme;
|
||||
|
||||
operator bool const() { return to_cme || from_cme; }
|
||||
};
|
||||
|
||||
struct Config {
|
||||
std::string cme_session; // NGG
|
||||
std::string firm; // 004
|
||||
bool failover_on_disconnect;
|
||||
std::function<void(RawMessageDirection, size_t sn, RawMsg const &)>
|
||||
raw_message_logger;
|
||||
};
|
||||
|
||||
enum class State {
|
||||
INIT,
|
||||
CONNECTING,
|
||||
NEGOTIATING,
|
||||
ESTABLISHING,
|
||||
RETRANSMITTING,
|
||||
READY,
|
||||
ERROR
|
||||
};
|
||||
const char *state_string(State s);
|
||||
typedef std::function<void(State)> OnStateChange;
|
||||
typedef std::function<void(const ExecutionReport *)> OnExecutionReport;
|
||||
typedef std::function<void(const Session &s)> OnSessionChange;
|
||||
typedef std::function<void(CancelReject &)> OnCancelReject;
|
||||
|
||||
struct Retransmit {
|
||||
static constexpr uint32_t MAX_RECOVERY = 2500;
|
||||
uint64_t uuid;
|
||||
uint32_t from;
|
||||
uint32_t to;
|
||||
};
|
||||
|
||||
class IL3MessageFramer;
|
||||
|
||||
// Does not allow re-entrance
|
||||
class IL3GW : IL3ConnectionHandler {
|
||||
const Config _config;
|
||||
State _x_state;
|
||||
IL3MessageFramer &_buffer;
|
||||
OnStateChange _on_state_change;
|
||||
OnExecutionReport _on_exe_report;
|
||||
OnSessionChange _on_session_change;
|
||||
OnCancelReject _on_cancel_reject;
|
||||
IL3Connection &_connection;
|
||||
Session _session;
|
||||
std::string _clorid_buffer;
|
||||
uint32_t _msg_count;
|
||||
TimeKeeper _time;
|
||||
boost::object_pool<ExecutionReport> _pool;
|
||||
IL3Parser _exe_parser;
|
||||
std::queue<Retransmit> _retransmit;
|
||||
|
||||
public:
|
||||
IL3GW(IL3Connection &, IL3MessageFramer &, IL3SecDB *, const Session &,
|
||||
const Config &, config::JetFIX::Connection const *);
|
||||
|
||||
void connect();
|
||||
void send_order(const CreateOrderMsg &);
|
||||
void send_cancel_replace(const CancelReplaceOrderMsg &);
|
||||
void send_cancel(const CancelOrderMsg &);
|
||||
void send_terminate(uint16_t code = 0);
|
||||
void flush(bool publish = true);
|
||||
void on_time(){
|
||||
// Currently we just reply to a heartbeat with another heartbeat
|
||||
// Probably better to track time and send them on demand
|
||||
};
|
||||
|
||||
// state change
|
||||
State state() { return _x_state; }
|
||||
void subscribe_state(OnStateChange o) { _on_state_change = o; }
|
||||
void subscribe_execution_reports(OnExecutionReport sub) {
|
||||
_on_exe_report = sub;
|
||||
}
|
||||
void subscribe_session(OnSessionChange cb) { _on_session_change = cb; }
|
||||
void subscribe_cancel_reject(OnCancelReject cb) { _on_cancel_reject = cb; }
|
||||
|
||||
// Only used for certification
|
||||
void send_sequence(bool lapsed = false);
|
||||
|
||||
private:
|
||||
void send_negotiate();
|
||||
void send_establish();
|
||||
void send_retransmit_request(uint64_t uuid, uint32_t from, size_t count);
|
||||
uint64_t send_party_details(const api::orderman::RoutingRecord &);
|
||||
|
||||
private:
|
||||
void set_state(State);
|
||||
uint32_t next_seq() {
|
||||
_session.to_cme += 1;
|
||||
return _session.to_cme - 1;
|
||||
}
|
||||
void publish_session_update() { _on_session_change(_session); }
|
||||
void on_connect_success() override;
|
||||
void on_disconnect() override;
|
||||
void enqueue_retransmit(uint32_t from, uint32_t to, uint64_t uuid);
|
||||
void begin_retransmit();
|
||||
void on_retransmit_complete();
|
||||
|
||||
template <class T> static auto serialize(const T &msg) -> auto {
|
||||
return [=]() -> auto {
|
||||
RawMessageData result;
|
||||
std::stringstream buffer;
|
||||
buffer << msg;
|
||||
result.json = buffer.str();
|
||||
result.binary = std::string(
|
||||
msg.buffer() + msg.offset() -
|
||||
iLinkBinary::MessageHeader::encodedLength(),
|
||||
msg.decodeLength() + iLinkBinary::MessageHeader::encodedLength());
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
template <class T> void log_in(const T &msg, size_t sn) {
|
||||
_config.raw_message_logger(RawMessageDirection::INCOMING, sn,
|
||||
serialize(msg));
|
||||
}
|
||||
template <class T> void log_out(const T &msg, size_t sn) {
|
||||
_config.raw_message_logger(RawMessageDirection::OUTGOING, sn,
|
||||
serialize(msg));
|
||||
}
|
||||
|
||||
//
|
||||
// Message handlers
|
||||
|
||||
size_t on_data(const std::string_view &) override;
|
||||
|
||||
template <class T> void handle_common(const T &msg) {
|
||||
auto uuid = msg.uUID();
|
||||
auto seq = msg.seqNum();
|
||||
log_in(msg, seq);
|
||||
// Test if replay is copmlete
|
||||
if (!_retransmit.empty() && _retransmit.front().to == seq) {
|
||||
on_retransmit_complete();
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle non-replay packet
|
||||
if (uuid == _session.uuid) {
|
||||
#ifdef MID_SESSION_REPLAY
|
||||
// Gap detected during normal operation
|
||||
auto expected = _session.from_cme + 1;
|
||||
if (seq > expected) {
|
||||
bool busy = !_retransmit.empty();
|
||||
enqueue_retransmit(expected, seq - 1, _session.uuid);
|
||||
if (!busy)
|
||||
begin_retransmit();
|
||||
flush();
|
||||
}
|
||||
#endif
|
||||
// msg may be a replay message with a lower sequence number
|
||||
if (msg.seqNum() > _session.from_cme) {
|
||||
_session.from_cme = msg.seqNum();
|
||||
publish_session_update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class T> void handle_exe_report(const T &msg) {
|
||||
auto *report = _pool.construct();
|
||||
bool result = _exe_parser.parse(msg, report);
|
||||
if (result) {
|
||||
_on_exe_report(report);
|
||||
} else {
|
||||
LOG(iLink3, Error, "Failed to parse error report.");
|
||||
}
|
||||
handle_common(msg);
|
||||
}
|
||||
|
||||
public:
|
||||
void handle(const iLinkBinary::NegotiationResponse501 &);
|
||||
void handle(const iLinkBinary::NegotiationReject502 &);
|
||||
void handle(const iLinkBinary::EstablishmentAck504 &);
|
||||
void handle(const iLinkBinary::EstablishmentReject505 &);
|
||||
void handle(const iLinkBinary::Sequence506 &);
|
||||
void handle(const iLinkBinary::Terminate507 &);
|
||||
void handle(const iLinkBinary::Retransmission509 &);
|
||||
void handle(const iLinkBinary::RetransmitReject510 &);
|
||||
void handle(const iLinkBinary::NotApplied513 &);
|
||||
void handle(const iLinkBinary::PartyDetailsDefinitionRequestAck519 &);
|
||||
void handle(const iLinkBinary::BusinessReject521 &);
|
||||
void handle(const iLinkBinary::ExecutionReportNew522 &);
|
||||
void handle(const iLinkBinary::ExecutionReportReject523 &);
|
||||
void handle(const iLinkBinary::ExecutionReportElimination524 &);
|
||||
void handle(const iLinkBinary::ExecutionReportTradeOutright525 &);
|
||||
void handle(const iLinkBinary::ExecutionReportTradeSpread526 &);
|
||||
void handle(const iLinkBinary::ExecutionReportTradeSpreadLeg527 &);
|
||||
void handle(const iLinkBinary::ExecutionReportModify531 &);
|
||||
void handle(const iLinkBinary::ExecutionReportStatus532 &);
|
||||
void handle(const iLinkBinary::ExecutionReportCancel534 &);
|
||||
void handle(const iLinkBinary::OrderCancelReject535 &);
|
||||
void handle(const iLinkBinary::OrderCancelReplaceReject536 &);
|
||||
void handle(const iLinkBinary::ExecutionReportTradeAddendumOutright548 &);
|
||||
void handle(const iLinkBinary::ExecutionReportTradeAddendumSpread549 &);
|
||||
void handle(const iLinkBinary::ExecutionReportTradeAddendumSpreadLeg550 &);
|
||||
};
|
||||
|
||||
} // namespace ilink3
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// Message templates
|
||||
|
||||
// BTS -> CME
|
||||
#include "generated/Negotiate500.h"
|
||||
#include "generated/Establish503.h"
|
||||
#include "generated/RetransmitRequest508.h"
|
||||
#include "generated/NewOrderSingle514.h"
|
||||
#include "generated/OrderCancelReplaceRequest515.h"
|
||||
#include "generated/OrderCancelRequest516.h"
|
||||
// #include "generated/MassQuote517.h"
|
||||
#include "generated/PartyDetailsDefinitionRequest518.h"
|
||||
// #include "generated/QuoteCancel528.h"
|
||||
// #include "generated/OrderMassActionRequest529.h"
|
||||
// #include "generated/OrderMassStatusRequest530.h"
|
||||
// #include "generated/OrderStatusRequest533.h"
|
||||
// #include "generated/PartyDetailsListRequest537.h"
|
||||
// #include "generated/RequestForQuote543.h"
|
||||
// #include "generated/SecurityDefinitionRequest560.h"
|
||||
|
||||
// CME -> BTS
|
||||
#include "generated/NegotiationResponse501.h"
|
||||
#include "generated/NegotiationReject502.h"
|
||||
#include "generated/EstablishmentAck504.h"
|
||||
#include "generated/EstablishmentReject505.h"
|
||||
#include "generated/Sequence506.h"
|
||||
#include "generated/Terminate507.h"
|
||||
#include "generated/Retransmission509.h"
|
||||
#include "generated/RetransmitReject510.h"
|
||||
#include "generated/NotApplied513.h"
|
||||
#include "generated/PartyDetailsDefinitionRequestAck519.h"
|
||||
#include "generated/BusinessReject521.h"
|
||||
#include "generated/ExecutionReportNew522.h"
|
||||
#include "generated/ExecutionReportReject523.h"
|
||||
#include "generated/ExecutionReportElimination524.h"
|
||||
#include "generated/ExecutionReportTradeOutright525.h"
|
||||
#include "generated/ExecutionReportTradeSpread526.h"
|
||||
#include "generated/ExecutionReportTradeSpreadLeg527.h"
|
||||
#include "generated/ExecutionReportModify531.h"
|
||||
#include "generated/ExecutionReportStatus532.h"
|
||||
#include "generated/ExecutionReportCancel534.h"
|
||||
#include "generated/OrderCancelReject535.h"
|
||||
#include "generated/OrderCancelReplaceReject536.h"
|
||||
// #include "generated/PartyDetailsListReport538.h"
|
||||
#include "generated/ExecutionAck539.h"
|
||||
// #include "generated/NewOrderCross544.h"
|
||||
// #include "generated/MassQuoteAck545.h"
|
||||
// #include "generated/RequestForQuoteAck546.h"
|
||||
// #include "generated/QuoteCancelAck547.h"
|
||||
#include "generated/ExecutionReportTradeAddendumOutright548.h"
|
||||
#include "generated/ExecutionReportTradeAddendumSpread549.h"
|
||||
#include "generated/ExecutionReportTradeAddendumSpreadLeg550.h"
|
||||
// #include "generated/OrderMassActionReport558.h"
|
||||
// #include "generated/SecurityDefinitionResponse561.h"
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
namespace iLinkBinary {
|
||||
class Negotiate500;
|
||||
class Establish503;
|
||||
class RetransmitRequest508;
|
||||
class NewOrderSingle514;
|
||||
class OrderCancelReplaceRequest515;
|
||||
class OrderCancelRequest516;
|
||||
class PartyDetailsDefinitionRequest518;
|
||||
class NegotiationResponse501;
|
||||
class NegotiationReject502;
|
||||
class EstablishmentAck504;
|
||||
class EstablishmentReject505;
|
||||
class Sequence506;
|
||||
class Terminate507;
|
||||
class Retransmission509;
|
||||
class RetransmitReject510;
|
||||
class NotApplied513;
|
||||
class PartyDetailsDefinitionRequestAck519;
|
||||
class BusinessReject521;
|
||||
class ExecutionReportNew522;
|
||||
class ExecutionReportReject523;
|
||||
class ExecutionReportElimination524;
|
||||
class ExecutionReportTradeOutright525;
|
||||
class ExecutionReportTradeSpread526;
|
||||
class ExecutionReportTradeSpreadLeg527;
|
||||
class ExecutionReportModify531;
|
||||
class ExecutionReportStatus532;
|
||||
class ExecutionReportCancel534;
|
||||
class OrderCancelReject535;
|
||||
class OrderCancelReplaceReject536;
|
||||
class ExecutionAck539;
|
||||
class ExecutionReportTradeAddendumOutright548;
|
||||
class ExecutionReportTradeAddendumSpread549;
|
||||
class ExecutionReportTradeAddendumSpreadLeg550;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include <cstring>
|
||||
#include "IL3Connection.h"
|
||||
#include "IL3ReceiveBuffer.h"
|
||||
|
||||
#include "generated/MessageHeader.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
namespace ilink3 {
|
||||
|
||||
struct FramingHeader {
|
||||
uint16_t message_size;
|
||||
uint16_t encoding_type;
|
||||
};
|
||||
|
||||
class IL3MessageFramer {
|
||||
std::vector<std::string_view> _buffer_ptrs;
|
||||
IL3ReceiveBuffer _memory;
|
||||
|
||||
public:
|
||||
IL3MessageFramer():
|
||||
_buffer_ptrs(), _memory()
|
||||
{
|
||||
_buffer_ptrs.reserve(512);
|
||||
}
|
||||
~IL3MessageFramer() = default;
|
||||
|
||||
//
|
||||
// Framing
|
||||
template <class Msg>
|
||||
Msg frame(size_t extra=0) {
|
||||
auto size =
|
||||
sizeof(FramingHeader) +
|
||||
iLinkBinary::MessageHeader::encodedLength() +
|
||||
Msg::sbeBlockLength() +
|
||||
extra;
|
||||
auto buffer = _memory.allocate(size);
|
||||
_memory.advance(size);
|
||||
FramingHeader* fhead = (FramingHeader*)(buffer.data());
|
||||
fhead->message_size = size;
|
||||
fhead->encoding_type = 0xCAFE;
|
||||
Msg msg;
|
||||
msg.wrapAndApplyHeader(const_cast<char*>(buffer.data()), sizeof(FramingHeader), size+sizeof(FramingHeader));
|
||||
_buffer_ptrs.push_back(buffer);
|
||||
return msg;
|
||||
}
|
||||
|
||||
void flush(IL3Connection& connection) {
|
||||
if (!_buffer_ptrs.empty()) {
|
||||
connection.send(_buffer_ptrs);
|
||||
_buffer_ptrs.clear();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}}} //namespace
|
||||
@@ -0,0 +1,361 @@
|
||||
|
||||
#include "IL3Parser.h"
|
||||
|
||||
#include "IL3Dispatcher.h"
|
||||
#include "IL3GeneratedFull.h"
|
||||
#include "ILink3Utils.h"
|
||||
#include "lib/domain_model/Security.h"
|
||||
#include "lib/md/IntPrice.h"
|
||||
#include "lib/orderman/actors/ilink3/IL3SecDB.h"
|
||||
#include "lib/orderman/orderman_utils/CancelReject.h"
|
||||
#include "lib/orderman/orderman_utils/fix_order_codec.h"
|
||||
#include "lib/orderman/orderman_utils/orderman_common.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
namespace ilink3 {
|
||||
|
||||
IL3Parser::IL3Parser(config::JetFIX::Connection const *cfg, IL3SecDB *db)
|
||||
: most_recent_account(), cfg(cfg), db(db) {}
|
||||
|
||||
const api::Security *IL3Parser::get_security(SecurityKey id) {
|
||||
if (db)
|
||||
return db->get_security(id);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const api::Security *IL3Parser::get_security(ExchangeSecurityKey id) {
|
||||
if (db)
|
||||
return db->get_security(id);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool IL3Parser::parse_common(const T &msg, ExecutionReport *data) {
|
||||
data->account_name = most_recent_account;
|
||||
static_assert(sizeof(OperatorID) == T::senderIDLength());
|
||||
memcpy(&data->operator_id.value(), msg.senderID(), msg.senderIDLength());
|
||||
data->exchange = api::VENUE_GLBX;
|
||||
data->exchange_order_id = ExchangeOrderID64{msg.orderID()};
|
||||
data->leg_security = nullptr;
|
||||
data->manual_order_indicator =
|
||||
map_manual_order_indicator(msg.manualOrderIndicator());
|
||||
data->msg_seq_num = msg.seqNum();
|
||||
SecurityKey sk;
|
||||
decode_clorid(msg.clOrdID(), &data->order_key, &sk);
|
||||
auto sec = get_security(sk);
|
||||
if (!sec) {
|
||||
LOG(iLink3, Error,
|
||||
"Cannot resolve security key {} in order {}. Clorid: {} Exchange "
|
||||
"order id: {}",
|
||||
sk.value(), data->order_key.value(), std::string(msg.clOrdID()),
|
||||
msg.orderID());
|
||||
return false;
|
||||
}
|
||||
data->security = sec;
|
||||
data->order_type = map_order_type(msg.ordType());
|
||||
auto &price = const_cast<T &>(msg).price();
|
||||
data->price = securities::decode_exchange_price(
|
||||
*sec, Price{price.mantissa() * md::pow10(price.exponent())});
|
||||
data->quantity = Quantity{msg.orderQty()};
|
||||
data->side = map_side(msg.side());
|
||||
auto &stop_price = const_cast<T &>(msg).stopPx();
|
||||
data->stop_price = securities::decode_exchange_price(
|
||||
*sec, Price{stop_price.mantissa() * md::pow10(stop_price.exponent())});
|
||||
data->time_in_force = map_time_in_force(msg.timeInForce());
|
||||
data->transact_time = ExchangeTimeStamp64{msg.transactTime()};
|
||||
data->ice_cl_ord_id = 0;
|
||||
data->ice_company_id = 0;
|
||||
data->cfg = cfg;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void IL3Parser::parse_trade(const T &msg, ExecutionReport *data) {
|
||||
orderman::to_array(msg.getExecIDAsStringView(),
|
||||
&data->exchange_fill_id.value());
|
||||
switch (msg.ordStatus()) {
|
||||
case iLinkBinary::OrdStatusTrd::Filled:
|
||||
data->order_status =
|
||||
api::orderman::NativeOrderStatus::NATIVE_ORDER_STATUS_FILLED;
|
||||
data->exec_type = api::orderman::EXEC_TYPE_FILL;
|
||||
break;
|
||||
case iLinkBinary::OrdStatusTrd::PartiallyFilled:
|
||||
data->order_status = api::orderman::NativeOrderStatus::
|
||||
NATIVE_ORDER_STATUS_PARTIALLY_FILLED;
|
||||
data->exec_type = api::orderman::EXEC_TYPE_PARTIAL_FILL;
|
||||
break;
|
||||
default:
|
||||
data->order_status =
|
||||
api::orderman::NativeOrderStatus::NATIVE_ORDER_STATUS_UNDEFINED;
|
||||
}
|
||||
data->last_shares = Quantity{msg.lastQty()};
|
||||
auto &price = const_cast<T &>(msg).lastPx();
|
||||
if (data->leg_security) {
|
||||
data->last_price = securities::decode_exchange_price(
|
||||
*data->leg_security,
|
||||
Price{price.mantissa() * md::pow10(price.exponent())});
|
||||
} else {
|
||||
data->last_price = securities::decode_exchange_price(
|
||||
*data->security,
|
||||
Price{price.mantissa() * md::pow10(price.exponent())});
|
||||
}
|
||||
data->filled_quantity = Quantity{msg.cumQty()};
|
||||
}
|
||||
|
||||
bool IL3Parser::has_account() const {
|
||||
return strlen(most_recent_account.value().data());
|
||||
}
|
||||
|
||||
bool IL3Parser::parse(const iLinkBinary::ExecutionReportNew522 &msg,
|
||||
ExecutionReport *data) {
|
||||
if (parse_common(msg, data)) {
|
||||
data->avg_price = Price{0.0};
|
||||
data->cust_order_handling_inst = "";
|
||||
data->exchange_fill_id = ExchangeFillID{};
|
||||
data->exec_type = api::orderman::EXEC_TYPE_NEW;
|
||||
data->filled_quantity = Quantity{0};
|
||||
data->last_price = Price{0.0};
|
||||
data->last_shares = Quantity{0};
|
||||
data->max_show = Quantity{0};
|
||||
data->memo = "";
|
||||
data->msg = "";
|
||||
data->order_status = api::orderman::NativeOrderStatus(*msg.ordStatus());
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class ER>
|
||||
bool try_parse_exe_report_helper(IL3Parser &parser, std::string_view const &msg,
|
||||
ExecutionReport *out) {
|
||||
|
||||
iLinkBinary::MessageHeader mheader{
|
||||
(char *)msg.data(), 0, msg.size(),
|
||||
iLinkBinary::MessageHeader::sbeSchemaVersion()};
|
||||
|
||||
if (mheader.templateId() == ER::sbeTemplateId()) {
|
||||
return parser.parse(
|
||||
ER{(char *)msg.data(), iLinkBinary::MessageHeader::encodedLength(),
|
||||
msg.size(), mheader.blockLength(), mheader.version()},
|
||||
out);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::optional<ExecutionReport>
|
||||
IL3Parser::try_parse_exe_report(std::string_view const &msg) {
|
||||
using namespace iLinkBinary;
|
||||
|
||||
if (has_account()) {
|
||||
ExecutionReport report;
|
||||
if (try_parse_exe_report_helper<ExecutionReportNew522>(*this, msg,
|
||||
&report))
|
||||
return {report};
|
||||
if (try_parse_exe_report_helper<ExecutionReportReject523>(*this, msg,
|
||||
&report))
|
||||
return {report};
|
||||
if (try_parse_exe_report_helper<ExecutionReportElimination524>(*this, msg,
|
||||
&report))
|
||||
return {report};
|
||||
if (try_parse_exe_report_helper<ExecutionReportTradeOutright525>(
|
||||
*this, msg, &report))
|
||||
return {report};
|
||||
if (try_parse_exe_report_helper<ExecutionReportTradeSpread526>(*this, msg,
|
||||
&report))
|
||||
return {report};
|
||||
if (try_parse_exe_report_helper<ExecutionReportTradeSpreadLeg527>(
|
||||
*this, msg, &report))
|
||||
return {report};
|
||||
if (try_parse_exe_report_helper<ExecutionReportModify531>(*this, msg,
|
||||
&report))
|
||||
return {report};
|
||||
if (try_parse_exe_report_helper<ExecutionReportStatus532>(*this, msg,
|
||||
&report))
|
||||
return {report};
|
||||
if (try_parse_exe_report_helper<ExecutionReportCancel534>(*this, msg,
|
||||
&report))
|
||||
return {report};
|
||||
}
|
||||
|
||||
iLinkBinary::MessageHeader mheader{
|
||||
(char *)msg.data(), 0, msg.size(),
|
||||
iLinkBinary::MessageHeader::sbeSchemaVersion()};
|
||||
|
||||
if (mheader.templateId() ==
|
||||
PartyDetailsDefinitionRequestAck519::sbeTemplateId())
|
||||
set_account(PartyDetailsDefinitionRequestAck519{
|
||||
(char *)msg.data(), iLinkBinary::MessageHeader::encodedLength(),
|
||||
msg.size(), mheader.blockLength(), mheader.version()});
|
||||
return {};
|
||||
}
|
||||
|
||||
bool IL3Parser::parse(const iLinkBinary::ExecutionReportReject523 &msg,
|
||||
ExecutionReport *data) {
|
||||
if (parse_common(msg, data)) {
|
||||
data->order_status = api::orderman::NativeOrderStatus(*msg.ordStatus());
|
||||
data->msg = msg.getTextAsStringView();
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
bool IL3Parser::parse(const iLinkBinary::ExecutionReportElimination524 &msg,
|
||||
ExecutionReport *data) {
|
||||
if (parse_common(msg, data)) {
|
||||
data->order_status = api::orderman::NativeOrderStatus(*msg.ordStatus());
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
bool IL3Parser::parse(const iLinkBinary::ExecutionReportTradeOutright525 &msg,
|
||||
ExecutionReport *data) {
|
||||
if (parse_common(msg, data)) {
|
||||
parse_trade(msg, data);
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
bool IL3Parser::parse(const iLinkBinary::ExecutionReportTradeSpread526 &msg,
|
||||
ExecutionReport *data) {
|
||||
if (parse_common(msg, data)) {
|
||||
parse_trade(msg, data);
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
bool IL3Parser::parse(const iLinkBinary::ExecutionReportTradeSpreadLeg527 &msg,
|
||||
ExecutionReport *data) {
|
||||
data->account_name = most_recent_account;
|
||||
data->avg_price = Price{0.0};
|
||||
static_assert(sizeof(OperatorID) ==
|
||||
iLinkBinary::ExecutionReportTradeSpread526::senderIDLength());
|
||||
memcpy(&data->operator_id.value(), msg.senderID(), msg.senderIDLength());
|
||||
data->exchange = api::VENUE_GLBX;
|
||||
data->exchange_order_id = ExchangeOrderID64{msg.orderID()};
|
||||
|
||||
data->msg_seq_num = msg.seqNum();
|
||||
SecurityKey sk;
|
||||
decode_clorid(msg.clOrdID(), &data->order_key, &sk);
|
||||
auto sec = get_security(sk);
|
||||
if (!sec) {
|
||||
LOG(iLink3, Error,
|
||||
"Cannot resolve security key {} in order {}. Clorid: {} Exchange "
|
||||
"order id: {}",
|
||||
sk.value(), data->order_key.value(), std::string(msg.clOrdID()),
|
||||
msg.orderID());
|
||||
return false;
|
||||
}
|
||||
data->security = sec;
|
||||
|
||||
data->leg_security =
|
||||
get_security(ExchangeSecurityKey{(uint64_t)msg.securityID()});
|
||||
if (data->leg_security == nullptr) {
|
||||
LOG(iLink3, Error,
|
||||
"Received execution report for an unknown spread leg"
|
||||
"security {}. Will not be "
|
||||
" able to process this report. This is likely a "
|
||||
"bug that could lead to"
|
||||
" lost leg fills. Please investigate. Spread sec_key: {} leg "
|
||||
"exchange "
|
||||
"security id: {}",
|
||||
sk.value(), msg.securityID());
|
||||
return false;
|
||||
}
|
||||
data->order_type = map_order_type(msg.ordType());
|
||||
auto &price =
|
||||
const_cast<iLinkBinary::ExecutionReportTradeSpreadLeg527 &>(msg)
|
||||
.lastPx();
|
||||
data->price = securities::decode_exchange_price(
|
||||
*data->leg_security,
|
||||
Price{price.mantissa() * md::pow10(price.exponent())});
|
||||
data->quantity = Quantity{0};
|
||||
data->side = map_side(msg.side());
|
||||
data->stop_price = Price{0.0};
|
||||
data->time_in_force = api::orderman::TimeInForce::TIME_IN_FORCE_UNDEFINED;
|
||||
data->transact_time = ExchangeTimeStamp64{msg.transactTime()};
|
||||
data->ice_cl_ord_id = 0;
|
||||
data->ice_company_id = 0;
|
||||
data->cfg = cfg;
|
||||
parse_trade(msg, data);
|
||||
return true;
|
||||
}
|
||||
bool IL3Parser::parse(const iLinkBinary::ExecutionReportModify531 &msg,
|
||||
ExecutionReport *data) {
|
||||
if (parse_common(msg, data)) {
|
||||
data->order_status = api::orderman::NativeOrderStatus(*msg.ordStatus());
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
bool IL3Parser::parse(const iLinkBinary::ExecutionReportStatus532 &msg,
|
||||
ExecutionReport *data) {
|
||||
return parse_common(msg, data);
|
||||
}
|
||||
bool IL3Parser::parse(const iLinkBinary::ExecutionReportCancel534 &msg,
|
||||
ExecutionReport *data) {
|
||||
if (parse_common(msg, data)) {
|
||||
data->order_status = api::orderman::NativeOrderStatus(*msg.ordStatus());
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IL3Parser::parse(const iLinkBinary::OrderCancelReject535 &msg,
|
||||
CancelReject *cr) {
|
||||
SecurityKey sk;
|
||||
OrderKey ok;
|
||||
decode_clorid(msg.clOrdID(), &ok, &sk);
|
||||
cr->order_key = ok;
|
||||
cr->reject_msg = msg.getTextAsStringView();
|
||||
// https://www.cmegroup.com/confluence/display/EPICSANDBOX/iLink+Reject+Codes
|
||||
if (msg.cxlRejReason() == 2045)
|
||||
cr->reason = CancelRejectReason::UnknownOrder;
|
||||
else
|
||||
cr->reason = CancelRejectReason::Other;
|
||||
return true;
|
||||
}
|
||||
|
||||
void IL3Parser::set_account(
|
||||
const iLinkBinary::PartyDetailsDefinitionRequestAck519 &msg) {
|
||||
// When using on-demand format the PartyDetailsDefinitionRequestAck519
|
||||
// is sent back immediately preceding the execution report on the wire.
|
||||
auto details =
|
||||
const_cast<iLinkBinary::PartyDetailsDefinitionRequestAck519 &>(msg)
|
||||
.noPartyDetails();
|
||||
while (details.hasNext()) {
|
||||
details.next();
|
||||
if (details.partyDetailRole() ==
|
||||
iLinkBinary::PartyDetailRole::CustomerAccount) {
|
||||
const char *p_account = details.partyDetailID();
|
||||
strncpy(most_recent_account.value().data(), p_account,
|
||||
most_recent_account.value().size());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ParseHandler {
|
||||
IL3Parser &parser;
|
||||
ExecutionReport *result;
|
||||
bool success = false;
|
||||
template <class T> void handle(const T &t) {
|
||||
success = parser.parse(t, result);
|
||||
}
|
||||
void handle(iLinkBinary::PartyDetailsDefinitionRequestAck519 &t) {
|
||||
parser.set_account(t);
|
||||
}
|
||||
};
|
||||
|
||||
bool parse_report(const std::string &data, IL3Parser &parser,
|
||||
ExecutionReport *result) {
|
||||
ParseHandler handler{parser, result};
|
||||
consume_messages(handler, data.c_str(), data.size(),
|
||||
dispatch_execution_reports<ParseHandler>);
|
||||
return handler.success;
|
||||
}
|
||||
|
||||
} // namespace ilink3
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/orderman/orderman_utils/ExecutionReport.h"
|
||||
#include "IL3GeneratedFwd.h"
|
||||
#include "lib/md/SecurityOracle.h"
|
||||
#include "lib/md/ExchangeSecurityKey.h"
|
||||
#include <boost/pool/object_pool.hpp>
|
||||
#include <google/btree/btree_map.h>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
class CancelReject;
|
||||
namespace ilink3 {
|
||||
|
||||
class IL3SecDB;
|
||||
|
||||
class IL3Parser {
|
||||
AccountName most_recent_account;
|
||||
config::JetFIX::Connection const *cfg;
|
||||
IL3SecDB *db;
|
||||
const api::Security* get_security(SecurityKey);
|
||||
const api::Security* get_security(ExchangeSecurityKey);
|
||||
|
||||
public:
|
||||
IL3Parser(config::JetFIX::Connection const *, IL3SecDB *sec_db);
|
||||
bool parse(const iLinkBinary::ExecutionReportNew522&, ExecutionReport*);
|
||||
bool parse(const iLinkBinary::ExecutionReportReject523&, ExecutionReport*);
|
||||
bool parse(const iLinkBinary::ExecutionReportElimination524&, ExecutionReport*);
|
||||
bool parse(const iLinkBinary::ExecutionReportTradeOutright525&, ExecutionReport*);
|
||||
bool parse(const iLinkBinary::ExecutionReportTradeSpread526&, ExecutionReport*);
|
||||
bool parse(const iLinkBinary::ExecutionReportTradeSpreadLeg527&, ExecutionReport*);
|
||||
bool parse(const iLinkBinary::ExecutionReportModify531&, ExecutionReport*);
|
||||
bool parse(const iLinkBinary::ExecutionReportStatus532&, ExecutionReport*);
|
||||
bool parse(const iLinkBinary::ExecutionReportCancel534&, ExecutionReport*);
|
||||
bool parse(const iLinkBinary::OrderCancelReject535&, CancelReject*);
|
||||
void set_account(const iLinkBinary::PartyDetailsDefinitionRequestAck519&);
|
||||
bool has_account() const;
|
||||
std::optional<ExecutionReport> try_parse_exe_report(std::string_view const&bytes);
|
||||
private:
|
||||
template <class T> bool parse_common(const T&, ExecutionReport*);
|
||||
template <class T> void parse_trade(const T&, ExecutionReport*);
|
||||
};
|
||||
|
||||
bool parse_report(const std::string&, IL3Parser&, ExecutionReport*);
|
||||
|
||||
}}}//namespace
|
||||
Loaded 100 of 320 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user