Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
704819c3e3 | ||
|
|
526a0a0a29 | ||
|
|
759ba55551 | ||
|
|
4ef82cc4ab | ||
|
|
a9834e6df8 | ||
|
|
f2d592f9c7 | ||
|
|
26fda7f88f | ||
|
|
9864d0b0fc | ||
|
|
59692852b5 | ||
|
|
ed3bc9f71c | ||
|
|
a2c7481301 | ||
|
|
f1fdaf1aca | ||
|
|
bf34963b88 | ||
|
|
ed1609a89f | ||
|
|
c66202117f | ||
|
|
49342e30dd | ||
|
|
20b8d095d8 | ||
|
|
995b4cbefe | ||
|
|
fb8c603b18 | ||
|
|
743b606030 | ||
|
|
4950796660 | ||
|
|
417fccb03c | ||
|
|
3014ceb85f | ||
|
|
c1efbc00a5 | ||
|
|
b8851f36bb | ||
|
|
9de3d80891 | ||
|
|
f07fd7044f | ||
|
|
f025eed845 | ||
|
|
cb0dfa50b3 | ||
|
|
2429e6019c | ||
|
|
e0bb48b0c7 | ||
|
|
a38b0dbc79 | ||
|
|
73065ab48a | ||
|
|
bd07c96504 | ||
|
|
dc4033875a | ||
|
|
130794c538 | ||
|
|
b1743f0b1c | ||
|
|
33492c9131 | ||
|
|
d434778a82 | ||
|
|
4c6cc9b3e0 | ||
|
|
6aaeddb7e9 | ||
|
|
1685a13994 | ||
|
|
54633dd6db | ||
|
|
510f163e5b | ||
|
|
ee4779da73 | ||
|
|
28e98259f6 | ||
|
|
82bc402216 | ||
|
|
ff70e9694b | ||
|
|
6a8930f594 | ||
|
|
e49e11feb5 | ||
|
|
a6d4a05253 | ||
|
|
db0ff984cb | ||
|
|
770c54ee88 | ||
|
|
7ac87269c2 | ||
|
|
3a2a52d708 | ||
|
|
525d0eda30 | ||
|
|
e9e85b44c9 | ||
|
|
2654b2e446 | ||
|
|
be45938b51 | ||
|
|
7119e18436 | ||
|
|
663f9ecc52 | ||
|
|
a7b8d39787 | ||
|
|
ce88ebcebe | ||
|
|
a6edbbe7b5 | ||
|
|
1b8cca55e5 | ||
|
|
a8f26e998b | ||
|
|
55eb830c7c | ||
|
|
0230ac06bd | ||
|
|
83005d7439 | ||
|
|
a74da85f18 | ||
|
|
4872e8ad7f | ||
|
|
51276d161c | ||
|
|
3fa699b4c9 | ||
|
|
c9396bd6af | ||
|
|
065f92937c | ||
|
|
cdfb60f5d9 | ||
|
|
b80f96fa5e | ||
|
|
b7dea6817c | ||
|
|
f2b407fdac | ||
|
|
f4dc550f1a | ||
|
|
bc978ed065 | ||
|
|
4c4fa77d3a | ||
|
|
2aa5a02ce2 | ||
|
|
5e1f642076 | ||
|
|
90b4c7e26f | ||
|
|
eccc3f5f38 | ||
|
|
202c5faffd | ||
|
|
de20957ae7 | ||
|
|
e410322fcd | ||
|
|
85cb481849 | ||
|
|
f7dec1161a | ||
|
|
f5e826b095 | ||
|
|
4cd3bc40d9 | ||
|
|
3800f3344b | ||
|
|
6ad139804f | ||
|
|
45d5c2d7cd | ||
|
|
0d24062f03 | ||
|
|
44e0eae281 | ||
|
|
152ab05b4e | ||
|
|
b7a733a306 | ||
|
|
11d7291acb | ||
|
|
d17b643e31 | ||
|
|
8832e97f52 | ||
|
|
c971d07958 | ||
|
|
55bb13e536 | ||
|
|
f7c37c0a61 | ||
|
|
f742364e46 | ||
|
|
3b6eef465a | ||
|
|
3d93038bc6 | ||
|
|
8d3b4f4957 | ||
|
|
d1764997d3 | ||
|
|
2cf9974b73 | ||
|
|
7f41cb6ca1 | ||
|
|
8c408dd06e | ||
|
|
40aad212db | ||
|
|
872c42d12c | ||
|
|
c80cdd8a52 | ||
|
|
ffcefa06aa | ||
|
|
c038bf0f89 | ||
|
|
f93dd9f307 | ||
|
|
1939c9c3c0 | ||
|
|
68b37ccfc8 | ||
|
|
65d55a7618 | ||
|
|
57c3ec34c2 | ||
|
|
c5d77d4a70 | ||
|
|
cbec2476be | ||
|
|
9fd3563ef8 | ||
|
|
b66d7b50f5 | ||
|
|
fcf6ed5a96 | ||
|
|
ae0aa8be2a | ||
|
|
11ee1357d4 | ||
|
|
937fcf9fb5 | ||
|
|
7601fb0a7d | ||
|
|
4257a172c1 | ||
|
|
e38b173a0e | ||
|
|
8afeedc488 | ||
|
|
f43bf20a54 | ||
|
|
721a08c4b4 | ||
|
|
41a3535e84 | ||
|
|
626629bf06 | ||
|
|
6ec2ee2182 | ||
|
|
8c89a91164 | ||
|
|
58c05b301a | ||
|
|
f5e2a3c28f | ||
|
|
0fd45ba92a | ||
|
|
4e440fc218 | ||
|
|
41c8351709 | ||
|
|
1238648c2b | ||
|
|
03ac88683f | ||
|
|
fe4c057b20 | ||
|
|
e6c6997e46 | ||
|
|
ddd8778bab | ||
|
|
f95d258210 | ||
|
|
a2e1cf8dd5 | ||
|
|
0b8b68e6e6 | ||
|
|
8658a11d1f | ||
|
|
d0aa90131a | ||
|
|
ffb30177b1 | ||
|
|
297093f9ce | ||
|
|
5ba8440877 | ||
|
|
228e49d152 | ||
|
|
a9e983a717 | ||
|
|
25445d58d0 | ||
|
|
0b313a8aa8 | ||
|
|
54f954fd4b | ||
|
|
980f38ba03 | ||
|
|
198086e639 | ||
|
|
9eada2724b | ||
|
|
b5f53ee918 | ||
|
|
a3a8eb14ad | ||
|
|
333acf0822 | ||
|
|
efc175f654 | ||
|
|
6074afd999 | ||
|
|
219dff4055 | ||
|
|
9a3b07b622 | ||
|
|
1af49376b6 | ||
|
|
f90f6cfb33 | ||
|
|
6433f9ba98 | ||
|
|
cc1882ea1a | ||
|
|
56e83a1e69 | ||
|
|
487aaef02f | ||
|
|
f22fc03e56 | ||
|
|
69d429fa4e | ||
|
|
c6cd5fcf93 | ||
|
|
e8c9e70a4a | ||
|
|
6c78850902 | ||
|
|
adab377e44 | ||
|
|
7bdaa35768 | ||
|
|
1c7f79f293 | ||
|
|
3a7246c5b0 | ||
|
|
3bd95de839 | ||
|
|
576d3836b3 | ||
|
|
177b96b453 | ||
|
|
292f66a774 | ||
|
|
f1788b172c | ||
|
|
ae5912d41d | ||
|
|
adbab4057f | ||
|
|
ca4a639b86 | ||
|
|
a539a06f45 | ||
|
|
1a87544ccb | ||
|
|
b97450297e | ||
|
|
6a1040a339 | ||
|
|
7fe20129d2 | ||
|
|
4f59c1bb47 | ||
|
|
3ba17f1c87 | ||
|
|
ef874dda7e | ||
|
|
6e966a6229 | ||
|
|
ed3b890c67 | ||
|
|
2a46fd6227 | ||
|
|
23e13846c6 | ||
|
|
39e4549972 | ||
|
|
d924962546 | ||
|
|
0f1c81eb48 | ||
|
|
5e6fe7282d | ||
|
|
a47dad1ce4 | ||
|
|
1809c778e2 | ||
|
|
2178e16d3c | ||
|
|
deadbc6cf2 | ||
|
|
445d77223f | ||
|
|
09b24e33fc | ||
|
|
84553d11c4 | ||
|
|
eb1bab5878 | ||
|
|
a7a58038b3 | ||
|
|
1b9af8f010 | ||
|
|
113c4fe539 | ||
|
|
c33662dc2c | ||
|
|
8817b22376 | ||
|
|
b48da514e5 | ||
|
|
59cba2456b | ||
|
|
839c3d430b | ||
|
|
5b1f2522e1 | ||
|
|
6c3ccdf856 | ||
|
|
157d834cbb | ||
|
|
4f2e9b19cc | ||
|
|
fed7ca1ff3 | ||
|
|
73cfa17791 | ||
|
|
474a53ba92 | ||
|
|
69612eaee7 | ||
|
|
b7ad777de4 | ||
|
|
d6a70d852e | ||
|
|
33f12edce5 | ||
|
|
ab2e9fe6bd | ||
|
|
8bcffea686 | ||
|
|
8c837f9f64 | ||
|
|
941472c5c0 | ||
|
|
d2a5e03976 | ||
|
|
97e3bce327 | ||
|
|
e766667584 | ||
|
|
a93c110c29 | ||
|
|
85f97ae552 | ||
|
|
e1c7b89408 | ||
|
|
ad3ce72a39 | ||
|
|
57f48472d3 | ||
|
|
45ae6ac585 | ||
|
|
7ca0d10eb0 | ||
|
|
5a90676a25 | ||
|
|
8536f782ce | ||
|
|
5f45ddf210 | ||
|
|
67c83c7d68 | ||
|
|
6f6e1a9e55 | ||
|
|
c80451bc5e | ||
|
|
d6a533ca5c | ||
|
|
e0112eff89 | ||
|
|
38b29f0afb | ||
|
|
8b9d689a5f | ||
|
|
097edb2726 | ||
|
|
12e3e9a222 | ||
|
|
ce19ba1419 | ||
|
|
c81a22e55d | ||
|
|
bd04f49ff5 | ||
|
|
3a9e8970d6 | ||
|
|
9837645d16 | ||
|
|
1789c02295 | ||
|
|
3280376df3 | ||
|
|
d251593f04 | ||
|
|
9afeb29c63 | ||
|
|
e4dc07ce3f | ||
|
|
2bbf22a153 | ||
|
|
a598ae8bd2 | ||
|
|
4d72b9d2e7 | ||
|
|
e000b1d0c0 | ||
|
|
ef4261fe7f | ||
|
|
c3b75aa742 | ||
|
|
2518be52fb | ||
|
|
f3ee6c0e30 | ||
|
|
94363767ab | ||
|
|
9dd6e39665 | ||
|
|
ca8aed1f2b | ||
|
|
b32d63fcda | ||
|
|
54d9d5e2f3 | ||
|
|
722ae68cf1 | ||
|
|
e39313ecf6 | ||
|
|
8095100bee | ||
|
|
a76415a52f | ||
|
|
06305ee4ac | ||
|
|
70e87151bc | ||
|
|
d1299f8a78 | ||
|
|
20e58dc80b | ||
|
|
9f7b0e5898 | ||
|
|
5e073c2330 | ||
|
|
1b425d9a7c | ||
|
|
3546b65c91 | ||
|
|
758da29e25 | ||
|
|
60e246036b | ||
|
|
4b34f959e6 | ||
|
|
8abbd24cbe | ||
|
|
932f852d6a | ||
|
|
5773945791 | ||
|
|
bda1bd8f96 | ||
|
|
c3632e02d3 | ||
|
|
1b959b09c8 | ||
|
|
f55637ea08 | ||
|
|
0272df9974 | ||
|
|
0e02428b79 | ||
|
|
721c889235 | ||
|
|
9957af655f | ||
|
|
eab92fb486 | ||
|
|
9f1cd47cfa | ||
|
|
90c3edbbe7 | ||
|
|
adee8b584c | ||
|
|
329ad323e0 | ||
|
|
a8473f9340 | ||
|
|
1c0115f8cf | ||
|
|
a6ef802d3f | ||
|
|
37b5c37015 | ||
|
|
1e28e214a4 | ||
|
|
c713b97441 | ||
|
|
4e8525f015 | ||
|
|
eb79264b9b | ||
|
|
9c359ddb33 | ||
|
|
67a16d5085 | ||
|
|
6049cc4b43 | ||
|
|
d916180132 | ||
|
|
ad9f28f782 | ||
|
|
2890e4ebcc | ||
|
|
6638e4c765 | ||
|
|
a251a8f411 | ||
|
|
e7790679ca | ||
|
|
2a5e777c15 | ||
|
|
fdbbce9ff3 | ||
|
|
d47ac768c4 | ||
|
|
4867f4fa53 | ||
|
|
902a99e7d0 | ||
|
|
faf5f664dc | ||
|
|
4af94aaaa8 | ||
|
|
2bea0a0a11 | ||
|
|
b55067be91 | ||
|
|
7ea20dbbff | ||
|
|
2dcf1424ea | ||
|
|
caedb1ed64 | ||
|
|
d39856a93a | ||
|
|
f8c7cc87b9 | ||
|
|
ee9a9bd721 | ||
|
|
7520d3516a | ||
|
|
a2a9df86fc | ||
|
|
aa31aa7a3e | ||
|
|
950b8686f2 | ||
|
|
b6ab217a11 | ||
|
|
3b8176d326 | ||
|
|
e9ec07cb2b | ||
|
|
78659b5d20 | ||
|
|
9e26a2c651 | ||
|
|
3243ce1a45 | ||
|
|
475b6ae25b | ||
|
|
b853af59d6 | ||
|
|
ded1ad42e7 | ||
|
|
f3541b6c7f | ||
|
|
3c40c84c02 | ||
|
|
d50420edb9 | ||
|
|
e0794f0725 | ||
|
|
fb6282ae9e | ||
|
|
23995e5cc6 | ||
|
|
161545b864 | ||
|
|
285250dded | ||
|
|
bbc3e03e48 | ||
|
|
6b8d0d203c | ||
|
|
c0bec8cfa5 | ||
|
|
19b0d8bf56 | ||
|
|
ede14ea7b3 | ||
|
|
48ae7c4c33 | ||
|
|
fc217fd904 | ||
|
|
b692a3e9d2 | ||
|
|
48f5e47335 | ||
|
|
a080a0ccaa | ||
|
|
90321045f6 | ||
|
|
8ad9e24415 | ||
|
|
2008786c4e | ||
|
|
57f8036796 | ||
|
|
21a304261e | ||
|
|
cefb2b2524 | ||
|
|
e26bdb228b | ||
|
|
174acf1597 | ||
|
|
bf32c6133a | ||
|
|
fe73874b19 | ||
|
|
0eb82a0d5c | ||
|
|
fc2165d85d | ||
|
|
a368b2ea16 | ||
|
|
6294ef6db2 | ||
|
|
a9cca80c6d | ||
|
|
aee9066ccf | ||
|
|
ea3c130738 | ||
|
|
cf62eae51b | ||
|
|
c7e49e8d21 | ||
|
|
8bc420190b | ||
|
|
62711a144b | ||
|
|
333273b48a | ||
|
|
dd194f8ac0 | ||
|
|
5992f4814d | ||
|
|
d67f15b3fb | ||
|
|
be8635788a | ||
|
|
d96355e6c4 | ||
|
|
4ef2c8a2da | ||
|
|
058fbe1aee | ||
|
|
bc0f9f574a | ||
|
|
f575b82ce0 | ||
|
|
050ea18a02 | ||
|
|
18829279d2 | ||
|
|
75703d54ea | ||
|
|
0a3fc1bca0 | ||
|
|
bc688ef44d | ||
|
|
4fcc70bcf0 | ||
|
|
cad6f2c1eb | ||
|
|
c16b898d86 | ||
|
|
4f98244c3a | ||
|
|
8770f98fb1 | ||
|
|
bbcf78517f | ||
|
|
b9a940b4e3 | ||
|
|
d8a4c1aaf7 | ||
|
|
9803cf31c8 | ||
|
|
4a36177992 | ||
|
|
421614198a | ||
|
|
51e227e921 | ||
|
|
74948d11c5 | ||
|
|
f88e1b5903 | ||
|
|
59115ce886 | ||
|
|
4b18d15421 | ||
|
|
9be591c634 | ||
|
|
462af2f1f3 | ||
|
|
ab35c943fd | ||
|
|
aa36b24165 | ||
|
|
547cdda3db | ||
|
|
3b77fd1a6c | ||
|
|
a8110c9a8d | ||
|
|
b6f80d6a4a | ||
|
|
18489e64a2 | ||
|
|
a3d2df9ba2 | ||
|
|
314700e2e7 | ||
|
|
461b6c15d6 | ||
|
|
d23ac7e8ef | ||
|
|
68c0179465 | ||
|
|
8bc1455813 | ||
|
|
ecaa04ecf8 | ||
|
|
44e3070544 | ||
|
|
1815950835 | ||
|
|
8762fbf7ce | ||
|
|
0459171d6e | ||
|
|
fcdf72c5d9 | ||
|
|
f5caf0b7ba | ||
|
|
a0f2673b3a | ||
|
|
ba3439b049 | ||
|
|
ae4d7f719b | ||
|
|
64916f6bfc | ||
|
|
1a9dd1c37a | ||
|
|
d77925c568 | ||
|
|
f1f1b68ffb | ||
|
|
835f453f03 | ||
|
|
0eb9518485 | ||
|
|
b5c70fc34e | ||
|
|
a1dba1d7d0 | ||
|
|
efdea5256f | ||
|
|
5df1e5f383 | ||
|
|
99750da31d | ||
|
|
49247dba3f | ||
|
|
a25257cb33 | ||
|
|
b1c180d663 | ||
|
|
6afb16abcb | ||
|
|
995fa3df35 | ||
|
|
18eb28dfd2 | ||
|
|
99cdfadf8d |
No files matched your search
@@ -34,3 +34,4 @@ trace_data/
|
||||
/doc/user/public/*
|
||||
.ionide/*
|
||||
/.ignore
|
||||
CMakeDeps.cmake
|
||||
Vendored
+8
-3
@@ -5,7 +5,9 @@
|
||||
"includePath": [
|
||||
"/usr/include",
|
||||
"/usr/local/include",
|
||||
"${workspaceRoot}"
|
||||
"${workspaceRoot}",
|
||||
"${workspaceFolder}/src",
|
||||
"${workspaceRoot}/externals/linux/include"
|
||||
],
|
||||
"defines": [],
|
||||
"intelliSenseMode": "clang-x64",
|
||||
@@ -13,13 +15,16 @@
|
||||
"path": [
|
||||
"/usr/include",
|
||||
"/usr/local/include",
|
||||
"${workspaceRoot}"
|
||||
"${workspaceRoot}",
|
||||
"${workspaceFolder}/src",
|
||||
"${workspaceRoot}/externals/linux/include"
|
||||
],
|
||||
"limitSymbolsToIncludedHeaders": true,
|
||||
"databaseFilename": ""
|
||||
},
|
||||
"cStandard": "c11",
|
||||
"cppStandard": "c++17"
|
||||
"cppStandard": "c++17",
|
||||
"compileCommands": "${workspaceFolder}/build/ninja_debug/compile_commands.json"
|
||||
},
|
||||
{
|
||||
"name": "Windows",
|
||||
|
||||
Vendored
+145
-12
@@ -44,9 +44,10 @@
|
||||
"debuggerPath": "/usr/bin/gdb"
|
||||
},
|
||||
"sourceFileMap": {
|
||||
"/home/bts/spark/": "${workspaceRoot}"
|
||||
"/home/bts/spark/": "${workspaceRoot}",
|
||||
"/home/bts/spark_host/": "${workspaceRoot}",
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "(gdb) Launch",
|
||||
"type": "cppdbg",
|
||||
@@ -98,11 +99,52 @@
|
||||
"externalConsole": true,
|
||||
"requireExactSource": false
|
||||
},
|
||||
{
|
||||
"name": "sparkcmd Launch",
|
||||
"type": "clr",
|
||||
"request": "launch",
|
||||
"program": "${workspaceRoot}/build/Debug/bin/net471/sparkcmd.exe",
|
||||
"args": [
|
||||
"historical",
|
||||
"--server",
|
||||
//"--rstart", "11/22/2019",
|
||||
//"--rend", "11/25/2019",
|
||||
//"--rsymbol", "ES",
|
||||
//"--rsecuritytype", "Synthetic",
|
||||
//"--post_process_file_type", "Trade",
|
||||
//"--upload_to_aws",
|
||||
],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": true,
|
||||
"requireExactSource": false
|
||||
},
|
||||
{
|
||||
"name": "sparkcmd simulation",
|
||||
"type": "clr",
|
||||
"request": "launch",
|
||||
"program": "${workspaceRoot}/build/Debug/bin/net471/sparkcmd.exe",
|
||||
"args": [
|
||||
"historical",
|
||||
"--rstart", "11/26/2019",
|
||||
"--rend", "11/26/2019",
|
||||
"--rsymbol", "ZN",
|
||||
"--rsecuritytype", "Synthetic",
|
||||
"--algo_security", "ZNH0;ZNZ9-ZNH0;ZNZ9",
|
||||
"--algo_type", "RoundTrip",
|
||||
"--algo_params", "size=10;tick_size=0.015625,0.0078125,0.015625;hedge_factors=1,1,-1",
|
||||
"--skip_preanalysis", "true",
|
||||
],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": true,
|
||||
"requireExactSource": false
|
||||
},
|
||||
{
|
||||
"name": "Excel Launch",
|
||||
"type": "clr",
|
||||
"request": "launch",
|
||||
"program": "C:/Program Files/Microsoft Office/Office14/EXCEL.EXE",
|
||||
"program": "C:/Program Files/Microsoft Office/Office16/EXCEL.EXE",
|
||||
"args": [
|
||||
"${workspaceRoot}/build/Debug/bin/net471/spark_excel-addin64-packed.xll"
|
||||
],
|
||||
@@ -111,6 +153,20 @@
|
||||
"externalConsole": true,
|
||||
"requireExactSource": false
|
||||
},
|
||||
{
|
||||
"name": "Fix Launch",
|
||||
"type": "clr",
|
||||
"request": "launch",
|
||||
"program": "${workspaceRoot}/build/Debug/bin/net471/sparkcmd.exe",
|
||||
"args": [
|
||||
"fix",
|
||||
"-order_session",
|
||||
],
|
||||
"cwd": "${workspaceRoot}/build/Debug/bin/net471/",
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": true,
|
||||
"requireExactSource": false
|
||||
},
|
||||
{
|
||||
"name": "Client Tests",
|
||||
"type": "clr",
|
||||
@@ -126,11 +182,18 @@
|
||||
"requireExactSource": false
|
||||
},
|
||||
{
|
||||
"name": "Client Attach",
|
||||
"name": ".NET Framework Attach",
|
||||
"type": "clr",
|
||||
"request": "attach",
|
||||
"processId": "${command:pickProcess}"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command:pickProcess}",
|
||||
"requireExactSource": false
|
||||
},
|
||||
{
|
||||
"name": "Spreader Tests",
|
||||
"type": "cppdbg",
|
||||
@@ -337,20 +400,24 @@
|
||||
"quoteArgs": true
|
||||
},
|
||||
"sourceFileMap": {
|
||||
"/home/bts/spark/": "${workspaceRoot}"
|
||||
"/home/bts/spark_host/": "${workspaceRoot}"
|
||||
},
|
||||
"justMyCode": true
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Remote Launch",
|
||||
"name": "sparkcmd vsdbg (c#)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"program": "/usr/bin/dotnet",
|
||||
"program": "sparkcmd",
|
||||
"args": [
|
||||
"sparkcmd.dll",
|
||||
"test",
|
||||
"test_join_create_and_takeout_market"
|
||||
"historical",
|
||||
"--rstart", "11/20/2019",
|
||||
"--rend", "11/20/2019",
|
||||
"--rsymbol", "CL",
|
||||
"--rsecuritytype", "Spread",
|
||||
"--post_process_db", "mbo_history",
|
||||
],
|
||||
"env": {"LD_LIBRARY_PATH" : "."},
|
||||
"stopAtEntry": false,
|
||||
"cwd": "/home/bts/spark/build/ninja_debug/server",
|
||||
"pipeTransport": {
|
||||
@@ -361,11 +428,77 @@
|
||||
"debuggerPath": "/home/bts/vsdbg/vsdbg",
|
||||
"pipeCwd": "${workspaceRoot}",
|
||||
"quoteArgs": true
|
||||
},
|
||||
},
|
||||
"sourceFileMap": {
|
||||
"/home/bts/spark/": "${workspaceRoot}"
|
||||
},
|
||||
"justMyCode": false
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "sparkcmd gdb (c++)",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "/home/bts/spark/build/ninja_debug/server/sparkcmd",
|
||||
"args": [
|
||||
"historical",
|
||||
"--rstart", "10/21/2019",
|
||||
"--rend", "10/21/2019",
|
||||
"--rsymbol", "CL",
|
||||
"--rsecuritytype", "Future",
|
||||
"--algo_security", "CLX9",
|
||||
"--algo_type", "TWAP",
|
||||
"--algo_params", "'size=100;profit_ticks=1;tick_size=1,1,1;;hedge_factors=1,1,-1'",
|
||||
"--skip_preanalysis", "true",
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "/home/bts/spark/build/ninja_debug/server/",
|
||||
"environment": [],
|
||||
"externalConsole": true,
|
||||
"MIMode": "gdb",
|
||||
"preLaunchTask": "",
|
||||
"logging": {
|
||||
"engineLogging": false
|
||||
},
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "enable pretty-printer",
|
||||
"ignoreFailures": true
|
||||
},
|
||||
{
|
||||
"description": "Skip STL",
|
||||
"text": "skip -gfi /usr/include/c++/7/bits/*.h",
|
||||
"ignoreFailures": true
|
||||
},
|
||||
{
|
||||
"description": "LD LIBRARY",
|
||||
"text": "set env LD_LIBRARY_PATH=.",
|
||||
"ignoreFailures": false
|
||||
}
|
||||
],
|
||||
"pipeTransport": {
|
||||
"pipeCwd": "${workspaceRoot}",
|
||||
"pipeProgram": "c:\\program files\\git\\usr\\bin\\ssh.exe",
|
||||
"pipeArgs": [
|
||||
"bts@sparkvm"
|
||||
],
|
||||
"debuggerPath": "/usr/bin/gdb"
|
||||
},
|
||||
"sourceFileMap": {
|
||||
"/home/bts/spark/": "${workspaceRoot}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Jupyter notebook",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"program": "jupyter",
|
||||
"args": ["notebook", "--notebook-dir=c:\\code\\bts\\spark\\src\\client\\spark_historical\\Notebooks"],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"stopAtEntry": false,
|
||||
"console": "internalConsole",
|
||||
|
||||
},
|
||||
|
||||
]
|
||||
}
|
||||
Vendored
+19
-10
@@ -14,24 +14,21 @@
|
||||
"focus": false,
|
||||
"panel": "shared"
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
"group": "build"
|
||||
},
|
||||
{
|
||||
"label": "server_build",
|
||||
"label": "server_build",
|
||||
"type": "shell",
|
||||
"command": ".\\tools\\buildsparkd.cmd",
|
||||
"problemMatcher": {
|
||||
"base": "$gcc",
|
||||
"problemMatcher": {
|
||||
"base": "$gcc",
|
||||
"owner": "cpp",
|
||||
"fileLocation": [
|
||||
"relative",
|
||||
"${workspaceFolder}"
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"pattern": {
|
||||
"regexp": "(.?)(home)(.?)(bts)(.?)(spark)(.?)(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)",
|
||||
"regexp": "(.?)(home)(.?)(bts)(.?)(spark)(.?)(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)",
|
||||
"file": 8,
|
||||
"line": 9,
|
||||
"column": 10,
|
||||
@@ -49,6 +46,18 @@
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "linux build (Debug)",
|
||||
"type": "shell",
|
||||
"command": "cd build/ninja_debug; time ninja",
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -48,6 +48,7 @@ else ()
|
||||
add_subdirectory(doc/user)
|
||||
add_subdirectory(src/sdk)
|
||||
add_subdirectory(src/data_files)
|
||||
add_subdirectory(src/client)
|
||||
|
||||
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/server
|
||||
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/server
|
||||
@@ -59,7 +60,17 @@ else ()
|
||||
COMMAND ln ARGS -sf ${EXTERNALS_ROOT}/lib/Release/libACE-5.7.5.so ${CMAKE_BINARY_DIR}/server
|
||||
COMMAND mkdir ARGS -p ${CMAKE_BINARY_DIR}/server/plugins
|
||||
COMMENT "Creating server runtime layout"
|
||||
DEPENDS sparkd data_files_dir spark_client_dir
|
||||
DEPENDS sparkd data_files_dir)
|
||||
|
||||
add_custom_target(server_layout ALL DEPENDS ${CMAKE_BINARY_DIR}/server)
|
||||
|
||||
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
|
||||
add_custom_command(TARGET server_layout POST_BUILD
|
||||
COMMAND ln -fs ${CMAKE_BINARY_DIR}/../${CMAKE_BUILD_TYPE}/bin/netcoreapp3.1/linux-x64/sparkcmd ${CMAKE_BINARY_DIR}/server/ )
|
||||
else()
|
||||
add_custom_command(TARGET server_layout POST_BUILD
|
||||
COMMAND ln -fs ${CMAKE_BINARY_DIR}/../${CMAKE_BUILD_TYPE}/bin/netcoreapp3.1/linux-x64/publish/sparkcmd ${CMAKE_BINARY_DIR}/server/ )
|
||||
endif()
|
||||
|
||||
endif()
|
||||
@@ -0,0 +1 @@
|
||||
[0108/231015.447:ERROR:file_io.cc(89)] ReadExactly: expected 36, observed 0
|
||||
@@ -1,6 +1,6 @@
|
||||
+++
|
||||
title="Client API"
|
||||
template="client.html"
|
||||
redirect_to = "client/getting-started/overview/"
|
||||
sort_by="weight"
|
||||
+++
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
+++
|
||||
title="Getting Started"
|
||||
template="client.html"
|
||||
sort_by="weight"
|
||||
weight = 1
|
||||
+++
|
||||
|
||||
@@ -1,9 +1,25 @@
|
||||
+++
|
||||
title = "Install Prerequisites"
|
||||
template="client.html"
|
||||
weight = 1
|
||||
weight = 10
|
||||
+++
|
||||
|
||||
## Coming Soon
|
||||
# C#/.NET
|
||||
|
||||
We target [.NET Standard 2.0](https://docs.microsoft.com/en-us/dotnet/standard/net-standard) so you can use .NET Framework 4.6.1+ or .NET Core 2.0+. Simply add a reference to the [Spark Nuget package](https://nuget.org) to get started.
|
||||
|
||||
```
|
||||
dotnet new console -lang c#
|
||||
dotnet add package spark_sdk
|
||||
dotnet build
|
||||
```
|
||||
|
||||
# C++
|
||||
|
||||
The easiest way to get started with C++ is to use the Spark Server SDK to develop your application. Follow the instructions to [download and install the Spark Server SDK](/server/getting-started/install) and open the client_sdk sample project. If you want to run your C++ Client SDK application on Windows [contact us](mailto://api@bluetradesys.com) to get the required headers and binaries.
|
||||
|
||||
# JavaScript
|
||||
|
||||
We use JavaScript internally with the Spark Client API over a websocket connection but the documentation and packaging isn't ready yet. If this is something you're interested in get in touch with us at [api@bluetradesys.com](mailto:api@bluetradesys.com).
|
||||
|
||||
|
||||
|
||||
* Install .net core
|
||||
@@ -0,0 +1,31 @@
|
||||
+++
|
||||
title = "Overview"
|
||||
weight = 1
|
||||
+++
|
||||
|
||||
The Spark Client SDK is a high level command and control API which can be used to build scripts or integrate Spark into your existing ecosystem. The API is divided into several independent **"services"** responsible for different aspects of the system. A Service can define both [remote procedure call (RPC)](/client/getting-started/services#rpc) and incremental [streaming](/client/getting-started/services#streams) data.
|
||||
|
||||
The [Spark Desktop](https://www.bluetradingsystems.com/bts-spark/) is built on top of this API so you can be assured that it is complete and well tested.
|
||||
|
||||
Spark uses [Google Protocol Buffers](https://developers.google.com/protocol-buffers/) as an interface definition language similar to [GRPC](https://grpc.io) but backed by our custom high-performance TCP protocol. We currently support C#/.NET and C++ <!--and Javascript--> but the architecture is designed for easy extension so contact us about your specific business needs.
|
||||
|
||||
## Orders
|
||||
|
||||
Use the [OrderService](/client/services/orderservice) to send and manage orders including native exchange orders, spreader orders, and custom Algo orders created using the [Spark Server SDK](https://api.bluetradesys.com/server/).
|
||||
|
||||
## Spreader
|
||||
|
||||
Use the [SyntheticSecurityService](/client/services/syntheticsecurityservice) to create and manage synthetic spreads. Once created these spreads show up in the security and market data feeds just like exchange listed spreads.
|
||||
|
||||
## Position
|
||||
|
||||
Use the [PositionService](/client/services/positionservice) to get your position and P&L reports or add fills manually to keep the Spark system up to date with an external system.
|
||||
|
||||
## Administration
|
||||
|
||||
Use the [AdminService](/client/services/adminservice) to manage users and control limits.
|
||||
|
||||
## Market Data
|
||||
|
||||
For .NET subscribe to market data though the high level MarketDataClient interface. From C++ or JavaScript use the MarketDataRelay service directly.
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
+++
|
||||
title = "Services"
|
||||
weight = 20
|
||||
+++
|
||||
|
||||
The Spark Client SDK uses [Google Protocol Buffers](https://developers.google.com/protocol-buffers/) to define the interface for each service in a language independent manner. Services have both functions which return a single result and streams of data which return values continuously while subscribed. This page describes the mapping from the Protocol Buffer definition to the concrete definition in each supported language.
|
||||
|
||||
# ServiceContext
|
||||
|
||||
To connect your client to the Spark Server you need to get or create a `ServiceContext` instance. A `ServiceContext` represents a connection to the Spark Server and a background thread for handling messages on that connection. Generally there should be a single `ServiceContext` per process. All of the methods on the `ServiceContext` are safe thread safe.
|
||||
|
||||
Construct a ServiceContext by calling the default constructor. The ServiceContext will find the Spark Server by loading the server configuration over an HTTP connection. To determine the URL it will search the following locations and use the first one that is present.
|
||||
|
||||
* A command line argument `-configserver <url>`
|
||||
* An environment variable `BTSCONFIG`
|
||||
* `%APPDATA%/bts/conf/spark.conf` (Windows)
|
||||
* /sparkdata/conf/spark.conf (Linux)
|
||||
* $HOME/sparkdata/conf/spark.conf (Linux)
|
||||
|
||||
If your application is running on a system with the BTS Client installed this will probably work without any further configuration. If you plan to run your client application on a separate machine we recommend setting the `BTSCONFIG` environment variable.
|
||||
|
||||
<div class="info">
|
||||
<i class="fa fa-lightbulb-o fa-fw" aria-hidden="true"></i>
|
||||
If you are using the Spark Server SDK to run a local copy of the Spark server set <p><strong>BTSCONFIG = http://localhost:9000/config/</strong></p>
|
||||
</div>
|
||||
|
||||
To get a proxy for a given service call ServiceContext.locate<T>("qualifier") where T is the type of the service and "qualifier" is an optional qualifier used to disambiguate between 2 instances of the same service. The locate call cannot fail but it may return a disconnected proxy. When you make a call on the proxy you should check the call result to see if the method call succeeded.
|
||||
|
||||
# RPC
|
||||
|
||||
Here is the OrderService reduced to a single method definition. A RPC method always takes exactly 1 argument and returns 1 value. In this example the `create_order` call takes a `Create` instance and returns a `Response`.
|
||||
|
||||
```C
|
||||
service OrderService {
|
||||
rpc create_order(Create) returns (Response);
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
The `Create` and `Response` types are also defined as protocol buffer messages. Each field can either be a primitive type another message or a list or map.
|
||||
|
||||
```C
|
||||
message Create {
|
||||
OrderDefinition new_order = 1;
|
||||
double price = 2;
|
||||
uint32 quantity = 3;
|
||||
}
|
||||
|
||||
message Response {
|
||||
uint32 order_key = 1;
|
||||
OrderError error_code = 2;
|
||||
string msg = 3;
|
||||
}
|
||||
```
|
||||
|
||||
Each RPC call generates both synchronous (blocking) and asynchronous variants. In C# the asynchronous calls have the `_async` suffix and return a `Task`. In C++ the call is overloaded to either return a value synchronously or accept a callback function to be called on the ServiceContext thread when the call completes. <!-- In Javascript only async methods returning a Promise are generated because it never makes sense to make a blocking call in the browser. -->
|
||||
|
||||
To call the resulting service locate a proxy using the [ServiceContext](#servicecontext) and then call `cancel_order` or `cancel_order_async`. If you are calling the Spark API from a GUI application you should always prefer the `_async` version of the calls.
|
||||
|
||||
|
||||
### C# example
|
||||
```c#
|
||||
var ctx = new ServiceContext();
|
||||
var orders = ctx.locate<OrderService>();
|
||||
var response =
|
||||
await orders.create_order_async(
|
||||
new Create { price = 2.25, quantity = 42 });
|
||||
if (response.success) {
|
||||
Console.WriteLine($"success: {response.value}");
|
||||
}
|
||||
else {
|
||||
Console.WriteLine($"Error: {response.error_message}");
|
||||
}
|
||||
```
|
||||
### C++ example
|
||||
```cpp
|
||||
auto ctx = ServiceContext{};
|
||||
auto orders = ctx.locate<OrderService>();
|
||||
Create c;
|
||||
c.set_price(2.25);
|
||||
c.set_quantity(42);
|
||||
// Instead of providing an _async method C++ uses overloading.
|
||||
// To make a syncronous call simply omit the callback
|
||||
orders.create_order(c, [=](const Result<Response>& response) {
|
||||
if(response.success()) {
|
||||
std::cout << "success.";
|
||||
}
|
||||
else {
|
||||
std::cout << "error: " << response.error_message();
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
# Streams
|
||||
|
||||
Streams allow you to subscribe to live updating data. Each stream represents a changing collection of protocol buffer objects. Similar to a database row each item has an `id` which uniquely identifies it within the collection. Updates from the Spark server can add, remove or replace entries in the collection. Since only the changed items are sent over the wire the stream can remain responsive even when it represents a large collection.
|
||||
|
||||
Streams are implemented using the language bindings for [ReativeX](http://reactivex.io/) which provide utility functions to drill down to the specific data your application needs. In C# we provide both mutable and immutable versions of the generated data types (C++ users can rely on `const`).
|
||||
|
||||
When defined in a proto file streams use the `stream` keyword on the result type.
|
||||
```C
|
||||
service OrderService {
|
||||
...
|
||||
rpc fills (FillsSub) returns (stream Fill);
|
||||
}
|
||||
```
|
||||
|
||||
### C# example
|
||||
```c#
|
||||
var sc = new ServiceContext();
|
||||
var orders = sc.locate<OrderService>();
|
||||
var fills_observable = orders.subscribei_fills();
|
||||
var unsub = fills_observable.Subscribe(update => {
|
||||
Console.WriteLine(
|
||||
"Added {0} items, Removed {1} items, Updated {2} items. Total items {3}",
|
||||
update.added.Count(),
|
||||
update.removed.Count(),
|
||||
update.changes.Count(),
|
||||
update.all.Count());
|
||||
});
|
||||
|
||||
Thread.Sleep(TimeSpan.FromMinutes(5));
|
||||
unsub.Dispose();
|
||||
```
|
||||
### C++ Example
|
||||
```cpp
|
||||
```
|
||||
@@ -0,0 +1,6 @@
|
||||
+++
|
||||
title="Samples"
|
||||
sort_by="weight"
|
||||
weight = 30
|
||||
+++
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
+++
|
||||
title = "AdminService"
|
||||
+++
|
||||
@@ -0,0 +1,3 @@
|
||||
+++
|
||||
title = "OrderService"
|
||||
+++
|
||||
@@ -0,0 +1,3 @@
|
||||
+++
|
||||
title = "PositionService"
|
||||
+++
|
||||
@@ -0,0 +1,3 @@
|
||||
+++
|
||||
title = "SyntheticService"
|
||||
+++
|
||||
@@ -0,0 +1,6 @@
|
||||
+++
|
||||
title="Services"
|
||||
#sort_by="weight"
|
||||
weight = 10
|
||||
+++
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
+++
|
||||
title = "Market Data"
|
||||
+++
|
||||
@@ -1,6 +1,5 @@
|
||||
+++
|
||||
title="Algo API"
|
||||
template="documentation.html"
|
||||
redirect_to = "server/getting-started/overview/"
|
||||
sort_by="weight"
|
||||
+++
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
+++
|
||||
title="Getting Started"
|
||||
template="documentation.html"
|
||||
sort_by="weight"
|
||||
weight = 1
|
||||
+++
|
||||
|
||||
@@ -71,12 +71,12 @@ The first step is to start the spark_sdk Docker container with the examples dire
|
||||
|
||||
Windows Command Prompt:
|
||||
{% clipable() %}
|
||||
docker run --rm -it -v %CD%:/examples -u bts -w /examples --shm-size 1024m --name spark_sdk -h spark_sdk --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -p 9000:9000 -p 9001:9001 spark_sdk bash
|
||||
docker run --rm -it -v %CD%:/examples -u bts -w /examples --shm-size 2048m --name spark_sdk -h spark_sdk --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -p 9000:9000 -p 9001:9001 spark_sdk bash
|
||||
{% end %}
|
||||
|
||||
**Powershell** / Linux / Mac:
|
||||
{% clipable() %}
|
||||
docker run --rm -it -v ${PWD}:/examples -u bts -w /examples --shm-size 1024m --name spark_sdk -h spark_sdk --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -p 9000:9000 -p 9001:9001 spark_sdk bash
|
||||
docker run --rm -it -v ${PWD}:/examples -u bts -w /examples --shm-size 2048m --name spark_sdk -h spark_sdk --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -p 9000:9000 -p 9001:9001 spark_sdk bash
|
||||
{% end %}
|
||||
|
||||
### Attach
|
||||
|
||||
@@ -5,7 +5,7 @@ weight = 2
|
||||
|
||||
## Request Access 🔑
|
||||
|
||||
To start using the Server SDK you will need to request access though our sales department. Please email <a href="mailto:info@bluetradesys.com">info@bluetradesys.com</a> or call <a href="tel:919-913-0850">(919) 913-0850</a> and we will provide download credentials.
|
||||
To start using the Server SDK you will need to request access though our sales department. Please email <a href="mailto:api@bluetradesys.com">api@bluetradesys.com</a> or call <a href="tel:919-913-0850">(919) 913-0850</a> and we will provide download credentials.
|
||||
|
||||
## Download
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
+++
|
||||
title="Reference"
|
||||
template="documentation.html"
|
||||
sort_by="weight"
|
||||
weight = 2
|
||||
+++
|
||||
|
||||
@@ -6,3 +6,9 @@ weight = 40
|
||||
## I need to make a call that might take a few seconds. What is the best way to do this?
|
||||
|
||||
Create a background thread in [do_before_launch](/server/ref/initialization#before-launch) or [do_launch](/server/ref/initialization#launch-launch-attached) to do the work. Use [on_timer](/server/ref/subscriptions#timer) to poll until the result is available.
|
||||
|
||||
## I don't see the header files in the .zip file. Where are they?
|
||||
|
||||
The SDK headers are baked into the docker image along with the build tools. Once you've loaded the image with `docker load < spark_sdk.img` you can run this command to copy them out to your local file system `docker run --rm -it -v $PWD:/out spark_sdk /bin/tar -cvf /out/headers.tar /sdk/include` This will copy the headers to the current directory in headers.tar. We still recommend doing the actual build inside the docker environment but having a copy of the headers can be useful for setting up your development environment.
|
||||
|
||||
|
||||
File renamed without changes.
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
@@ -1,6 +1,5 @@
|
||||
+++
|
||||
title="Samples"
|
||||
template="documentation.html"
|
||||
sort_by="weight"
|
||||
weight = 3
|
||||
+++
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
{% extends "index.html" %}
|
||||
|
||||
{% block extra_nav_class %}{% endblock extra_nav_class %}
|
||||
{% block extra_content_class %}content--reversed{% endblock extra_content_class %}
|
||||
|
||||
{% block content %}
|
||||
{% set section = get_section(path="client/_index.md") %}
|
||||
<div class="documentation">
|
||||
<aside class="documentation__sidebar">
|
||||
<ul>
|
||||
{% for p in section.subsections %}
|
||||
{% set subsection = get_section(path=p) %}
|
||||
<li>
|
||||
<span class="documentation__sidebar__title">{{ subsection.title }}</span>
|
||||
<ul>
|
||||
{% for page in subsection.pages %}
|
||||
<li class="{% if current_path == page.path %}active{% endif %}">
|
||||
<a href="{{page.permalink}}">{{page.title}}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</aside>
|
||||
<div class="documentation__content">
|
||||
{% block doc_content %}
|
||||
{% endblock doc_content %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
@@ -1,36 +0,0 @@
|
||||
{% extends "index.html" %}
|
||||
|
||||
{% block extra_nav_class %}{% endblock extra_nav_class %}
|
||||
{% block extra_content_class %}content--reversed{% endblock extra_content_class %}
|
||||
|
||||
{% block content %}
|
||||
{%if page.extra.section %}
|
||||
{% set section = get_section(path="{{page.extra.section}}/_index.md") %}
|
||||
{% else %}
|
||||
{% set section = get_section(path="server/_index.md") %}
|
||||
{% endif %}
|
||||
<div class="documentation">
|
||||
<aside class="documentation__sidebar">
|
||||
<ul>
|
||||
{% for p in section.subsections %}
|
||||
{% set subsection = get_section(path=p) %}
|
||||
<li>
|
||||
<span class="documentation__sidebar__title">{{ subsection.title }}</span>
|
||||
<ul>
|
||||
{% for page in subsection.pages %}
|
||||
<li class="{% if current_path == page.path %}active{% endif %}">
|
||||
<a href="{{page.permalink}}">{{page.title}}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</aside>
|
||||
<div class="documentation__content">
|
||||
{% block doc_content %}
|
||||
{% endblock doc_content %}
|
||||
{% block next_link %} {% endblock next_link %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
@@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en-gb">
|
||||
<html lang="en-us">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
@@ -14,6 +14,7 @@
|
||||
<link rel="stylesheet" href="{{ get_url(path="site.css") }}"/>
|
||||
<link rel="icon" href="{{ get_url(path="favicon.ico") }}">
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||
<script> dataLayer = [{ 'visitorType': 'geek' }]; </script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -36,13 +37,13 @@
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<div class="content {% block extra_content_class %}{% endblock extra_content_class %}">
|
||||
<div class="content content--reversed">
|
||||
{% block content %}
|
||||
<div class="hero">
|
||||
<h1>Spark SDK</h1>
|
||||
<p class="hero__tagline">
|
||||
Spark consists of a client UI
|
||||
(<a class="white" href="https://www.bluetradingsystems.com/bts-spark#ladder-algo-screen">Spark Client</a>),
|
||||
(<a href="https://www.bluetradingsystems.com/bts-spark#ladder-algo-screen">Spark Client</a>),
|
||||
a high-performance professional futures front end, connected via our proprietary protocol over TCP to our Spark Server, which in turn connects to execution venues via their native protocols.
|
||||
Use the Spark SDK to extend Spark Server with your custom Algos, then use the Client SDK to launch and control them.
|
||||
</p>
|
||||
@@ -64,7 +65,7 @@
|
||||
<a href="{{ get_url(path="@/server/_index.md") }}" class="button">Get started</a>
|
||||
</div>
|
||||
|
||||
<div class="selling-point disabled">
|
||||
<div class="selling-point">
|
||||
<h2>
|
||||
Client SDK
|
||||
<i class="fa fa-gamepad" aria-hidden="true"></i>
|
||||
@@ -72,19 +73,9 @@
|
||||
<p>
|
||||
The Spark client SDK allows you to integrate spark with your existing ecosystem. The Spark Client is built entirely on this simple, powerful API.
|
||||
</p>
|
||||
<a href="" class="button" disabled>Get started</a>
|
||||
<a href="" class="button">Get started</a>
|
||||
</div>
|
||||
|
||||
<!-- <div class="selling-point disabled">
|
||||
<h2>
|
||||
Microsoft Excel
|
||||
<i class="fa fa-table" aria-hidden="true"></i>
|
||||
</h2>
|
||||
<p>
|
||||
More of your business is built on excel than probably should be. Continue this worrying trend with the Spark Excel API.
|
||||
</p>
|
||||
<a href="" class="button" disabled>Get started</a>
|
||||
</div> -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -94,6 +85,15 @@
|
||||
© Blue Trading Systems
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
if (location.hostname == "api.bluetradesys.com") {
|
||||
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
||||
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
||||
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
||||
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
||||
})(window,document,'script','dataLayer','GTM-56FHG8R');
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript" src="{{ get_url(path="elasticlunr.min.js") }}"></script>
|
||||
<script type="text/javascript" src="{{ get_url(path="search_index.en.js") }}"></script>
|
||||
<script type="text/javascript" src="{{ get_url(path="search.js") }}"></script>
|
||||
|
||||
@@ -1,13 +1,39 @@
|
||||
{% extends "documentation.html" %}
|
||||
{% extends "index.html" %}
|
||||
{# this has access to the "page" variable but documentation.html does not #}
|
||||
|
||||
{% block title %}{{ page.title }} | {{ super() }} {% endblock title %}
|
||||
{% block doc_content %}
|
||||
<h1>{{page.title}}</h1>
|
||||
{{page.content | safe}}
|
||||
{% endblock doc_content %}
|
||||
|
||||
{% block next_link %}
|
||||
<p>
|
||||
{% endblock next_link %}
|
||||
|
||||
{% block content %}
|
||||
{% set section = get_section(path=page.ancestors[1]) %}
|
||||
{#
|
||||
{#<div>{{ section.title }} </div>#}
|
||||
<div class="documentation">
|
||||
<aside class="documentation__sidebar">
|
||||
<ul>
|
||||
{% for p in section.subsections %}
|
||||
{% set subsection = get_section(path=p) %}
|
||||
<li>
|
||||
<span class="documentation__sidebar__title">{{ subsection.title }}</span>
|
||||
<ul>
|
||||
{% for page in subsection.pages %}
|
||||
<li class="{% if current_path == page.path %}active{% endif %}">
|
||||
<a href="{{page.permalink}}">{{page.title}}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</aside>
|
||||
<div class="documentation__content">
|
||||
<h1>{{page.title}}</h1>
|
||||
{{page.content | safe}}
|
||||
|
||||
{# next/pre links #}
|
||||
<p>
|
||||
{% if page.lighter %}
|
||||
<a href="{{ page.lighter.permalink }}">
|
||||
<i class="fa fa-chevron-left fa-fw" aria-hidden="true"></i>
|
||||
@@ -21,5 +47,7 @@
|
||||
<i class="fa fa-chevron-right fa-fw" aria-hidden="true"></i>
|
||||
</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
{% endblock next_link %}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
@@ -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/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)
|
||||
@@ -4,6 +4,15 @@ weight = 3
|
||||
sort_by = "weight"
|
||||
insert_anchor_links = "right"
|
||||
+++
|
||||
## 2.15.3
|
||||
### Bug Fixes
|
||||
- Fixed a bug where some CME currency spreads exhibited incorrect tick values
|
||||
## 2.15.2
|
||||
### User Visible Changes
|
||||
- Excel RTD plugin can now receive ICE market data
|
||||
## 2.15.1
|
||||
### Bug Fixes
|
||||
- Fixed a FIX log parsing issue that resulted in exchange gateway logon problems
|
||||
## 2.15.0
|
||||
### User Visible Changes
|
||||
- Added ability to hide Ladder status messages via Ladder Settings -> Left Panel tab -> Show/Hide groupbox -> Status Message
|
||||
|
||||
+1
-1
Submodule docker/linux updated: 68f43cef8d...e106e6e704.
+1
-1
Submodule externals updated: 6d8f64ca5c...c695e96940.
@@ -25,7 +25,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_excel", "src\client\s
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_fix", "src\client\spark_fix\spark_fix.csproj", "{D8031C13-7BEA-430A-BB60-40927D15CFC3}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_historical", "src\client\spark_historical\spark_historical.csproj", "{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(Performance) = preSolution
|
||||
HasPerformanceSessions = true
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
@@ -241,6 +246,30 @@ Global
|
||||
{D8031C13-7BEA-430A-BB60-40927D15CFC3}.RelWithDebInfo|x64.Build.0 = Release|x64
|
||||
{D8031C13-7BEA-430A-BB60-40927D15CFC3}.RelWithDebInfo|x86.ActiveCfg = Release|x64
|
||||
{D8031C13-7BEA-430A-BB60-40927D15CFC3}.RelWithDebInfo|x86.Build.0 = Release|x64
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.MinSizeRel|x64.Build.0 = Debug|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.MinSizeRel|x86.ActiveCfg = Debug|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.MinSizeRel|x86.Build.0 = Debug|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.Release|x64.Build.0 = Release|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.Release|x86.Build.0 = Release|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU
|
||||
{5F64A360-43F4-4AD8-8B04-3C3F4424BCBC}.RelWithDebInfo|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(spark_client)
|
||||
include(${CMAKE_SOURCE_DIR}/tools/safe_dep_glob.cmake)
|
||||
|
||||
file(GLOB_RECURSE spark_client_sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cs)
|
||||
file(GLOB_RECURSE spark_client_csproj RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.csproj)
|
||||
file(GLOB_RECURSE spark_ui_sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} spark/*.cs)
|
||||
file(GLOB_RECURSE spark_ui_csproj RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} spark/*.csproj)
|
||||
list(REMOVE_ITEM spark_ui_sources ${spark_client_sources} )
|
||||
list(REMOVE_ITEM spark_ui_csproj ${spark_client_csproj} )
|
||||
|
||||
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/../
|
||||
COMMAND /bin/bash ${CMAKE_CURRENT_SOURCE_DIR}/build_spark_dotnetcore.sh
|
||||
ARGS ${CMAKE_BUILD_TYPE} ${CMAKE_BINARY_DIR}
|
||||
COMMENT "Building sparkcmd in netcore3"
|
||||
DEPENDS libspark ${spark_client_sources} ${spark_client_csproj} ${CMAKE_CURRENT_SOURCE_DIR}/build_spark_dotnetcore.sh)
|
||||
|
||||
add_custom_target(spark_client_dir ALL DEPENDS ${CMAKE_BINARY_DIR}/../)
|
||||
@@ -5,6 +5,7 @@
|
||||
<SparkRoot>$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)\..\..))</SparkRoot>
|
||||
<SourceRoot>$([System.IO.Path]::GetFullPath($(SparkRoot)\src))</SourceRoot>
|
||||
<Externals>$(SparkRoot)\externals\windows</Externals>
|
||||
<Externals Condition=" '$(OS)' != 'Windows_NT' ">$(SparkRoot)/externals/linux</Externals>
|
||||
<DepotName>$([System.IO.Path]::GetFileName($([System.IO.Path]::GetFullPath($(SparkRoot)))))</DepotName>
|
||||
<ErrorReport>None</ErrorReport>
|
||||
<Prefer32Bit>False</Prefer32Bit>
|
||||
@@ -19,20 +20,25 @@
|
||||
<OutputPath>$(BaseOutputPath)\bin</OutputPath>
|
||||
<BaseIntermediateOutputPath>$(BaseOutputPath)\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<IntermediateOutputPath>$(BaseOutputPath)\obj\$(MSBuildProjectName)</IntermediateOutputPath>
|
||||
<BaseIntermediateOutputPath Condition=" '$(OS)' != 'Windows_NT' ">$(BaseOutputPath)\linuxobj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<IntermediateOutputPath Condition=" '$(OS)' != 'Windows_NT' ">$(BaseOutputPath)\linuxobj\$(MSBuildProjectName)</IntermediateOutputPath>
|
||||
<GenDir>$(BaseOutputPath)\gen\$(MSBuildProjectName)</GenDir>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<Import Project="$(ComputerSpecificConfig)" Condition="Exists($(ComputerSpecificConfig))" />
|
||||
|
||||
<ItemGroup>
|
||||
<AvailableItemName Include="Proto2">
|
||||
<Targets>CompileProto3</Targets>
|
||||
<Targets Condition=" '$(OS)' == 'Windows_NT' " >CompileProto2</Targets>
|
||||
<Targets Condition=" '$(OS)' != 'Windows_NT' " >CompileProto2Linux</Targets>
|
||||
</AvailableItemName>
|
||||
<AvailableItemName Include="Proto3">
|
||||
<Targets>CompileProto3</Targets>
|
||||
<Targets Condition=" '$(OS)' == 'Windows_NT' " >CompileProto3</Targets>
|
||||
<Targets Condition=" '$(OS)' != 'Windows_NT' " >CompileProto3Linux</Targets>
|
||||
</AvailableItemName>
|
||||
<AvailableItemName Include="Proto3Excel">
|
||||
<Targets>CompileProto3Excel</Targets>
|
||||
<Targets Condition=" '$(OS)' == 'Windows_NT' ">CompileProto3Excel</Targets>
|
||||
</AvailableItemName>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -43,6 +49,14 @@
|
||||
<protogen>$(Externals)\bin\protogen.exe</protogen>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Label="ProtoBuf" Condition=" '$(OS)' != 'Windows_NT' ">
|
||||
<ProtocPluginBase>$(SparkRoot)/src/lib/api/service_compiler</ProtocPluginBase>
|
||||
<ProtoInclude>$(Externals)/include</ProtoInclude>
|
||||
<protoc>$(Externals)/bin/protoc</protoc>
|
||||
<protoc_rename>$(Externals)/bin/lowercase_files.sh</protoc_rename>
|
||||
<protogen>$(Externals)/bin/protogen</protogen>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemDefinitionGroup>
|
||||
<Proto2>
|
||||
</Proto2>
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
|
||||
<Target Name="CompileProto2"
|
||||
Condition="'@(Proto2)'!=''"
|
||||
Condition="'@(Proto2)'!='' AND '$(OS)' == 'Windows_NT' "
|
||||
Inputs="$(MSBuildProjectFile);$(protogen);%(Proto2.FullPath)"
|
||||
Outputs="$(GenDir)\proto2\%(Proto2.filename).cs"
|
||||
AfterTargets="PreBuildEvent">
|
||||
@@ -28,7 +28,7 @@
|
||||
passes wipes out the additional compile includes that we add.
|
||||
-->
|
||||
<Target Name="CompileProto3" AfterTargets="GetAssemblyVersion"
|
||||
Condition="'@(Proto3)'!=''"
|
||||
Condition="'@(Proto3)'!='' AND '$(OS)' == 'Windows_NT' "
|
||||
Inputs="$(protoc);
|
||||
%(Proto3.Identity);$(ProtocPluginBase)\plugin.py;
|
||||
$(ProtocPluginBase)\templates\c#\client.pb.cs;
|
||||
@@ -58,7 +58,7 @@
|
||||
</Target>
|
||||
|
||||
<Target Name="CompileProto3Excel" AfterTargets="GetAssemblyVersion"
|
||||
Condition="'@(Proto3Excel)'!=''"
|
||||
Condition="'@(Proto3Excel)'!='' AND '$(OS)' == 'Windows_NT' "
|
||||
Inputs="$(protoc);
|
||||
%(Proto3Excel.Identity);$(ProtocPluginBase)\plugin.py;
|
||||
$(ProtocPluginBase)\templates\excel\excel.pb.cs;"
|
||||
@@ -82,12 +82,74 @@
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
|
||||
<Target Name="CompileProto2Linux"
|
||||
Condition="'@(Proto2)'!='' AND '$(OS)' != 'Windows_NT' "
|
||||
Inputs="$(MSBuildProjectFile);$(protogen);%(Proto2.FullPath)"
|
||||
Outputs="$(GenDir)/proto2/%(Proto2.filename).cs"
|
||||
AfterTargets="PreBuildEvent">
|
||||
<PropertyGroup>
|
||||
<SourceRelativeFile>$([System.String]::Copy('%(proto2.fullpath)').Replace($(SourceRoot), ''))</SourceRelativeFile>
|
||||
<SourceRelativeDir>$([System.IO.Path]::GetDirectoryName($(SourceRelativeFile)))</SourceRelativeDir>
|
||||
<WorkingDirectory>$(GenDir)/proto2</WorkingDirectory>
|
||||
</PropertyGroup>
|
||||
<MakeDir Directories="$(WorkingDirectory)" />
|
||||
<Copy SourceFiles="%(Proto2.FullPath)" DestinationFolder="$(WorkingDirectory)" SkipUnchangedFiles="True" UseHardLinksIfPossible="True" />
|
||||
<Error Text="protogen.exe does not exist. If you forgot to clone with externals try: git submodule update --init --recursive" Condition="!Exists($(protogen))" />
|
||||
<Message Importance="High" Text="Doing Proto2 %(proto2.filename)" />
|
||||
<Exec Command="PYTHONPATH=$(Externals)/python $(Protogen) %(Proto2.filename)%(proto2.extension) --csharp_out=. -I. -I$(SourceRoot) -I$(Externals)/include"
|
||||
WorkingDirectory="$(WorkingDirectory)" />
|
||||
<ItemGroup>
|
||||
<Compile Include="$(WorkingDirectory)/%(Proto2.filename).cs" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
<Target Name="CompileProto3Linux" AfterTargets="GetAssemblyVersion"
|
||||
Condition="'@(Proto3)'!='' AND '$(OS)' != 'Windows_NT' "
|
||||
Inputs="$(protoc);
|
||||
%(Proto3.Identity);$(ProtocPluginBase)/plugin.py;
|
||||
$(ProtocPluginBase)/templates/c#/client.pb.cs;
|
||||
$(ProtocPluginBase)/templates/c#/server.pb.cs;
|
||||
$(ProtocPluginBase)/templates/c#/immutable.pb.cs;"
|
||||
Outputs="%(Proto3.OutCS);%(Proto3.OutCSServer);%(Proto3.OutCSClient);%(Proto3.OutCSImmutable)">
|
||||
<MakeDir Directories="%(Proto3.OutBase)" />
|
||||
<MakeDir Directories="$(IntermediateOutputPath)/gen" />
|
||||
|
||||
<Message Importance="High" Text="Generating service %(Proto3.FileName)" />
|
||||
<Exec Command="
|
||||
PYTHONPATH=$(Externals)/python $(protoc) \
|
||||
%(Proto3.FullPath) \
|
||||
--error_format=gcc \
|
||||
--proto_path=$(protoinc):$(SourceRoot) \
|
||||
--plugin='protoc-gen-service=$(ProtocPluginBase)/plugin.py' \
|
||||
--service_out=lang=c#,strip_out_path=1:%(Proto3.OutBase) \
|
||||
--csharp_out=%(CompileOptions)%(Proto3.OutBase)"
|
||||
WorkingDirectory="%(relativedir)" />
|
||||
|
||||
<!-- <Exec Command="$(protoc_rename) %(Proto3.OutBase)" /> -->
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="%(Proto3.OutCS)" />
|
||||
<Compile Include="%(Proto3.OutCSClient)" />
|
||||
<Compile Include="%(Proto3.OutCSServer)" />
|
||||
<Compile Include="%(Proto3.OutCSImmutable)" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
<!-- <Target Name="RenameProto3Linux" AfterTargets="CompileProto3Linux"
|
||||
Condition="'@(Proto3)'!='' AND '$(OS)' != 'Windows_NT' ">
|
||||
<Move SourceFiles="$(OutBase)\Apicore.cs" DestinationFiles="$(OutBase)\apicore.cs" />
|
||||
<Move SourceFiles="$(OutBase)\Apioptions.cs" DestinationFiles="$(OutBase)\apioptions.cs" />
|
||||
<Move SourceFiles="$(OutBase)\Co2.cs" DestinationFiles="$(OutBase)\co2.cs" />
|
||||
</Target> -->
|
||||
|
||||
|
||||
<Target Name="AfterClean" AfterTargets="Clean">
|
||||
<Delete Files="%(Proto3.OutCS)" />
|
||||
<Delete Files="%(Proto3.OutCSClient)" />
|
||||
<Delete Files="%(Proto3.OutCSServer)" />
|
||||
<Delete Files="%(Proto3.OutCSImmutable)" />
|
||||
<Delete Files="$(GenDir)\proto2\*" />
|
||||
<Delete Files="$(GenDir)/proto2/*" />
|
||||
<Delete Files="%(Proto3Excel.OutCSExcel)" />
|
||||
</Target>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
#$1 = Debug / Release (CMAKE_BUILD_TYPE), $2 = CMAKE_BINARY_DIR
|
||||
cd "$(dirname "$0")"
|
||||
echo $PWD dotnet build -c $1 ./sparkcmd/
|
||||
dotnet build -c $1 -o $2/../$1/bin/netcoreapp3.1/linux-x64 ./sparkcmd/
|
||||
|
||||
if [ "$1" == "Release" ]
|
||||
then
|
||||
dotnet publish -c $1 -o $2/../$1/bin/netcoreapp3.1/linux-x64 ./sparkcmd/
|
||||
ln -fs $2/src/lib/libspark.so $2/../$1/bin/netcoreapp3.1/linux-x64/publish
|
||||
fi
|
||||
|
||||
ln -fs $2/src/lib/libspark.so $2/../$1/bin/netcoreapp3.1/linux-x64
|
||||
@@ -1,6 +1,7 @@
|
||||
using bts.api;
|
||||
using bts.co2;
|
||||
using bts.collections;
|
||||
using bts.utils.csv;
|
||||
using mbts.persist;
|
||||
using mbts.spark.filters;
|
||||
using mbts.ui;
|
||||
@@ -52,7 +53,7 @@ namespace mbts.spark {
|
||||
columns.Add(new RenderTextColumn<Row, TimeAndSalesView.Columns>(col_key, r => r[col_key], filter, filter_template, r => _get_aggressor_brush(r))
|
||||
{ id = col_id(col_key), Header = header, Width = width, sort_member_path = sort_member_path, horizontal_alignment = h_alignment }
|
||||
);
|
||||
|
||||
|
||||
// be sure to load GridSettings AFTER the columns collection has been populated, the grid settings manager looks columns by id to apply the appropriate settings,
|
||||
// if the collection is not populated, the column settings will not be applied
|
||||
grid_settings_manager = new SimpleGridSettingsManager<Row>(columns, new Dictionary<string, GridColumnSettingsFeatureFlags> { }, row_vms);
|
||||
@@ -173,6 +174,19 @@ namespace mbts.spark {
|
||||
}
|
||||
}
|
||||
|
||||
public static System.Collections.Specialized.OrderedDictionary csv_ordered_properties =>
|
||||
CsvHelper.create_ordering_maintainer(
|
||||
typeof(TimeAndSalesVM.Row),
|
||||
new string[] {
|
||||
nameof(security),
|
||||
nameof(time),
|
||||
nameof(price),
|
||||
nameof(size),
|
||||
nameof(aggressor_side),
|
||||
nameof(security_key),
|
||||
});
|
||||
|
||||
|
||||
public void raise_invalidated() => invalidated?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using bts.api;
|
||||
using bts.shell;
|
||||
using bts.shell.fills;
|
||||
using bts.spark;
|
||||
using bts.utils.csv;
|
||||
using mbts.co2;
|
||||
using mbts.persist;
|
||||
using mbts.ui;
|
||||
@@ -63,6 +64,7 @@ namespace mbts.spark {
|
||||
var current_smd_source = connectable_builder.create(vm => vm.current_security_md_observable(_bus)).OnDispatcher();
|
||||
var selected_secs_source = connectable_builder.create(vm => vm.selected_securities_observable()).OnDispatcher();
|
||||
_commands = new SparkCommand[] {
|
||||
new SparkCommandCommand("Export to csv", Icons.Export, FileDialogCommand.export_csv(() => _vm.value.row_vms.ToCsv(TimeAndSalesVM.Row.csv_ordered_properties), "TaS")),
|
||||
SparkCommands.ShowLadder(SparkCommands.KeyGestures.ShowLadder).complete(current_smd_source, md => md.HasValue, ConvertUtils.ValueOrDefault),
|
||||
SparkCommands.ShowOrderTicketFromSecurity(SparkCommands.KeyGestures.ShowOrderTicket).complete(current_smd_source, md => md.HasValue, ConvertUtils.ValueOrDefault),
|
||||
SparkCommands.ShowFills(SparkCommands.KeyGestures.ShowFills).complete(selected_secs_source, always_true, get_fills_startup_data),
|
||||
|
||||
@@ -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;
|
||||
@@ -23,6 +24,7 @@ using System.Linq;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using static bts.api.orderman.Fill.Types;
|
||||
using static bts.shell.FillsWindowFactory;
|
||||
@@ -310,6 +312,7 @@ namespace mbts.spark {
|
||||
public FillStatus fill_status => _fill.FillStatus;
|
||||
public string fill_key => _fill.FillKey;
|
||||
public string order_key => _order.Key.ToString();
|
||||
public string symbol => fill_tuple.security?.Symbol;
|
||||
public bool is_selected {
|
||||
get => _is_selected;
|
||||
set => Set(ref _is_selected, value);
|
||||
@@ -330,6 +333,28 @@ 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(symbol),
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using bts.api;
|
||||
using bts.shell;
|
||||
using bts.shell.fills;
|
||||
using bts.spark;
|
||||
using bts.utils.csv;
|
||||
using mbts.persist;
|
||||
using mbts.ui;
|
||||
using mbts.ui.settings;
|
||||
@@ -54,6 +55,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>(
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -4,6 +4,7 @@ using bts.shell;
|
||||
using bts.shell.fills;
|
||||
using bts.shell.orderbook;
|
||||
using bts.spark;
|
||||
using bts.utils.csv;
|
||||
using bts.view;
|
||||
using mbts.persist;
|
||||
using mbts.ui;
|
||||
@@ -184,6 +185,7 @@ namespace mbts.spark {
|
||||
show_grid_settings_command.group = CommandGroups.Auxiliary;
|
||||
|
||||
_commands = new SparkCommand[] {
|
||||
new SparkCommandCommand("Export to csv", Icons.Export, FileDialogCommand.export_csv(() => _vm.rows.ToCsv(OrderBookRowVM.csv_ordered_properties), "OrderBook")),
|
||||
toggle_show_right_panel_command,
|
||||
attach_selected_orders_command,
|
||||
detach_selected_orders_command,
|
||||
|
||||
@@ -653,54 +653,25 @@ namespace mbts.spark.utilities {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
static CustomOrderDefinition.CustomOneofCase[] algo_config(
|
||||
Func<bts.config.AlgoPermissions, List<string>> selector)
|
||||
{
|
||||
var conf = mbts.config.Configuration.get<bts.config.AlgoPermissions>();
|
||||
return selector(conf).Select(x =>
|
||||
{
|
||||
return (CustomOrderDefinition.CustomOneofCase)System.Enum.Parse(typeof(CustomOrderDefinition.CustomOneofCase), x, true);
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
public static readonly CustomOrderDefinition.CustomOneofCase[]
|
||||
|
||||
// exchange_order_types are the types which can be submitted on an exchange security
|
||||
exchange_order_types = new[] {
|
||||
CustomOrderDefinition.CustomOneofCase.Market,
|
||||
CustomOrderDefinition.CustomOneofCase.Limit,
|
||||
CustomOrderDefinition.CustomOneofCase.Stop,
|
||||
CustomOrderDefinition.CustomOneofCase.StopLimit,
|
||||
CustomOrderDefinition.CustomOneofCase.GlbxIceberg,
|
||||
CustomOrderDefinition.CustomOneofCase.Iceberg,
|
||||
CustomOrderDefinition.CustomOneofCase.Lean,
|
||||
CustomOrderDefinition.CustomOneofCase.Join,
|
||||
CustomOrderDefinition.CustomOneofCase.Cover,
|
||||
CustomOrderDefinition.CustomOneofCase.Top,
|
||||
CustomOrderDefinition.CustomOneofCase.Offset,
|
||||
CustomOrderDefinition.CustomOneofCase.Splitter,
|
||||
CustomOrderDefinition.CustomOneofCase.Scratch,
|
||||
CustomOrderDefinition.CustomOneofCase.Prorata,
|
||||
},
|
||||
spreader_order_types = new[] {
|
||||
CustomOrderDefinition.CustomOneofCase.Spreader,
|
||||
CustomOrderDefinition.CustomOneofCase.Iceberg,
|
||||
CustomOrderDefinition.CustomOneofCase.Lean,
|
||||
CustomOrderDefinition.CustomOneofCase.Join,
|
||||
CustomOrderDefinition.CustomOneofCase.Cover,
|
||||
CustomOrderDefinition.CustomOneofCase.Top,
|
||||
CustomOrderDefinition.CustomOneofCase.Splitter,
|
||||
CustomOrderDefinition.CustomOneofCase.Scratch,
|
||||
CustomOrderDefinition.CustomOneofCase.Prorata,
|
||||
},
|
||||
attachable_order_types = new[] {
|
||||
CustomOrderDefinition.CustomOneofCase.Iceberg,
|
||||
CustomOrderDefinition.CustomOneofCase.Lean,
|
||||
CustomOrderDefinition.CustomOneofCase.Join,
|
||||
CustomOrderDefinition.CustomOneofCase.Cover,
|
||||
CustomOrderDefinition.CustomOneofCase.Top,
|
||||
CustomOrderDefinition.CustomOneofCase.Offset,
|
||||
CustomOrderDefinition.CustomOneofCase.Scratch,
|
||||
CustomOrderDefinition.CustomOneofCase.Prorata,
|
||||
},
|
||||
outright_order_types = new[] {
|
||||
CustomOrderDefinition.CustomOneofCase.Market,
|
||||
CustomOrderDefinition.CustomOneofCase.Limit,
|
||||
CustomOrderDefinition.CustomOneofCase.Stop,
|
||||
CustomOrderDefinition.CustomOneofCase.StopLimit,
|
||||
CustomOrderDefinition.CustomOneofCase.GlbxIceberg,
|
||||
};
|
||||
exchange_order_types = algo_config(x => x.exchange_order_types),
|
||||
spreader_order_types = algo_config(x => x.spreader_order_types),
|
||||
attachable_order_types = algo_config(x => x.attachable_order_types),
|
||||
outright_order_types = algo_config(x => x.outright_order_types);
|
||||
|
||||
public static readonly CustomOrderDefinition.CustomOneofCase[] all_order_types = exchange_order_types.Union(spreader_order_types).ToArray();
|
||||
|
||||
public static void copy_values(CustomOrderDefinitionImmutable source, ref CustomOrderDefinition target) =>
|
||||
|
||||
@@ -28,15 +28,17 @@ namespace mbts.spark
|
||||
where TMutable : class, IMessage, new()
|
||||
{
|
||||
TMutable _message;
|
||||
readonly protected Func<IMessage, IMessage> _message_override;
|
||||
|
||||
protected GenericOrderParamVM(FieldDescriptor descriptor)
|
||||
protected GenericOrderParamVM(FieldDescriptor descriptor, Func<IMessage, IMessage> message_override = null)
|
||||
{
|
||||
_message = new TMutable();
|
||||
_message_override = message_override;
|
||||
this.descriptor = descriptor;
|
||||
}
|
||||
|
||||
public FieldDescriptor descriptor { get; set; }
|
||||
public Google.Protobuf.IMessage message
|
||||
public virtual Google.Protobuf.IMessage message
|
||||
{
|
||||
get => _message;
|
||||
set
|
||||
@@ -53,11 +55,12 @@ namespace mbts.spark
|
||||
where TMutable : class, IMessage, new()
|
||||
{
|
||||
readonly Func<TModel, TView> _convert;
|
||||
readonly Func<TView, TModel> _convert_back;
|
||||
readonly Func<TView, TModel> _convert_back;
|
||||
TView _value;
|
||||
|
||||
public GenericOrderParamVM(FieldDescriptor field_descriptor, Func<TModel, TView> convert, Func<TView, TModel> convert_back) :
|
||||
base(field_descriptor)
|
||||
public GenericOrderParamVM(FieldDescriptor field_descriptor, Func<TModel, TView> convert,
|
||||
Func<TView, TModel> convert_back, Func<IMessage, IMessage> message_override = null) :
|
||||
base(field_descriptor, message_override)
|
||||
{
|
||||
_convert = convert;
|
||||
_convert_back = convert_back;
|
||||
@@ -68,7 +71,8 @@ namespace mbts.spark
|
||||
get => _value;
|
||||
set
|
||||
{
|
||||
this.descriptor.Accessor.SetValue(this.message, _convert_back(_value = value));
|
||||
this.descriptor.Accessor.SetValue( _message_override == null ? this.message : _message_override(this.message),
|
||||
_convert_back(_value = value));
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
@@ -84,7 +88,7 @@ namespace mbts.spark
|
||||
|
||||
protected override void on_param_changed()
|
||||
{
|
||||
_value = _convert(ConvertUtils.try_convert<TModel>(this.descriptor.Accessor.GetValue(this.message)));
|
||||
_value = _convert(ConvertUtils.try_convert<TModel>(this.descriptor.Accessor.GetValue(_message_override == null ? this.message : _message_override(this.message))));
|
||||
RaisePropertyChanged(nameof(value));
|
||||
}
|
||||
}
|
||||
@@ -92,8 +96,8 @@ namespace mbts.spark
|
||||
class GenericOrderEnumeratedVM<TMutable> : GenericOrderParamVM<TMutable>, IGenericOrderParamVM<string>
|
||||
where TMutable : class, IMessage, new()
|
||||
{
|
||||
public GenericOrderEnumeratedVM(FieldDescriptor descriptor)
|
||||
: base(descriptor)
|
||||
public GenericOrderEnumeratedVM(FieldDescriptor descriptor, Func<IMessage, IMessage> message_override = null)
|
||||
: base(descriptor, message_override)
|
||||
{
|
||||
elements = new ObservableCollection<string>(_get_elements(descriptor));
|
||||
}
|
||||
@@ -102,11 +106,13 @@ namespace mbts.spark
|
||||
|
||||
public string selected_element
|
||||
{
|
||||
get => GenericOrderHelper.get_enumerated_value(message, descriptor);
|
||||
get => GenericOrderHelper.get_enumerated_value(_message_override == null ? this.message : _message_override(this.message),
|
||||
descriptor);
|
||||
set
|
||||
{
|
||||
var orig = selected_element;
|
||||
GenericOrderHelper.set_enumerated_value(message, descriptor, value);
|
||||
GenericOrderHelper.set_enumerated_value(_message_override == null ? this.message : _message_override(this.message),
|
||||
descriptor, value);
|
||||
if (selected_element != orig)
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
@@ -148,22 +154,23 @@ namespace mbts.spark
|
||||
class GenericOrderQuantityVM<TMutable> : GenericOrderParamVM<TMutable>, IGenericOrderParamVM<QuantityMeasureImmutable?>
|
||||
where TMutable : class, IMessage, new()
|
||||
{
|
||||
public GenericOrderQuantityVM(FieldDescriptor descriptor)
|
||||
: base(descriptor) { }
|
||||
public GenericOrderQuantityVM(FieldDescriptor descriptor, Func<IMessage, IMessage> message_override = null)
|
||||
: base(descriptor, message_override) { }
|
||||
|
||||
QuantityMeasureImmutable? IGenericOrderParamVM<QuantityMeasureImmutable?>.value { get => quantity; set => quantity= value; }
|
||||
public QuantityMeasureImmutable? quantity
|
||||
{
|
||||
get => GenericOrderHelper.get_quantity_value(message, descriptor);
|
||||
get => GenericOrderHelper.get_quantity_value(_message_override == null ? this.message : _message_override(this.message),
|
||||
descriptor);
|
||||
set
|
||||
{
|
||||
var orig = quantity;
|
||||
GenericOrderHelper.set_quantity_value(message, descriptor, value);
|
||||
GenericOrderHelper.set_quantity_value(_message_override == null ? this.message : _message_override(this.message),
|
||||
descriptor, value);
|
||||
if (quantity != orig)
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public IObservable<QuantityMeasureImmutable?> subscribe_value()
|
||||
{
|
||||
return Observable.Create<QuantityMeasureImmutable?>(o =>
|
||||
@@ -174,10 +181,9 @@ namespace mbts.spark
|
||||
o.OnNext(quantity);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void on_param_changed()
|
||||
{
|
||||
RaisePropertyChanged(nameof(quantity));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,9 +96,41 @@ namespace mbts.spark {
|
||||
{
|
||||
Google.Protobuf.Reflection.MessageDescriptor desc = new TMutable().Descriptor;
|
||||
_parameters.SyncWithDictionary(
|
||||
desc.Fields.InDeclarationOrder().Where(_is_value_param_desc).ToDictionary(p => p.Name), _mk_param_vm);
|
||||
desc.Fields.InDeclarationOrder().Where(_is_value_param_desc).ToDictionary(p => p.Name), x => _mk_param_vm(x));
|
||||
add_message_params(desc);
|
||||
}
|
||||
}
|
||||
void add_message_params(Google.Protobuf.Reflection.MessageDescriptor desc)
|
||||
{
|
||||
var msgs = desc.Fields.InDeclarationOrder().Where(x => !_is_value_param_desc(x) &&
|
||||
x.MessageType.ClrType != typeof(CustomOrderDefinition) );
|
||||
foreach(var message_field in msgs)
|
||||
{
|
||||
foreach (var fd in message_field.MessageType.Fields.InDeclarationOrder())
|
||||
{
|
||||
if(_is_value_param_desc(fd)) //one level deep
|
||||
{
|
||||
var mk = _mk_param_vm(fd,
|
||||
outside_object =>
|
||||
{
|
||||
var msgfield = message_field.Accessor.GetValue(outside_object);
|
||||
if(msgfield == null)
|
||||
{
|
||||
message_field.Accessor.SetValue(outside_object, Activator.CreateInstance(message_field.MessageType.ClrType));
|
||||
msgfield = message_field.Accessor.GetValue(outside_object);
|
||||
}
|
||||
return (IMessage)msgfield;
|
||||
});
|
||||
if(mk == null)
|
||||
continue;
|
||||
|
||||
if(!_parameters.Add(mk))
|
||||
_parameters.Add(message_field.Name + "_" + mk.descriptor.Name, mk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool _is_value_param_desc(FieldDescriptor desc)
|
||||
{
|
||||
return (desc.FieldType != Google.Protobuf.Reflection.FieldType.Message ||
|
||||
@@ -117,50 +149,53 @@ namespace mbts.spark {
|
||||
return v;
|
||||
}
|
||||
|
||||
GenericOrderParamVM<TMutable> _mk_param_vm(FieldDescriptor descriptor)
|
||||
GenericOrderParamVM<TMutable> _mk_param_vm(FieldDescriptor descriptor, Func<IMessage, IMessage> message_override = null)
|
||||
{
|
||||
ExceptionAssert.Argument.NotNull(descriptor, nameof(descriptor));
|
||||
|
||||
if (descriptor.FieldType == FieldType.Message &&
|
||||
descriptor.MessageType.FullName == typeof(bts.spark.QuantityMeasure).FullName)
|
||||
{
|
||||
var qm = new GenericOrderQuantityVM<TMutable>(descriptor);
|
||||
return attached(qm, GenericOrderHelper.get_quantity_value, GenericOrderHelper.set_quantity_value);
|
||||
var qm = new GenericOrderQuantityVM<TMutable>(descriptor, message_override);
|
||||
return attached(qm, GenericOrderHelper.get_quantity_value, GenericOrderHelper.set_quantity_value, message_override);
|
||||
}
|
||||
else if(descriptor.FieldType == FieldType.Enum)
|
||||
{
|
||||
var pvm = new GenericOrderEnumeratedVM<TMutable>(descriptor);
|
||||
attached(pvm, GenericOrderHelper.get_enumerated_value, GenericOrderHelper.set_enumerated_value);
|
||||
var pvm = new GenericOrderEnumeratedVM<TMutable>(descriptor, message_override);
|
||||
attached(pvm, GenericOrderHelper.get_enumerated_value, GenericOrderHelper.set_enumerated_value, message_override);
|
||||
return pvm;
|
||||
}
|
||||
else if (descriptor.FieldType == FieldType.Bool)
|
||||
return mk<bool?, bool>(descriptor, v => v, v => v.GetValueOrDefault());
|
||||
return mk<bool?, bool>(descriptor, v => v, v => v.GetValueOrDefault(), message_override);
|
||||
else if (descriptor.FieldType == FieldType.Double || descriptor.FieldType == FieldType.Float)
|
||||
return mk<double, double>(descriptor, v => v, v => v, double.NaN);
|
||||
return mk<double, double>(descriptor, v => v, v => v, message_override, double.NaN);
|
||||
else if (descriptor.FieldType == FieldType.Int32)
|
||||
return mk<int?, int>(descriptor, v => v, v => v.GetValueOrDefault());
|
||||
return mk<int?, int>(descriptor, v => v, v => v.GetValueOrDefault(), message_override);
|
||||
else if (descriptor.FieldType == FieldType.UInt32)
|
||||
return mk<uint?, uint>(descriptor, v => v, v => v.GetValueOrDefault());
|
||||
return mk<uint?, uint>(descriptor, v => v, v => v.GetValueOrDefault(), message_override);
|
||||
else if (descriptor.FieldType == FieldType.String)
|
||||
return mk<string, string>(descriptor, v => v, v => v);
|
||||
return mk<string, string>(descriptor, v => v, v => v, message_override);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
GenericOrderParamVM<TMutable, TView, TModel> mk<TView, TModel>(FieldDescriptor fdesc, Func<TModel, TView> convert, Func<TView, TModel> convert_back, TView default_value = default)
|
||||
GenericOrderParamVM<TMutable, TView, TModel> mk<TView, TModel>(FieldDescriptor fdesc, Func<TModel, TView> convert, Func<TView, TModel> convert_back,
|
||||
Func<IMessage, IMessage> message_override = null, TView default_value = default)
|
||||
{
|
||||
var pvm = new GenericOrderParamVM<TMutable, TView, TModel>(fdesc, convert, convert_back);
|
||||
return attached<TView, GenericOrderParamVM<TMutable, TView, TModel>>(pvm, get_from_param, assign_to_param, default_value);
|
||||
var pvm = new GenericOrderParamVM<TMutable, TView, TModel>(fdesc, convert, convert_back, message_override);
|
||||
return attached<TView, GenericOrderParamVM<TMutable, TView, TModel>>(pvm, get_from_param, assign_to_param,
|
||||
message_override, default_value);
|
||||
|
||||
TView get_from_param(IMessage param, FieldDescriptor fd) => convert(ConvertUtils.try_convert<TModel>(fdesc.Accessor.GetValue(param)));
|
||||
void assign_to_param(IMessage param, FieldDescriptor fd, TView value) => fdesc.Accessor.SetValue(param, convert_back(value));
|
||||
}
|
||||
|
||||
TParam attached<T, TParam>(TParam pvm, Func<IMessage, FieldDescriptor, T> selector, Action<IMessage, FieldDescriptor, T> assign_to_param, T default_value = default) where TParam : GenericOrderParamVM<TMutable>, IGenericOrderParamVM<T>
|
||||
TParam attached<T, TParam>(TParam pvm, Func<IMessage, FieldDescriptor, T> selector, Action<IMessage, FieldDescriptor, T> assign_to_param,
|
||||
Func<IMessage, IMessage> message_override = null, T default_value = default) where TParam : GenericOrderParamVM<TMutable>, IGenericOrderParamVM<T>
|
||||
{
|
||||
add_property<T>(
|
||||
pvm.descriptor.Name,
|
||||
mdef => mdef != null ? selector(mdef, pvm.descriptor) : default_value,
|
||||
(mdef, v) => assign_to_param(mdef, pvm.descriptor, v),
|
||||
mdef => mdef != null ? selector( message_override == null ? mdef : message_override(mdef), pvm.descriptor) : default_value,
|
||||
(mdef, v) => assign_to_param(message_override == null ? mdef : message_override(mdef), pvm.descriptor, v),
|
||||
() => pvm.value,
|
||||
v => pvm.value = v,
|
||||
pvm.subscribe_value(),
|
||||
|
||||
@@ -4,14 +4,14 @@ using OffsetDefi = bts.api.orderman.OffsetOrderDefinitionImmutable;
|
||||
namespace mbts.spark {
|
||||
static partial class OrderTypeVMFactory {
|
||||
class OffsetOrderVM : OrderTypeVMBase<OffsetDef, OffsetDefi> {
|
||||
readonly Property<uint?> _tick_offset_on_deploy;
|
||||
readonly Property<int?> _tick_offset_on_deploy;
|
||||
|
||||
public OffsetOrderVM(AlgoKey key, string display_name, AlgoEditingPermissions editing_permissions)
|
||||
: base(key, display_name, editing_permissions) {
|
||||
_tick_offset_on_deploy = add_nullable_property(nameof(tick_offset_on_deploy), OffsetDef.TickOffsetOnDeployFieldNumber, 0u);
|
||||
_tick_offset_on_deploy = add_nullable_property(nameof(tick_offset_on_deploy), OffsetDef.TickOffsetOnDeployFieldNumber, 0);
|
||||
}
|
||||
|
||||
public uint? tick_offset_on_deploy { get => _tick_offset_on_deploy.Value; set => _tick_offset_on_deploy.set(value); }
|
||||
public int? tick_offset_on_deploy { get => _tick_offset_on_deploy.Value; set => _tick_offset_on_deploy.set(value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,8 @@
|
||||
<LangVersion>7.2</LangVersion>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<WarningsAsErrors />
|
||||
<Version>1.0.0</Version>
|
||||
<Version>$(major).$(minor).$(patch)</Version>
|
||||
<Version Condition="'$(version)'=='..'">1.0.0</Version>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../spark_api/spark_api.csproj" />
|
||||
@@ -34,7 +35,7 @@
|
||||
<PackageReference Include="Google.Protobuf" Version="3.6.1" />
|
||||
<PackageReference Include="IronPython" Version="2.7.7" />
|
||||
<PackageReference Include="NAudio" Version="1.8.4" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
|
||||
<PackageReference Include="NUnit" Version="3.10.1" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />
|
||||
|
||||
@@ -691,7 +691,7 @@
|
||||
<TextBlock VerticalAlignment="Center" >Tick Offset</TextBlock>
|
||||
<c:HelpButton Margin="{StaticResource Margin.LP1}" ToolTip="How many ticks off the inside market to deploy the order, this guards against crossing the market inadventently" />
|
||||
</StackPanel>
|
||||
<c:TickUpDownUInt x:Name="PART_TickOffsetOnDeploy_TickUpDownUInt" Grid.Column="2" Value="{Binding tick_offset_on_deploy}"/>
|
||||
<c:TickUpDownInt x:Name="PART_TickOffsetOnDeploy_TickUpDownUInt" Grid.Column="2" Value="{Binding tick_offset_on_deploy}"/>
|
||||
<uag:AlgoPickerNodeView
|
||||
x:Name="PART_Child_AlgoPickerNodeView"
|
||||
Grid.Row="2"
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -292,7 +292,9 @@ namespace mbts.spark {
|
||||
int count = 0;
|
||||
double factored_base = log10_diff > 0 ? reduced_target_base * Math.Pow(10, Math.Ceiling(log10_diff)) : reduced_target_base;
|
||||
do {
|
||||
if (factored_base % raw_base == 0)
|
||||
// Note that the modulus operator is not used here due to rounding errors.
|
||||
// Such a rounding errror was the cause of the bug https://bluetradesys.atlassian.net/browse/SP-283.
|
||||
if (MathUtils.is_int(factored_base / raw_base))
|
||||
return new TickFactors(factored_base, factored_base / raw_base);
|
||||
factored_base *= 10;
|
||||
} while (++count < 10);
|
||||
|
||||
@@ -4,6 +4,8 @@ using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using Google.Protobuf;
|
||||
using security_key = System.UInt32;
|
||||
using bts.co2;
|
||||
using System.Linq;
|
||||
|
||||
namespace mbts.co2
|
||||
{
|
||||
@@ -85,6 +87,7 @@ namespace mbts.co2
|
||||
|
||||
[DllImport("libspark")]
|
||||
internal unsafe static extern void post_on_scan_security_thread(Action callback);
|
||||
|
||||
}
|
||||
|
||||
internal static class Co2NativeTestMethods
|
||||
@@ -133,5 +136,59 @@ namespace mbts.co2
|
||||
[DllImport("libspark")]
|
||||
internal static extern void co2_test_get_constants(out ulong max_depth, out ulong max_implied_depth, out sbyte nan_exponent);
|
||||
|
||||
internal unsafe delegate void raw_receive_pb_or_string(byte* buffer, int buffer_size);
|
||||
[DllImport("libspark")]
|
||||
private static unsafe extern void raw_co2_compute_synthetic_book(
|
||||
byte[] security_buffer,
|
||||
int security_length,
|
||||
IntPtr[] leg_books,
|
||||
int[] leg_lengths,
|
||||
int leg_books_length,
|
||||
raw_receive_pb_or_string callback);
|
||||
|
||||
internal static unsafe BookMessageImmutable co2_compute_synthetic_book(SecurityImmutable synthetic, params BookMessageImmutable[] books) {
|
||||
BookMessage result = null;
|
||||
string error = null;
|
||||
|
||||
var security_buffer = synthetic.ToByteArray();
|
||||
// var h = GCHandle.Alloc(null, GCHandleType.Pinned).
|
||||
var book_buffers =
|
||||
books
|
||||
.Select(b => b.ToByteArray())
|
||||
.ToArray();
|
||||
GCHandle[] book_buffer_handles =
|
||||
book_buffers
|
||||
.Select(b => GCHandle.Alloc(b,GCHandleType.Pinned))
|
||||
.ToArray();
|
||||
IntPtr[] book_buffer_pointers =
|
||||
book_buffer_handles
|
||||
.Select(h => h.AddrOfPinnedObject())
|
||||
.ToArray();
|
||||
var lengths =
|
||||
book_buffers
|
||||
.Select(b => b.Length)
|
||||
.ToArray();
|
||||
|
||||
raw_co2_compute_synthetic_book(
|
||||
security_buffer,
|
||||
security_buffer.Length,
|
||||
book_buffer_pointers,
|
||||
lengths,
|
||||
book_buffers.Length,
|
||||
(byte* buffer, int length) => {
|
||||
if (length < 0) {
|
||||
error = new string((char*)buffer,0,-1 * length);
|
||||
}
|
||||
else {
|
||||
result = Co2NativeMethods.deserialize<BookMessage>(buffer, (ulong)length);
|
||||
}
|
||||
});
|
||||
|
||||
if(error != null) {
|
||||
// C# style multiple return values
|
||||
throw new Exception(error);
|
||||
}
|
||||
return new BookMessageImmutable(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,49 @@ namespace mbts.co2 {
|
||||
return _mantissa.GetHashCode();
|
||||
}
|
||||
|
||||
public static IntPrice from_double(double price, sbyte precision) {
|
||||
if (double.IsNaN(price)) return NaN;
|
||||
if (Math.Abs(price%1) != 0) {
|
||||
double rounding = 0.5 * Math.Pow(10,-precision);
|
||||
price += (price > 0) ? rounding : -rounding;
|
||||
price *= Math.Pow(10,precision);
|
||||
return new IntPrice((long)price, (sbyte)-precision);
|
||||
}
|
||||
return new IntPrice((long)price, 0);
|
||||
}
|
||||
|
||||
public static IntPrice NaN = new IntPrice(0,127);
|
||||
|
||||
static double[] powers_10 = {
|
||||
1E-20, 1E-19, 1E-18, 1E-17, 1E-16, 1E-15, 1E-14, 1E-13, 1E-12, 1E-11, 1E-10, 1E-9, 1E-8, 1E-7, 1E-6, 1E-5, 1E-4, 1E-3, 1E-2, 1E-1,
|
||||
1E0,
|
||||
1E1, 1E2, 1E3, 1E4, 1E5, 1E6, 1E7, 1E8, 1E9, 1E10, 1E11, 1E12, 1E13, 1E14, 1E15, 1E16, 1E17, 1E18, 1E19, 1E20};
|
||||
static int max_abs_power_10 = powers_10.Length / 2;
|
||||
static double pow10(int power)
|
||||
{
|
||||
int offset = power + max_abs_power_10;
|
||||
int powers_10_sz = powers_10.Length;
|
||||
bts.Log.assert(offset >= 0 && offset < powers_10_sz);
|
||||
if (offset >= 0 && offset < powers_10_sz)
|
||||
{
|
||||
return powers_10[offset];
|
||||
}
|
||||
return double.NaN;
|
||||
}
|
||||
|
||||
public static IntPrice from_double(double price, int precision = 9)
|
||||
{
|
||||
if (Double.IsNaN(price))
|
||||
return NaN;
|
||||
if (Math.Abs(price - Math.Truncate(price)) != 0.0)
|
||||
{
|
||||
double rounding = 0.5 * pow10(-precision);
|
||||
price += (price > 0.0) ? rounding : -rounding;
|
||||
price *= pow10(precision);
|
||||
return new IntPrice((long)price, Convert.ToSByte(-precision));
|
||||
}
|
||||
return new IntPrice((long)price, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using bts;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace mbts.co2 {
|
||||
public static class NativePriceHelpers {
|
||||
@@ -38,6 +40,60 @@ namespace mbts.co2 {
|
||||
public const uint COCONUT_MAX_DEPTH = 10;
|
||||
public const uint COCONUT_MAX_IMPLIED_DEPTH = 2;
|
||||
internal const sbyte COCONUT_NAN_EXPONENT = 127;
|
||||
|
||||
public static double side_at(this bts.co2.BookMessage book, bts.api.Side side, int level)
|
||||
{
|
||||
if(side == bts.api.Side.Buy)
|
||||
return bid_at(book, level);
|
||||
else
|
||||
return ask_at(book, level);
|
||||
}
|
||||
public static uint sidesize_at(this bts.co2.BookMessage book, bts.api.Side side, int level)
|
||||
{
|
||||
if (side == bts.api.Side.Buy)
|
||||
return bidsize_at(book, level);
|
||||
else
|
||||
return asksize_at(book, level);
|
||||
}
|
||||
public static double bid_at(this bts.co2.BookMessage book, int level)
|
||||
{
|
||||
var lev = book.Bids[level];
|
||||
return NativePriceHelpers.to_double(lev.Mantissa, (sbyte)lev.Exponent);
|
||||
}
|
||||
public static double ask_at(this bts.co2.BookMessage book, int level)
|
||||
{
|
||||
var lev = book.Asks[level];
|
||||
return NativePriceHelpers.to_double(lev.Mantissa, (sbyte)lev.Exponent);
|
||||
}
|
||||
public static uint bidsize_at(this bts.co2.BookMessage book, int level)
|
||||
{
|
||||
var lev = book.Bids[level];
|
||||
return lev.Size;
|
||||
}
|
||||
public static uint asksize_at(this bts.co2.BookMessage book, int level)
|
||||
{
|
||||
var lev = book.Asks[level];
|
||||
return lev.Size;
|
||||
}
|
||||
public static double price(this bts.co2.PriceSizeMessage p)
|
||||
{
|
||||
return NativePriceHelpers.to_double(p.Mantissa, (sbyte)p.Exponent);
|
||||
}
|
||||
public static double price(this bts.co2.TradeMessage p)
|
||||
{
|
||||
return NativePriceHelpers.to_double(p.Mantissa, (sbyte)p.Exponent);
|
||||
}
|
||||
|
||||
public static IList<double> all_bids(this bts.co2.BookMessage book)
|
||||
{
|
||||
var lev = book.Bids.Select(x => NativePriceHelpers.to_double(x.Mantissa, (sbyte)x.Exponent)).ToList();
|
||||
return lev;
|
||||
}
|
||||
public static IList<double> all_asks(this bts.co2.BookMessage book)
|
||||
{
|
||||
var lev = book.Asks.Select(x => NativePriceHelpers.to_double(x.Mantissa, (sbyte)x.Exponent)).ToList();
|
||||
return lev;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,4 +4,5 @@ using System.Runtime.CompilerServices;
|
||||
[assembly: InternalsVisibleTo("sparkcmd")]
|
||||
[assembly: InternalsVisibleTo("spark_test")]
|
||||
[assembly: InternalsVisibleTo("spark_fix")]
|
||||
[assembly: InternalsVisibleTo("spark_historical")]
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace bts.api
|
||||
{
|
||||
//keep in sync with apioptions.proto
|
||||
public static partial class ApioptionsReflection
|
||||
{
|
||||
public enum MessageOptions
|
||||
{
|
||||
fix_algostrategy_tagbase = 8506,
|
||||
}
|
||||
public enum FieldOptions
|
||||
{
|
||||
fix_tag = 8507,
|
||||
fix_tag_is_header = 8509,
|
||||
}
|
||||
public enum EnumValueOptions
|
||||
{
|
||||
fix_value = 8508,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.Collections;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using mbts.co2;
|
||||
|
||||
namespace bts.history
|
||||
{
|
||||
public interface IHasMsgSeqNum
|
||||
{
|
||||
uint MsgSeqNum { get; }
|
||||
}
|
||||
|
||||
public interface IHasDateTimeStamp
|
||||
{
|
||||
DateTime trade_date { get; set;}
|
||||
DateTime sending_time { get; set;}
|
||||
DateTime transact_time { get; set; }
|
||||
}
|
||||
|
||||
public interface IHasTimestamp
|
||||
{
|
||||
Timestamp SendingTime { get; set; }
|
||||
Timestamp TransactTime { get; set; }
|
||||
}
|
||||
|
||||
public interface IHasMdPacket
|
||||
{
|
||||
MarketDataIncrementalRefresh Md{ get; }
|
||||
}
|
||||
|
||||
public interface IHasMdEntry
|
||||
{
|
||||
MDEntry MdEntry { get; }
|
||||
int EntryIndex { get; }
|
||||
}
|
||||
|
||||
public interface IHasTopBook : IHasMdEntry, IHasMdPacket
|
||||
{
|
||||
co2.TopBookMessage TopBook { get; set; }
|
||||
}
|
||||
|
||||
public interface IHasBook : IHasMdEntry, IHasMdPacket
|
||||
{
|
||||
co2.BookMessage Book { get; set; }
|
||||
}
|
||||
|
||||
public interface IHasTrade : IHasMdEntry, IHasMdPacket
|
||||
{
|
||||
co2.TradeMessage Trade { get; set; }
|
||||
}
|
||||
|
||||
public interface IHasMBO : IHasMdPacket
|
||||
{
|
||||
RepeatedField<OrderIDEntry> Orders { get; }
|
||||
}
|
||||
|
||||
public sealed partial class HistoryRow : IHasTopBook, IHasMBO, IHasTrade, IHasBook, IHasDateTimeStamp, IHasTimestamp, IHasMsgSeqNum
|
||||
{
|
||||
public DateTime trade_date { get { return DateTime.SpecifyKind(this.TradeDate.ToDateTime(), DateTimeKind.Utc); }
|
||||
set { this.TradeDate = Timestamp.FromDateTime(value); } }
|
||||
public DateTime sending_time { get { return DateTime.SpecifyKind(this.SendingTime.ToDateTime(), DateTimeKind.Utc); }
|
||||
set { this.SendingTime = Timestamp.FromDateTime(value); } }
|
||||
public DateTime transact_time { get { return DateTime.SpecifyKind(this.TransactTime.ToDateTime(), DateTimeKind.Utc); }
|
||||
set { this.TransactTime = Timestamp.FromDateTime(value); } }
|
||||
|
||||
public HistoryRow add_orders(IEnumerable<OrderIDEntry> orderentries)
|
||||
{
|
||||
this.Orders.AddRange(orderentries);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IMBOMessage
|
||||
{
|
||||
MDUpdateAction OrderUpdateAction {get;}
|
||||
ulong OrderId {get;}
|
||||
uint SecurityId {get;}
|
||||
string SecurityDesc {get;}
|
||||
ulong MdOrderPriority {get;}
|
||||
double MdEntryPx {get;}
|
||||
uint MdPriceLevel {get;}
|
||||
ulong MdDisplayQty {get;}
|
||||
uint LastQty {get;}
|
||||
MDEntryType MdEntryType {get;}
|
||||
uint ReferenceId {get;}
|
||||
}
|
||||
|
||||
public sealed partial class MBOMessage : IMBOMessage
|
||||
{
|
||||
public MDUpdateAction OrderUpdateAction => OrderEntry != null ? OrderEntry.OrderUpdateAction : MdEntry.MdUpdateAction;
|
||||
public ulong OrderId => OrderEntry != null ? OrderEntry.OrderId : MdEntry.OrderId;
|
||||
public uint SecurityId => MdEntry.SecurityId;
|
||||
public string SecurityDesc => MdEntry.Symbol;
|
||||
public ulong MdOrderPriority => OrderEntry != null ? OrderEntry.MdOrderPriority : MdEntry.MdOrderPriority;
|
||||
public double MdEntryPx => MdEntry.MdEntryPx;
|
||||
public uint MdPriceLevel => MdEntry.MdPriceLevel;
|
||||
public ulong MdDisplayQty => OrderEntry != null ? OrderEntry.MdDisplayQty : MdEntry.MdDisplayQty;
|
||||
public uint LastQty => OrderEntry != null ? OrderEntry.LastQty : MdEntry.LastQty;
|
||||
public MDEntryType MdEntryType => MdEntry.MdEntryType;
|
||||
public uint ReferenceId => OrderEntry != null ? OrderEntry.ReferenceId : MdEntry.ReferenceId;
|
||||
public uint NumberOfOrders => MdEntry.NumberOfOrders;
|
||||
}
|
||||
|
||||
public sealed partial class MarketDataIncrementalRefresh
|
||||
{
|
||||
public MarketDataIncrementalRefresh add_entries(IEnumerable<MDEntry> mdentries, IEnumerable<OrderIDEntry> orderentries)
|
||||
{
|
||||
this.MdEntries.AddRange(mdentries);
|
||||
this.OrderIdEntries.AddRange(orderentries);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public interface ITradeDetail
|
||||
{
|
||||
ulong OrderId { get; set; }
|
||||
uint LastQty { get; set; }
|
||||
ITradeDetail clone();
|
||||
}
|
||||
|
||||
public sealed partial class OrderIDEntry : ITradeDetail
|
||||
{
|
||||
ITradeDetail ITradeDetail.clone()
|
||||
{
|
||||
return this.Clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace bts.co2
|
||||
{
|
||||
public sealed partial class BookMessage
|
||||
{
|
||||
public BookMessage add_bids_and_asks(IEnumerable<PriceSizeMessage> bids, IEnumerable<PriceSizeMessage> asks)
|
||||
{
|
||||
this.Bids.AddRange(bids);
|
||||
this.Asks.AddRange(asks);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed partial class TradeMessage
|
||||
{
|
||||
public double price => NativePriceHelpers.to_double(this.Mantissa, (sbyte)this.Exponent);
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,8 @@ namespace bts.api {
|
||||
return security.Glbx.SecurityDesc;
|
||||
else if(security.HasIce)
|
||||
return security.Ice.SecurityDesc;
|
||||
else if(security.HasSynthetic)
|
||||
return security.Synthetic.Name;
|
||||
else
|
||||
{
|
||||
Log.assert(false, "security_desc not implemented for exchange");
|
||||
|
||||
@@ -3,17 +3,19 @@
|
||||
<TargetFrameworks>netstandard2.0</TargetFrameworks>
|
||||
<Authors>Blue Trading Systems</Authors>
|
||||
<Company>Blue Trading Systems</Company>
|
||||
<Product>Spark</Product>
|
||||
<Description />
|
||||
<PackageId>Spark_API</PackageId>
|
||||
<Product>Spark</Product>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Platforms>x64</Platforms>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<WarningsAsErrors />
|
||||
<Version>1.0.0</Version>
|
||||
<Version>$(major).$(minor).$(patch)</Version>
|
||||
<Version Condition="'$(version)'=='..'">0.0.0</Version>
|
||||
<LangVersion>7.2</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Google.Protobuf" Version="3.6.1" />
|
||||
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
|
||||
@@ -24,12 +26,10 @@
|
||||
<Proto3 Include="**/*.proto" />
|
||||
<Proto3 Include="../../lib/api/*.proto" />
|
||||
<Proto3 Include="../../lib/api/services/*.proto" />
|
||||
<!--Proto3 Remove="../../lib/api/services/MarketDataRelay.proto" /-->
|
||||
<Proto3 Include="../../lib/md/protos/co2.proto" />
|
||||
<Proto3 Include="../../lib/md/protos/Co2.proto" />
|
||||
<Proto3 Include="../../lib/domain_model/Security.proto" />
|
||||
<Proto3 Include="../../lib/sparkproto/SparkProtos.proto" />
|
||||
<Proto3 Update="../../lib/api/services/OutOfProcessURLListener.proto">
|
||||
<!-- <CompileOptions>internal_access:</CompileOptions> -->
|
||||
</Proto3>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -28,5 +28,8 @@ namespace bts.utils
|
||||
|
||||
[DllImport("libspark")]
|
||||
public static extern bool initialize_nothrow(StringBuilder buffer, int length);
|
||||
|
||||
//public static string bts_data_path()
|
||||
//use mbts.config.Configuration.get<bts.config.System>().data_path;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using Google.Protobuf;
|
||||
namespace bts.api {
|
||||
|
||||
public sealed partial class Product : ICustomDiagnosticMessage {
|
||||
public string ToDiagnosticString() {
|
||||
return $"{this.Symbol}:{this.Type}:{this.Exchange}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
namespace bts.api
|
||||
{
|
||||
public static class TimestampExtensions
|
||||
{
|
||||
public static Timestamp add_nanos(this Timestamp lhs, int nanos)
|
||||
{
|
||||
var c = new Timestamp(lhs);
|
||||
c.Nanos += nanos;
|
||||
return c;
|
||||
}
|
||||
public static bool less(this Timestamp lhs, Timestamp rhs)
|
||||
{
|
||||
return lhs.compare(rhs) < 0;
|
||||
}
|
||||
public static bool less_or_equal(this Timestamp lhs, Timestamp rhs)
|
||||
{
|
||||
return lhs.compare(rhs) <= 0;
|
||||
}
|
||||
public static bool greater(this Timestamp lhs, Timestamp rhs)
|
||||
{
|
||||
return lhs.compare(rhs) > 0;
|
||||
}
|
||||
public static bool greater_or_equal(this Timestamp lhs, Timestamp rhs)
|
||||
{
|
||||
return lhs.compare(rhs) >= 0;
|
||||
}
|
||||
public static int compare(this Timestamp lhs, Timestamp rhs)
|
||||
{
|
||||
int secdiff = lhs.Seconds.CompareTo(rhs.Seconds);
|
||||
return (secdiff != 0) ? secdiff : (lhs.Nanos.CompareTo(rhs.Nanos));
|
||||
}
|
||||
public static Comparer<Timestamp> timestamp_comparer => Comparer<Timestamp>.Create((x, y) => x.compare(y));
|
||||
|
||||
public static Timestamp parse_timestamp(string data)
|
||||
{
|
||||
DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
try
|
||||
{
|
||||
if (data.Length <= 8)
|
||||
{
|
||||
dt = DateTime.ParseExact(data, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
else
|
||||
{
|
||||
int sep = 14;
|
||||
var yyMMddhhmmss = data.Substring(0, sep);
|
||||
dt = DateTime.ParseExact(yyMMddhhmmss, "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture);
|
||||
var nnanos = data.Substring(sep, data.Length - sep);
|
||||
long nano = long.Parse(nnanos);
|
||||
dt = dt.AddTicks(nano / 100);
|
||||
}
|
||||
}
|
||||
catch (Exception _)
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(_ != null); //UNUSED(_)
|
||||
}
|
||||
dt = DateTime.SpecifyKind(dt, DateTimeKind.Utc);
|
||||
var ts = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(dt);
|
||||
return ts;
|
||||
}
|
||||
public static string to_fix_string(this Timestamp ts)
|
||||
{
|
||||
return ts.ToDateTime().ToString("yyyyMMdd-HH:mm:ss.fff");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace bts.api
|
||||
{
|
||||
public class TypeUtils
|
||||
{
|
||||
static public List<Type> find_all_types_in_all_assemblies(string type, string assembly_regex = null)
|
||||
{
|
||||
List<Type> res = new List<Type>();
|
||||
var asses = AppDomain.CurrentDomain.GetAssemblies();
|
||||
foreach (Assembly a in asses)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(assembly_regex))
|
||||
{
|
||||
if (!Regex.Match(a.GetName().Name, assembly_regex).Success)
|
||||
continue;
|
||||
}
|
||||
Type t = a.GetType(type, false, true);
|
||||
if (t != null)
|
||||
res.Add(t);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,4 +2,5 @@ using System.Runtime.CompilerServices;
|
||||
[assembly: InternalsVisibleTo("spark")]
|
||||
[assembly: InternalsVisibleTo("sparkcmd")]
|
||||
[assembly: InternalsVisibleTo("spark_test")]
|
||||
[assembly: InternalsVisibleTo("spark_historical")]
|
||||
|
||||
@@ -70,10 +70,13 @@ namespace bts.test {
|
||||
psi.RedirectStandardOutput = true;
|
||||
psi.RedirectStandardError = true;
|
||||
psi.UseShellExecute = false;
|
||||
|
||||
|
||||
try{
|
||||
var p = Process.Start(psi);
|
||||
p.WaitForExit((int)time_out.TotalMilliseconds);
|
||||
var errorlevel = p.ExitCode;
|
||||
string stdout = p.StandardOutput.ReadToEnd();
|
||||
string stderr = p.StandardError.ReadToEnd();
|
||||
if (p.HasExited) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFrameworks>netstandard2.0</TargetFrameworks>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Platforms>x64</Platforms>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<WarningsAsErrors />
|
||||
<Version>1.0.0</Version>
|
||||
<Version>$(major).$(minor).$(patch)</Version>
|
||||
<Version Condition="'$(version)'=='..'">0.0.0</Version>
|
||||
<LangVersion>7.2</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -66,9 +66,23 @@ namespace bts.excel.rtd
|
||||
if (string.IsNullOrEmpty(contract))
|
||||
return Observable.Return(new []{"Can't Parse Contract: " + contract ?? string.Empty});
|
||||
|
||||
Func<SecurityImmutable, bool> where = (x => x.Exchange == ven && x.Symbol == symbol && x.security_type() == sectype &&
|
||||
x.Glbx.SecurityDesc == contract);
|
||||
Func<SecurityImmutable, bool> desc = null;
|
||||
switch(ven)
|
||||
{
|
||||
case Venue.Sim:
|
||||
case Venue.Glbx:
|
||||
desc = (x=> x.Glbx.SecurityDesc == contract);
|
||||
break;
|
||||
case Venue.Ice:
|
||||
desc = (x=> x.Ice.SecurityDesc == contract);
|
||||
break;
|
||||
default:
|
||||
desc = (x => true);
|
||||
break;
|
||||
}
|
||||
|
||||
Func<SecurityImmutable, bool> where = (x => x.Exchange == ven && x.Symbol == symbol && x.security_type() == sectype && desc(x) );
|
||||
|
||||
var stream = market_data(ven).subscribe_combined(where);
|
||||
return stream;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<WarningsAsErrors />
|
||||
<Version>1.0.0</Version>
|
||||
<Version>$(major).$(minor).$(patch)</Version>
|
||||
<Version Condition="'$(version)'=='..'">1.0.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -25,7 +26,7 @@
|
||||
<PackageReference Include="System.Reactive" Version="3.1.1" />
|
||||
<PackageReference Include="System.Reactive.PlatformServices" Version="3.1.1" />
|
||||
<PackageReference Include="NUnit" Version="3.10.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="System.Linq.Dynamic" Version="1.0.7" />
|
||||
|
||||
<PackageReference Include="ExcelDna.AddIn" Version="0.34.6" />
|
||||
|
||||
Binary file not shown.
@@ -90,7 +90,14 @@ namespace bts.excel
|
||||
{
|
||||
if(string.IsNullOrEmpty(json))
|
||||
json = "{}";
|
||||
request = JsonParser.Default.Parse(json, desc);
|
||||
try
|
||||
{
|
||||
request = JsonParser.Default.Parse(json, desc);
|
||||
}
|
||||
catch(InvalidProtocolBufferException)
|
||||
{
|
||||
request = (IMessage) Newtonsoft.Json.JsonConvert.DeserializeObject(json, desc.ClrType);
|
||||
}
|
||||
}
|
||||
}
|
||||
return request;
|
||||
|
||||
@@ -25,7 +25,68 @@ namespace bts.excel
|
||||
else if (!string.IsNullOrEmpty(key1))
|
||||
val = jo[key1];
|
||||
return val.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
static Google.Protobuf.JsonFormatter _formatter =
|
||||
new Google.Protobuf.JsonFormatter(new Google.Protobuf.JsonFormatter.Settings(true));
|
||||
[ExcelFunction]
|
||||
public static object bts_json_create(string type)
|
||||
{
|
||||
System.Type t = find_full_type_in_all_assemblies(type);
|
||||
object obj = Activator.CreateInstance(t);
|
||||
foreach(var pr in t.GetProperties())
|
||||
{
|
||||
object val = null;
|
||||
try
|
||||
{
|
||||
val = Activator.CreateInstance(pr.PropertyType);
|
||||
}
|
||||
catch {}
|
||||
try
|
||||
{
|
||||
pr.SetValue(obj, val);
|
||||
}
|
||||
catch {}
|
||||
}
|
||||
string s = "{}";
|
||||
if(obj is Google.Protobuf.IMessage imsg)
|
||||
s = _formatter.Format(imsg);
|
||||
else
|
||||
s = JsonConvert.SerializeObject(obj, Formatting.Indented);
|
||||
return s;
|
||||
}
|
||||
[ExcelFunction]
|
||||
public static object bts_json_fill(string root, string key, string value)
|
||||
{
|
||||
var jo = JObject.Parse(root);
|
||||
jo[key] = value;
|
||||
var s = jo.ToString();
|
||||
return s;
|
||||
}
|
||||
|
||||
[ExcelFunction]
|
||||
public static object bts_date_to_json(object dt, bool is_duration = false)
|
||||
{
|
||||
string s = "{}";
|
||||
if(is_duration)
|
||||
{
|
||||
var span = TimeSpan.FromDays((double)dt);
|
||||
var ts = Google.Protobuf.WellKnownTypes.Duration.FromTimeSpan(span);
|
||||
s = JsonConvert.SerializeObject(ts, Formatting.None);
|
||||
s = _formatter.Format(ts);
|
||||
s = s.Replace(@"""", "");
|
||||
}
|
||||
else
|
||||
{
|
||||
var dd = DateTime.FromOADate((double)dt);
|
||||
var utc = DateTime.SpecifyKind(dd, DateTimeKind.Utc);
|
||||
var ts = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(utc);
|
||||
s = JsonConvert.SerializeObject(ts, Formatting.None);
|
||||
s = _formatter.Format(ts);
|
||||
s = s.Replace(@"""", "");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static bool parse_venue(string exch, out Venue ven)
|
||||
{
|
||||
|
||||
@@ -17,6 +17,8 @@ using bts.md;
|
||||
using bts.api.admin;
|
||||
|
||||
using security_key = System.UInt32;
|
||||
using QuickFix.FIX42;
|
||||
using Message = QuickFix.Message;
|
||||
|
||||
namespace bts.fix
|
||||
{
|
||||
@@ -34,13 +36,29 @@ namespace bts.fix
|
||||
class FixRouter : QuickFix.MessageCracker, IFIXSession, IFixRouter
|
||||
{
|
||||
readonly ConcurrentDictionary<SessionID, QuickFix.IApplication> _sessions = new ConcurrentDictionary<SessionID, IApplication>();
|
||||
readonly Func<IFixRouter, SessionID, IApplication> _factory;
|
||||
readonly MarketDataClient _md = new MarketDataClient();
|
||||
readonly Func<IFixRouter, SessionID, IApplication> _factory;
|
||||
readonly object _lock = new object();
|
||||
readonly MarketDataService _md;
|
||||
private readonly IDisposable _security_sub;
|
||||
readonly ConcurrentDictionary<security_key, SecurityImmutable> _id_to_security = new ConcurrentDictionary<security_key, SecurityImmutable>();
|
||||
readonly ConcurrentDictionary<string, SecurityImmutable> _desc_to_security = new ConcurrentDictionary<string, SecurityImmutable>();
|
||||
|
||||
public FixRouter(Func<IFixRouter, SessionID, IApplication> factory)
|
||||
{
|
||||
_factory = factory;
|
||||
using(var service_context = new ServiceContext())
|
||||
{
|
||||
_md = service_context.locate<MarketDataService>();
|
||||
_security_sub = _md.subscribe_securities().Subscribe( x =>
|
||||
{
|
||||
foreach( var sec in x.all)
|
||||
{
|
||||
var imm = sec.immutable();
|
||||
_id_to_security[sec.Id] = imm;
|
||||
_desc_to_security[imm.security_desc()] = imm;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
IApplication session(SessionID sessionID)
|
||||
@@ -75,18 +93,18 @@ namespace bts.fix
|
||||
|
||||
public void send_session_reject(SessionID sess, string text, Message refmessage = null)
|
||||
{
|
||||
QuickFix.FIX44.Reject rej = null;
|
||||
Reject rej = null;
|
||||
if (refmessage != null && refmessage.Header.IsSetField(Tags.MsgSeqNum))
|
||||
rej = new QuickFix.FIX44.Reject(new QuickFix.Fields.RefSeqNum(refmessage.Header.GetInt(Tags.MsgSeqNum)));
|
||||
rej = new Reject(new QuickFix.Fields.RefSeqNum(refmessage.Header.GetInt(Tags.MsgSeqNum)));
|
||||
else
|
||||
rej = new QuickFix.FIX44.Reject();
|
||||
rej = new Reject();
|
||||
rej.Text = new Text(text);
|
||||
send(rej, sess);
|
||||
}
|
||||
|
||||
public void send_biz_reject(SessionID sess, string text, Message refmessage, int reason_code = 0)
|
||||
{
|
||||
QuickFix.FIX44.BusinessMessageReject rej = new QuickFix.FIX44.BusinessMessageReject();
|
||||
BusinessMessageReject rej = new BusinessMessageReject();
|
||||
|
||||
rej.RefMsgType = new QuickFix.Fields.RefMsgType(refmessage.Header.GetString(Tags.MsgType));
|
||||
rej.RefSeqNum = new QuickFix.Fields.RefSeqNum(refmessage.Header.GetInt(Tags.MsgSeqNum));
|
||||
@@ -212,18 +230,21 @@ namespace bts.fix
|
||||
|
||||
IEnumerable<SecurityImmutable> IFixRouter.get_securities()
|
||||
{
|
||||
return _md.securities;
|
||||
return _id_to_security.Values;
|
||||
}
|
||||
|
||||
SecurityImmutable? IFixRouter.lookup(uint key)
|
||||
{
|
||||
return _md.lookup(key);
|
||||
if(_id_to_security.TryGetValue(key, out SecurityImmutable sec))
|
||||
return sec;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
SecurityImmutable? IFixRouter.lookup(string desc)
|
||||
{
|
||||
if (_md.lookup_security_key_from_desc(desc, out uint key))
|
||||
return _md.lookup(key);
|
||||
if (_desc_to_security.TryGetValue(desc, out SecurityImmutable sec))
|
||||
return sec;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -81,12 +81,12 @@ namespace bts.fix
|
||||
case "/resetSessions":
|
||||
responseString = ResetSessions(request);
|
||||
break;
|
||||
case "/refreshSession":
|
||||
responseString = RefreshSession(request);
|
||||
break;
|
||||
case "/refreshSessions":
|
||||
responseString = RefreshSessions(request);
|
||||
break;
|
||||
// case "/refreshSession":
|
||||
// responseString = RefreshSession(request);
|
||||
// break;
|
||||
// case "/refreshSessions":
|
||||
// responseString = RefreshSessions(request);
|
||||
// break;
|
||||
case "/enableSessions":
|
||||
responseString = EnableSessions(request);
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,293 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.Reflection;
|
||||
using System.Linq;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using bts.api;
|
||||
|
||||
|
||||
namespace bts.fix
|
||||
{
|
||||
public static class ProtoFix
|
||||
{
|
||||
static readonly QuickFix.IMessageFactory _factory = new QuickFix.DefaultMessageFactory();
|
||||
public static T parse_fix<T>(string fixstring) where T : IMessage, new()
|
||||
{
|
||||
return (T) parse_fix(new T().Descriptor, fixstring);
|
||||
}
|
||||
|
||||
public static IMessage parse_fix(MessageDescriptor desc, string fixstring)
|
||||
{
|
||||
QuickFix.Message fix = new QuickFix.Message(fixstring, false);
|
||||
var msg = create_message(desc, fix);
|
||||
return msg;
|
||||
}
|
||||
|
||||
static string get_between(string source, string start, string end)
|
||||
{
|
||||
int spos = source.IndexOf(start, 0);
|
||||
if(spos < 0)
|
||||
return string.Empty;
|
||||
spos += start.Length;
|
||||
int epos = source.IndexOf(end, spos);
|
||||
if(epos < 0)
|
||||
return string.Empty;
|
||||
return source.Substring(spos, epos - spos);
|
||||
}
|
||||
|
||||
public static Timestamp peek_timestamp(string fixstring, int field = 60)
|
||||
{
|
||||
string ts = get_between(fixstring, field.ToString() + "=", "\u0001");
|
||||
if(!string.IsNullOrEmpty(ts))
|
||||
{
|
||||
var stamp = TimestampExtensions.parse_timestamp(ts);
|
||||
return stamp;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string peek_field(string fixstring, int field)
|
||||
{
|
||||
string ts = get_between(fixstring, field.ToString() + "=", "\u0001");
|
||||
return ts;
|
||||
}
|
||||
|
||||
public static string peek_symbol(string fixstring)
|
||||
{
|
||||
return peek_field(fixstring, 55);
|
||||
}
|
||||
|
||||
public static IMessage create_message(MessageDescriptor desc, QuickFix.FieldMap fix)
|
||||
{
|
||||
object obj = Activator.CreateInstance(desc.ClrType);
|
||||
IMessage msg = (IMessage)obj;
|
||||
return setup_message(msg, fix);
|
||||
}
|
||||
|
||||
public static IMessage setup_message(IMessage msg, QuickFix.FieldMap fix)
|
||||
{
|
||||
foreach (var fd in msg.Descriptor.Fields.InDeclarationOrder())
|
||||
{
|
||||
try
|
||||
{
|
||||
set_field(msg, fd, fix);
|
||||
}
|
||||
catch(QuickFix.FieldNotFoundException) {}
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
static int get_tag(IMessage msg, FieldDescriptor fd, out bool is_header)
|
||||
{
|
||||
is_header = false;
|
||||
int fieldnum = 0;
|
||||
if(fd.CustomOptions?.TryGetInt32((int)ApioptionsReflection.FieldOptions.fix_tag, out fieldnum) ?? false)
|
||||
{
|
||||
fd.CustomOptions.TryGetBool((int)ApioptionsReflection.FieldOptions.fix_tag_is_header, out is_header);
|
||||
return fieldnum;
|
||||
}
|
||||
else
|
||||
{
|
||||
int tagbase = 0;
|
||||
if(msg.Descriptor.CustomOptions?.TryGetInt32((int)ApioptionsReflection.MessageOptions.fix_algostrategy_tagbase, out tagbase) ?? false)
|
||||
return fd.FieldNumber + tagbase;
|
||||
}
|
||||
throw new QuickFix.FieldNotFoundException(fd.FieldNumber);
|
||||
}
|
||||
|
||||
static void set_field(IMessage msg, FieldDescriptor fd, QuickFix.FieldMap fix)
|
||||
{
|
||||
switch (fd.FieldType)
|
||||
{
|
||||
case FieldType.Bool:
|
||||
{
|
||||
int tag = get_tag(msg, fd, out bool is_header);
|
||||
var data = is_header ? ((QuickFix.Message)fix).Header.GetBoolean(tag) : fix.GetBoolean(tag);
|
||||
fd.Accessor.SetValue(msg, data);
|
||||
}
|
||||
break;
|
||||
case FieldType.Float:
|
||||
{
|
||||
int tag = get_tag(msg, fd, out bool is_header);
|
||||
var data = is_header ? ((QuickFix.Message)fix).Header.GetDecimal(tag) : fix.GetDecimal(tag);
|
||||
object conv = Convert.ChangeType(data, fd.Accessor.GetValue(msg).GetType());
|
||||
fd.Accessor.SetValue(msg, conv);
|
||||
}
|
||||
break;
|
||||
case FieldType.Double:
|
||||
{
|
||||
int tag = get_tag(msg, fd, out bool is_header);
|
||||
var data = is_header ? ((QuickFix.Message)fix).Header.GetDecimal(tag) : fix.GetDecimal(tag);
|
||||
double d = decimal.ToDouble(data);
|
||||
fd.Accessor.SetValue(msg, d);
|
||||
}
|
||||
break;
|
||||
case FieldType.Int32:
|
||||
case FieldType.SInt32:
|
||||
case FieldType.UInt32:
|
||||
{
|
||||
int tag = get_tag(msg, fd, out bool is_header);
|
||||
var data = is_header ? ((QuickFix.Message)fix).Header.GetInt(tag) : fix.GetInt(tag);
|
||||
object conv = Convert.ChangeType(data, fd.Accessor.GetValue(msg).GetType());
|
||||
fd.Accessor.SetValue(msg, conv);
|
||||
}
|
||||
break;
|
||||
case FieldType.Int64:
|
||||
case FieldType.SInt64:
|
||||
case FieldType.UInt64:
|
||||
{
|
||||
int tag = get_tag(msg, fd, out bool is_header);
|
||||
try
|
||||
{
|
||||
var data = is_header ? ((QuickFix.Message)fix).Header.GetDecimal(tag) : fix.GetDecimal(tag);
|
||||
object conv = Convert.ChangeType(data, fd.Accessor.GetValue(msg).GetType());
|
||||
fd.Accessor.SetValue(msg, conv);
|
||||
}
|
||||
catch(Exception ex) when (ex is QuickFix.FieldConvertError || ex is FormatException)
|
||||
{
|
||||
try
|
||||
{
|
||||
var snot = fix.GetString(tag); //scientific notation apparently appears in the files
|
||||
var data = Double.Parse(snot, System.Globalization.NumberStyles.Float);
|
||||
object conv = Convert.ChangeType(data, fd.Accessor.GetValue(msg).GetType());
|
||||
fd.Accessor.SetValue(msg, conv);
|
||||
}
|
||||
catch {}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FieldType.Enum:
|
||||
{
|
||||
EnumValueDescriptor val = find_enum_by_attribute(msg, fd, fix);
|
||||
if(val == null)
|
||||
{
|
||||
int tag = get_tag(msg, fd, out bool is_header);
|
||||
char data = is_header ? ((QuickFix.Message)fix).Header.GetChar(tag) : fix.GetChar(tag);
|
||||
val = fd.EnumType.FindValueByNumber((int)data);
|
||||
val = val ?? fd.EnumType.FindValueByNumber(0);
|
||||
}
|
||||
fd.Accessor.SetValue(msg, val.Number);
|
||||
}
|
||||
break;
|
||||
case FieldType.String:
|
||||
{
|
||||
int tag = get_tag(msg, fd, out bool is_header);
|
||||
var data = is_header ? ((QuickFix.Message)fix).Header.GetString(tag) : fix.GetString(tag);
|
||||
fd.Accessor.SetValue(msg, data);
|
||||
}
|
||||
break;
|
||||
case FieldType.Message:
|
||||
{
|
||||
handle_message(msg, fd, fix);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException("unsupported field type " + fd.FieldType.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private static EnumValueDescriptor find_enum_by_attribute(IMessage msg, FieldDescriptor fd, QuickFix.FieldMap fix)
|
||||
{
|
||||
int tag = get_tag(msg, fd, out bool is_header);
|
||||
var fval = is_header ? ((QuickFix.Message)fix).Header.GetString(tag) : fix.GetString(tag);
|
||||
foreach(var val in fd.EnumType.Values)
|
||||
{
|
||||
string eval = null;
|
||||
if(val.CustomOptions?.TryGetString((int)ApioptionsReflection.EnumValueOptions.fix_value, out eval) ?? false)
|
||||
{
|
||||
if(eval != null && eval == fval)
|
||||
return val;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static void handle_timestamp(IMessage msg, FieldDescriptor fd, QuickFix.FieldMap fix)
|
||||
{
|
||||
int tag = get_tag(msg, fd, out bool is_header);
|
||||
var data = is_header ? ((QuickFix.Message)fix).Header.GetString(tag) : fix.GetString(tag);
|
||||
Timestamp ts = TimestampExtensions.parse_timestamp(data);
|
||||
fd.Accessor.SetValue(msg, ts);
|
||||
}
|
||||
static void handle_quantitymeasure(IMessage msg, FieldDescriptor fd, QuickFix.FieldMap fix)
|
||||
{
|
||||
int tag = get_tag(msg, fd, out bool is_header);
|
||||
var data = is_header ? ((QuickFix.Message)fix).Header.GetInt(tag) : fix.GetInt(tag);
|
||||
var qm = new bts.spark.QuantityMeasure { Absolute = (uint) Math.Abs(data) };
|
||||
fd.Accessor.SetValue(msg, qm);
|
||||
}
|
||||
|
||||
static void handle_message(IMessage msg, FieldDescriptor fd, QuickFix.FieldMap fix)
|
||||
{
|
||||
if (fd.MessageType.ClrType == typeof(Google.Protobuf.WellKnownTypes.Timestamp))
|
||||
{
|
||||
handle_timestamp(msg, fd, fix);
|
||||
}
|
||||
else if(fd.MessageType.ClrType == typeof(bts.spark.QuantityMeasure))
|
||||
{
|
||||
handle_quantitymeasure(msg, fd, fix);
|
||||
}
|
||||
else if(fd.MessageType.ClrType == typeof(bts.api.orderman.CustomOrderDefinition))
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!fd.IsRepeated)
|
||||
{
|
||||
var submsg = create_message(fd.MessageType, fix);
|
||||
fd.Accessor.SetValue(msg, submsg);
|
||||
}
|
||||
else //for repeating groups we assume that the fd.FieldNumber corresponds to the "no" (number) tag in the fix
|
||||
{
|
||||
int tag = get_tag(msg, fd, out bool is_header);
|
||||
int group = tag;//fd.FieldNumber;
|
||||
int nvals = fix.GetInt(group);
|
||||
IList list = (IList)fd.Accessor.GetValue(msg);
|
||||
if (nvals == 1)
|
||||
{
|
||||
var submsg = create_message(fd.MessageType, fix);
|
||||
list.Add(submsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
var delimproto = fd.MessageType.Fields.InDeclarationOrder()[0];
|
||||
var delim = delimproto.FieldNumber;
|
||||
|
||||
List<QuickFix.Fields.IField> repeated = new List<QuickFix.Fields.IField>();
|
||||
var forder = fix.RepeatedTags.Select(x => x.Tag).Distinct();
|
||||
var dict = fix.ToDictionary();
|
||||
foreach(int fo in forder)
|
||||
{
|
||||
if(dict.TryGetValue(fo, out QuickFix.Fields.IField field))
|
||||
repeated.Add(field);
|
||||
}
|
||||
repeated.AddRange(fix.RepeatedTags);
|
||||
QuickFix.FieldMap fm = null;
|
||||
foreach (var rep in repeated)
|
||||
{
|
||||
if (rep.Tag == delim)
|
||||
{
|
||||
if (fm != null)
|
||||
{
|
||||
var submsg = create_message(fd.MessageType, fm);
|
||||
list.Add(submsg);
|
||||
}
|
||||
fm = new QuickFix.FieldMap();
|
||||
}
|
||||
if (fm != null)
|
||||
fm.SetField(rep);
|
||||
} //the last one
|
||||
if (fm != null && fm.Count() > 0)
|
||||
{
|
||||
var submsg = create_message(fd.MessageType, fm);
|
||||
list.Add(submsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using bts.api.orderman;
|
||||
|
||||
namespace bts.fix
|
||||
{
|
||||
public class ATDL
|
||||
{
|
||||
readonly Dictionary<string, FIXAlgoDefinition> _atdl = new Dictionary<string, FIXAlgoDefinition>();
|
||||
public IReadOnlyDictionary<string, FIXAlgoDefinition> algo_definitions => _atdl;
|
||||
public ATDL(string path = "./spark_algos.json")
|
||||
{
|
||||
using(var fs = new StreamReader(path))
|
||||
{
|
||||
var algos = Google.Protobuf.JsonParser.Default.Parse<FIXAlgoDefinitions>(fs);
|
||||
foreach(var algo in algos.AlgoStrategy)
|
||||
{
|
||||
_atdl[algo.Name] = algo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void write_json(FIXAlgoDefinitions defs, string path)
|
||||
{
|
||||
using (var fs = new StreamWriter(path))
|
||||
{
|
||||
var s = Google.Protobuf.JsonFormatter.Settings.Default;
|
||||
|
||||
var raw = Google.Protobuf.JsonFormatter.Default.Format(defs);
|
||||
object parsed = Newtonsoft.Json.JsonConvert.DeserializeObject(raw);
|
||||
|
||||
string indented = Newtonsoft.Json.JsonConvert.SerializeObject(parsed, Newtonsoft.Json.Formatting.Indented);
|
||||
fs.Write(indented);
|
||||
}
|
||||
}
|
||||
|
||||
public static void write_sample_json(string path = "./spark_algos.json")
|
||||
{
|
||||
FIXAlgoDefinition tc = new FIXAlgoDefinition()
|
||||
{
|
||||
Name = "TickAndCover",
|
||||
Definition = new CustomOrderDefinition
|
||||
{
|
||||
Cover = new CoverOrderDefinition
|
||||
{
|
||||
Child = new CustomOrderDefinition
|
||||
{
|
||||
Top = new TopOrderDefinition { Child = new CustomOrderDefinition { Limit = new LimitOrderDefinition() } }
|
||||
},
|
||||
Hedge = new CustomOrderDefinition
|
||||
{
|
||||
Lean = new LeanOrderDefinition { Child = new CustomOrderDefinition { Limit = new LimitOrderDefinition() } }
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
FIXAlgoDefinition sc = new FIXAlgoDefinition()
|
||||
{
|
||||
Name = "SmashAndCover",
|
||||
Definition = new CustomOrderDefinition
|
||||
{
|
||||
Cover = new CoverOrderDefinition
|
||||
{
|
||||
Child = new CustomOrderDefinition
|
||||
{
|
||||
Lean = new LeanOrderDefinition{ Child = new CustomOrderDefinition { Limit = new LimitOrderDefinition() } }
|
||||
},
|
||||
Hedge = new CustomOrderDefinition
|
||||
{
|
||||
Lean = new LeanOrderDefinition { Child = new CustomOrderDefinition { Limit = new LimitOrderDefinition() } }
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
FIXAlgoDefinitions defs = new FIXAlgoDefinitions();
|
||||
defs.AlgoStrategy.Add(tc);
|
||||
defs.AlgoStrategy.Add(sc);
|
||||
write_json(defs, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,11 @@ using bts.api.admin;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
using QuickFix.FIX42;
|
||||
using Message = QuickFix.Message;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bts.fix
|
||||
{
|
||||
class DropCopySession : SessionBase
|
||||
@@ -26,6 +31,7 @@ namespace bts.fix
|
||||
|
||||
protected readonly ConcurrentDictionary<uint, OrderRecordImmutable> _order_cache = new ConcurrentDictionary<uint, OrderRecordImmutable>();
|
||||
protected readonly ConcurrentDictionary<uint, string> _fix_clorderids = new ConcurrentDictionary<uint, string>();
|
||||
protected readonly ConcurrentDictionary<string, uint> _external_id_vs_bts_key = new ConcurrentDictionary<string, uint>();
|
||||
public DropCopySession(IFixRouter router, SessionID sess) : base(router, sess)
|
||||
{
|
||||
}
|
||||
@@ -67,18 +73,19 @@ namespace bts.fix
|
||||
}
|
||||
}
|
||||
|
||||
virtual public void OnMessage(QuickFix.FIX44.OrderStatusRequest req, SessionID s)
|
||||
virtual public void OnMessage(OrderStatusRequest req, SessionID s)
|
||||
{
|
||||
uint oid = uint.Parse(req.OrderID.getValue());
|
||||
if (_order_cache.TryGetValue(oid, out OrderRecordImmutable order))
|
||||
{
|
||||
var ostat = build_order_status(s, order);
|
||||
ostat.OrdStatusReqID = new OrdStatusReqID(req.OrdStatusReqID.getValue());
|
||||
//ostat.OrdStatusReqID = new OrdStatusReqID(req.OrdStatusReqID.getValue());
|
||||
//TODO
|
||||
_router.send(ostat, s);
|
||||
}
|
||||
}
|
||||
|
||||
virtual public void OnMessage(QuickFix.FIX44.SecurityDefinitionRequest req, SessionID s)
|
||||
virtual public void OnMessage(SecurityDefinitionRequest req, SessionID s)
|
||||
{
|
||||
if (req.SecurityRequestType.getValue() == SecurityRequestType.REQUEST_LIST_SECURITIES)
|
||||
{
|
||||
@@ -90,30 +97,36 @@ namespace bts.fix
|
||||
if (req.IsSetSecurityExchange())
|
||||
secs = secs.Where(x => exchanges_equal(x.Exchange, req.SecurityExchange));
|
||||
|
||||
var def = new QuickFix.FIX44.SecurityDefinition(req.SecurityReqID,
|
||||
var def = new SecurityDefinition(req.SecurityReqID,
|
||||
new SecurityResponseID(Guid.NewGuid().ToString()),
|
||||
new SecurityResponseType(SecurityResponseType.LIST_OF_SECURITIES_RETURNED_PER_REQUEST));
|
||||
new TotalNumSecurities(secs.Count()));
|
||||
_router.send(def, s);
|
||||
}
|
||||
else
|
||||
throw new IncorrectTagValue(req.SecurityRequestType.Tag);
|
||||
throw new IncorrectTagValue(QuickFix.Fields.Tags.SecurityRequestType);
|
||||
}
|
||||
|
||||
void _add_order_info_to_caches(OrderRecordImmutable o) {
|
||||
_order_cache[o.Key] = o;
|
||||
if (o.HasDef && !string.IsNullOrEmpty(o.Def.ExternalOrderId)) {
|
||||
_external_id_vs_bts_key[o.Def.ExternalOrderId] = o.Key;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
virtual protected void subscribe_fills_and_orders(SessionID sessionID)
|
||||
virtual async protected void subscribe_fills_and_orders(SessionID sessionID)
|
||||
{
|
||||
var scheduler = TaskPoolScheduler.Default;
|
||||
var interval = TimeSpan.FromMilliseconds(500);
|
||||
var on_orders = _orderservice.Value.subscribei_orders().Naggle(interval, scheduler).PermissionFilter(_adminobservable).Table().Cache();
|
||||
var on_fills = _orderservice.Value.subscribei_fills().Naggle(interval, scheduler).PermissionFilter(_adminobservable).Table().Cache();
|
||||
|
||||
var odone = new TaskCompletionSource<int>();
|
||||
_ordersdisp = on_orders.Subscribe(o =>
|
||||
{
|
||||
foreach (var order in o.added)
|
||||
{
|
||||
var ostat = build_order_status(sessionID, order);
|
||||
_order_cache[order.Key] = order;
|
||||
_add_order_info_to_caches(order);
|
||||
_router.send(ostat, sessionID);
|
||||
}
|
||||
foreach (var order in o.changed)
|
||||
@@ -121,8 +134,10 @@ namespace bts.fix
|
||||
var ostat = build_order_status(sessionID, order, true);
|
||||
_router.send(ostat, sessionID);
|
||||
}
|
||||
odone.TrySetResult(0);
|
||||
});
|
||||
|
||||
|
||||
await odone.Task;
|
||||
_fillsdisp = on_fills.Subscribe(f =>
|
||||
{
|
||||
foreach (var fill in f.added)
|
||||
@@ -148,7 +163,7 @@ namespace bts.fix
|
||||
fstatus = translate_status(state, ref native);
|
||||
}
|
||||
|
||||
protected bts.api.SecurityImmutable? resolve_execution_report_security(bts.api.SecurityImmutable? sec, QuickFix.FIX44.ExecutionReport report)
|
||||
protected bts.api.SecurityImmutable? resolve_execution_report_security(bts.api.SecurityImmutable? sec, ExecutionReport report)
|
||||
{
|
||||
report.SecurityExchange = convert_exchange(sec.Value.Exchange);
|
||||
var sectype = sec.Value.security_type();
|
||||
@@ -171,14 +186,15 @@ namespace bts.fix
|
||||
return sec;
|
||||
}
|
||||
|
||||
virtual protected QuickFix.FIX44.ExecutionReport build_fill(SessionID sess, in FillImmutable fill, bool change = false)
|
||||
virtual protected ExecutionReport build_fill(SessionID sess, in FillImmutable fill, bool change = false)
|
||||
{
|
||||
var exec = new QuickFix.Fields.ExecType(QuickFix.Fields.ExecType.PARTIAL_FILL);
|
||||
QuickFix.Fields.OrdStatus status = new QuickFix.Fields.OrdStatus();
|
||||
uint filled = 0; uint leaves = 0; double prx = 0.0;
|
||||
uint filled = 0; uint leaves = 0; double prx = 0.0; uint orig_qty = 0;
|
||||
OrderRecordImmutable order; NativeOrderStateImmutable? native = null;
|
||||
if (_order_cache.TryGetValue(fill.OrderKey, out order))
|
||||
{
|
||||
orig_qty = order.State.Quantity;
|
||||
process_order_state(order.State, ref filled, ref leaves, ref prx, ref status, ref native);
|
||||
if(Convert.ToDouble(order.State.Quantity) == fill.LastShares)
|
||||
exec = new QuickFix.Fields.ExecType(QuickFix.Fields.ExecType.FILL);
|
||||
@@ -187,9 +203,10 @@ namespace bts.fix
|
||||
exec = new QuickFix.Fields.ExecType(QuickFix.Fields.ExecType.TRADE_CORRECT);
|
||||
|
||||
var sec = _router.lookup(fill.SecurityKey);
|
||||
QuickFix.FIX44.ExecutionReport report = new QuickFix.FIX44.ExecutionReport(
|
||||
ExecutionReport report = new ExecutionReport(
|
||||
new OrderID(fill.OrderKey.ToString()),
|
||||
new ExecID(fill.FillKey.ToString()),
|
||||
new ExecID(fill.FillKey.ToString()),
|
||||
new QuickFix.Fields.ExecTransType( ExecTransType.NEW ),
|
||||
exec,
|
||||
status,
|
||||
new Symbol(sec?.Symbol ?? string.Empty),
|
||||
@@ -199,7 +216,8 @@ namespace bts.fix
|
||||
new AvgPx(Convert.ToDecimal(prx)));
|
||||
|
||||
report.Account = new Account(fill.Account);
|
||||
report.LastQty = new LastQty(Convert.ToDecimal(fill.LastShares));
|
||||
report.OrderQty = new OrderQty(orig_qty);
|
||||
report.LastShares = new LastShares(Convert.ToDecimal(fill.LastShares));
|
||||
report.LastPx = new LastPx(Convert.ToDecimal(fill.LastPrice));
|
||||
var ts = fill.HasTimestamp ? fill.Timestamp.ToDateTime() : DateTime.MinValue;
|
||||
report.TransactTime = new TransactTime(ts, true);
|
||||
@@ -219,7 +237,7 @@ namespace bts.fix
|
||||
return report;
|
||||
}
|
||||
|
||||
virtual protected QuickFix.FIX44.ExecutionReport build_order_status(SessionID sess, in OrderRecordImmutable order, bool change = false)
|
||||
virtual protected ExecutionReport build_order_status(SessionID sess, in OrderRecordImmutable order, bool change = false)
|
||||
{
|
||||
var exec = new QuickFix.Fields.ExecType(QuickFix.Fields.ExecType.NEW);
|
||||
if (_order_cache.TryGetValue(order.Key, out OrderRecordImmutable _))
|
||||
@@ -230,9 +248,10 @@ namespace bts.fix
|
||||
process_order_state(order.State, ref filled, ref leaves, ref prx, ref status, ref native);
|
||||
|
||||
var sec = _router.lookup(order.Def.SecurityKey);
|
||||
QuickFix.FIX44.ExecutionReport report = new QuickFix.FIX44.ExecutionReport(
|
||||
ExecutionReport report = new ExecutionReport(
|
||||
new OrderID(order.Key.ToString()),
|
||||
new ExecID("0"),
|
||||
new QuickFix.Fields.ExecTransType(ExecTransType.STATUS),
|
||||
exec,
|
||||
status,
|
||||
new Symbol(sec?.Symbol ?? string.Empty),
|
||||
|
||||
@@ -9,19 +9,36 @@ using QuickFix.Fields;
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
|
||||
using QuickFix.FIX42;
|
||||
using Message = QuickFix.Message;
|
||||
|
||||
namespace bts.fix
|
||||
{
|
||||
/* Some test fix
|
||||
order for 4 lot CLZ8
|
||||
8=FIX.4.49=15635=D49=SPARK56=CLIENT134=150=3073797=Y52=20000809-20:20:5011=900010081=ACC A21=255=SIM:CLZ854=138=440=259=044=7460=20000809-18:20:32207=SIM10=045
|
||||
|
||||
order for 4 lot CLZ8-CLH9
|
||||
8=FIX.4.49=15635=D49=SPARK56=CLIENT134=150=3073797=Y52=20000809-20:20:5011=900010081=ACC A21=255=SIM:CLZ8-CLH954=138=440=259=044=7460=20000809-18:20:32207=SIM10=045
|
||||
|
||||
*/
|
||||
/*
|
||||
create limit
|
||||
8=FIX.4.29=15635=D49=CQG56=SPARK34=150=3073797=N52=20200109-20:20:5011=900010081=ACC A21=255=SIM:ESH0207=SIM54=160=20200809-18:20:3238=1040=244=320059=010=129
|
||||
|
||||
update limit
|
||||
8=FIX.4.29=11035=G49=CQG56=SPARK37=1341=9000100811=9000200821=155= ESH054=160=20200113-19:45:2938=1040=244=320110=017
|
||||
|
||||
delete limit
|
||||
8=FIX.4.29=9335=F49=CQG56=SPARK41= 9000100837=1311=9000300855=ESH054=160=20200113-19:45:2738=1010=247
|
||||
|
||||
create algo
|
||||
8=FIX.4.29=15635=D49=CQG56=SPARK34=150=3073797=N52=20200109-20:20:5011=900010081=ACC A21=255=SIM:ESH0207=SIM54=160=20200809-18:20:3238=1040=244=320059=06401=Lean8401=118402=28405=010=128
|
||||
|
||||
jake:
|
||||
new
|
||||
8=FIX.4.29=15635=D49=CQG56=SPARK34=150=3073797=N52=20200109-20:20:5011=86753091=ACC A21=255=SIM:ESH0207=SIM54=160=20200809-18:20:3238=1040=244=320059=010=128
|
||||
cancel-replace
|
||||
8=FIX.4.29=11035=G49=CQG56=SPARK37=1341=867530911=867531021=155=ESH054=160=20200113-19:45:2938=1040=244=320110=017
|
||||
cancel
|
||||
8=FIX.4.29=8935=F49=CQG56=SPARK41=867530937=1311=867531155=ESH054=160=20200113-19:45:2738=1010=123
|
||||
|
||||
*/
|
||||
class OrderSession : DropCopySession
|
||||
{
|
||||
readonly ATDL _atdl = new ATDL();
|
||||
public OrderSession(IFixRouter router, SessionID sess) : base(router, sess)
|
||||
{
|
||||
}
|
||||
@@ -47,120 +64,140 @@ namespace bts.fix
|
||||
}
|
||||
}
|
||||
|
||||
virtual public void OnMessage(QuickFix.FIX44.OrderCancelRequest cancel, SessionID s)
|
||||
virtual public void OnMessage(OrderCancelRequest cancel, SessionID s)
|
||||
{
|
||||
var id = cancel.OrderID.getValue();
|
||||
if(!uint.TryParse(id, out uint key))
|
||||
throw new IncorrectTagValue(cancel.OrderID.Tag);
|
||||
var original_client_id = cancel.OrigClOrdID.getValue();
|
||||
if (!base._external_id_vs_bts_key.ContainsKey(original_client_id))
|
||||
throw new IncorrectTagValue(QuickFix.Fields.Tags.OrigClOrdID);
|
||||
var key = base._external_id_vs_bts_key[original_client_id];
|
||||
var resp = _orderservice.Value.cancel_order(new Cancel { OrderKey = key });
|
||||
if (resp.ErrorCode != OrderError.Ok)
|
||||
{
|
||||
send_cancel_reject(s, "Cancel Rejected: " + resp.ErrorCode.ToString() + " - " + resp.Msg, cancel);
|
||||
send_cancel_reject(s, resp.ErrorCode, "Cancel Rejected: " + resp.ErrorCode.ToString() + " - " + resp.Msg, cancel);
|
||||
}
|
||||
}
|
||||
|
||||
virtual public void OnMessage(QuickFix.FIX44.OrderCancelReplaceRequest replace, SessionID s)
|
||||
virtual public void OnMessage(OrderCancelReplaceRequest replace, SessionID s)
|
||||
{
|
||||
var id = replace.OrderID.getValue();
|
||||
if (!uint.TryParse(id, out uint key))
|
||||
throw new IncorrectTagValue(replace.OrderID.Tag);
|
||||
var original_client_id = replace.OrigClOrdID.getValue();
|
||||
if (!base._external_id_vs_bts_key.ContainsKey(original_client_id))
|
||||
throw new IncorrectTagValue(QuickFix.Fields.Tags.OrigClOrdID);
|
||||
var key = base._external_id_vs_bts_key[original_client_id];
|
||||
double price = Convert.ToDouble(replace.Price.getValue());
|
||||
uint sz = Convert.ToUInt32(Math.Abs(replace.OrderQty.getValue()));
|
||||
var resp = _orderservice.Value.update_order(new Update
|
||||
var upd = new Update
|
||||
{
|
||||
OrderKey = key,
|
||||
Price = price,
|
||||
Quantity = sz,
|
||||
});
|
||||
Custom = get_custom(replace),
|
||||
};
|
||||
var resp = _orderservice.Value.update_order(upd);
|
||||
if (resp.ErrorCode != OrderError.Ok)
|
||||
{
|
||||
send_cancel_reject(s, "Cancel Rejected: " + resp.ErrorCode.ToString() + " - " + resp.Msg, replace);
|
||||
send_cancel_reject(s, resp.ErrorCode, "Cancel Rejected: " + resp.ErrorCode.ToString() + " - " + resp.Msg, replace);
|
||||
}
|
||||
}
|
||||
|
||||
virtual public void OnMessage(QuickFix.FIX44.NewOrderSingle create, SessionID s)
|
||||
virtual public void OnMessage(NewOrderSingle create, SessionID s)
|
||||
{
|
||||
Venue ven = convert_exchange(create.SecurityExchange);
|
||||
Venue ven = Venue.Glbx;
|
||||
if(create.IsSetSecurityExchange())
|
||||
ven = convert_exchange(create.SecurityExchange);
|
||||
if(create.IsSetExDestination())
|
||||
ven = convert_exchange(create.ExDestination);
|
||||
if (ven == bts.api.Venue.Unset)
|
||||
throw new IncorrectTagValue(create.SecurityExchange.Tag);
|
||||
throw new IncorrectTagValue(QuickFix.Fields.Tags.SecurityExchange);
|
||||
|
||||
var sec = _router.lookup(create.Symbol.getValue());
|
||||
if (!sec.HasValue)
|
||||
sec = _router.lookup(create.SecurityDesc.getValue());
|
||||
|
||||
if (!sec.HasValue)
|
||||
throw new IncorrectTagValue(create.SecurityDesc.Tag);
|
||||
throw new IncorrectTagValue(QuickFix.Fields.Tags.Symbol);
|
||||
|
||||
OrderDefinition def = null;
|
||||
try
|
||||
{
|
||||
string manual = "Y";
|
||||
if(create.IsSetField(Tags.ManualOrderIndicator))
|
||||
manual = create.GetField(Tags.ManualOrderIndicator);
|
||||
def = new OrderDefinition()
|
||||
{
|
||||
Account = create.Account.getValue(),
|
||||
AccountId = lookup_account(create.Account.getValue()),
|
||||
SecurityKey = sec.Value.Id,
|
||||
Side = (api.Side)(int)create.Side.getValue(),
|
||||
TimeInForce = (api.orderman.TimeInForce)(int)create.TimeInForce.getValue(),
|
||||
User = _user_name,
|
||||
UserId = lookup_user(_user_name),
|
||||
ManualOrderIndicator = manual == "Y" ? bts.api.orderman.ManualOrderIndicator.Yes : bts.api.orderman.ManualOrderIndicator.No,
|
||||
};
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new IncorrectTagValue(create.TimeInForce.Tag);
|
||||
}
|
||||
OrderDefinition def = (OrderDefinition)ProtoFix.create_message(OrderDefinition.Descriptor, create);
|
||||
def.SecurityKey = sec.Value.Id;
|
||||
def.User = _login_name;
|
||||
def.UserId = lookup_user(_login_name);
|
||||
def.AccountId = lookup_account(def.Account);
|
||||
|
||||
set_ordertype(def, create, out bool price_req);
|
||||
Create cr = new Create();
|
||||
cr.NewOrder = def;
|
||||
def.CustomDef = get_custom(create);
|
||||
cr.NewOrder = def;
|
||||
try
|
||||
{
|
||||
if (price_req)
|
||||
if (create.IsSetPrice())
|
||||
cr.Price = Convert.ToDouble(create.Price.getValue());
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new IncorrectTagValue(create.Price.Tag);
|
||||
}
|
||||
catch { throw new IncorrectTagValue(QuickFix.Fields.Tags.Price); }
|
||||
try
|
||||
{
|
||||
if(!create.IsSetOrderQty() || create.OrderQty.getValue() < 0)
|
||||
throw new IncorrectTagValue(QuickFix.Fields.Tags.OrderQty);
|
||||
cr.Quantity = Convert.ToUInt32(Math.Abs(create.OrderQty.getValue()));
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new IncorrectTagValue(create.OrderQty.Tag);
|
||||
}
|
||||
catch { throw new IncorrectTagValue(QuickFix.Fields.Tags.OrderQty); }
|
||||
if (!create.IsSetClOrdID())
|
||||
throw new IncorrectTagValue(QuickFix.Fields.Tags.ClOrdID);
|
||||
else
|
||||
def.ExternalOrderId = create.ClOrdID.ToString();
|
||||
|
||||
var resp = _orderservice.Value.create_order(cr);
|
||||
_fix_clorderids[resp.OrderKey] = create.ClOrdID.getValue();
|
||||
if (resp.ErrorCode != OrderError.Ok)
|
||||
{
|
||||
_router.send_biz_reject(s, "Order Rejected: " + resp.ErrorCode.ToString() + " - " + resp.Msg, create);
|
||||
}
|
||||
}
|
||||
|
||||
private void set_ordertype(OrderDefinition def, QuickFix.FIX44.NewOrderSingle req, out bool price_req)
|
||||
|
||||
CustomOrderDefinition get_custom(Message fix)
|
||||
{
|
||||
price_req = false;
|
||||
switch (req.OrdType.getValue())
|
||||
FIXAlgoDefinition.Descriptor.FindFieldByNumber(FIXAlgoDefinition.NameFieldNumber).
|
||||
CustomOptions.TryGetInt32((int)ApioptionsReflection.FieldOptions.fix_tag, out int algotag);
|
||||
if(fix.IsSetField(algotag))
|
||||
{
|
||||
case '1':
|
||||
def.CustomDef = new CustomOrderDefinition { Market = new MarketOrderDefinition() };
|
||||
break;
|
||||
case '2':
|
||||
def.CustomDef = new CustomOrderDefinition { Limit = new LimitOrderDefinition() };
|
||||
price_req = true;
|
||||
break;
|
||||
case '3':
|
||||
def.CustomDef = new CustomOrderDefinition { Stop = new StopOrderDefinition() {StopPrice = Convert.ToDouble(req.StopPx.getValue()) } };
|
||||
break;
|
||||
case '4':
|
||||
def.CustomDef = new CustomOrderDefinition { StopLimit = new StopLimitOrderDefinition() { StopPrice = Convert.ToDouble(req.StopPx.getValue()) } };
|
||||
price_req = true;
|
||||
break;
|
||||
default:
|
||||
throw new IncorrectTagValue(req.OrdType.Tag);
|
||||
string algotype = fix.GetString(algotag);
|
||||
if(!_atdl.algo_definitions.TryGetValue(algotype, out FIXAlgoDefinition algodef))
|
||||
throw new IncorrectTagValue(algotag);
|
||||
else
|
||||
{
|
||||
var custom = algodef.Definition.Clone();
|
||||
foreach (var fd in CustomOrderDefinition.Descriptor.Fields.InDeclarationOrder())
|
||||
{
|
||||
var val = fd.Accessor.GetValue(custom);
|
||||
if(val != null && val is Google.Protobuf.IMessage valmsg)
|
||||
{
|
||||
ProtoFix.setup_message(valmsg, fix);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return custom;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!fix.IsSetField(QuickFix.Fields.Tags.OrdType))
|
||||
throw new IncorrectTagValue(QuickFix.Fields.Tags.OrdType);
|
||||
switch (fix.GetChar(QuickFix.Fields.Tags.OrdType))
|
||||
{
|
||||
case '1':
|
||||
return new CustomOrderDefinition { Market = new MarketOrderDefinition() };
|
||||
case '2':
|
||||
return new CustomOrderDefinition { Limit = new LimitOrderDefinition() };
|
||||
case '3':
|
||||
return new CustomOrderDefinition { Stop = new StopOrderDefinition()
|
||||
{
|
||||
StopPrice = Convert.ToDouble(fix.GetDecimal(QuickFix.Fields.Tags.StopPx)) }
|
||||
};
|
||||
case '4':
|
||||
return new CustomOrderDefinition { StopLimit = new StopLimitOrderDefinition()
|
||||
{
|
||||
StopPrice = Convert.ToDouble(fix.GetDecimal(QuickFix.Fields.Tags.StopPx)) }
|
||||
};
|
||||
default:
|
||||
throw new IncorrectTagValue(QuickFix.Fields.Tags.OrdType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ using bts.api.orderman;
|
||||
using bts.api.user;
|
||||
using bts.api.admin;
|
||||
|
||||
using QuickFix.FIX42;
|
||||
using Message = QuickFix.Message;
|
||||
|
||||
namespace bts.fix
|
||||
{
|
||||
@@ -27,7 +29,7 @@ namespace bts.fix
|
||||
protected static Lazy<bts.metrics.ShellLatencyService> _latencyservice =
|
||||
new Lazy<bts.metrics.ShellLatencyService>(() => bts.api.Locator.locate<bts.metrics.ShellLatencyService>(), true);
|
||||
|
||||
protected string _user_name;
|
||||
protected string _login_name;
|
||||
protected AuthToken _token;
|
||||
|
||||
protected IDisposable _admindisp;
|
||||
@@ -51,7 +53,7 @@ namespace bts.fix
|
||||
|
||||
_adminobservable = _adminservice.Value.subscribei_admin_data().Select(x =>
|
||||
{
|
||||
return new AdminModelWrapper(x.all.TryFirst(), _user_name);
|
||||
return new AdminModelWrapper(x.all.TryFirst(), _login_name);
|
||||
});
|
||||
_admindisp = _adminobservable.Subscribe(x => _admin_data = x.admin_data);
|
||||
}
|
||||
@@ -78,13 +80,18 @@ namespace bts.fix
|
||||
{
|
||||
try
|
||||
{
|
||||
QuickFix.FIX44.Logon msg = (QuickFix.FIX44.Logon)message;
|
||||
_user_name = msg.Username.getValue();
|
||||
string pass = string.Empty;
|
||||
if(msg.IsSetPassword())
|
||||
pass = msg.Password.getValue();
|
||||
Logon msg = (Logon)message;
|
||||
|
||||
var fixlogin = new QuickFix.Fields.SenderCompID();
|
||||
string login = msg.Header.GetString(fixlogin.Tag).ToLower();
|
||||
// var fixuser = new QuickFix.Fields.TargetSubID();
|
||||
// string user = msg.Header.GetString(fixuser.Tag);
|
||||
_login_name = login;
|
||||
string pass = string.Empty;
|
||||
if(msg.IsSetRawData())
|
||||
pass = msg.RawData.getValue();
|
||||
var resp = _authservice.authenticate_login(new AuthenticateLoginRequest {
|
||||
Login = msg.Username.getValue(), Password = pass});
|
||||
Login = login, Password = pass});
|
||||
if (resp != null && resp.IsValid)
|
||||
_token = resp.Token;
|
||||
else
|
||||
@@ -102,7 +109,7 @@ namespace bts.fix
|
||||
break;
|
||||
case MsgType.HEARTBEAT:
|
||||
{
|
||||
QuickFix.FIX44.Heartbeat hb = (QuickFix.FIX44.Heartbeat)message;
|
||||
Heartbeat hb = (Heartbeat)message;
|
||||
handle_heartbeat(hb, sessionID);
|
||||
}
|
||||
break;
|
||||
@@ -112,10 +119,10 @@ namespace bts.fix
|
||||
}
|
||||
}
|
||||
|
||||
async protected void handle_heartbeat(QuickFix.FIX44.Heartbeat hb, SessionID sessionID)
|
||||
async protected void handle_heartbeat(Heartbeat hb, SessionID sessionID)
|
||||
{
|
||||
var resp = await _latencyservice.Value.report_async(new bts.metrics.Report { HostName = "BTSFIX_" + sessionID.ToString(),
|
||||
Timestamp = _clock, User = _user_name });
|
||||
Timestamp = _clock, User = _login_name });
|
||||
if (resp.success)
|
||||
_router.send(hb, sessionID);
|
||||
}
|
||||
@@ -131,12 +138,12 @@ namespace bts.fix
|
||||
log_info("CREATE");
|
||||
}
|
||||
|
||||
virtual public void OnMessage(QuickFix.FIX44.BusinessMessageReject n, SessionID s)
|
||||
virtual public void OnMessage(BusinessMessageReject n, SessionID s)
|
||||
{
|
||||
//Log.assert(false, "biz reject wtf " + n.EncodedText.getValue());
|
||||
Log.FIX.warn(_sess.ToString() + " Business Reject " + n.BusinessRejectReason.getValue() + " " + n.Text.getValue());
|
||||
}
|
||||
virtual public void OnMessage(QuickFix.FIX44.News n, SessionID s)
|
||||
virtual public void OnMessage(News n, SessionID s)
|
||||
{
|
||||
log_info("news " + n.EncodedHeadline.getValue());
|
||||
}
|
||||
@@ -152,36 +159,41 @@ namespace bts.fix
|
||||
Log.FIX.error(_sess.ToString() + " " + message, file, line);
|
||||
}
|
||||
|
||||
protected void send_cancel_reject(SessionID sess, string text, Message refmessage)
|
||||
protected void send_cancel_reject(SessionID sess, OrderError reject_reason, string text, Message refmessage)
|
||||
{
|
||||
QuickFix.FIX44.OrderCancelReject rej = new QuickFix.FIX44.OrderCancelReject();
|
||||
if (refmessage is QuickFix.FIX44.OrderCancelRequest cancel)
|
||||
OrderCancelReject rej = new OrderCancelReject();
|
||||
if (reject_reason == OrderError.UnknownOrder) {
|
||||
rej.CxlRejReason = new CxlRejReason(CxlRejReason.UNKNOWN_ORDER);
|
||||
rej.OrdStatus = new OrdStatus(OrdStatus.REJECTED);
|
||||
rej.OrderID = new OrderID("NONE");
|
||||
}
|
||||
|
||||
if (refmessage is QuickFix.FIX42.OrderCancelRequest cancel)
|
||||
{
|
||||
if (cancel.IsSetClOrdID())
|
||||
rej.SetField(cancel.ClOrdID);
|
||||
if (cancel.IsSetOrigClOrdID())
|
||||
rej.SetField(cancel.OrigClOrdID);
|
||||
if (cancel.IsSetOrderID())
|
||||
if (cancel.IsSetOrderID() && reject_reason != OrderError.UnknownOrder)
|
||||
rej.SetField(cancel.OrderID);
|
||||
rej.CxlRejResponseTo = new CxlRejResponseTo('1');
|
||||
rej.CxlRejResponseTo = new CxlRejResponseTo(CxlRejResponseTo.ORDER_CANCEL_REQUEST);
|
||||
rej.Text = new Text(text);
|
||||
_router.send(rej, sess);
|
||||
}
|
||||
else if (refmessage is QuickFix.FIX44.OrderCancelReplaceRequest replace)
|
||||
else if (refmessage is OrderCancelReplaceRequest replace)
|
||||
{
|
||||
if (replace.IsSetClOrdID())
|
||||
rej.SetField(replace.ClOrdID);
|
||||
if (replace.IsSetOrigClOrdID())
|
||||
rej.SetField(replace.OrigClOrdID);
|
||||
if (replace.IsSetOrderID())
|
||||
if (replace.IsSetOrderID() && reject_reason != OrderError.UnknownOrder)
|
||||
rej.SetField(replace.OrderID);
|
||||
rej.CxlRejResponseTo = new CxlRejResponseTo('2');
|
||||
rej.CxlRejResponseTo = new CxlRejResponseTo(CxlRejResponseTo.ORDER_CANCEL_REPLACE_REQUEST);
|
||||
rej.Text = new Text(text);
|
||||
_router.send(rej, sess);
|
||||
}
|
||||
else
|
||||
throw new UnsupportedMessageType();
|
||||
|
||||
}
|
||||
|
||||
protected bool security_types_equal(bts.api.SecurityType btstype, QuickFix.Fields.SecurityType fixtype)
|
||||
@@ -255,7 +267,17 @@ namespace bts.fix
|
||||
|
||||
protected bts.api.Venue convert_exchange(QuickFix.Fields.SecurityExchange fixtype)
|
||||
{
|
||||
switch (fixtype.getValue())
|
||||
return convert_exchange(fixtype.getValue());
|
||||
}
|
||||
|
||||
protected bts.api.Venue convert_exchange(QuickFix.Fields.ExDestination fixtype)
|
||||
{
|
||||
return convert_exchange(fixtype.getValue());
|
||||
}
|
||||
|
||||
protected bts.api.Venue convert_exchange(string venue)
|
||||
{
|
||||
switch (venue)
|
||||
{
|
||||
case "BTS":
|
||||
return bts.api.Venue.Bts;
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
{
|
||||
"algoStrategy": [
|
||||
{
|
||||
"name": "TickAndCover",
|
||||
"definition":
|
||||
{
|
||||
"cover":
|
||||
{
|
||||
"child":
|
||||
{
|
||||
"top": { "child": { "limit": {} } }
|
||||
},
|
||||
"hedge":
|
||||
{
|
||||
"lean": { "child": { "limit": {} } }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "SmashAndCover",
|
||||
"definition":
|
||||
{
|
||||
"cover":
|
||||
{
|
||||
"child":
|
||||
{
|
||||
"lean": { "child": { "limit": {} } }
|
||||
},
|
||||
"hedge":
|
||||
{
|
||||
"lean": { "child": { "limit": {} } }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "JoinAndCover",
|
||||
"definition":
|
||||
{
|
||||
"cover":
|
||||
{
|
||||
"child":
|
||||
{
|
||||
"join": { "child": { "limit": {} } }
|
||||
},
|
||||
"hedge":
|
||||
{
|
||||
"lean": { "child": { "limit": {} } }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Prorata",
|
||||
"definition":
|
||||
{
|
||||
"prorata":
|
||||
{
|
||||
"child": { "limit": {} },
|
||||
"hedge":
|
||||
{
|
||||
"scratch": { "child": { "limit": {} } }
|
||||
},
|
||||
"overfill_hedge":
|
||||
{
|
||||
"lean": { "child": { "limit": {} } }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{ "name": "Top", "definition": { "top": { "child": { "limit": {} } } } },
|
||||
{ "name": "Cover",
|
||||
"definition":
|
||||
{
|
||||
"cover":
|
||||
{
|
||||
"child" : { "limit": {} },
|
||||
"hedge" : { "limit": {} }
|
||||
}
|
||||
}
|
||||
},
|
||||
{ "name": "Lean", "definition": { "lean": { "child": { "limit": {} } } } },
|
||||
{ "name": "Join", "definition": { "join": { "child": { "limit": {} } } } },
|
||||
{ "name": "Iceberg", "definition": { "iceberg": { "child": { "limit": {} } } } },
|
||||
{ "name": "Scratch", "definition": { "scratch": { "child": { "limit": {} } } } },
|
||||
{ "name": "Spreader", "definition": { "spreader": { } } },
|
||||
{ "name": "ISpreader", "definition": { "iceberg": { "child": { "spreader": {} } } } }
|
||||
]
|
||||
}
|
||||
@@ -8,7 +8,7 @@ SocketReuseAddress=Y
|
||||
StartTime=00:00:00
|
||||
EndTime=00:00:00
|
||||
FileLogPath=log
|
||||
UseDataDictionary=Y
|
||||
UseDataDictionary=N
|
||||
ResetOnLogon=Y
|
||||
ResetOnLogout=Y
|
||||
ResetOnDisconnect=Y
|
||||
@@ -27,16 +27,16 @@ SSLEnable=N
|
||||
|
||||
|
||||
[SESSION]
|
||||
BeginString=FIX.4.4
|
||||
BeginString=FIX.4.2
|
||||
SenderCompID=SPARK
|
||||
TargetCompID=CLIENT1
|
||||
TargetCompID=CQG
|
||||
FileStorePath=store
|
||||
DataDictionary=./spec/fix/FIX44.xml
|
||||
DataDictionary=./spec/fix/FIX42.xml
|
||||
|
||||
[SESSION]
|
||||
BeginString=FIX.4.4
|
||||
BeginString=FIX.4.2
|
||||
SenderCompID=SPARK
|
||||
TargetCompID=CLIENT2
|
||||
FileStorePath=store
|
||||
DataDictionary=./spec/fix/FIX44.xml
|
||||
DataDictionary=./spec/fix/FIX42.xml
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<Product>Spark</Product>
|
||||
<Description />
|
||||
<Platforms>x64</Platforms>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<WarningsAsErrors />
|
||||
<LangVersion>7.2</LangVersion>
|
||||
@@ -21,7 +21,8 @@
|
||||
<PackageReference Include="NUnit" Version="3.10.1" />
|
||||
|
||||
<PackageReference Include="QuickFix.Net.NETCore" Version="1.8.1" />
|
||||
<PackageReference Include="QuickFix.Net.NETCore.FIX44" Version="1.8.1" />
|
||||
<PackageReference Include="QuickFix.Net.NETCore.FIX42" Version="1.8.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -30,12 +31,16 @@
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="copy_fix" AfterTargets="PostBuildEvent" >
|
||||
<Copy SourceFiles="./spark_fix.cfg" DestinationFolder="$(OutputPath)\" SkipUnchangedFiles="true" />
|
||||
<Copy SourceFiles="./spark_fix.cfg" DestinationFolder="$(OutputPath)/" SkipUnchangedFiles="true" />
|
||||
<Copy SourceFiles="./spark_algos.json" DestinationFolder="$(OutputPath)/" SkipUnchangedFiles="true" />
|
||||
<Copy SourceFiles="./spec/fix/FIX42.xml" DestinationFolder="$(OutputPath)/spec/fix/" SkipUnchangedFiles="true" />
|
||||
<Copy SourceFiles="./spec/fix/FIX44.xml" DestinationFolder="$(OutputPath)/spec/fix/" SkipUnchangedFiles="true" />
|
||||
</Target>
|
||||
|
||||
<Target Name="copy_fix471" AfterTargets="PostBuildEvent" >
|
||||
<Copy SourceFiles="./spark_fix.cfg" DestinationFolder="$(OutputPath)/../net471" SkipUnchangedFiles="true" />
|
||||
<Copy SourceFiles="./spark_algos.json" DestinationFolder="$(OutputPath)/../net471" SkipUnchangedFiles="true" />
|
||||
<Copy SourceFiles="./spec/fix/FIX42.xml" DestinationFolder="$(OutputPath)/../net471/spec/fix/" SkipUnchangedFiles="true" />
|
||||
<Copy SourceFiles="./spec/fix/FIX44.xml" DestinationFolder="$(OutputPath)/../net471/spec/fix/" SkipUnchangedFiles="true" />
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using bts.api;
|
||||
using MathNet.Numerics.Statistics;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
using bts.co2;
|
||||
|
||||
namespace bts.history
|
||||
{
|
||||
public interface IAlgo
|
||||
{
|
||||
bool is_completed();
|
||||
void set_param(string name, string val);
|
||||
|
||||
void process_book(string security_desc, uint security_key, co2.BookMessage current_book, co2.BookMessage curr_book,
|
||||
MarketDataIncrementalRefresh packet);
|
||||
void process_trades(string security_desc, uint security_key, IEnumerable<co2.TradeMessage> trades,
|
||||
MarketDataIncrementalRefresh packet);
|
||||
}
|
||||
|
||||
abstract public partial class AlgoBase : IAlgo
|
||||
{
|
||||
public readonly Guid guid = Guid.NewGuid();
|
||||
public ulong order_key { get; private set;}
|
||||
|
||||
public string[] security_list { get; private set; }
|
||||
public Action<FillEntry> on_fill;
|
||||
public Action<OrderStatus> on_status;
|
||||
|
||||
protected IOrderSink _sink;
|
||||
public IOrderSink sink => _sink;
|
||||
|
||||
readonly protected SortedDictionary< string, Func<MDEntry, OrderIDEntry, bool> > _filter = new SortedDictionary<string, Func<MDEntry, OrderIDEntry, bool>>();
|
||||
|
||||
protected AlgoBase(IOrderSink sink, string[] security_list)
|
||||
{
|
||||
on_fill = new Action<FillEntry>(f => {});
|
||||
on_status = new Action<OrderStatus>(s => {});
|
||||
this._sink = sink;
|
||||
this.security_list = security_list;
|
||||
foreach (var sec in security_list)
|
||||
_filter[sec] = (MDEntry md, OrderIDEntry id) => md.Symbol == sec;
|
||||
}
|
||||
|
||||
readonly Dictionary<string, string> _algo_params = new Dictionary<string, string>();
|
||||
public IReadOnlyDictionary<string, string> algo_params => _algo_params;
|
||||
public virtual void set_param(string name, string val)
|
||||
{
|
||||
_algo_params[name] = val;
|
||||
var pi = this.GetType().GetProperty(name);
|
||||
if(pi != null)
|
||||
{
|
||||
if(val.Contains(','))
|
||||
{
|
||||
var elem = pi.PropertyType.GetElementType();
|
||||
var ary = val.Split(',').Select(x => Convert.ChangeType(x, elem)).ToArray();
|
||||
var tary = Array.CreateInstance(elem, ary.Length);
|
||||
Array.Copy(ary, tary, ary.Length);
|
||||
pi.SetValue(this, tary);
|
||||
}
|
||||
else
|
||||
pi.SetValue(this, Convert.ChangeType(val, pi.PropertyType));
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void process_book(string security_desc, uint security_key, co2.BookMessage current_book, co2.BookMessage curr_book,
|
||||
MarketDataIncrementalRefresh packet)
|
||||
{
|
||||
if(!_filter.ContainsKey(security_desc))
|
||||
return;
|
||||
on_book(security_desc, security_key, current_book, curr_book, packet);
|
||||
}
|
||||
|
||||
public virtual void process_trades(string security_desc, uint security_key, IEnumerable<co2.TradeMessage> trades,
|
||||
MarketDataIncrementalRefresh packet)
|
||||
{
|
||||
if (!_filter.ContainsKey(security_desc))
|
||||
return;
|
||||
on_trades(security_desc, security_key, trades, packet);
|
||||
}
|
||||
|
||||
public abstract object report();
|
||||
public abstract bool is_completed();
|
||||
|
||||
protected virtual void on_book(string security_desc, uint security_key, co2.BookMessage current_book, co2.BookMessage working_book,
|
||||
MarketDataIncrementalRefresh packet) { }
|
||||
protected virtual void on_trades(string security_desc, uint security_key, IEnumerable<TradeMessage> trades,
|
||||
MarketDataIncrementalRefresh packet) { }
|
||||
|
||||
protected abstract void do_launch(string[] security_list, api.Side side, double price, uint size, Timestamp asof, ulong order_key);
|
||||
|
||||
protected abstract void do_update(Timestamp asof, double price, uint size = uint.MinValue);
|
||||
protected virtual void do_update(Timestamp asof, Dictionary<string, string> algo_params, double price, uint size = uint.MinValue)
|
||||
{
|
||||
foreach (var s in algo_params)
|
||||
this.set_param(s.Key, s.Value);
|
||||
this.do_update(asof, price, size);
|
||||
}
|
||||
protected abstract void do_cancel(Timestamp asof);
|
||||
protected virtual void get_done(Timestamp asof) {}
|
||||
|
||||
public class Handle : IEquatable<Handle>
|
||||
{
|
||||
readonly AlgoBase _algo;
|
||||
public Handle(AlgoBase algo)
|
||||
{
|
||||
_algo = algo;
|
||||
}
|
||||
|
||||
public AlgoBase algo => _algo;
|
||||
public ulong order_key => _algo.order_key;
|
||||
public void launch(string[] security_list, api.Side side, double price, uint size, Timestamp asof, ulong order_key = ulong.MinValue)
|
||||
{
|
||||
if(order_key == ulong.MinValue)
|
||||
order_key = IDGenerator.next_order_id();
|
||||
_algo.do_launch(security_list, side, price, size, asof, order_key);
|
||||
}
|
||||
public void update(Timestamp asof, double price, uint size = uint.MinValue)
|
||||
{
|
||||
_algo.do_update(asof, price, size);
|
||||
}
|
||||
public void update(Timestamp asof, Dictionary<string, string> algo_params, double price, uint size = uint.MinValue)
|
||||
{
|
||||
foreach (var s in algo_params)
|
||||
_algo.set_param(s.Key, s.Value);
|
||||
update(asof, price, size);
|
||||
}
|
||||
public void cancel(Timestamp asof)
|
||||
{
|
||||
_algo.do_cancel(asof);
|
||||
}
|
||||
public void get_done(Timestamp asof)
|
||||
{
|
||||
_algo.get_done(asof);
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.algo.guid.GetHashCode();
|
||||
}
|
||||
public bool Equals(Handle other)
|
||||
{
|
||||
return this.algo.guid == other.algo.guid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using MathNet.Numerics.Statistics;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using bts.api;
|
||||
|
||||
namespace bts.history
|
||||
{
|
||||
public class AlgoFactory
|
||||
{
|
||||
static public AlgoBase algo_factory<AlgoType>(IOrderSink sink,string[] security_list, string algo_params = null)
|
||||
where AlgoType : AlgoBase
|
||||
{
|
||||
return AlgoBase.algo_factory(typeof(AlgoType), sink, security_list, algo_params);
|
||||
}
|
||||
static public void set_algo_params(IAlgo inst, string algo_params)
|
||||
{
|
||||
AlgoBase.set_algo_params((AlgoBase) inst, algo_params);
|
||||
}
|
||||
static public void set_algo_params(IAlgo inst, IEnumerable<string> param)
|
||||
{
|
||||
AlgoBase.set_algo_params((AlgoBase)inst, param);
|
||||
}
|
||||
public static AlgoBase.Handle launch(AlgoBase algo, api.Side side, double price, uint size, Timestamp asof,
|
||||
Action<AlgoBase.Handle, FillEntry> more_on_fill = null,
|
||||
Action<AlgoBase.Handle, OrderStatus> more_on_status = null)
|
||||
{
|
||||
var order_key = IDGenerator.next_order_id();
|
||||
//I am activating myself at the top\
|
||||
var h = new AlgoBase.Handle(algo);
|
||||
h.launch(algo.security_list, side, price, size, asof, order_key);
|
||||
if (more_on_fill != null)
|
||||
algo.on_fill += f => more_on_fill(h, f);
|
||||
if (more_on_status != null)
|
||||
algo.on_status += s => more_on_status(h, s);
|
||||
return h;
|
||||
}
|
||||
}
|
||||
abstract partial class AlgoBase
|
||||
{
|
||||
static public AlgoBase algo_factory(System.Type t, IOrderSink sink,
|
||||
string[] security_list, string algo_params = null)
|
||||
{
|
||||
AlgoBase inst = inst = (AlgoBase)Activator.CreateInstance(t, sink, security_list);
|
||||
|
||||
if(algo_params != null)
|
||||
set_algo_params(inst, algo_params);
|
||||
return inst;
|
||||
}
|
||||
public virtual Handle create<C>(Action<Handle, FillEntry> more_on_fill = null,
|
||||
Action<Handle, OrderStatus> more_on_status = null)
|
||||
where C : AlgoBase
|
||||
{
|
||||
var child = AlgoBase.algo_factory(typeof(C), _sink, security_list);
|
||||
Handle h = hookup_child(child, more_on_fill, more_on_status);
|
||||
return h;
|
||||
}
|
||||
|
||||
protected Handle hookup_child(AlgoBase child, Action<Handle, FillEntry> more_on_fill, Action<Handle, OrderStatus> more_on_status)
|
||||
{
|
||||
child.order_key = order_key;
|
||||
AlgoBase.set_algo_params(child, this.algo_params);
|
||||
child.on_fill += f => this.on_fill(f);
|
||||
//child.on_status += s => this.on_status(s);
|
||||
var h = new Handle(child);
|
||||
if (more_on_fill != null)
|
||||
child.on_fill += (f => more_on_fill(h, f));
|
||||
if (more_on_status != null)
|
||||
child.on_status += (s => more_on_status(h, s));
|
||||
|
||||
return h;
|
||||
}
|
||||
static public void set_algo_params(AlgoBase inst, string algo_params)
|
||||
{
|
||||
string[] param = algo_params.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
set_algo_params(inst, param);
|
||||
}
|
||||
static public void set_algo_params(AlgoBase inst, IEnumerable<string> param)
|
||||
{
|
||||
foreach (var par in param)
|
||||
{
|
||||
string[] tup = par.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
Log.assert(tup.Length == 2);
|
||||
inst.set_param(tup[0], tup[1]);
|
||||
}
|
||||
}
|
||||
static public void set_algo_params(AlgoBase inst, IReadOnlyDictionary<string, string> param)
|
||||
{
|
||||
foreach (var par in param)
|
||||
inst.set_param(par.Key, par.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using mbts.co2;
|
||||
|
||||
using bts.api;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using MathNet.Numerics.Statistics;
|
||||
|
||||
namespace bts.history
|
||||
{
|
||||
public class CompletionCoverAlgo<Child, Hedge> : CompositeHedgeAlgo<Child, Hedge>
|
||||
where Child : AlgoBase
|
||||
where Hedge : AlgoBase
|
||||
{
|
||||
public CompletionCoverAlgo(IOrderSink sink, string[] security_list) : base(sink, security_list) { }
|
||||
|
||||
string[] _security_list;
|
||||
Side _myside;
|
||||
double _myprice;
|
||||
uint _mysize;
|
||||
|
||||
//algo parameters
|
||||
public double hedge_ticks { get; set; } = 0.0;
|
||||
public double hedge_factor { get; set; } = 1.0;
|
||||
|
||||
protected override void do_launch(string[] security_list, Side side, double price, uint size, Timestamp asof, ulong order_key)
|
||||
{
|
||||
_security_list = security_list;
|
||||
_myside = side;
|
||||
_myprice = price;
|
||||
_mysize = size;
|
||||
_child = this.create<Child>();
|
||||
_child.launch(security_list, side, price, size, asof);
|
||||
}
|
||||
|
||||
protected override void on_child_status(Handle child, OrderStatus stat)
|
||||
{
|
||||
if(_child?.Equals(child) ?? false)
|
||||
{
|
||||
if(stat.state.Status == api.orderman.OrderStatus.Completed)
|
||||
{
|
||||
var side = Utils.opposite_side(_myside);
|
||||
uint size = (uint)(_mysize * this.hedge_factor);
|
||||
double price = (side == Side.Buy) ?
|
||||
_myprice - this.hedge_ticks :
|
||||
_myprice + this.hedge_ticks;
|
||||
|
||||
send_hedge(_security_list, side, price, size, stat.TransactTime, null,
|
||||
(status_handle, status_entry) => { this.on_status?.Invoke(status_entry); }
|
||||
);
|
||||
}
|
||||
this.on_status?.Invoke(stat);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void do_update(Timestamp asof, double price, uint size = uint.MinValue)
|
||||
{
|
||||
_child.update(asof, price, size);
|
||||
}
|
||||
|
||||
protected override void do_cancel(Timestamp asof)
|
||||
{
|
||||
_child.cancel(asof);
|
||||
}
|
||||
|
||||
protected override void on_child_fill(Handle child, FillEntry fill)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MathNet.Numerics.Statistics;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
namespace bts.history
|
||||
{
|
||||
public abstract class CompositeBase<Child, Hedge> : AlgoBase
|
||||
where Hedge : AlgoBase
|
||||
{
|
||||
protected List<Handle> _children = new List<Handle>();
|
||||
protected Handle _child
|
||||
{
|
||||
get
|
||||
{
|
||||
Log.assert(_children.Count <= 1);
|
||||
return _children.FirstOrDefault();
|
||||
}
|
||||
set
|
||||
{
|
||||
Log.assert(_children.Count <= 1);
|
||||
if(value == null)
|
||||
{
|
||||
if(_children.Count == 1)
|
||||
_children.RemoveAt(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_children.Count == 0)
|
||||
_children.Add(value);
|
||||
else
|
||||
_children[0] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
public CompositeBase(IOrderSink sink, string[] security_list) : base(sink, security_list)
|
||||
{
|
||||
}
|
||||
|
||||
public override Handle create<C>(Action<Handle, FillEntry> more_on_fill = null,
|
||||
Action<Handle, OrderStatus> more_on_status = null)
|
||||
{
|
||||
if(typeof(C) == this.GetType())
|
||||
{
|
||||
Log.assert(false);
|
||||
return null;
|
||||
//return AlgoBase.activate_self(this, side, price, size, asof, more_on_fill, more_on_status);
|
||||
}
|
||||
else
|
||||
{
|
||||
Action<Handle, FillEntry> of = new Action<Handle, FillEntry>((h, f) => on_child_fill(h, f));
|
||||
if (more_on_fill != null)
|
||||
of += more_on_fill;
|
||||
Action<Handle, OrderStatus> os = new Action<Handle, OrderStatus>((h, s) =>
|
||||
{
|
||||
on_child_status(h, s);
|
||||
if (s.is_terminal())
|
||||
_children.Remove(h);
|
||||
});
|
||||
if (more_on_status != null)
|
||||
os += more_on_status;
|
||||
|
||||
var handle = base_create<C>(of, os);
|
||||
_children.Add(handle);
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
|
||||
protected Handle base_create<C>(Action<Handle, FillEntry> of, Action<Handle, OrderStatus> os)
|
||||
where C : AlgoBase
|
||||
{
|
||||
return base.create<C>(of, os);
|
||||
}
|
||||
|
||||
protected override void do_update(Timestamp asof, double price, uint size = uint.MinValue)
|
||||
{
|
||||
foreach(var child in _children.ToArray())
|
||||
child?.update(asof, price, size);
|
||||
}
|
||||
|
||||
protected override void get_done(Timestamp asof)
|
||||
{
|
||||
base.get_done(asof);
|
||||
foreach (var child in _children.ToArray())
|
||||
child?.get_done(asof);
|
||||
}
|
||||
|
||||
protected override void do_cancel(Timestamp asof)
|
||||
{
|
||||
foreach (var child in _children.ToArray())
|
||||
child?.cancel(asof);
|
||||
}
|
||||
protected virtual void on_child_fill(Handle child, FillEntry fill) { }
|
||||
|
||||
protected abstract void on_child_status(Handle child, OrderStatus stat);
|
||||
}
|
||||
|
||||
public abstract class CompositeAlgo<Child> : CompositeBase<Child, NullAlgo>
|
||||
{
|
||||
public CompositeAlgo(IOrderSink sink, string[] security_list) : base(sink, security_list) { }
|
||||
|
||||
public override bool is_completed()
|
||||
{
|
||||
bool comp = true;
|
||||
foreach (var child in _children)
|
||||
comp &= child.algo.is_completed();
|
||||
return comp;
|
||||
}
|
||||
|
||||
public override object report()
|
||||
{
|
||||
string c = "";
|
||||
foreach (var child in _children)
|
||||
c+= child.algo.report();
|
||||
return $"{c}";
|
||||
}
|
||||
|
||||
public override void set_param(string name, string val)
|
||||
{
|
||||
base.set_param(name, val);
|
||||
foreach (var child in _children)
|
||||
child?.algo.set_param(name, val);
|
||||
}
|
||||
|
||||
public override void process_book(string security_desc, uint security_key, co2.BookMessage current_book, co2.BookMessage working_book,
|
||||
MarketDataIncrementalRefresh packet)
|
||||
{
|
||||
base.process_book(security_desc, security_key, current_book, working_book, packet);
|
||||
foreach (var child in _children.ToArray()) //copy because this could remove / add a child
|
||||
child?.algo.process_book(security_desc, security_key, current_book, working_book, packet);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class CompositeHedgeAlgo<Child, Hedge> : CompositeBase<Child, Hedge>
|
||||
where Hedge : AlgoBase
|
||||
{
|
||||
protected int _payupcount;
|
||||
protected Dictionary<Handle, Hedge> _hedges = new Dictionary<Handle, Hedge>();
|
||||
public CompositeHedgeAlgo(IOrderSink sink, string[] security_list) : base(sink, security_list) {}
|
||||
|
||||
public override bool is_completed()
|
||||
{
|
||||
bool comp = true;
|
||||
foreach (var child in _children)
|
||||
comp &= child.algo.is_completed();
|
||||
foreach (var sub in _hedges.Values)
|
||||
{
|
||||
var hc = sub.is_completed();
|
||||
if(!hc)
|
||||
Log.assert(true);
|
||||
comp &= hc;
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
protected override void get_done(Timestamp asof)
|
||||
{
|
||||
base.get_done(asof);
|
||||
foreach (var child in _children.ToArray())
|
||||
child?.get_done(asof);
|
||||
foreach (var sub in _hedges.Keys.ToArray())
|
||||
sub.get_done(asof);
|
||||
}
|
||||
|
||||
public override object report()
|
||||
{
|
||||
string c = "";
|
||||
foreach (var child in _children)
|
||||
c+= child.algo.report();
|
||||
|
||||
int ih = 0;
|
||||
string sh = string.Empty;
|
||||
foreach (var sub in _hedges.Values)
|
||||
{
|
||||
if(sub.report() is string sr)
|
||||
sh += sr;
|
||||
if(sub.report() is int ir)
|
||||
ih += ir;
|
||||
}
|
||||
return $"{c} Hedge Payups {sh} {ih+_payupcount} Incomplete {_hedges.Values.Sum( x => x.is_completed() ? 0u : 1u) } ";
|
||||
}
|
||||
|
||||
public override void set_param(string name, string val)
|
||||
{
|
||||
base.set_param(name, val);
|
||||
foreach (var child in _children)
|
||||
child?.algo.set_param(name, val);
|
||||
foreach (var sub in _hedges.Values)
|
||||
sub.set_param(name, val);
|
||||
}
|
||||
|
||||
public override void process_book(string security_desc, uint security_key, co2.BookMessage current_book, co2.BookMessage working_book,
|
||||
MarketDataIncrementalRefresh packet)
|
||||
{
|
||||
base.process_book(security_desc, security_key, current_book, working_book, packet);
|
||||
foreach (var child in _children.ToArray())
|
||||
child?.algo.process_book(security_desc, security_key, current_book, working_book, packet);
|
||||
foreach (var sub in _hedges.Values.ToArray())
|
||||
sub.process_book(security_desc, security_key, current_book, working_book, packet);
|
||||
}
|
||||
|
||||
public override Handle create<C>(Action<Handle, FillEntry> more_on_fill = null,
|
||||
Action<Handle, OrderStatus> more_on_status = null)
|
||||
{
|
||||
if (typeof(Hedge) == typeof(C))
|
||||
{
|
||||
Action<Handle, FillEntry> of = new Action<Handle, FillEntry>((h, f) => {} );
|
||||
if (more_on_fill != null)
|
||||
of += more_on_fill;
|
||||
Action<Handle, OrderStatus> os = new Action<Handle, OrderStatus>((h, s) => {} );
|
||||
if (more_on_status != null)
|
||||
os += more_on_status;
|
||||
|
||||
var handle = base_create<Hedge>(of, os);
|
||||
_hedges[handle] = (Hedge)handle.algo;
|
||||
return handle;
|
||||
}
|
||||
else
|
||||
return base.create<C>(more_on_fill, more_on_status);
|
||||
}
|
||||
|
||||
protected void send_hedge(string security_desc, api.Side side, double price, uint size, Timestamp asof,
|
||||
Action<Handle, FillEntry> more_on_fill = null,
|
||||
Action<Handle, OrderStatus> more_on_status = null)
|
||||
{
|
||||
send_hedge(new[] { security_desc }, side, price, size, asof, more_on_fill, more_on_status);
|
||||
}
|
||||
|
||||
protected void send_hedge(string[] security_list, api.Side side, double price, uint size, Timestamp asof,
|
||||
Action<Handle, FillEntry> more_on_fill = null,
|
||||
Action<Handle, OrderStatus> more_on_status = null)
|
||||
{
|
||||
Action<Handle, FillEntry> hedge_on_fill = (hand, f) =>
|
||||
{
|
||||
if(more_on_fill != null)
|
||||
more_on_fill(hand, f);
|
||||
if (f.fully_filled)
|
||||
{
|
||||
if (_hedges.TryGetValue(hand, out Hedge h))
|
||||
{
|
||||
if (h.report() is int pay)
|
||||
_payupcount += pay;
|
||||
_hedges.Remove(hand);
|
||||
}
|
||||
}
|
||||
};
|
||||
Action<Handle, OrderStatus> hedge_on_status = (hand,s) =>
|
||||
{
|
||||
if(more_on_status != null)
|
||||
more_on_status(hand, s);
|
||||
if (s.is_terminal())
|
||||
_hedges.Remove(hand);
|
||||
};
|
||||
|
||||
var handle = this.create<Hedge>(hedge_on_fill, hedge_on_status);
|
||||
handle.launch(security_list, side, price, size, asof);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using mbts.co2;
|
||||
|
||||
using bts.api;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using MathNet.Numerics.Statistics;
|
||||
|
||||
namespace bts.history
|
||||
{
|
||||
public class CoverAlgo<Child, Hedge> : CompositeHedgeAlgo<Child, Hedge>
|
||||
where Child : AlgoBase
|
||||
where Hedge : AlgoBase
|
||||
{
|
||||
public CoverAlgo(IOrderSink sink, string[] security_list) : base(sink, security_list) { }
|
||||
|
||||
//algo state
|
||||
private MarketDataIncrementalRefresh _packet;
|
||||
string[] _security_list;
|
||||
|
||||
//algo parameters
|
||||
public double hedge_ticks { get; set; } = 0.0;
|
||||
public double hedge_factor { get; set; } = 1.0;
|
||||
|
||||
protected override void do_launch(string[] security_list, Side side, double price, uint size, Timestamp asof, ulong order_key)
|
||||
{
|
||||
_security_list = security_list;
|
||||
_child = this.create<Child>();
|
||||
_child.launch(security_list, side, price, size, asof);
|
||||
}
|
||||
|
||||
protected override void on_child_status(Handle child, OrderStatus stat)
|
||||
{
|
||||
if(_child?.Equals(child) ?? false)
|
||||
this.on_status?.Invoke(stat);
|
||||
}
|
||||
|
||||
protected override void do_update(Timestamp asof, double price, uint size = uint.MinValue)
|
||||
{
|
||||
_child.update(asof, price, size);
|
||||
}
|
||||
|
||||
protected override void do_cancel(Timestamp asof)
|
||||
{
|
||||
_child.cancel(asof);
|
||||
}
|
||||
|
||||
protected override void on_book(string security_desc, uint security_key, co2.BookMessage current_book, co2.BookMessage working_book,
|
||||
MarketDataIncrementalRefresh packet)
|
||||
{
|
||||
_packet = packet;
|
||||
}
|
||||
|
||||
protected override void on_child_fill(Handle child, FillEntry fill)
|
||||
{
|
||||
if(!child.Equals(_child))
|
||||
return;
|
||||
|
||||
base.on_child_fill(child, fill);
|
||||
|
||||
var side = Utils.opposite_side(fill.order.side);
|
||||
uint size = (uint)(fill.size*this.hedge_factor);
|
||||
double price = (side == Side.Buy) ?
|
||||
fill.price - this.hedge_ticks :
|
||||
fill.price + this.hedge_ticks;
|
||||
|
||||
send_hedge(fill.order.security_desc, side, price, size, fill.TransactTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
|
||||
namespace bts.history
|
||||
{
|
||||
static class IDGenerator
|
||||
{
|
||||
static uint __myid = 999_999;
|
||||
static public uint next_order_id()
|
||||
{
|
||||
return (++__myid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
|
||||
using System;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using MathNet.Numerics.Statistics;
|
||||
using mbts.co2;
|
||||
|
||||
namespace bts.history
|
||||
{
|
||||
public class JoinAlgo<Child> : CompositeAlgo<Child>
|
||||
where Child : AlgoBase
|
||||
{
|
||||
enum AlgoState
|
||||
{
|
||||
Begin, WaitingForJoin, Joined, Done
|
||||
}
|
||||
|
||||
//algo state
|
||||
AlgoState _state;
|
||||
OrderStatus _status;
|
||||
api.Side _myside;
|
||||
uint _mysize;
|
||||
Timestamp _myasof;
|
||||
|
||||
co2.BookMessage _snapshot, _currentbook;
|
||||
int _turncount, _pilecount;
|
||||
|
||||
public JoinAlgo(IOrderSink sink, string[] security_list) : base(sink, security_list) { }
|
||||
//algo parameters
|
||||
public bool initial_pile { get; set; } = false;
|
||||
public bool should_chase { get; set; } = true;
|
||||
public double join_factor { get; set; } = 1.0;
|
||||
public uint join_quantity{ get; set; } = 0;
|
||||
|
||||
|
||||
protected override void do_launch(string[] security_list, api.Side side, double price, uint size, Timestamp asof, ulong order_key)
|
||||
{
|
||||
_state = AlgoState.Begin;
|
||||
_myside = side;
|
||||
_mysize = size;
|
||||
_myasof = asof;
|
||||
_child = null;
|
||||
}
|
||||
|
||||
public override bool is_completed()
|
||||
{
|
||||
return _state == AlgoState.Done;
|
||||
}
|
||||
|
||||
public override object report()
|
||||
{
|
||||
var b = base.report();
|
||||
return $"{b} Turns,Piles,Join(Size,Price,piq)={_turncount},{_pilecount},({_status?.state?.Quantity},{_status?.state?.Price})";
|
||||
}
|
||||
|
||||
protected override void on_child_status(Handle child, OrderStatus stat)
|
||||
{
|
||||
_status = stat;
|
||||
if(stat.is_terminal())
|
||||
_state = AlgoState.Done;
|
||||
this.on_status?.Invoke(_status);
|
||||
}
|
||||
|
||||
bool has_turned()
|
||||
{
|
||||
bool turn = ((_myside == api.Side.Buy &&
|
||||
_currentbook.side_at(_myside, 0) > _snapshot.side_at(_myside, 0)) || //new top level bid price greater than old, market turn
|
||||
(_myside == api.Side.Sell &&
|
||||
_currentbook.side_at(_myside, 0) < _snapshot.side_at(_myside, 0))); //new top level ask price less than old, market turn
|
||||
return turn;
|
||||
}
|
||||
|
||||
protected override void on_book(string security_desc, uint security_key, co2.BookMessage current_book, co2.BookMessage working_book,
|
||||
MarketDataIncrementalRefresh packet)
|
||||
{
|
||||
if(_snapshot == null)
|
||||
_snapshot = current_book.Clone();
|
||||
_currentbook = current_book;
|
||||
switch (_state)
|
||||
{
|
||||
case AlgoState.Begin:
|
||||
{
|
||||
if(initial_pile)
|
||||
{
|
||||
var thresh = (this.join_quantity > 0 ? this.join_quantity : this.join_factor * _mysize);
|
||||
if(_currentbook.sidesize_at(_myside, 0) >= thresh)
|
||||
{
|
||||
_pilecount++;
|
||||
deploy_join_function(packet, security_desc, _currentbook.side_at(_myside, 0));
|
||||
_state = AlgoState.Joined;
|
||||
_snapshot = _currentbook.Clone();
|
||||
}
|
||||
}
|
||||
else
|
||||
_state = AlgoState.WaitingForJoin;
|
||||
}
|
||||
break;
|
||||
case AlgoState.WaitingForJoin:
|
||||
{
|
||||
bool turn = has_turned();
|
||||
var thresh = (this.join_quantity > 0 ? this.join_quantity : this.join_factor * _mysize);
|
||||
if(turn &&_currentbook.sidesize_at(_myside, 0) >= thresh)
|
||||
{
|
||||
_turncount++;
|
||||
deploy_join_function(packet, security_desc, _currentbook.side_at(_myside, 0));
|
||||
_state = AlgoState.Joined;
|
||||
}
|
||||
_snapshot = _currentbook.Clone();
|
||||
}
|
||||
break;
|
||||
case AlgoState.Joined:
|
||||
{
|
||||
if (this.should_chase)
|
||||
{
|
||||
bool turn = has_turned();
|
||||
var thresh = (this.join_quantity > 0 ? this.join_quantity : this.join_factor * _mysize);
|
||||
if (turn && _currentbook.sidesize_at(_myside, 0) >= thresh)
|
||||
{
|
||||
_turncount++;
|
||||
deploy_join_function(packet, security_desc, _currentbook.side_at(_myside, 0));
|
||||
_snapshot = _currentbook.Clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AlgoState.Done:
|
||||
break;
|
||||
default:
|
||||
Log.assert(false, "invalid algo state");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void deploy_join_function(MarketDataIncrementalRefresh packet, string security_desc, double joinprice)
|
||||
{
|
||||
Log.Testing.info("deploy_join_function ");
|
||||
if(_currentbook.bid_at(0) == _currentbook.ask_at(0))
|
||||
{
|
||||
Log.Testing.error("crossed book");
|
||||
return;
|
||||
}
|
||||
if(_child == null)
|
||||
{
|
||||
_child = this.create<Child>();
|
||||
_child.launch(new[] { security_desc }, _myside, joinprice, _mysize, packet.timestamp());
|
||||
}
|
||||
else
|
||||
{
|
||||
_child.update(packet.timestamp(), joinprice);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using mbts.co2;
|
||||
using System.Linq;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using MathNet.Numerics.Statistics;
|
||||
|
||||
namespace bts.history
|
||||
{
|
||||
public class LeanAlgo<Child> : CompositeAlgo<Child>
|
||||
where Child : AlgoBase
|
||||
{
|
||||
enum AlgoState
|
||||
{
|
||||
LeanWatch, Payup, Done
|
||||
}
|
||||
|
||||
//algo state
|
||||
AlgoState _state;
|
||||
OrderStatus _status;
|
||||
api.Side _myside;
|
||||
double _myprice;
|
||||
uint _mysize;
|
||||
|
||||
co2.BookMessage _snapshot, _currentbook;
|
||||
int _payupcount;
|
||||
|
||||
public LeanAlgo(IOrderSink sink, string[] security_list) : base(sink, security_list) { }
|
||||
//algo parameters
|
||||
public double lean_factor { get; set; } = 3.0;
|
||||
public uint lean_quantity { get; set; } = 0;
|
||||
|
||||
protected override void do_launch(string[] security_list, api.Side side, double price, uint size, Timestamp asof, ulong order_key)
|
||||
{
|
||||
_state = AlgoState.LeanWatch;
|
||||
_myside = side;
|
||||
_mysize = size;
|
||||
_myprice = price;
|
||||
_child = this.create<Child>();
|
||||
_child.launch(security_list, side, price, size, asof);
|
||||
}
|
||||
|
||||
public override bool is_completed()
|
||||
{
|
||||
return _state == AlgoState.Done;
|
||||
}
|
||||
|
||||
public override object report()
|
||||
{
|
||||
return _payupcount;
|
||||
}
|
||||
|
||||
protected override void on_child_status(Handle child, OrderStatus stat)
|
||||
{
|
||||
_status = stat;
|
||||
if (stat.is_terminal())
|
||||
_state = AlgoState.Done;
|
||||
this.on_status?.Invoke(_status);
|
||||
}
|
||||
|
||||
protected override void on_book(string security_desc, uint security_key, co2.BookMessage current_book, co2.BookMessage working_book,
|
||||
MarketDataIncrementalRefresh packet)
|
||||
{
|
||||
if (_snapshot == null)
|
||||
_snapshot = current_book.Clone();
|
||||
_currentbook = current_book;
|
||||
|
||||
switch (_state)
|
||||
{
|
||||
case AlgoState.LeanWatch:
|
||||
{
|
||||
bool payupprice = false, payupsize = false;
|
||||
var leansize = (this.lean_quantity == 0) ? this.lean_factor * this._mysize : this.lean_quantity;
|
||||
if (_myside == api.Side.Buy)
|
||||
{
|
||||
double best_ask = _snapshot.ask_at(0);
|
||||
var best_ask_size = _snapshot.asksize_at(0);
|
||||
payupprice = _currentbook.ask_at(0) > best_ask;
|
||||
payupsize = best_ask_size < leansize;
|
||||
}
|
||||
else
|
||||
{
|
||||
double best_bid = _snapshot.bid_at(0);
|
||||
var best_bid_size = _snapshot.bidsize_at(0);
|
||||
payupprice = _currentbook.bid_at(0) < best_bid;
|
||||
payupsize = best_bid_size < leansize;
|
||||
}
|
||||
if (payupprice || payupsize)
|
||||
{
|
||||
_payupcount++;
|
||||
_state = AlgoState.Payup;
|
||||
payup_function(packet.timestamp());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AlgoState.Payup:
|
||||
break;
|
||||
case AlgoState.Done:
|
||||
break;
|
||||
default:
|
||||
Log.assert(false, "invalid algo state");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void get_done(Timestamp asof)
|
||||
{
|
||||
payup_function(asof);
|
||||
}
|
||||
|
||||
void payup_function(Timestamp asof)
|
||||
{
|
||||
double newprice = 0.0;
|
||||
//plow through
|
||||
if (_myside == api.Side.Sell)
|
||||
newprice = _currentbook.all_bids().Min();
|
||||
else
|
||||
newprice = _currentbook.all_asks().Max();
|
||||
//this should precipitate a fill
|
||||
_child.update(asof, newprice);
|
||||
Log.Testing.info($"payup_function ");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using bts.api;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using MathNet.Numerics.Statistics;
|
||||
|
||||
namespace bts.history
|
||||
{
|
||||
public class LimitOrder : AlgoBase
|
||||
{
|
||||
public LimitOrder(IOrderSink sink, string[] security_list) : base(sink, security_list) { }
|
||||
|
||||
protected OrderEntry _myorder;
|
||||
OrderStatus _status;
|
||||
uint _mysize;
|
||||
double _debug_price;
|
||||
|
||||
public override object report() { return string.Empty; }
|
||||
|
||||
protected override void do_launch(string[] security_list, api.Side side, double price, uint size, Timestamp asof, ulong order_key)
|
||||
{
|
||||
setup_order(security_list, side, price, size, asof, order_key);
|
||||
_sink.send(_myorder);
|
||||
}
|
||||
|
||||
protected void setup_order(string[] security_list, Side side, double price, uint size, Timestamp asof, ulong order_key)
|
||||
{
|
||||
_debug_price = price;
|
||||
_mysize = size;
|
||||
Log.assert(security_list.Length == 1);
|
||||
var security_desc = security_list[0];
|
||||
Action<FillEntry> fill_action = f =>
|
||||
{
|
||||
if (this.on_fill != null)
|
||||
this.on_fill(f);
|
||||
};
|
||||
Action<OrderStatus> status_action = s =>
|
||||
{
|
||||
_status = s;
|
||||
if (this.on_status != null)
|
||||
this.on_status(s.clone());
|
||||
};
|
||||
Log.assert(_myorder == null);
|
||||
_myorder = new OrderEntry(asof, order_key, security_desc, side, price, size, fill_action, status_action);
|
||||
}
|
||||
|
||||
protected override void do_update(Timestamp asof, double price, uint size = uint.MinValue)
|
||||
{
|
||||
if(size == _mysize)
|
||||
size = uint.MinValue;
|
||||
_debug_price = price;
|
||||
_sink.update(_myorder.security_desc, asof, _myorder.order_id, price, size);
|
||||
}
|
||||
protected override void do_cancel(Timestamp asof)
|
||||
{
|
||||
if(_myorder == null)
|
||||
return;
|
||||
_sink.cancel(_myorder.security_desc, asof, _myorder.order_id);
|
||||
}
|
||||
|
||||
public override bool is_completed() => _status?.is_terminal() ?? false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using bts.api;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using MathNet.Numerics.Statistics;
|
||||
|
||||
namespace bts.history
|
||||
{
|
||||
public class MarketOrder : LimitOrder
|
||||
{
|
||||
public MarketOrder(IOrderSink sink, string[] security_list) : base(sink, security_list) { }
|
||||
|
||||
protected override void do_launch(string[] security_list, api.Side side, double price, uint size, Timestamp asof, ulong order_key)
|
||||
{
|
||||
setup_order(security_list, side, price, size, asof, order_key);
|
||||
_myorder.market_order = true;
|
||||
_sink.send(_myorder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace bts.history
|
||||
{
|
||||
static class AlgoTestNativeMethods
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
internal unsafe delegate void child_launch_callback(byte* OrderDefinition, ulong length, uint order_key, double price, uint size);
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
internal unsafe delegate void child_update_callback(byte* Update, ulong length, uint order_key);
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
internal unsafe delegate void child_cancel_callback(uint order_key);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
internal unsafe delegate void child_status_callback(byte* OrderState, ulong length, uint order_key);
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
internal unsafe delegate void child_fill_callback(byte* Fill, ulong length, uint order_key);
|
||||
|
||||
[DllImport("libspark")]
|
||||
internal static extern IntPtr try_create_algo(api.orderman.CustomOrderDefinition.CustomOneofCase algo_type);
|
||||
|
||||
[DllImport("libspark")]
|
||||
internal static extern IntPtr create_algo_driver(byte[] Security, int seclength,
|
||||
byte[] OrderDefinition, int deflength,
|
||||
child_launch_callback launch_cb,
|
||||
child_update_callback update_cb,
|
||||
child_cancel_callback cancel_cb,
|
||||
|
||||
child_status_callback stat_cb,
|
||||
child_fill_callback fill_cb);
|
||||
[DllImport("libspark")]
|
||||
internal static extern void destroy_algo_driver(IntPtr algo_driver);
|
||||
[DllImport("libspark")]
|
||||
internal static extern void destroy_algo(IntPtr algo_driver);
|
||||
|
||||
[DllImport("libspark")]
|
||||
internal static extern void launch_algo(IntPtr algo_driver, uint order_key, double price, uint size);
|
||||
|
||||
[DllImport("libspark")]
|
||||
internal static extern void update_price(IntPtr algo_driver, double price);
|
||||
[DllImport("libspark")]
|
||||
internal static extern void update_size(IntPtr algo_driver, uint size);
|
||||
[DllImport("libspark")]
|
||||
internal static extern void cancel(IntPtr algo_driver);
|
||||
|
||||
|
||||
[DllImport("libspark")]
|
||||
internal static extern void advance_time(IntPtr algo_driver, ulong microsecond, uint steps);
|
||||
[DllImport("libspark")]
|
||||
internal static extern void update_book(IntPtr algo_driver, uint security_id, byte[] BookMessage, int length);
|
||||
[DllImport("libspark")]
|
||||
internal static extern void update_ticker(IntPtr algo_driver, uint security_id, byte[] TradeMessage, int length);
|
||||
|
||||
[DllImport("libspark")]
|
||||
internal static extern void fill(IntPtr algo_driver, uint order_key, double price, uint quantity);
|
||||
|
||||
|
||||
//see AlgoTestDriver.h
|
||||
internal enum AlgoDriverState
|
||||
{
|
||||
CREATED,
|
||||
// before_Launch() ->
|
||||
READY,
|
||||
// launch() ->
|
||||
RUNNING,
|
||||
CANCELED,
|
||||
TERMINATED,
|
||||
COMPLETED
|
||||
};
|
||||
|
||||
[DllImport("libspark")]
|
||||
internal static extern AlgoDriverState algo_driver_state(IntPtr algo_driver);
|
||||
|
||||
internal static bool state_is_terminal(AlgoDriverState st)
|
||||
{
|
||||
return st == AlgoDriverState.CANCELED || st == AlgoDriverState.TERMINATED || st == AlgoDriverState.COMPLETED;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,320 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using MathNet.Numerics.Statistics;
|
||||
using mbts.co2;
|
||||
|
||||
namespace bts.history
|
||||
{
|
||||
public class NativeAlgo : CompositeAlgo<AlgoBase>
|
||||
{
|
||||
readonly Dictionary<ulong, api.orderman.OrderState> _order_key_vs_state = new Dictionary<ulong, api.orderman.OrderState>();
|
||||
api.Side _myside;
|
||||
double _myprice;
|
||||
uint _mysize;
|
||||
Timestamp _myasof;
|
||||
|
||||
api.Security _sec;
|
||||
readonly api.orderman.OrderDefinition _def;
|
||||
IntPtr _proxy;
|
||||
|
||||
readonly AlgoTestNativeMethods.child_launch_callback _launchcb;
|
||||
readonly AlgoTestNativeMethods.child_update_callback _updatecb;
|
||||
readonly AlgoTestNativeMethods.child_cancel_callback _cancelcb;
|
||||
|
||||
readonly AlgoTestNativeMethods.child_status_callback _statcb;
|
||||
readonly AlgoTestNativeMethods.child_fill_callback _fillcb;
|
||||
|
||||
MessageParser<api.orderman.OrderDefinition> _defparser = new MessageParser<api.orderman.OrderDefinition>(() => new api.orderman.OrderDefinition());
|
||||
MessageParser<api.orderman.Update> _updateparser = new MessageParser<api.orderman.Update>(() => new api.orderman.Update());
|
||||
MessageParser<api.orderman.OrderState> _stateparser = new MessageParser<api.orderman.OrderState>(() => new api.orderman.OrderState());
|
||||
MessageParser<api.orderman.Fill> _fillparser = new MessageParser<api.orderman.Fill>(() => new api.orderman.Fill());
|
||||
OrderEntry _fake_order_for_status;
|
||||
|
||||
|
||||
public NativeAlgo(IOrderSink sink, string[] security_list,
|
||||
api.orderman.OrderDefinition def) : base(sink, security_list)
|
||||
{
|
||||
_def = def;
|
||||
unsafe
|
||||
{
|
||||
_launchcb =
|
||||
(byte * OrderDefinition, ulong length, uint order_key, double price, uint size) => {
|
||||
on_native_launch(OrderDefinition, length, order_key, price, size); } ;
|
||||
_updatecb =
|
||||
(byte* Update, ulong length, uint order_key) => {
|
||||
on_native_update(Update, length, order_key); };
|
||||
_cancelcb =
|
||||
(uint order_key) => {
|
||||
on_native_cancel(order_key); };
|
||||
|
||||
_statcb =
|
||||
(byte * OrderState, ulong length, uint order_key) => {
|
||||
on_native_status(OrderState, length, order_key); } ;
|
||||
_fillcb =
|
||||
(byte * Fill, ulong length, uint order_key) => {
|
||||
on_native_fill(Fill, length, order_key); } ;
|
||||
}
|
||||
init_proxy(security_list);
|
||||
}
|
||||
|
||||
void init_proxy(string[] security_list)
|
||||
{
|
||||
Log.assert(security_list != null && security_list.Length == 1);
|
||||
_sec = new api.Security { Id = _def.SecurityKey, Symbol = security_list[0] };
|
||||
if (_sec.Symbol.Contains(':') || _sec.Symbol.Contains('-'))
|
||||
_sec.Spread = new api.SpreadContract() { Normalized = true };
|
||||
else
|
||||
_sec.Future = new api.FutureContract();
|
||||
reset();
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
if(_proxy != IntPtr.Zero)
|
||||
{
|
||||
AlgoTestNativeMethods.destroy_algo_driver(_proxy);
|
||||
_order_key_vs_state.Clear();
|
||||
}
|
||||
|
||||
var secser = _sec.ToByteArray();
|
||||
var defser = _def.ToByteArray();
|
||||
_proxy = AlgoTestNativeMethods.create_algo_driver(secser, secser.Length, defser, defser.Length,
|
||||
_launchcb, _updatecb, _cancelcb,
|
||||
_statcb, _fillcb);
|
||||
Log.assert(_proxy != IntPtr.Zero);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void do_launch(string[] security_list, api.Side side, double price, uint size, Timestamp asof, ulong order_key)
|
||||
{
|
||||
Log.assert(security_list != null && security_list.Length == 1);
|
||||
Log.assert(side == _def.Side);
|
||||
_myside = side;
|
||||
_myprice = price;
|
||||
_mysize = size;
|
||||
_myasof = asof;
|
||||
AlgoTestNativeMethods.launch_algo(_proxy, (uint)order_key, price, size);
|
||||
_fake_order_for_status = new OrderEntry(asof, order_key, security_list[0], side, price, size, null, null, "Native");
|
||||
}
|
||||
|
||||
Handle hookup_child(AlgoBase child, string[] security_list, api.Side side,
|
||||
double price, uint size, Timestamp asof, uint order_key)
|
||||
{
|
||||
Action<Handle, FillEntry> of = new Action<Handle, FillEntry>((h, f) =>
|
||||
on_child_fill(h, f));
|
||||
Action<Handle, OrderStatus> os = new Action<Handle, OrderStatus>((h, s) =>
|
||||
{
|
||||
on_child_status(h, s);
|
||||
if (s.is_terminal())
|
||||
_children.Remove(h);
|
||||
});
|
||||
var handle = this.hookup_child(child, of, os);
|
||||
_children.Add(handle);
|
||||
handle.launch(security_list, side, price, size, asof, order_key);
|
||||
return handle;
|
||||
}
|
||||
|
||||
// callback when this child launches other guys
|
||||
unsafe void on_native_launch(byte* OrderDefinition, ulong length, uint order_key, double price, uint size)
|
||||
{
|
||||
byte[] arr = new byte[length];
|
||||
Marshal.Copy((IntPtr)OrderDefinition, arr, 0, (int)length);
|
||||
|
||||
api.orderman.OrderDefinition def = _defparser.ParseFrom(arr);
|
||||
switch(def.CustomDef.CustomCase)
|
||||
{
|
||||
case api.orderman.CustomOrderDefinition.CustomOneofCase.Market:
|
||||
{
|
||||
var child = AlgoBase.algo_factory(typeof(MarketOrder), _sink, this.security_list);
|
||||
hookup_child(child, this.security_list, def.Side, price, size, _myasof, order_key);
|
||||
}
|
||||
break;
|
||||
case api.orderman.CustomOrderDefinition.CustomOneofCase.Limit:
|
||||
case api.orderman.CustomOrderDefinition.CustomOneofCase.GlbxIceberg:
|
||||
{
|
||||
var child = AlgoBase.algo_factory(typeof(LimitOrder), _sink, this.security_list);
|
||||
hookup_child(child, this.security_list, def.Side, price, size, _myasof, order_key);
|
||||
}
|
||||
break;
|
||||
|
||||
case api.orderman.CustomOrderDefinition.CustomOneofCase.Stop:
|
||||
case api.orderman.CustomOrderDefinition.CustomOneofCase.StopLimit:
|
||||
Log.assert(false);
|
||||
break;
|
||||
|
||||
case api.orderman.CustomOrderDefinition.CustomOneofCase.Dynamic:
|
||||
Log.assert(false);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
IntPtr native = AlgoTestNativeMethods.try_create_algo(def.CustomDef.CustomCase);
|
||||
if(native != IntPtr.Zero)
|
||||
{
|
||||
AlgoTestNativeMethods.destroy_algo(native); //TODO, boolean
|
||||
var child = new NativeAlgo(_sink, this.security_list, def);
|
||||
hookup_child(child, this.security_list, def.Side, price, size, _myasof, order_key);
|
||||
// var handle = this.hookup_child(child, security_list, def.Side, price, size, _myasof, null, null, order_key);
|
||||
// _children.Add(handle);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
unsafe void on_native_update(byte* Update, ulong length, uint order_key)
|
||||
{
|
||||
byte[] arr = new byte[length];
|
||||
Marshal.Copy((IntPtr)Update, arr, 0, (int)length);
|
||||
api.orderman.Update upd = _updateparser.ParseFrom(arr);
|
||||
|
||||
var f = _children.FirstOrDefault(h => h.order_key == order_key);
|
||||
if(f != null)
|
||||
f.update(_lastmd.timestamp(), upd.Price, upd.Quantity);
|
||||
}
|
||||
|
||||
unsafe void on_native_cancel(uint order_key)
|
||||
{
|
||||
var f = _children.FirstOrDefault(h => h.order_key == order_key);
|
||||
if(f != null)
|
||||
f.cancel(_lastmd.timestamp());
|
||||
}
|
||||
|
||||
protected override void on_child_status(Handle child, OrderStatus stat)
|
||||
{
|
||||
_order_key_vs_state[child.order_key] = stat.state;
|
||||
process_status(stat.state);
|
||||
}
|
||||
|
||||
protected override void on_child_fill(Handle child, FillEntry fill)
|
||||
{
|
||||
AlgoTestNativeMethods.fill(_proxy, (uint)fill.order.order_id, fill.price, (uint)fill.size);
|
||||
this.on_fill?.Invoke(fill);
|
||||
}
|
||||
|
||||
unsafe void on_native_status(byte* OrderState, ulong length, uint order_key)
|
||||
{
|
||||
byte[] arr = new byte[length];
|
||||
Marshal.Copy((IntPtr)OrderState, arr, 0, (int)length);
|
||||
|
||||
api.orderman.OrderState curr = _stateparser.ParseFrom(arr);
|
||||
_order_key_vs_state[order_key] = curr;
|
||||
process_status(curr);
|
||||
}
|
||||
|
||||
|
||||
private void process_status(api.orderman.OrderState curr)
|
||||
{
|
||||
bool done = is_completed();
|
||||
api.orderman.OrderState aggstate = new api.orderman.OrderState
|
||||
{
|
||||
Status = done ? api.orderman.OrderStatus.Completed : curr.Status,
|
||||
Price = curr.Price,
|
||||
Quantity = curr.Quantity,
|
||||
AvgPrice = _order_key_vs_state.Values.Average(x => x.Price),
|
||||
FilledQuantity = _order_key_vs_state.Values.Sum(x => x.FilledQuantity),
|
||||
LastChange = curr.LastChange,
|
||||
LastMsg = curr.LastMsg,
|
||||
LastPrice = curr.LastPrice
|
||||
};
|
||||
OrderStatus agg = new OrderStatus(_fake_order_for_status, aggstate);
|
||||
agg.TransactTime = curr.LastChange ?? _lastmd?.SendingTime;
|
||||
agg.SendingTime = curr.LastChange ?? _lastmd?.SendingTime;
|
||||
this.on_status?.Invoke(agg);
|
||||
}
|
||||
|
||||
unsafe void on_native_fill(byte* Fill, ulong length, uint order_key)
|
||||
{
|
||||
byte[] arr = new byte[length];
|
||||
Marshal.Copy((IntPtr)Fill, arr, 0, (int)length);
|
||||
|
||||
api.orderman.Fill fill = _fillparser.ParseFrom(arr);
|
||||
//this method is called as a result of us sending a fill down in AlgoTestNativeMethods.fill so we do nothing
|
||||
|
||||
}
|
||||
|
||||
~NativeAlgo()
|
||||
{
|
||||
AlgoTestNativeMethods.destroy_algo_driver(_proxy);
|
||||
}
|
||||
|
||||
public override bool is_completed()
|
||||
{
|
||||
bool done = false;
|
||||
if(_order_key_vs_state.Count > 0)
|
||||
{
|
||||
var astate = AlgoTestNativeMethods.algo_driver_state(_proxy);
|
||||
done = AlgoTestNativeMethods.state_is_terminal(astate);
|
||||
foreach(var st in _order_key_vs_state.Values)
|
||||
done &= OrderStatus.is_terminal(st);
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
public override object report()
|
||||
{
|
||||
return $"Native";
|
||||
}
|
||||
|
||||
protected override void do_update(Timestamp asof, double price, uint size = uint.MinValue)
|
||||
{
|
||||
base.do_update(asof, price, size);
|
||||
AlgoTestNativeMethods.update_price(_proxy, price);
|
||||
if(size != uint.MinValue)
|
||||
{
|
||||
AlgoTestNativeMethods.update_size(_proxy, size);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void do_cancel(Timestamp asof)
|
||||
{
|
||||
base.do_cancel(asof);
|
||||
AlgoTestNativeMethods.cancel(_proxy);
|
||||
}
|
||||
|
||||
MarketDataIncrementalRefresh _lastmd;
|
||||
protected override void on_book(string security_desc, uint security_key, co2.BookMessage current_book, co2.BookMessage working_book,
|
||||
MarketDataIncrementalRefresh packet)
|
||||
{
|
||||
security_key = _def.SecurityKey; //to fake this up for the AlgoTestDriver
|
||||
var book = current_book.ToByteArray();
|
||||
AlgoTestNativeMethods.update_book(_proxy, security_key, book, book.Length);
|
||||
|
||||
advance_time(packet);
|
||||
}
|
||||
|
||||
protected override void on_trades(string security_desc, uint security_key, IEnumerable<co2.TradeMessage> trades,
|
||||
MarketDataIncrementalRefresh packet)
|
||||
{
|
||||
security_key = _def.SecurityKey;
|
||||
foreach(var trade in trades)
|
||||
{
|
||||
var tr = trade.ToByteArray();
|
||||
AlgoTestNativeMethods.update_ticker(_proxy, security_key, tr, tr.Length);
|
||||
}
|
||||
|
||||
advance_time(packet);
|
||||
}
|
||||
|
||||
void advance_time(MarketDataIncrementalRefresh packet)
|
||||
{
|
||||
if (_lastmd != null)
|
||||
{
|
||||
var dt = packet.timestamp() - _lastmd.timestamp();
|
||||
if (dt.Seconds >= 0 && dt.Nanos > 0)
|
||||
{
|
||||
ulong us = (ulong)dt.Seconds * 1000_000ul + ((ulong)dt.Nanos / 1000ul);
|
||||
AlgoTestNativeMethods.advance_time(_proxy, us, 1);
|
||||
}
|
||||
}
|
||||
_lastmd = packet;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
using System;
|
||||
using bts.api;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using MathNet.Numerics.Statistics;
|
||||
|
||||
namespace bts.history
|
||||
{
|
||||
public class NullAlgo : AlgoBase
|
||||
{
|
||||
public NullAlgo(IOrderSink sink, string[] security_list) : base(sink, security_list) { }
|
||||
public override bool is_completed() => true;
|
||||
|
||||
public override object report() { return string.Empty; }
|
||||
|
||||
protected override void do_launch(string[] security_list, Side side, double price, uint size, Timestamp asof, ulong order_key) { }
|
||||
|
||||
protected override void do_update(Timestamp asof, double price, uint size = uint.MinValue) { }
|
||||
|
||||
protected override void do_cancel(Timestamp asof) { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,324 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using MathNet.Numerics.Statistics;
|
||||
using mbts.co2;
|
||||
|
||||
namespace bts.history
|
||||
{
|
||||
public class SpreaderAlgo<Child, Hedge> : CompositeHedgeAlgo<Child, Hedge>
|
||||
where Child : AlgoBase
|
||||
where Hedge : AlgoBase
|
||||
{
|
||||
enum AlgoState
|
||||
{
|
||||
Begin, Quoting, Done
|
||||
}
|
||||
|
||||
//algo state
|
||||
string[] _security_list;
|
||||
AlgoState _state;
|
||||
double _myprice;
|
||||
uint _mysize;
|
||||
bool _sizeupdate;
|
||||
api.Side _myside;
|
||||
SortedList<string, co2.BookMessage> _current_book = new SortedList<string, co2.BookMessage>();
|
||||
OrderStatus _buystatus, _sellstatus;
|
||||
Handle _buychild;
|
||||
Handle _sellchild;
|
||||
OrderEntry _fake_order_for_status;
|
||||
|
||||
private MarketDataIncrementalRefresh _packet;
|
||||
|
||||
public SpreaderAlgo(IOrderSink sink, string[] security_list) : base(sink, security_list) { }
|
||||
//algo parameters
|
||||
public double profit_ticks { get; set; } = 0.0;
|
||||
public double[] tick_size { get; set; }
|
||||
public double[] hedge_factors { get; set; }
|
||||
public double[] price_factors { get; set; }
|
||||
public double lean_factor { get; set; } = 1.0;
|
||||
public bool accumulate_delta { get; set; } = false;
|
||||
public bool dont_cross { get; set; } = false;
|
||||
public bool wait_for_opposite_side_to_continue { get; set; } = false;
|
||||
|
||||
Dictionary<string, double> _tick_size = new Dictionary<string, double>();
|
||||
Dictionary<string, double> _hedge_factors = new Dictionary<string, double>();
|
||||
Dictionary<string, double> _price_factors = new Dictionary<string, double>();
|
||||
Dictionary<string, double> _delta = new Dictionary<string, double>();
|
||||
string _quote_leg;
|
||||
readonly List<bool> _sides = new List<bool>();
|
||||
|
||||
protected override void do_launch(string[] security_list, api.Side side, double price, uint size, Timestamp asof, ulong order_key)
|
||||
{
|
||||
_security_list = security_list;
|
||||
for(int i = 0; i < _security_list.Length; i++)
|
||||
{
|
||||
_current_book[_security_list[i]] = null;
|
||||
_tick_size[_security_list[i]] = tick_size[i];
|
||||
_hedge_factors[_security_list[i]] = hedge_factors[i];
|
||||
if(price_factors == null || price_factors.Length < _security_list.Length)
|
||||
_price_factors[_security_list[i]] = hedge_factors[i];
|
||||
else
|
||||
_price_factors[_security_list[i]] = price_factors[i];
|
||||
_delta[_security_list[i]] = 0.0;
|
||||
_quote_leg = _security_list[i]; //last
|
||||
}
|
||||
_state = AlgoState.Begin;
|
||||
_myprice = price;
|
||||
_mysize = size;
|
||||
_myside = side;
|
||||
_fake_order_for_status = new OrderEntry(asof, order_key, string.Join("_", security_list.Select(x=>x)),
|
||||
side, price, size, null, null, "SpreaderAlgo");
|
||||
|
||||
if (_myside == api.Side.Buy)
|
||||
_sides.Add(false);
|
||||
else if (_myside == api.Side.Sell)
|
||||
_sides.Add(true);
|
||||
else
|
||||
{
|
||||
_sides.Add(false);
|
||||
_sides.Add(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void do_update(Timestamp asof, double price, uint size = uint.MinValue)
|
||||
{
|
||||
_myprice = price;
|
||||
if(size > uint.MinValue)
|
||||
{
|
||||
_mysize = size;
|
||||
_sizeupdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool is_completed()
|
||||
{
|
||||
return base.is_completed() && _state == AlgoState.Done;
|
||||
}
|
||||
|
||||
public override object report()
|
||||
{
|
||||
var b = base.report();
|
||||
string qtleg = _security_list.Last();
|
||||
return b;
|
||||
}
|
||||
|
||||
protected override void on_child_status(Handle child, OrderStatus stat)
|
||||
{
|
||||
if(stat.side == api.Side.Buy && (_buychild?.Equals(child) ?? false))
|
||||
{
|
||||
_buystatus = stat;
|
||||
if(stat.is_terminal() && !this.wait_for_opposite_side_to_continue)
|
||||
_sellchild?.cancel(_buystatus.SendingTime);
|
||||
this.on_status?.Invoke(_buystatus);
|
||||
}
|
||||
else if(stat.side == api.Side.Sell && (_sellchild?.Equals(child) ?? false))
|
||||
{
|
||||
_sellstatus = stat;
|
||||
if(stat.is_terminal() && !this.wait_for_opposite_side_to_continue)
|
||||
_buychild?.cancel(_sellstatus.SendingTime);
|
||||
this.on_status?.Invoke(_sellstatus);
|
||||
}
|
||||
//hedges are looked after elsewhere
|
||||
if( (_buystatus?.is_terminal() ?? true) && (_sellstatus?.is_terminal() ?? true) )
|
||||
_state = AlgoState.Done;
|
||||
|
||||
send_my_status(stat);
|
||||
}
|
||||
|
||||
private void send_my_status(OrderStatus curr)
|
||||
{
|
||||
bool done = is_completed();
|
||||
api.orderman.OrderState aggstate = new api.orderman.OrderState
|
||||
{
|
||||
Status = done ? api.orderman.OrderStatus.Completed : api.orderman.OrderStatus.Working,
|
||||
Price = _myprice,
|
||||
Quantity = _mysize,
|
||||
AvgPrice = 0.0,
|
||||
FilledQuantity = done ? _mysize : 0,
|
||||
LastChange = curr.TransactTime,
|
||||
LastMsg = curr.state.LastMsg,
|
||||
LastPrice = curr.state.LastPrice
|
||||
};
|
||||
uint bqty = _buystatus?.state.FilledQuantity ?? 0;
|
||||
uint sqty = _sellstatus?.state.FilledQuantity ?? 0;
|
||||
aggstate.FilledQuantity = (uint) ( (bqty + sqty) / this._hedge_factors[_quote_leg] );
|
||||
OrderStatus agg = new OrderStatus(_fake_order_for_status, aggstate);
|
||||
agg.TransactTime = curr.TransactTime ?? _fake_order_for_status.last_change;
|
||||
agg.SendingTime = curr.SendingTime ?? _fake_order_for_status.last_change;
|
||||
this.on_status?.Invoke(agg);
|
||||
}
|
||||
|
||||
protected override void on_child_fill(Handle child, FillEntry fill)
|
||||
{
|
||||
var ff = factor_side(this._hedge_factors[_quote_leg]);
|
||||
bool invert = ff != fill.order.side;
|
||||
|
||||
foreach(var sec in _security_list)
|
||||
{
|
||||
if(sec == _quote_leg)
|
||||
continue;
|
||||
|
||||
var hedgeside = factor_side(this._hedge_factors[sec], invert);
|
||||
|
||||
var ratio = Math.Abs(this._hedge_factors[sec] / this._hedge_factors[_quote_leg]);
|
||||
double price = (hedgeside == api.Side.Buy) ? _current_book[sec].ask_at(0) : _current_book[sec].bid_at(0);
|
||||
uint hedgesize_available = (hedgeside == api.Side.Buy) ? _current_book[sec].asksize_at(0) : _current_book[sec].bidsize_at(0);
|
||||
uint size = (uint)(fill.size * ratio);
|
||||
|
||||
if(this.accumulate_delta)
|
||||
{
|
||||
_delta[sec] += fill.size * ratio - size;
|
||||
if(_delta[sec] > 1.0)
|
||||
{
|
||||
var usize = (uint)_delta[sec];
|
||||
size += usize;
|
||||
_delta[sec] -= usize;
|
||||
}
|
||||
}
|
||||
if(size > 0)
|
||||
send_hedge(sec, hedgeside, price, size, fill.TransactTime, handle_hedge_fill, handle_hedge_status);
|
||||
else
|
||||
fill.tag = (fill.tag ?? "") + $"SmallHedge: {price.ToString("0")} {hedgesize_available}";
|
||||
}
|
||||
}
|
||||
|
||||
private void handle_hedge_status(Handle handle, OrderStatus stat)
|
||||
{
|
||||
Log.assert(true);
|
||||
}
|
||||
|
||||
private void handle_hedge_fill(Handle handle, FillEntry fill)
|
||||
{
|
||||
Log.assert(true);
|
||||
}
|
||||
|
||||
api.Side factor_side(double mult, bool invert = false)
|
||||
{
|
||||
api.Side sd = api.Side.Undefined;
|
||||
if(mult >= 0.0)
|
||||
sd = api.Side.Buy;
|
||||
else
|
||||
sd = api.Side.Sell;
|
||||
if(invert)
|
||||
sd = Utils.opposite_side(sd);
|
||||
return sd;
|
||||
}
|
||||
|
||||
static double round_tick_up(double input, double tick)
|
||||
{
|
||||
return Math.Ceiling(input / tick) * tick;
|
||||
}
|
||||
static double round_tick_dn(double input, double tick)
|
||||
{
|
||||
return Math.Floor(input / tick) * tick;
|
||||
}
|
||||
|
||||
protected override void on_book(string security_desc, uint security_key, co2.BookMessage current_book, co2.BookMessage working_book,
|
||||
MarketDataIncrementalRefresh packet)
|
||||
{
|
||||
_packet = packet;
|
||||
_current_book[security_desc] = current_book;
|
||||
var look_book = _current_book;
|
||||
switch (_state)
|
||||
{
|
||||
case AlgoState.Begin:
|
||||
{
|
||||
if( !_current_book.Values.Any(x => x == null) )
|
||||
_state = AlgoState.Quoting;
|
||||
}
|
||||
break;
|
||||
case AlgoState.Quoting:
|
||||
{
|
||||
double qtbid = _myprice - profit_ticks; uint szbid = 0;
|
||||
double qtask = _myprice + profit_ticks; uint szask = 0;
|
||||
foreach(var sec in _security_list)
|
||||
{
|
||||
var book = look_book[sec];
|
||||
if (sec != _quote_leg)
|
||||
{
|
||||
var hedge_sidebid = factor_side(this._hedge_factors[sec], false);
|
||||
var hedge_sideask = factor_side(this._hedge_factors[sec], true);
|
||||
var cross_sidebid = Utils.opposite_side(hedge_sidebid);
|
||||
var cross_sideask = Utils.opposite_side(hedge_sideask);
|
||||
var legbid = this._price_factors[sec] * book.side_at(cross_sidebid, 0);
|
||||
var legask = this._price_factors[sec] * book.side_at(cross_sideask, 0);
|
||||
qtbid -= legbid;
|
||||
qtask -= legask;
|
||||
|
||||
var hratio = Math.Abs(this._hedge_factors[sec] / this._hedge_factors[_quote_leg]);
|
||||
hratio *= this.lean_factor;
|
||||
var quote_size = (uint) (_mysize * Math.Abs(this._hedge_factors[_quote_leg]));
|
||||
szbid = Math.Min(quote_size, (uint) (book.sidesize_at(cross_sidebid, 0) / hratio));
|
||||
szask = Math.Min(quote_size, (uint) (book.sidesize_at(cross_sideask, 0) / hratio));
|
||||
}
|
||||
else
|
||||
{
|
||||
qtbid /= this._price_factors[_quote_leg];
|
||||
qtask /= this._price_factors[_quote_leg];
|
||||
double temp = qtbid;
|
||||
qtbid = qtask;
|
||||
qtask = temp;
|
||||
|
||||
double tick = _tick_size[sec];
|
||||
qtbid = round_tick_dn(qtbid, tick);
|
||||
qtask = round_tick_up(qtask, tick);
|
||||
if (this.dont_cross)
|
||||
{
|
||||
qtbid = Math.Min(qtbid, book.bid_at(0));
|
||||
qtask = Math.Max(qtask, book.ask_at(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var invert in _sides)
|
||||
{
|
||||
api.Side quoteside = factor_side(this._hedge_factors[_quote_leg], invert);
|
||||
|
||||
if(quoteside == api.Side.Buy && szbid > 0 && (_buystatus?.state?.Price != qtbid || _sizeupdate) && (!_buystatus?.is_terminal() ?? true))
|
||||
quote_function(packet, _quote_leg, quoteside, qtbid, szbid);
|
||||
else if(quoteside == api.Side.Sell && szask > 0 && (_sellstatus?.state?.Price != qtask || _sizeupdate) && (!_sellstatus?.is_terminal() ?? true))
|
||||
quote_function(packet, _quote_leg, quoteside, qtask, szask);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AlgoState.Done:
|
||||
break;
|
||||
default:
|
||||
Log.assert(false, "invalid algo state");
|
||||
break;
|
||||
}
|
||||
}
|
||||
void quote_function(MarketDataIncrementalRefresh packet, string qtleg,
|
||||
api.Side quoteside, double qt, uint sz)
|
||||
{
|
||||
if (quoteside == api.Side.Buy)
|
||||
{
|
||||
if (_buychild == null)
|
||||
{
|
||||
_buychild = this.create<Child>();
|
||||
_buychild.launch(new[] { qtleg }, quoteside, qt, sz, packet.timestamp());
|
||||
}
|
||||
else if(_buystatus != null)
|
||||
{
|
||||
_buychild.update(packet.timestamp(), qt, sz);
|
||||
_sizeupdate = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_sellchild == null)
|
||||
{
|
||||
_sellchild = this.create<Child>();
|
||||
_sellchild.launch(new[] { qtleg }, quoteside, qt, sz, packet.timestamp());
|
||||
}
|
||||
else if (_sellstatus != null)
|
||||
{
|
||||
_sellchild.update(packet.timestamp(), qt, sz);
|
||||
_sizeupdate = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
namespace bts.history
|
||||
{
|
||||
public class StackerAlgo<Child> : CompositeAlgo<Child>
|
||||
where Child : AlgoBase
|
||||
{
|
||||
Handle[] _handles;
|
||||
Dictionary<Handle, OrderStatus> _status = new Dictionary<Handle, OrderStatus>();
|
||||
api.Side _myside;
|
||||
double _myprice;
|
||||
|
||||
public StackerAlgo(IOrderSink sink, string[] security_list) : base(sink, security_list) { }
|
||||
|
||||
public double[] tick_size { get; set; }
|
||||
public uint stack_length { get; set; } = 2;
|
||||
double _tick_size;
|
||||
|
||||
protected override void do_launch(string[] security_list, api.Side side, double price, uint size, Timestamp asof, ulong order_key)
|
||||
{
|
||||
_myside = side;
|
||||
_myprice = price;
|
||||
_handles = new Handle[this.stack_length];
|
||||
for (int i = 0; i < this.security_list.Length; i++)
|
||||
{
|
||||
if(this.security_list[i] == security_list[0])
|
||||
_tick_size = tick_size[i];
|
||||
}
|
||||
|
||||
if(this.stack_length <= 1)
|
||||
throw new NotSupportedException("StackerAlgo must have stack_length > 1");
|
||||
for(int i = 0; i < this.stack_length; i++)
|
||||
{
|
||||
if(side == api.Side.Buy)
|
||||
{
|
||||
var h = _handles[i] = this.create<Child>();
|
||||
h.launch(security_list, side, price - i * _tick_size, size, asof);
|
||||
}
|
||||
else
|
||||
{
|
||||
var h = _handles[i] = this.create<Child>();
|
||||
h.launch(security_list, side, price + i * _tick_size, size, asof);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void do_update(Timestamp asof, double price, uint size = uint.MinValue)
|
||||
{
|
||||
bool better = (_myside == api.Side.Buy ? price > _myprice : price < _myprice);
|
||||
if(price == _myprice)
|
||||
{
|
||||
Log.Testing.error("update of StackerAlgo for same price");
|
||||
return;
|
||||
}
|
||||
double px = _myprice;
|
||||
if(better)
|
||||
{
|
||||
double tick = (_myside == api.Side.Buy ? _tick_size : -_tick_size);
|
||||
while(Math.Abs(price - px) > _tick_size / 10.0)
|
||||
{
|
||||
px += tick;
|
||||
var mover = _handles[_handles.Length - 1];
|
||||
for(int j = _handles.Length-1; j >= 1; j--)
|
||||
_handles[j] = _handles[j-1];
|
||||
_handles[0] = mover;
|
||||
mover.update(asof, px, size);
|
||||
}
|
||||
var stat0 = _status[_handles[0]];
|
||||
var stat1 = _status[_handles[1]];
|
||||
Log.assert(stat0.state.Price == price);
|
||||
Log.assert(stat1.state.Price == price - tick);
|
||||
}
|
||||
else
|
||||
{
|
||||
double tick = (_myside == api.Side.Buy ? -_tick_size : _tick_size);
|
||||
while (Math.Abs(price - px) > _tick_size / 10.0)
|
||||
{
|
||||
var mover = _handles[0];
|
||||
for (int j = 0; j < _handles.Length-1; j++)
|
||||
_handles[j] = _handles[j+1];
|
||||
_handles[_handles.Length-1] = mover;
|
||||
double endprice = px + tick * (_handles.Length);
|
||||
mover.update(asof, endprice, size);
|
||||
px += tick;
|
||||
}
|
||||
var stat0 = _status[_handles[0]];
|
||||
var stat1 = _status[_handles[1]];
|
||||
Log.assert(stat0.state.Price == price);
|
||||
Log.assert(stat1.state.Price == price + tick);
|
||||
on_child_status(_handles[0], stat0); //to force status update since this order didn't actually get updated
|
||||
}
|
||||
_myprice = px;
|
||||
}
|
||||
|
||||
protected override void on_child_status(Handle child, OrderStatus stat)
|
||||
{
|
||||
_status[child] = stat;
|
||||
if(_handles[0]?.Equals(child) ?? false)
|
||||
{
|
||||
this.on_status?.Invoke(stat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loaded 100 of 342 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user