Compare commits
17
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e29edf5cd | ||
|
|
f83cdef962 | ||
|
|
8535d72875 | ||
|
|
d2deb768b9 | ||
|
|
73f9dd0292 | ||
|
|
eb6f5ac046 | ||
|
|
f0b5e398f0 | ||
|
|
c8e9906591 | ||
|
|
b9c8f59541 | ||
|
|
ab550ddfbe | ||
|
|
adb77dafac | ||
|
|
65bda258e1 | ||
|
|
43d26be0f4 | ||
|
|
a93382d98f | ||
|
|
a8fb11ca86 | ||
|
|
c4f57273aa | ||
|
|
6410e50673 |
No files matched your search
@@ -39,7 +39,6 @@ SPARKD__CONFIG_DIR=src/server/sparkd/configurations/dev
|
||||
# Defaults to a volume named "sparkd_<config_port>" (e.g., sparkd_8000).
|
||||
# SPARKD__DATA_DIR=/home/bts/sparkdata/data
|
||||
SPARKD__SOURCE_DIR=install/sparkd-release-gcc
|
||||
SPARKD__RUNTIME_CONF_DIR=/home/ubuntu/8000/sparkdata/conf/
|
||||
SPARKD__CONFIG_PORT=8000
|
||||
SPARKD__QUICKBUS_PORT=8001
|
||||
SPARKD__SIM_FIX_PORT=8002
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[submodule "externals"]
|
||||
path = externals
|
||||
url = https://bitbucket.org/bluetradesys/externals.git
|
||||
url = git@bitbucket.org:bluetradesys/externals.git
|
||||
[submodule "vcpkg"]
|
||||
path = vcpkg
|
||||
url = https://github.com/microsoft/vcpkg.git
|
||||
Vendored
+3
-2
@@ -2,9 +2,10 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"name": "Attach Spark",
|
||||
"type": "coreclr",
|
||||
"request": "attach"
|
||||
"request": "attach",
|
||||
"processId": "${command:pickProcess}"
|
||||
},
|
||||
{
|
||||
"name": "DataStreamPublisher",
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
project(spark)
|
||||
include(GNUInstallDirs)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/GitVersion.cmake)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
get_version_from_git()
|
||||
if(WIN32)
|
||||
set(platform "windows")
|
||||
else()
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
include_guard(GLOBAL)
|
||||
|
||||
function(get_version_from_git)
|
||||
find_package(Git QUIET)
|
||||
if(NOT Git_FOUND)
|
||||
message(WARNING "Git not found")
|
||||
return()
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} describe --tags --always
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE GIT_TAG
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
RESULT_VARIABLE GIT_RESULT
|
||||
)
|
||||
|
||||
if(NOT GIT_RESULT EQUAL 0)
|
||||
message(WARNING "Failed to get git tag")
|
||||
return()
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} rev-parse --short=7 HEAD
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
OUTPUT_VARIABLE GIT_COMMIT_SHORT_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
set(PROJECT_VERSION_BUILD_METADATA ${GIT_COMMIT_SHORT_HASH})
|
||||
set(PROJECT_VERSION_BUILD_METADATA ${GIT_COMMIT_SHORT_HASH} PARENT_SCOPE)
|
||||
|
||||
string(REGEX REPLACE "^v" "" CLEAN_TAG "${GIT_TAG}")
|
||||
if(CLEAN_TAG MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)(-.*)?$")
|
||||
set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1})
|
||||
set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1} PARENT_SCOPE)
|
||||
set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_2})
|
||||
set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_2} PARENT_SCOPE)
|
||||
set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_3})
|
||||
set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_3} PARENT_SCOPE)
|
||||
|
||||
set(PROJECT_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
|
||||
set(PROJECT_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}" PARENT_SCOPE)
|
||||
set(PROJECT_VERSION_FULL "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}+${GIT_COMMIT_SHORT_HASH}")
|
||||
set(PROJECT_VERSION_FULL "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}+${GIT_COMMIT_SHORT_HASH}" PARENT_SCOPE)
|
||||
else()
|
||||
message(WARNING "Tag '${CLEAN_TAG}' does not match semver format")
|
||||
endif()
|
||||
endfunction()
|
||||
@@ -1,11 +0,0 @@
|
||||
#ifndef BTS_SPARK_VERSION_H
|
||||
#define BTS_SPARK_VERSION_H
|
||||
|
||||
#define BTS_SPARK_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
|
||||
#define BTS_SPARK_VERSION_MINOR @PROJECT_VERSION_MINOR@
|
||||
#define BTS_SPARK_VERSION_PATCH @PROJECT_VERSION_PATCH@
|
||||
#define BTS_SPARK_VERSION_BUILD_METADATA @PROJECT_VERSION_BUILD_METADATA@
|
||||
#define BTS_SPARK_VERSION "@PROJECT_VERSION@"
|
||||
#define BTS_SPARK_VERSION_FULL "@PROJECT_VERSION_FULL@"
|
||||
|
||||
#endif
|
||||
@@ -33,43 +33,6 @@ services:
|
||||
resources:
|
||||
limits:
|
||||
memory: "${SPARKD__MEMORY:-4gb}"
|
||||
sparkd-symbols:
|
||||
volumes:
|
||||
- ${SPARKD__DATA_DIR:-sparkd_data}:/home/bts/sparkdata/data
|
||||
- ${SPARKD__RUNTIME_CONF_DIR:-sparkd_conf}:/home/bts/sparkdata/conf
|
||||
build:
|
||||
dockerfile: src/server/sparkd/Dockerfile
|
||||
args:
|
||||
- IMAGE=${SPARKD__IMAGE}
|
||||
- SOURCE_DIR=${SPARKD__SOURCE_DIR}
|
||||
- CONFIG_DIR=${SPARKD__CONFIG_DIR}
|
||||
shm_size: "${SPARKD__SHM_SIZE:-512mb}"
|
||||
command: >
|
||||
sh -c "
|
||||
echo bts | sudo -S chown -R bts:bts /home/bts/sparkdata/data
|
||||
if [ -e "/home/bts/sparkdata/data/logging.sparkd/log" ]; then
|
||||
mv "/home/bts/sparkdata/data/logging.sparkd/log" "/home/bts/sparkdata/data/logging.sparkd/log_$(date '+%Y%m%d-%H%M')"
|
||||
fi
|
||||
ls -alh /home/bts/sparkdata/conf/
|
||||
cat /home/bts/sparkdata/conf/.env.local
|
||||
if [ -e "/home/bts/sparkdata/conf/.env.local" ]; then
|
||||
echo 'Sourcing /home/bts/sparkdata/conf/.env.local'
|
||||
set -a
|
||||
. /home/bts/sparkdata/conf/.env.local
|
||||
set +a
|
||||
fi
|
||||
./sparkd run"
|
||||
env_file:
|
||||
- .env
|
||||
- ${SPARKD__CONFIG_DIR}/.env
|
||||
ports:
|
||||
- "${SPARKD__CONFIG_PORT}:${SPARKD__CONFIG_PORT}"
|
||||
- "${SPARKD__QUICKBUS_PORT}:${SPARKD__QUICKBUS_PORT}"
|
||||
- "${SPARKD__SIM_FIX_PORT}:${SPARKD__SIM_FIX_PORT}"
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: "${SPARKD__MEMORY:-4gb}"
|
||||
|
||||
sparkd-tail:
|
||||
image: bluetradingsystems/linux_dotnet7
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"sdk": {
|
||||
"version": "6.0.200",
|
||||
"rollForward": "latestMajor"
|
||||
}
|
||||
}
|
||||
+1
-8
@@ -1,20 +1,14 @@
|
||||
astroid==2.7.3
|
||||
autopep8==1.5.7
|
||||
blinker==1.9.0
|
||||
boto3==1.37.9
|
||||
botocore==1.37.9
|
||||
certifi==2023.5.7
|
||||
charset-normalizer==3.1.0
|
||||
click==8.1.8
|
||||
colorama==0.4.4
|
||||
Flask==3.1.0
|
||||
idna==3.4
|
||||
isort==5.9.3
|
||||
itsdangerous==2.2.0
|
||||
Jinja2==3.1.6
|
||||
jmespath==1.0.1
|
||||
lazy-object-proxy==1.6.0
|
||||
MarkupSafe==3.0.2
|
||||
mccabe==0.6.1
|
||||
platformdirs==2.3.0
|
||||
protobuf==4.21.12
|
||||
@@ -23,14 +17,13 @@ pycodestyle==2.7.0
|
||||
pycparser==2.20
|
||||
pylint==2.10.2
|
||||
PyMeta3==0.5.1
|
||||
python-dateutil==2.9.0.post0
|
||||
python-dotenv==1.0.1
|
||||
python-dateutil==2.9.0.post0
|
||||
requests==2.31.0
|
||||
s3transfer==0.11.4
|
||||
six==1.17.0
|
||||
termcolor==1.1.0
|
||||
toml==0.10.2
|
||||
urllib3==2.0.3
|
||||
Werkzeug==3.1.3
|
||||
wrapt==1.12.1
|
||||
yapf==0.31.0
|
||||
@@ -45,7 +45,8 @@ namespace mbts.spark {
|
||||
Func<AnalyticsExpirationParameters, bool> is_unexpired = (p) => {
|
||||
var st = p.driver_security.security_tuple.to_api_sec_tuple();
|
||||
var exp = p.security.expiration;
|
||||
return SecurityExpirationHelper.is_unexpired(st, exp);
|
||||
return exp.Date >= DateTime.Now.Date;
|
||||
//return SecurityExpirationHelper.is_unexpired(st, exp);
|
||||
};
|
||||
exp_params = exp_params.Where(t => is_unexpired(t));
|
||||
// listens to the commit tag and saves it
|
||||
|
||||
@@ -12,8 +12,8 @@ using bts.api;
|
||||
using mbts.ui.converters;
|
||||
|
||||
namespace mbts.spark {
|
||||
// This class gathers all the inputs needed to calculate InterpGreeks, pass it to
|
||||
// VolSurfacePrecomputedTheosProducer, and publishes the InterpGreeks to the bus
|
||||
// This class gathers all the inputs needed to calculate InterpGreeks for a single vol surface,
|
||||
// passes it to VolSurfacePrecomputedTheosProducer, and publishes the InterpGreeks to the bus
|
||||
// (called SingleVolSurfaceClientPrecomputedTheosPublisher in Edge)
|
||||
// It listens to
|
||||
// a. vol surface inputs
|
||||
|
||||
@@ -20,6 +20,7 @@ using Spark.Core.Protobuf;
|
||||
using mbts.ui;
|
||||
using bts.config.toggles;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using BCG;
|
||||
// using mbts.bb;
|
||||
|
||||
namespace mbts.spark
|
||||
@@ -92,11 +93,11 @@ namespace mbts.spark
|
||||
// in tags
|
||||
private readonly ITag<SystemContractData> _in_scdata_tag =
|
||||
SparkTags.SystemContractsTag;
|
||||
private readonly ITag<NMSheetSymbol> _archive_ivs_tag = SparkTags.TC2Tags.ArchiveIVsTag;
|
||||
private readonly ITag<VolSurfaceSettings> _in_bb_create_tag = SparkTags.VolSurfaceCreateTag;
|
||||
private readonly ITag<int> _in_bb_delete_tag = SparkTags.VolSurfaceDeleteTag;
|
||||
private readonly ITag<AnalyticsExpirationParametersMap> _in_bb_exp_params_tag =
|
||||
SparkTags.ExpirationParametersInputTag;
|
||||
private readonly ITag<ClientArchivedVolRequest> _in_bb_req_vol = SparkTags.RequestArchivedVols;
|
||||
// state
|
||||
private SystemContractData _contract_data = null;
|
||||
private IDictionary<int, SingleVolSurfaceManager> _vs_manager_map =
|
||||
@@ -106,6 +107,43 @@ namespace mbts.spark
|
||||
private bts.api.IBus _bus;
|
||||
private List<IDisposable> _subs = new List<IDisposable>();
|
||||
|
||||
private static void add_temp_vsu_entries(IDictionary<string, int> name_id_map,
|
||||
VolSurfaceUsageList ulist) {
|
||||
Action<string, Venue, string> add_entry = (option_name, option_venue, vs_name) => {
|
||||
|
||||
int vs_key;
|
||||
if (name_id_map.TryGetValue(vs_name, out vs_key)) {
|
||||
ulist.UsageList.Add(new VolSurfaceUsageEntry() {
|
||||
VsId = vs_key,
|
||||
SymbolName = option_name,
|
||||
SecTup = new bts.api.SecurityTuple {
|
||||
Type = SecurityType.Option,
|
||||
Venue = option_venue,
|
||||
Symbol = option_name
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
add_entry("SPX", Venue.Cboe, "CBOE_skews");
|
||||
add_entry("SPXW", Venue.Cboe, "CBOE_skews");
|
||||
add_entry("E1B", Venue.Glbx, "CME_Skews");
|
||||
add_entry("E1C", Venue.Glbx, "CME_Skews");
|
||||
add_entry("E3B", Venue.Glbx, "CME_Skews");
|
||||
add_entry("E3C", Venue.Glbx, "CME_Skews");
|
||||
add_entry("E3D", Venue.Glbx, "CME_Skews");
|
||||
add_entry("E4A", Venue.Glbx, "CME_Skews");
|
||||
add_entry("E4B", Venue.Glbx, "CME_Skews");
|
||||
add_entry("E4C", Venue.Glbx, "CME_Skews");
|
||||
add_entry("E4C", Venue.Glbx, "CME_Skews");
|
||||
add_entry("E4D", Venue.Glbx, "CME_Skews");
|
||||
add_entry("ES", Venue.Glbx, "CME_Skews");
|
||||
add_entry("EW1", Venue.Glbx, "CME_Skews");
|
||||
add_entry("EW2", Venue.Glbx, "CME_Skews");
|
||||
add_entry("EW3", Venue.Glbx, "CME_Skews");
|
||||
add_entry("EW4", Venue.Glbx, "CME_Skews");
|
||||
}
|
||||
|
||||
public VolSurfaceBusManager(bts.api.IBus bus,
|
||||
bts.api.analytics.AnalyticsService analytics_service,
|
||||
bts.api.orderman.OrderService order_service)
|
||||
@@ -119,7 +157,7 @@ namespace mbts.spark
|
||||
_bb.subscribe(_in_bb_create_tag);
|
||||
_bb.subscribe(_in_bb_delete_tag);
|
||||
_bb.subscribe(_in_bb_exp_params_tag);
|
||||
_bb.subscribe(_in_bb_req_vol);
|
||||
_bb.subscribe(_archive_ivs_tag);
|
||||
_bb.data_callback += _on_bb_update;
|
||||
_bb.timer_callback += _on_timer;
|
||||
var contracts_throttle = TimeSpan.FromMilliseconds(200);
|
||||
@@ -127,11 +165,25 @@ namespace mbts.spark
|
||||
var vs_sub = _analytics_service.subscribei_volsurfaces()
|
||||
.ObserveOn(SynchronizationContext.Current)
|
||||
.Subscribe(_on_vss);
|
||||
//var hist_theos_sub_obs = _analytics_service.subscribei_archived_theos_table();
|
||||
//var obs = hist_theos_sub_obs.ObserveOn(SynchronizationContext.Current);//.Subcribe(_on_hist_theos);
|
||||
//obs.Subscribe(tu => {
|
||||
// Log.Gen.info("Received historical theos");
|
||||
// _on_hist_theos(tu);
|
||||
//});
|
||||
|
||||
var archived_theos_obs = _analytics_service.subscribei_archived_theos().ObserveOn(SynchronizationContext.Current).Subscribe(tu => {
|
||||
Log.Gen.info("Received historical theos");
|
||||
_on_hist_theos(tu);
|
||||
});
|
||||
|
||||
|
||||
var vs_usage_sub = _analytics_service.subscribei_volsurface_usage()
|
||||
.ObserveOn(SynchronizationContext.Current)
|
||||
.Subscribe(_on_vs_usage_update);
|
||||
_subs.Add(vs_sub);
|
||||
_subs.Add(vs_usage_sub);
|
||||
_subs.Add(archived_theos_obs);
|
||||
_subs.Add(new AnalyticsParametersManager(bus, _analytics_service));
|
||||
_subs.Add(new ResourceAllocator(bus, _bb, contracts_throttle));
|
||||
_subs.Add(new SymbolAggregationPublisher<OptionDriverPriceMap>(
|
||||
@@ -143,7 +195,7 @@ namespace mbts.spark
|
||||
_subs.Add(new LiveTheoPublisher(_bb));
|
||||
_subs.Add(new InterpTheosServerPublisher(_bb, bus, order_service, contracts_throttle));
|
||||
_subs.Add(new VolSurfaceInterpGreeksMultiplexer(_bb));
|
||||
// usage
|
||||
// list of all volsurface. in this callback, we read the usage config, and detemine the id of the named vol surface
|
||||
var list_sub = _bus.subscribe(SparkTags.VolSurfaceListTag).OnDispatcher().Subscribe(t =>
|
||||
{
|
||||
VolSurfaceUsageList ulist = new VolSurfaceUsageList();
|
||||
@@ -154,9 +206,12 @@ namespace mbts.spark
|
||||
}
|
||||
Log.Ui.info($"VolSurfaceUsageList name_to_ids count: {name_to_ids.Count}");
|
||||
var vs_usage = mbts.config.Configuration.get<bts.config.toggles.VolSurfaceUsage>();
|
||||
Log.Ui.info($"VolSurfaceUsageList vs_usage acount: {vs_usage.Items.Count}");
|
||||
Log.Ui.info($"VolSurfaceUsageList vs_usage acount: {vs_usage.Items.Count}");
|
||||
foreach (var u in vs_usage.Items)
|
||||
{
|
||||
if (string.Compare(u.OptionName, "SPX", 0) == 0 || string.Compare(u.OptionName, "SPXW", 0) == 0){
|
||||
continue;
|
||||
}
|
||||
if (string.Compare(u.OptionName, "SPX", 0) == 0 || string.Compare(u.OptionName, "SPXW", 0) == 0 && u.OptionVenue == Venue.Unset)
|
||||
{
|
||||
u.OptionVenue = Venue.Cboe;
|
||||
@@ -186,10 +241,11 @@ namespace mbts.spark
|
||||
else
|
||||
{
|
||||
Log.Gen.error($"Could not find vol surface with name: {vs_name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
add_temp_vsu_entries(name_to_ids, ulist);
|
||||
var list_imm = new VolSurfaceUsageListImmutable(ulist);
|
||||
Log.Ui.info(list_imm.log_string());
|
||||
Log.Ui.info("VolSurfaceUsage: " + list_imm.log_string());
|
||||
_bb.post(SparkTags.VolSurfaceUsageTag, list_imm);
|
||||
_spin_vss(list_imm);
|
||||
});
|
||||
@@ -292,6 +348,8 @@ namespace mbts.spark
|
||||
|
||||
void _on_vs_usage_update(Update<VolSurfaceUsageListImmutable, int> update)
|
||||
{
|
||||
var state = update.all;
|
||||
Log.Gen.info($"VSBBMan._on_vs_usage_update size: {state.Count()}");
|
||||
// TODO
|
||||
return;
|
||||
}
|
||||
@@ -310,6 +368,17 @@ namespace mbts.spark
|
||||
_init_vss(to_publish.Keys);
|
||||
}
|
||||
|
||||
void _on_hist_theos(Update<bts.api.analytics.ArchivedTheoListImmutable, ulong> update) {
|
||||
//var total_state = update.state;
|
||||
Log.Gen.info($"VSBBMan._on_hist_theos update: {update}");
|
||||
foreach (var kv in update.all) {
|
||||
bts.Log.Gen.info($"kv: {kv}");
|
||||
_bb.post(SparkTags.ArchivedTheos, kv);
|
||||
break;
|
||||
}
|
||||
//Log.assert(false);
|
||||
}
|
||||
|
||||
private void _init_vss(IEnumerable<int> vs_ids)
|
||||
{
|
||||
// we consider every vs in the db as "activated" which might prove to be expensive
|
||||
@@ -362,29 +431,56 @@ namespace mbts.spark
|
||||
_bb.post(SparkTags.VolSurfaceNonVolInputTag,
|
||||
new mbts.analytics.VolSurfaceNonVolInput(exp_param_map.exp_map.ToDictionary()));
|
||||
}
|
||||
else if (_in_bb_req_vol.Equals(tag))
|
||||
{
|
||||
ClientArchivedVolRequest client_req = _bb.read_state(_in_bb_req_vol);
|
||||
bts.Log.Ui.info($"VolSurfaceBusManager._on_bb_update ClientArchivedVolRequest: {client_req.ToString()}");
|
||||
ArchivedTheoRetrieval ret = client_req.ret;
|
||||
if (ret == null || ret.SecTup == null)
|
||||
{
|
||||
bts.Log.Ui.warn($"VolSurfaceBusManager malformed ArchivedTheoRetrieval");
|
||||
ArchivedTheoList empty = new ArchivedTheoList();
|
||||
_bb.post(SparkTags.ResponseArchivedVols, Tuple.Create(client_req, empty));
|
||||
return;
|
||||
// this is publishe dby the sheets
|
||||
else if (_archive_ivs_tag.Equals(tag)){
|
||||
//Log.assert(false);
|
||||
NMSheetSymbol sym = data as NMSheetSymbol;
|
||||
SystemContractData sc_data = _bb.read_state(SparkTags.SystemContractsTag);
|
||||
var associated_syms = _get_associated_symbols(sym);
|
||||
List<ArchivedSecurityTheo> theo_list = new List<ArchivedSecurityTheo>();
|
||||
foreach (NMSheetSymbol s in associated_syms){
|
||||
ExpStrikeKeyedData<TheoPoint> symbol_theos = _bb.read_state(SparkTags.TC2Tags.LiveTheosTag((s.option_name, s.option_exchange)));
|
||||
foreach (var t in symbol_theos.get_data_linearly()){
|
||||
Venue v = s.option_exchange;
|
||||
string symbol = s.option_name;
|
||||
DateTime exp = t.first;
|
||||
double strike = t.second;
|
||||
TheoPoint tp = t.third;
|
||||
Tuple<uint?, uint?> cp_id = sc_data.get_option_sec_id(v, symbol, exp, strike);
|
||||
if (cp_id != null && cp_id.Item1.HasValue && cp_id.Item2.HasValue){
|
||||
// call
|
||||
ArchivedSecurityTheo c_theo = new ArchivedSecurityTheo();
|
||||
c_theo.Id = cp_id.Item1.Value;
|
||||
c_theo.Driver = tp.driver;
|
||||
c_theo.Vol = tp.vol;
|
||||
c_theo.Theo = tp.call;
|
||||
c_theo.Delta = tp.cdelta;
|
||||
theo_list.Add(c_theo);
|
||||
// put
|
||||
ArchivedSecurityTheo p_theo = new ArchivedSecurityTheo();
|
||||
p_theo.Id = cp_id.Item1.Value;
|
||||
p_theo.Driver = tp.driver;
|
||||
p_theo.Vol = tp.vol;
|
||||
p_theo.Theo = tp.put;
|
||||
p_theo.Delta = tp.pdelta;
|
||||
theo_list.Add(p_theo);
|
||||
}
|
||||
}
|
||||
}
|
||||
bts.Log.Ui.info($"VolSurfaceBusManager ArchivedTheoRetrieval id: {client_req.id} save_time: {ret.SaveTime} " +
|
||||
$"sec_tup: {ret.SecTup.Venue}_{ret.SecTup.Type}_{ret.SecTup.Symbol}");
|
||||
var timer = Stopwatch.StartNew();
|
||||
ArchivedTheoList arch_theos = _analytics_service.get_archived_theos(ret);
|
||||
timer.Stop();
|
||||
bts.Log.Ui.info($"VolSurfaceBusManager ArchivedTheoRetrieval time: {timer.Elapsed.TotalMilliseconds}ms " +
|
||||
$"n_entries: {arch_theos.SecTheo.Count}");
|
||||
_bb.post(SparkTags.ResponseArchivedVols, Tuple.Create(client_req, arch_theos));
|
||||
ArchivedTheoList rv_list = new ArchivedTheoList();
|
||||
// we dont care abouyt the save time any more, and dont want it to te the ky of the table anymore
|
||||
rv_list.SaveTime = 0;
|
||||
rv_list.SecTheo.AddRange(theo_list);
|
||||
bts.Log.Gen.info($"VSBBMan archiving {rv_list.SecTheo.Count} entries");
|
||||
_analytics_service.clean_and_archive_theos(rv_list);
|
||||
// send it to the server
|
||||
}
|
||||
}
|
||||
|
||||
private List<NMSheetSymbol> _get_associated_symbols(NMSheetSymbol symbol){
|
||||
return new List<NMSheetSymbol>() {new NMSheetSymbol(Venue.Cboe, "SPX"),new NMSheetSymbol(Venue.Cboe, "SPXW")};
|
||||
}
|
||||
|
||||
private int _timer_count = 0;
|
||||
private void _on_timer()
|
||||
{
|
||||
|
||||
@@ -14,6 +14,11 @@ namespace mbts.spark {
|
||||
// Publishes theos for all options (on the side, also publishes the theos for TC2).
|
||||
// Listens to driver and interp theos, on a change, calls _interp_and_publish
|
||||
public class LiveTheoPublisher : IDisposable {
|
||||
public enum Impetus {
|
||||
DRIVER,
|
||||
SKEW,
|
||||
}
|
||||
|
||||
private ThreadedBlackboard _bb;
|
||||
private readonly ITag<IReadOnlyDictionary<(string, Venue), OptionTheoInterpolationData>>
|
||||
_greeks_tag = SparkTags.AllInterpGreeks;
|
||||
@@ -30,13 +35,14 @@ namespace mbts.spark {
|
||||
_bb.subscribe(_drivers_tag);
|
||||
_bb.data_callback += _on_data;
|
||||
_bb.timer_callback += _on_timer;
|
||||
_interp_and_publish();
|
||||
_interp_and_publish(Impetus.SKEW);
|
||||
}
|
||||
|
||||
private void _on_data(object tag, object data) {
|
||||
if (tag.Equals(_drivers_tag) ||
|
||||
tag.Equals(_greeks_tag)) {
|
||||
_interp_and_publish();
|
||||
Impetus imp = tag.Equals(_drivers_tag) ? Impetus.DRIVER : Impetus.SKEW;
|
||||
_interp_and_publish(imp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +109,7 @@ namespace mbts.spark {
|
||||
return TheoPoint.getNulledObject();
|
||||
}
|
||||
|
||||
private void _publish_tc2_theos(IDictionary<SecurityStrike, TheoPoint> theos) {
|
||||
private void _publish_tc2_theos(IDictionary<SecurityStrike, TheoPoint> theos, Impetus imp) {
|
||||
var rv = new Dictionary<(string, Venue), ExpStrikeKeyedData<TheoPoint>>();
|
||||
foreach (var kv in theos) {
|
||||
SecurityStrike k = kv.Key;
|
||||
@@ -118,6 +124,9 @@ namespace mbts.spark {
|
||||
_override_theos(ref rv);
|
||||
foreach (var kv in rv) {
|
||||
_bb.post(SparkTags.TC2Tags.LiveTheosTag(kv.Key), kv.Value);
|
||||
if (imp == Impetus.SKEW) {
|
||||
_bb.post(SparkTags.TC2Tags.VolSaveEventTheosTag(kv.Key), kv.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,6 +141,8 @@ namespace mbts.spark {
|
||||
double strike = t.second;
|
||||
TheoPoint tp = t.third;
|
||||
var call_sec_md = sc_data.get_option(exchange, sym, exp, strike, PutOrCall.Call);
|
||||
if (call_sec_md == null)
|
||||
continue;
|
||||
{
|
||||
NativePriceSize call_bid, call_ask;
|
||||
ulong time = 0;
|
||||
@@ -141,6 +152,8 @@ namespace mbts.spark {
|
||||
}
|
||||
{
|
||||
var put_sec_md = sc_data.get_option(exchange, sym, exp, strike, PutOrCall.Put);
|
||||
if (put_sec_md == null)
|
||||
continue;
|
||||
NativePriceSize put_bid, put_ask;
|
||||
ulong time = 0;
|
||||
put_sec_md.Value.md.get_bbo(ref time, out put_bid, out put_ask);
|
||||
@@ -163,7 +176,7 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
|
||||
private void _interp_and_publish() {
|
||||
private void _interp_and_publish(Impetus imp) {
|
||||
var timer = Stopwatch.StartNew();
|
||||
var res = new Dictionary<uint, GreeksTuple>();
|
||||
var driver_map = _bb.read_state(_drivers_tag);
|
||||
@@ -205,13 +218,13 @@ namespace mbts.spark {
|
||||
}
|
||||
// copy and publish
|
||||
IReadOnlyDictionary<uint, GreeksTuple> res_ro = res;
|
||||
bts.Log.Gen.info($"LiveTheoPublisher._interp_and_publish posting " +
|
||||
bts.Log.Gen.info($"LiveTheoPublisher._interp_and_publish Impetus: {imp} posting " +
|
||||
$"count: {res_ro.Count}");
|
||||
timer.Stop();
|
||||
_logger.log(_log_id, _log_id, timer.Elapsed.TotalMilliseconds);
|
||||
_bb.post(SparkTags.Greeks, res_ro);
|
||||
// oh and those TC2 theos for comptability
|
||||
_publish_tc2_theos(k_theos);
|
||||
_publish_tc2_theos(k_theos, imp);
|
||||
}
|
||||
|
||||
// If we do any rolls like SP for futures, it will be here
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
namespace mbts.spark {
|
||||
using bts.api;
|
||||
|
||||
using Spark.Api.Data;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -25,14 +23,14 @@ namespace mbts.spark {
|
||||
foreach (var kv in driver_map.get_price_map()) {
|
||||
var exp = kv.Key;
|
||||
var dmd = kv.Value;
|
||||
IEnumerable<SecurityMD> exp_secs = sc_data.get_securities((sec_md) => {
|
||||
var s = sec_md.security;
|
||||
return s.security_type() == SecurityType.Option &&
|
||||
s.Symbol == driver_map.option_symbol &&
|
||||
s.earliest_expiration() == (Security.is_perpetual_exp(exp.expiration)
|
||||
? ExpirationDate.Perpetual
|
||||
: ExpirationDate.FixedDate(exp.expiration));
|
||||
});
|
||||
IEnumerable<SecurityMD> exp_secs = sc_data.get_securities(
|
||||
(sec_md) => {
|
||||
var s = sec_md.security;
|
||||
return s.security_type() == SecurityType.Option &&
|
||||
s.Symbol == driver_map.option_symbol &&
|
||||
s.earliest_expiration() == exp.expiration;
|
||||
}
|
||||
);
|
||||
foreach (var sec_md in exp_secs) {
|
||||
rv[sec_md.security.Id] = kv.Value;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace mbts.spark {
|
||||
case SecurityType.Future:
|
||||
case SecurityType.Option:
|
||||
rv.GetOrAdd((sec.Exchange, sec.security_type(), sec.Symbol), _ => new())
|
||||
.Add(sec.earliest_expiration().Value);
|
||||
.Add(sec.earliest_expiration());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.analytics {
|
||||
public static class VolSurfaceConstants {
|
||||
public static int vol_time_sample_mins = 1;
|
||||
public static int vol_time_sample_mins = 5;
|
||||
}
|
||||
// TODO: remove this
|
||||
public static class VolSurfaceTemp {
|
||||
|
||||
@@ -21,13 +21,23 @@ namespace mbts.analytics {
|
||||
private class TimeCalculator : IVolSurfaceTimeCalculator {
|
||||
// TODO, this should be passed in the exp itself
|
||||
private Dictionary<string, TimeSpan> utc_time_of_exp_map = new Dictionary<string, TimeSpan>() {
|
||||
// TODO: get it from config
|
||||
{"BTC", TimeSpan.FromHours(8)},
|
||||
{"ETH", TimeSpan.FromHours(8)}
|
||||
{"ETH", TimeSpan.FromHours(8)},
|
||||
{"SPXW", TimeSpan.FromHours(20)},
|
||||
{"SPX", new TimeSpan(13, 30, 0)}
|
||||
};
|
||||
public void compute_vol_time(VolSurfaceInput vs_input, VolSurfaceExpiration exp,
|
||||
DateTime voltime, double days_shift,
|
||||
out double yrs, out double days_per_yr) {
|
||||
|
||||
days_per_yr = 365;
|
||||
if (vs_input != null && vs_input.surface_settings != null && vs_input.surface_settings.core_settings != null
|
||||
&& vs_input.surface_settings.core_settings.time_settings != null) {
|
||||
if (vs_input.surface_settings.core_settings.time_settings.vol_time_measure.account_for_holidays_and_weekends) {
|
||||
days_per_yr = vs_input.surface_settings.core_settings.time_settings.vol_time_measure.days_per_year;
|
||||
}
|
||||
}
|
||||
TimeSpan time_of_exp = TimeSpan.Zero;
|
||||
utc_time_of_exp_map.TryGetValue(exp.symbol, out time_of_exp);
|
||||
// assumes exp is the utc date of expiration
|
||||
|
||||
@@ -9,8 +9,8 @@ using bts.api;
|
||||
using mbts.spark;
|
||||
|
||||
namespace mbts.analytics {
|
||||
// This class computes the theos/greeks for a number of driver
|
||||
// prices (specified in the vs settings).
|
||||
// This class computes interp theos/greeks (ie for a number of driver
|
||||
// prices (specified in the vs settings)) for a volsurface
|
||||
// It has public setters that get
|
||||
// 1. contracts
|
||||
// 2. vs input
|
||||
@@ -41,7 +41,8 @@ namespace mbts.analytics {
|
||||
private IDictionary<VolSurfaceExpiration, Tuple<double, double>>
|
||||
_computed_driver_range_map = new Dictionary<VolSurfaceExpiration, Tuple<double, double>>();
|
||||
private readonly IEnumerable<double> _default_abs_moves =
|
||||
new double[] { 300, -200, -125, -100, -75, -50, -25, 0, 25, 50, 75, 100, 125, 200, 300 };
|
||||
//new double[] { 300, -200, -125, -100, -75, -50, -25, 0, 25, 50, 75, 100, 125, 200, 300 };
|
||||
new double[] { -100, -50, 0, 50, 100 };
|
||||
private readonly double _cushion_percentage = 25.0;
|
||||
|
||||
public event
|
||||
@@ -135,8 +136,8 @@ namespace mbts.analytics {
|
||||
false, true, false, false, false, _filter_map);
|
||||
timer.stop();
|
||||
vol_compute_time = timer.last_interval_time_ms;
|
||||
Log.Gen.info($"VolSurfacePrecomputedTheosProducer._compute_and_fire volmat time " +
|
||||
$"{timer.last_interval_time_ms}");
|
||||
Log.Gen.info($"VolSurfacePrecomputedTheosProducer._compute_and_fire volmat input_type: {input_type} vs_id: {_vs_id} time " +
|
||||
$"{timer.last_interval_time_ms} tid: {System.Threading.Thread.CurrentThread.ManagedThreadId}");
|
||||
timer.start();
|
||||
IDictionary<VolSurfaceExpiration, IEnumerable<Theos>> exp_theo_map =
|
||||
VolSurfaceTheoCalculator.compute_standard_greeks(synced_vs_input.surface_settings,
|
||||
|
||||
@@ -111,13 +111,43 @@ namespace bts
|
||||
_merge_and_post();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static bool is_active(SecurityMD sec_md) {
|
||||
SecurityImmutable sec = sec_md.security;
|
||||
// temp: to see if spreads work
|
||||
bool fut_or_option = (sec.security_type() == bts.api.SecurityType.Future || sec.security_type() == bts.api.SecurityType.Option);
|
||||
if (!fut_or_option)
|
||||
return true;
|
||||
Func<bool> is_daily_option = () => {
|
||||
bool is_daily = false;
|
||||
if (sec.Exchange == Venue.Cboe) {
|
||||
is_daily = sec.Symbol.ToLower() == "spxw";
|
||||
}
|
||||
if (sec.Exchange == Venue.Glbx) {
|
||||
string symbol = sec.Symbol.ToLower();
|
||||
int unused;
|
||||
is_daily = symbol.Length >= 3 && symbol[0] == 'e' && Int32.TryParse(symbol[1].ToString(), out unused);
|
||||
}
|
||||
return is_daily;
|
||||
};
|
||||
bool is_expired = !SecurityExpirationHelper.is_unexpired(sec);
|
||||
if (is_expired) {
|
||||
return false;
|
||||
}
|
||||
if (sec.security_type() == bts.api.SecurityType.Option) {
|
||||
int days_to_exp = Convert.ToInt32((sec.earliest_expiration() - DateTime.Now).TotalDays);
|
||||
if (is_daily_option()) {
|
||||
return days_to_exp <= 14;
|
||||
} else {
|
||||
return days_to_exp <= 90;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void _merge_and_post()
|
||||
{
|
||||
Func<SecurityMD, bool> is_active = (sec_md) =>
|
||||
{
|
||||
var sec = sec_md.security;
|
||||
return SecurityExpirationHelper.is_unexpired(sec);
|
||||
};
|
||||
var to_pub = _server_sec_map.Where(kv => is_active(kv.Value)).ToDictionary(kv => kv.Key, kv => kv.Value);
|
||||
foreach (var kv in _fake_sec_map)
|
||||
{
|
||||
|
||||
@@ -11,9 +11,8 @@ namespace Spark.Trading {
|
||||
|
||||
using mbts.analytics;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
|
||||
using Spark.Api.Data;
|
||||
using Spark.Api.MarketData;
|
||||
using Spark.Api.Orders;
|
||||
using Spark.Api.Reactive;
|
||||
using Spark.Core;
|
||||
@@ -82,11 +81,6 @@ namespace Spark.Trading {
|
||||
pnl = bus.subscribe(SparkTags.ReportBlackboardTags.PNL.PNLData)
|
||||
.Select(d => d.position_data.ToDictionary(u => u.id(), PNLRowData.from_pnl_unit))
|
||||
.Table(PNLRowData.key_fn)
|
||||
.JoinBbo(
|
||||
bus.subscribe(SparkTags.SecuritiesTag),
|
||||
pnlRow => pnlRow.key.security_id,
|
||||
(pnlRow, bbo) => pnlRow.with(bid_price: bbo.BidPrice, ask_price: bbo.AskPrice),
|
||||
PNLRowData.key_fn)
|
||||
.FullJoin(
|
||||
order_data.working_account_security_orders,
|
||||
PNLRowData.key_fn,
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -626,22 +626,6 @@
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
<TextBlock
|
||||
Grid.Column="6"
|
||||
x:Name="PART_SpreaderType_Label"
|
||||
VerticalAlignment="Center"
|
||||
Margin="{StaticResource Margin.LHeaderPanelItem}"
|
||||
Text="Type"
|
||||
/>
|
||||
<ComboBox
|
||||
x:Name="PART_SpreaderType_DropDown"
|
||||
Grid.Column="7"
|
||||
HorizontalAlignment="Stretch"
|
||||
Margin="{StaticResource Margin.LHeaderPanelItem}"
|
||||
ItemsSource="{TemplateBinding SpreaderTypeItemsSource}"
|
||||
ItemTemplate="{StaticResource EnumDescriptionTemplate}"
|
||||
SelectedItem="{Binding SpreaderType, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
/>
|
||||
<!-- <TextBlock
|
||||
Grid.Column="6"
|
||||
x:Name="PART_HedgePricing_Label"
|
||||
VerticalAlignment="Center"
|
||||
@@ -658,7 +642,7 @@
|
||||
ItemTemplate="{StaticResource EnumDescriptionTemplate}"
|
||||
SelectedItem="{Binding HedgePricing, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Visibility="Collapsed"
|
||||
/> -->
|
||||
/>
|
||||
</Grid>
|
||||
<c:DataGridEx
|
||||
x:Name="PART_DataGrid"
|
||||
|
||||
@@ -237,29 +237,6 @@ namespace mbts.ui.spark {
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SpreaderTypeItemsSource
|
||||
public static readonly DependencyProperty SpreaderTypeItemsSourceProperty =
|
||||
WPFHelper.create_dp<IEnumerable, ExecutionStrategyEditor>(
|
||||
nameof(SpreaderTypeItemsSource));
|
||||
|
||||
public IEnumerable SpreaderTypeItemsSource {
|
||||
get => GetValue(SpreaderTypeItemsSourceProperty) as IEnumerable;
|
||||
set => SetValue(SpreaderTypeItemsSourceProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SpreaderType
|
||||
public static readonly DependencyProperty SpreaderTypeProperty =
|
||||
WPFHelper.create_dp<object, ExecutionStrategyEditor>(
|
||||
nameof(SpreaderType),
|
||||
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault);
|
||||
|
||||
public object SpreaderType {
|
||||
get => GetValue(SpreaderTypeProperty);
|
||||
set => SetValue(SpreaderTypeProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public override void OnApplyTemplate() =>
|
||||
_connect_leg_tuples();
|
||||
|
||||
|
||||
@@ -117,14 +117,6 @@ namespace bts.shell {
|
||||
public static QuoteInsideMarketDistanceThrottle QuoteInsideMarketDistanceThrottle => new QuoteInsideMarketDistanceThrottle();
|
||||
#endregion
|
||||
|
||||
public static SniperQuoteParams SniperQuoteParams => new() {
|
||||
NTicks = 0
|
||||
};
|
||||
|
||||
public static ReverseHedgeQuoteParams ReverseHedgeQuoteParams => new() {
|
||||
NTicks = 0
|
||||
};
|
||||
|
||||
#region PreHedge
|
||||
public static PreHedgeParams PreHedgeParams => new PreHedgeParams {
|
||||
MaxPriceFromInsideMarket = PreHedgeMaxPriceFromInsideMarket,
|
||||
|
||||
@@ -36,8 +36,6 @@
|
||||
ContractPickerVM="{Binding contract_picker_vm}"
|
||||
HedgePricing="{Binding hedge_pricing}"
|
||||
HedgePricingItemsSource="{Binding hedge_pricing_options}"
|
||||
SpreaderType="{Binding spreader_type}"
|
||||
SpreaderTypeItemsSource="{Binding spreader_type_options}"
|
||||
UseFractionalTicks="{Binding use_fractional_ticks}"
|
||||
IntegerTickSize="{Binding integer_tick_size}"
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using mbts.ui.spark;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace mbts.spark {
|
||||
partial class SyntheticEditorVM {
|
||||
class IsQuoteModel : RowModelBase<bool> {
|
||||
public override string display_name { get; } = "Enable Quoting";
|
||||
public override string help_text { get; } = "This parameter is in the form of a check box, where if the box is checked the leg will be quoted versus not checked, it will not be shown in the market. If it is not actively quoted in the market, the leg will still be used for calculation of the entire synthetic.";
|
||||
public override string man_page { get; } = string.Empty;
|
||||
|
||||
public override bool get_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
leg_tup.leg_params.IsActiveQuoting;
|
||||
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, bool value) =>
|
||||
leg_tup.leg_params.IsActiveQuoting = value;
|
||||
|
||||
public override bool has_errors(IReadOnlyCollection<LegSpreaderParamsTuple> leg_tups) =>
|
||||
!leg_tups.Any(lt => lt.leg_params.IsActiveQuoting);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
using mbts.ui.spark;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace mbts.spark;
|
||||
|
||||
partial class SyntheticEditorVM {
|
||||
class QuoteEnabledModel : RowModelBase<bool> {
|
||||
public override string display_name => string.Empty;
|
||||
public override string help_text => string.Empty;
|
||||
public override string man_page => string.Empty;
|
||||
|
||||
public override ParameterSection[] section_path { get; } = new[] { Sections.Quote };
|
||||
|
||||
public override bool get_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
leg_tup.leg_params.IsActiveQuoting;
|
||||
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, bool value) =>
|
||||
leg_tup.leg_params.IsActiveQuoting = value;
|
||||
|
||||
public override bool has_errors(IReadOnlyCollection<LegSpreaderParamsTuple> leg_tups) =>
|
||||
!leg_tups.Any(lt => lt.leg_params.IsActiveQuoting);
|
||||
}
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
using bts.shell;
|
||||
|
||||
using mbts.ui.spark;
|
||||
|
||||
namespace mbts.spark;
|
||||
|
||||
partial class SyntheticEditorVM {
|
||||
class ReverseHedgeEnabledModel : RowModelBase<bool> {
|
||||
readonly ReverseHedgeTicksModel _ticks_model;
|
||||
|
||||
public ReverseHedgeEnabledModel(ReverseHedgeTicksModel ticks_model) =>
|
||||
_ticks_model = ticks_model;
|
||||
|
||||
public override string display_name => string.Empty;
|
||||
public override string help_text => string.Empty;
|
||||
public override string man_page => string.Empty;
|
||||
|
||||
public override ParameterSection[] section_path { get; } = new[] { Sections.ReverseHedge };
|
||||
|
||||
public override bool get_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
leg_tup.leg_params.ReverseHedgeQuoteParams is not null;
|
||||
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, bool value) {
|
||||
if (value) {
|
||||
if (leg_tup.leg_params.ReverseHedgeQuoteParams is null) {
|
||||
leg_tup.leg_params.ReverseHedgeQuoteParams = SyntheticDataHelper.Defaults.ReverseHedgeQuoteParams;
|
||||
_ticks_model.apply_value(leg_tup);
|
||||
}
|
||||
} else {
|
||||
leg_tup.leg_params.ReverseHedgeQuoteParams = null;
|
||||
}
|
||||
_ticks_model.set_enabled(leg_tup, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
using bts.spark;
|
||||
|
||||
using mbts.ui.spark;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace mbts.spark;
|
||||
|
||||
partial class SyntheticEditorVM {
|
||||
internal class ReverseHedgeTicksModel : RowModelBase<int> {
|
||||
readonly Dictionary<int, int> _value_store = new();
|
||||
|
||||
public override string display_name => "Ticks";
|
||||
public override string help_text => string.Empty;
|
||||
public override string man_page => string.Empty;
|
||||
|
||||
public override ParameterSection[] section_path { get; } = new[] { Sections.ReverseHedge };
|
||||
|
||||
public void apply_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
_get_params(leg_tup).NTicks = _value_from_store(leg_tup);
|
||||
|
||||
public override int get_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
_get_params(leg_tup)?.NTicks ?? _value_from_store(leg_tup);
|
||||
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, int value) {
|
||||
_value_store[leg_tup.id] = value;
|
||||
var s = _get_params(leg_tup);
|
||||
if (s is not null) {
|
||||
s.NTicks = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) =>
|
||||
_get_params(leg_tup) != null;
|
||||
|
||||
ReverseHedgeQuoteParams _get_params(LegSpreaderParamsTuple leg_tup) =>
|
||||
leg_tup.leg_params.ReverseHedgeQuoteParams;
|
||||
|
||||
int _value_from_store(LegSpreaderParamsTuple leg_tup) =>
|
||||
_value_store.get_value(leg_tup.id, _ => 0);
|
||||
}
|
||||
}
|
||||
@@ -94,9 +94,7 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
private static class Sections {
|
||||
public static ParameterSection Sniper => new("Sniper", true);
|
||||
public static ParameterSection ReverseHedge => new("Reverse Hedge", true);
|
||||
public static ParameterSection Quote => new("Quote", true);
|
||||
public static ParameterSection Quote => new ParameterSection("Quote");
|
||||
public static ParameterSection PreHedge => new ParameterSection("Pre-Hedge");
|
||||
public static ParameterSection PostHedge => new ParameterSection("Post-Hedge");
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
using bts.shell;
|
||||
|
||||
using mbts.ui.spark;
|
||||
|
||||
namespace mbts.spark;
|
||||
|
||||
partial class SyntheticEditorVM {
|
||||
class SniperEnabledModel : RowModelBase<bool> {
|
||||
readonly SniperTicksModel _ticks_model;
|
||||
|
||||
public SniperEnabledModel(SniperTicksModel ticks_model) =>
|
||||
_ticks_model = ticks_model;
|
||||
|
||||
public override string display_name => string.Empty;
|
||||
public override string help_text => string.Empty;
|
||||
public override string man_page => string.Empty;
|
||||
|
||||
public override ParameterSection[] section_path { get; } = new[] { Sections.Sniper };
|
||||
|
||||
public override bool get_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
leg_tup.leg_params.SniperQuoteParams is not null;
|
||||
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, bool value) {
|
||||
if (value) {
|
||||
if (leg_tup.leg_params.SniperQuoteParams is null) {
|
||||
leg_tup.leg_params.SniperQuoteParams = SyntheticDataHelper.Defaults.SniperQuoteParams;
|
||||
_ticks_model.apply_value(leg_tup);
|
||||
}
|
||||
} else {
|
||||
leg_tup.leg_params.SniperQuoteParams = null;
|
||||
}
|
||||
_ticks_model.set_enabled(leg_tup, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
using bts.spark;
|
||||
|
||||
using mbts.ui.spark;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace mbts.spark;
|
||||
|
||||
partial class SyntheticEditorVM {
|
||||
internal class SniperTicksModel : RowModelBase<int> {
|
||||
readonly Dictionary<int, int> _value_store = new();
|
||||
|
||||
public override string display_name => "Ticks";
|
||||
public override string help_text => string.Empty;
|
||||
public override string man_page => string.Empty;
|
||||
|
||||
public override ParameterSection[] section_path { get; } = new[] { Sections.Sniper };
|
||||
|
||||
public void apply_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
_get_params(leg_tup).NTicks = _value_from_store(leg_tup);
|
||||
|
||||
public override int get_value(LegSpreaderParamsTuple leg_tup) =>
|
||||
_get_params(leg_tup)?.NTicks ?? _value_from_store(leg_tup);
|
||||
|
||||
public override void set_value(LegSpreaderParamsTuple leg_tup, int value) {
|
||||
_value_store[leg_tup.id] = value;
|
||||
var s = _get_params(leg_tup);
|
||||
if (s is not null) {
|
||||
s.NTicks = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool _get_enabled(LegSpreaderParamsTuple leg_tup) =>
|
||||
_get_params(leg_tup) != null;
|
||||
|
||||
SniperQuoteParams _get_params(LegSpreaderParamsTuple leg_tup) =>
|
||||
leg_tup.leg_params.SniperQuoteParams;
|
||||
|
||||
int _value_from_store(LegSpreaderParamsTuple leg_tup) =>
|
||||
_value_store.get_value(leg_tup.id, _ => 0);
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,6 @@ using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
using HedgePricing = bts.spark.ExecutionStrategy.Types.HedgePricing;
|
||||
using SpreaderType = bts.spark.ExecutionStrategy.Types.SpreaderType;
|
||||
|
||||
namespace mbts.spark {
|
||||
/// <summary>
|
||||
@@ -48,7 +47,6 @@ namespace mbts.spark {
|
||||
int _integer_tick_size = 1;
|
||||
ExecutionStrategyImmutable _strategy;
|
||||
HedgePricing _hedge_pricing;
|
||||
SpreaderType _spreader_type;
|
||||
|
||||
/// <summary>
|
||||
/// Inititalizes a new instance of SyntheticEditorVM class. This constructor may only be used for already-existing synthetic securities (id must be non-zero).
|
||||
@@ -200,8 +198,6 @@ namespace mbts.spark {
|
||||
} else {
|
||||
_can_add_leg = backing(nameof(can_add_leg), false);
|
||||
}
|
||||
var sniper_ticks_model = new SniperTicksModel();
|
||||
var reverse_hedge_ticks_model = new ReverseHedgeTicksModel();
|
||||
var show_quantity_quantity = new ShowQuantityQuantityModel();
|
||||
|
||||
var quote_throttle_outside_ticks = new QuoteThrottleOutsideTicksModel();
|
||||
@@ -229,18 +225,15 @@ namespace mbts.spark {
|
||||
|
||||
var post_hedge_opposite_market_based_cross_threshold = new PostHedgeOppositeMarketVolumeBasedCrossThresholdModel();
|
||||
var post_hedge_opposite_market_based_cross_cross_ticks = new PostHedgeOppositeMarketVolumeBasedCrossCrossTicksModel();
|
||||
var is_quote_model = new IsQuoteModel();
|
||||
rows = new IRowModel[] {
|
||||
_quantity_model,
|
||||
_price_mult_model,
|
||||
is_quote_model,
|
||||
//new EnableHedgeModel(), //TAHA_SPREADER
|
||||
new HedgeRatioModel(),
|
||||
new SniperEnabledModel(sniper_ticks_model),
|
||||
sniper_ticks_model,
|
||||
new ReverseHedgeEnabledModel(reverse_hedge_ticks_model),
|
||||
reverse_hedge_ticks_model,
|
||||
//new MinLeanQtyModel(), //TAHA_SPREADER
|
||||
//new QuoteHiddenModel(),
|
||||
new QuoteEnabledModel(),
|
||||
new QuoteQueueHolderModel(),
|
||||
new MarketDataTypeModel(),
|
||||
new ShowQuantityEnabledModel(show_quantity_quantity),
|
||||
@@ -344,13 +337,6 @@ namespace mbts.spark {
|
||||
public HedgePricing hedge_pricing { get => _hedge_pricing; set => Set(ref _hedge_pricing, value); }
|
||||
public IEnumerable<HedgePricing> hedge_pricing_options => EnumHelper.get_values<HedgePricing>();
|
||||
|
||||
// spreader type
|
||||
public SpreaderType spreader_type {
|
||||
get => _spreader_type;
|
||||
set => Set(ref _spreader_type, value);
|
||||
}
|
||||
public IEnumerable<SpreaderType> spreader_type_options => EnumHelper.get_values<SpreaderType>();
|
||||
|
||||
public ExecutionStrategyImmutable get_strategy() {
|
||||
var mutable_strategy = _strategy.CloneToMutable();
|
||||
mutable_strategy.LegParamsMap.Clear();
|
||||
@@ -366,7 +352,6 @@ namespace mbts.spark {
|
||||
_synthetic.Exchange = Venue.Bts;
|
||||
_strategy = strategy;
|
||||
hedge_pricing = strategy.HedgePricing;
|
||||
spreader_type = strategy.SpreaderType;
|
||||
leg_tuples.SetItems(_get_legs(_synthetic, strategy));
|
||||
if (synthetic.HasContractSpec) {
|
||||
/// assign the fields <see cref="_use_fractional_ticks"/> and <see cref="_integer_tick_size"/>,
|
||||
|
||||
@@ -8,7 +8,6 @@ using mbts.ui.controls;
|
||||
|
||||
using ProtoBuf;
|
||||
|
||||
using Spark.Api.Data;
|
||||
using Spark.Api.Orders;
|
||||
|
||||
using System;
|
||||
@@ -92,7 +91,7 @@ namespace bts.shell.fills {
|
||||
|
||||
// PNL's Expiration group popups use this prop to filtered data by a particular exp (it isn't
|
||||
// serialized bc it's not part of the main window's settings)
|
||||
public ExpirationDate? exp_date { get; set; }
|
||||
public DateTime? exp_date { get; set; }
|
||||
}
|
||||
|
||||
static class FillsFilterStatesExtensions {
|
||||
@@ -122,7 +121,7 @@ namespace bts.shell.fills {
|
||||
pb.add_numeric(fs.price, ft => ft.fill.LastPrice);
|
||||
|
||||
if (fs.exp_date.HasValue) {
|
||||
pb.add_exp_date(fs.exp_date.Value, f => f.security?.earliest_expiration());
|
||||
pb.add_date_time(fs.exp_date.Value, f => f.security?.earliest_expiration());
|
||||
}
|
||||
return pb.to_predicate();
|
||||
}
|
||||
|
||||
@@ -41,8 +41,6 @@ namespace mbts.spark {
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
using SpreaderType = bts.spark.ExecutionStrategy.Types.SpreaderType;
|
||||
|
||||
class LadderVM : DisposableViewModelBase, IWillLetYouKnowWhenIDispose, IKeyListener {
|
||||
static readonly Brush _transparent_status_brush = BTSColors.UI.transparent;
|
||||
|
||||
@@ -105,7 +103,6 @@ namespace mbts.spark {
|
||||
ulong _misc_time = 0;
|
||||
ulong _last_trade_time = 0;
|
||||
ulong _last_bbo_time = 0;
|
||||
SpreaderType _spreader_type = SpreaderType.Requote;
|
||||
IReadOnlyDictionary<uint, OrderRecordTuple> _cache = DictionaryHelper.empty<uint, OrderRecordTuple>();
|
||||
ImmutableDictionary<AlgoKey, LadderFavoriteAlgoMetadata> _favorite_algo_metadata_map =
|
||||
ImmutableDictionary<AlgoKey, LadderFavoriteAlgoMetadata>.Empty;
|
||||
@@ -129,9 +126,6 @@ namespace mbts.spark {
|
||||
size_calculator.display_settings = model.security_md.quantity_display;
|
||||
_slot_price_vs_orders = new Dictionary<double, LadderOrderVM>(_equality);
|
||||
this.order_properties_vm = order_properties_vm;
|
||||
if (model.security.HasSynthetic) {
|
||||
spreader_type_choices.AddRange(EnumHelper.get_values<SpreaderType>());
|
||||
}
|
||||
_session_high = backing(nameof(session_high), double.NaN);
|
||||
_session_low = backing(nameof(session_low), double.NaN);
|
||||
_day_change = backing(nameof(day_change), double.NaN);
|
||||
@@ -283,7 +277,9 @@ namespace mbts.spark {
|
||||
var orders_source = settings.Select(s => s.ticks_per_row).DistinctUntilChanged()
|
||||
.SelectSeries(tpr => {
|
||||
var spec = TickUtils.multiply_tick_size(security.regional_ticks(), tpr);
|
||||
return _order_price_source(model.orders, p => spec.round_to_tick(p, RoundingMode.AbsDown));
|
||||
var price_comp = Comparer<double>.Create((a, b) =>
|
||||
Comparer<long?>.Default.Compare(spec.count_ticks(a), spec.count_ticks(b)));
|
||||
return _order_price_source(model.orders, price_comp, p => spec.round_to_tick(p, RoundingMode.AbsDown));
|
||||
});
|
||||
_day_change.Changed += (o, n) => RaisePropertyChanged(
|
||||
nameof(day_change_font_color), nameof(day_change_background_color));
|
||||
@@ -584,12 +580,6 @@ namespace mbts.spark {
|
||||
public ObservableCollection<FairValueLineVM> fair_value_lines { get; } =
|
||||
new ObservableCollection<FairValueLineVM>();
|
||||
|
||||
public SpreaderType spreader_type {
|
||||
get => _spreader_type;
|
||||
set => Set(ref _spreader_type, value);
|
||||
}
|
||||
public ObservableCollection<SpreaderType> spreader_type_choices { get; } = new();
|
||||
|
||||
public uint orders_column_width {
|
||||
get => _orders_column_width.Value;
|
||||
set => _orders_column_width.set(value);
|
||||
@@ -769,21 +759,15 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
var order = order_properties_vm.create(side);
|
||||
var def = order.CustomDef;
|
||||
if (def is not null) {
|
||||
if (def.Stop is not null) {
|
||||
def.Stop.StopPrice = price;
|
||||
} else if (def.StopLimit is not null) {
|
||||
if (order.CustomDef is not null) {
|
||||
if (order.CustomDef.Stop is not null) {
|
||||
order.CustomDef.Stop.StopPrice = price;
|
||||
} else if (order.CustomDef.StopLimit is not null) {
|
||||
// swap the prices here so that the level clicked
|
||||
// in the ladder is the StopPrice (trigger) and the Price
|
||||
// is what was specificed in the extra parameter box
|
||||
(price, def.StopLimit.StopPrice) =
|
||||
(def.StopLimit.StopPrice, price);
|
||||
} else if (def.Spreader is not null) {
|
||||
var strategy = def.Spreader.ExecutionStrategy;
|
||||
if (strategy is not null) {
|
||||
strategy.SpreaderType = spreader_type;
|
||||
}
|
||||
(price, order.CustomDef.StopLimit.StopPrice) =
|
||||
(order.CustomDef.StopLimit.StopPrice, price);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -822,8 +806,10 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
static IObservable<(ImmutableSortedDictionary<double, ImmutableDictionary<uint, OrderRecordTuple>> price_index, IReadOnlyDictionary<uint, OrderRecordTuple> map)> _order_price_source(
|
||||
IObservable<TableUpdate<OrderRecordTuple, uint>> source, Func<double, double> normalize_price) {
|
||||
var price_comp = MathUtils.error_margin_comparer(1E-9);
|
||||
IObservable<TableUpdate<OrderRecordTuple, uint>> source,
|
||||
IComparer<double> price_comp,
|
||||
Func<double, double> normalize_price
|
||||
) {
|
||||
return Observable.Create<(ImmutableSortedDictionary<double, ImmutableDictionary<uint, OrderRecordTuple>>, IReadOnlyDictionary<uint, OrderRecordTuple>)>(o => {
|
||||
var state = ImmutableSortedDictionary.Create<double, ImmutableDictionary<uint, OrderRecordTuple>>(price_comp);
|
||||
var sub = source.Subscribe(table => {
|
||||
@@ -867,18 +853,15 @@ namespace mbts.spark {
|
||||
return sub;
|
||||
});
|
||||
|
||||
bool price_changed(Change<OrderRecordTuple> ch) =>
|
||||
price_comp.Compare(ch.New.order.ui_price(), ch.Old.order.ui_price()) != 0;
|
||||
|
||||
double get_price(OrderRecordTuple order) {
|
||||
var p = order.order.ui_price();
|
||||
if (!(normalize_price is null))
|
||||
p = normalize_price(p);
|
||||
return p;
|
||||
}
|
||||
|
||||
bool price_changed(Change<OrderRecordTuple> ch) {
|
||||
var oldp = get_price(ch.Old);
|
||||
var newp = get_price(ch.New);
|
||||
return price_comp.Compare(oldp, newp) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
double _normalize_price(double price) =>
|
||||
|
||||
@@ -626,30 +626,10 @@ namespace mbts.spark {
|
||||
|
||||
void _send_parameterized_order(Point point, Side side) {
|
||||
Disposable.dispose(ref _parameterized_order_popup);
|
||||
void on_cannot_send(string reason) {
|
||||
Log.Ui.warn($"LadderGridHost cannot send parameterized order. {reason}");
|
||||
}
|
||||
if (_vm is null) {
|
||||
on_cannot_send("ViewModel is null");
|
||||
if (side == Side.Undefined)
|
||||
throw new ArgumentException("Side is undefined.", nameof(side));
|
||||
if (!(_vm.size_calculator.value is double size) || size == 0 || !(_vm.order_properties_vm?.selected_algo_definition?.algo_root?.can_expand ?? false))
|
||||
return;
|
||||
}
|
||||
switch (side) {
|
||||
case Side.Buy:
|
||||
case Side.Sell:
|
||||
break;
|
||||
default:
|
||||
on_cannot_send($"Invalid side '{side}'");
|
||||
return;
|
||||
}
|
||||
double size = _vm?.size_calculator?.value ?? 0;
|
||||
if (size > 0) {
|
||||
return;
|
||||
}
|
||||
bool can_expand = _vm?.order_properties_vm?.selected_algo_definition?.algo_root?.can_expand ?? false;
|
||||
if (!can_expand) {
|
||||
on_cannot_send("Selected algo not parameterized");
|
||||
return;
|
||||
}
|
||||
double price = _price_for_row(_row_for_point(point));
|
||||
var grid = new Grid { DataContext = _vm };
|
||||
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
|
||||
@@ -721,10 +701,6 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
async Task _show_mbo_popup(Point point) {
|
||||
if (_vm is null) {
|
||||
Log.Ui.warn("Cannot show mbo popup. ViewModel is null.");
|
||||
return;
|
||||
}
|
||||
var query = MBOPopupModel.default_query.with(
|
||||
security_id: _vm.model.security.Id,
|
||||
price_level: price_for_point(point)
|
||||
@@ -1448,7 +1424,7 @@ namespace mbts.spark {
|
||||
double best_ask = _get_top_price(_asks);
|
||||
var v = best_bid
|
||||
.if_nan(_spec.tickdown(best_ask))
|
||||
.if_nan(_vm?.settlement ?? double.NaN);
|
||||
.if_nan(_vm.settlement);
|
||||
return _spec.round_to_tick(v, RoundingMode.AbsDown);
|
||||
}
|
||||
|
||||
@@ -1456,14 +1432,11 @@ namespace mbts.spark {
|
||||
TickUtils.normalize_price(_spec, price);
|
||||
|
||||
double _get_ask_market_break() {
|
||||
if (_vm is null) {
|
||||
return double.NaN;
|
||||
}
|
||||
double best_bid = _get_top_price(_bids);
|
||||
double best_ask = _get_top_price(_asks);
|
||||
var v = _spec.tickdown(best_ask)
|
||||
.if_nan(best_bid)
|
||||
.if_nan(_vm?.settlement ?? double.NaN);
|
||||
.if_nan(_vm.settlement);
|
||||
return _spec.round_to_tick(v, RoundingMode.AbsDown);
|
||||
}
|
||||
|
||||
@@ -1473,15 +1446,15 @@ namespace mbts.spark {
|
||||
var v = TickUtils.mid_tick(_spec, best_bid, best_ask)
|
||||
.if_nan(best_bid)
|
||||
.if_nan(_spec?.tickdown(best_ask) ?? double.NaN)
|
||||
.if_nan(_vm?.settlement ?? double.NaN);
|
||||
.if_nan(_vm.settlement);
|
||||
return _spec.round_to_tick(v, RoundingMode.AbsDown);
|
||||
}
|
||||
|
||||
double _get_session_low() => _normalize_price(_get_session_low_raw());
|
||||
double _get_session_high() => _normalize_price(_get_session_high_raw());
|
||||
|
||||
double _get_session_low_raw() => _vm?.md?.session_low ?? double.NaN;
|
||||
double _get_session_high_raw() => _vm?.md?.session_high ?? double.NaN;
|
||||
double _get_session_low_raw() => _vm.md.session_low;
|
||||
double _get_session_high_raw() => _vm.md.session_high;
|
||||
|
||||
void _render_mkt_break(DrawingVisual vis, double price, uint color) =>
|
||||
LadderRender.render_mkt_break(vis, _row_for_price(price), _settings.row_height, color);
|
||||
@@ -1502,7 +1475,7 @@ namespace mbts.spark {
|
||||
}
|
||||
/// The viewmodel will always have the most up-to-date settings, so ignore <see cref="s"/> and just get it from <see cref="_vm"/>.
|
||||
/// This is a workaround for the global settings-defaults issue: when defaults are updated, some properties are inadvertantly overwritten, such as column-widths, etc.
|
||||
_settings = _vm?.get_save_state() ?? s;
|
||||
_settings = _vm.get_save_state();
|
||||
_pending_scroll_to_origin |= _settings == null;
|
||||
_invalidate_spec();
|
||||
if (_price_list != null) {
|
||||
@@ -1578,17 +1551,15 @@ namespace mbts.spark {
|
||||
_visual_host.AddVisualChild(_mid_mkt_break_vis);
|
||||
_visual_host.AddVisualChild(_ask_mkt_break_vis);
|
||||
_visual_host.AddVisualChild(_bid_mkt_break_vis);
|
||||
if (_vm is not null) {
|
||||
_fair_value_lines_sub = ui.utility.ObservableAutoWrapper.connect(
|
||||
_vm.fair_value_lines,
|
||||
_mkt_break_lines.fair_value_line_views,
|
||||
vm => {
|
||||
var with_vis = new FairValueLineWithVis(vm);
|
||||
_visual_host.AddVisualChild(with_vis.vis);
|
||||
return with_vis;
|
||||
},
|
||||
with_vis => _visual_host.RemoveVisualChild(with_vis.vis));
|
||||
}
|
||||
_fair_value_lines_sub = ui.utility.ObservableAutoWrapper.connect(
|
||||
_vm.fair_value_lines,
|
||||
_mkt_break_lines.fair_value_line_views,
|
||||
vm => {
|
||||
var with_vis = new FairValueLineWithVis(vm);
|
||||
_visual_host.AddVisualChild(with_vis.vis);
|
||||
return with_vis;
|
||||
},
|
||||
with_vis => _visual_host.RemoveVisualChild(with_vis.vis));
|
||||
_visual_host.AddVisualChild(_session_low_vis);
|
||||
_visual_host.AddVisualChild(_session_high_vis);
|
||||
_render_grid_background();
|
||||
|
||||
@@ -956,13 +956,6 @@
|
||||
</Style>
|
||||
</uag:OrderDetailsPopupControl.Resources>
|
||||
</uag:OrderDetailsPopupControl>
|
||||
|
||||
<ComboBox
|
||||
Margin="2"
|
||||
ItemsSource="{Binding spreader_type_choices}"
|
||||
SelectedItem="{Binding spreader_type}"
|
||||
Visibility="{Binding HasItems, Mode=OneWay, RelativeSource={RelativeSource Self}, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
/>
|
||||
|
||||
<!-- Position into Qty Button -->
|
||||
<Button
|
||||
|
||||
@@ -5,7 +5,6 @@ using mbts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
|
||||
using Spark.Api.Data;
|
||||
using Spark.Core.Data;
|
||||
using Spark.Core.Disposables;
|
||||
using Spark.Core.Reflection;
|
||||
|
||||
@@ -8,7 +8,6 @@ using bts.utils;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
|
||||
using Spark.Api.Data;
|
||||
using Spark.Api.Orders;
|
||||
using Spark.Core.Collections;
|
||||
using Spark.ViewModel.Commands;
|
||||
|
||||
@@ -1,317 +1,527 @@
|
||||
using bts.api;
|
||||
using bts.api.position;
|
||||
using bts.utils;
|
||||
|
||||
using mbts;
|
||||
using mbts.analytics;
|
||||
using mbts.spark;
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Api.Data;
|
||||
using Spark.Api.Position;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
using PNLKey = bts.AccountSecurityKey;
|
||||
|
||||
namespace bts.shell.pnl {
|
||||
public enum PNLCalculationType {
|
||||
None,
|
||||
Bid,
|
||||
Ask,
|
||||
Opposite,
|
||||
Same,
|
||||
[Description("Cascade")]
|
||||
Waterfall,
|
||||
Last,
|
||||
Mid,
|
||||
Settle
|
||||
}
|
||||
|
||||
readonly struct PNLRowData : IEquatable<PNLRowData> {
|
||||
public static readonly Func<PNLRowData, PNLKey> key_fn = d => d.key;
|
||||
public static IComparer<PNLRowData> key_comparer = Comparer<PNLKey>.Default.wrap<PNLKey, PNLRowData>(d => d.key);
|
||||
|
||||
public readonly PNLKey key;
|
||||
public readonly SecurityImmutable? security;
|
||||
public readonly QuantityConversionData<double> qty_conversion;
|
||||
public readonly uint account_id;
|
||||
public readonly string account_name;
|
||||
public readonly PNLCalculationType calc_type;
|
||||
public readonly PositionPriceSizeWithGreeks sod;
|
||||
public readonly PositionPriceSizeWithGreeks day;
|
||||
public readonly WorkingOrderData working;
|
||||
|
||||
public readonly double
|
||||
default_cpp,
|
||||
bid_price,
|
||||
ask_price,
|
||||
last_price,
|
||||
settlement_price;
|
||||
|
||||
public readonly double? override_cpp;
|
||||
|
||||
public PNLRowData(
|
||||
PNLKey key,
|
||||
double default_cpp = 1,
|
||||
double? override_cpp = null,
|
||||
double pnl_price = double.NaN,
|
||||
double bid_price = 0,
|
||||
double ask_price = 0,
|
||||
double last_price = 0,
|
||||
double settlement_price = 0,
|
||||
PositionPriceSizeWithGreeks? sod = null,
|
||||
PositionPriceSizeWithGreeks? day = null,
|
||||
WorkingOrderData? working = null,
|
||||
SecurityImmutable? security = null,
|
||||
uint account_id = 0,
|
||||
string account_name = null,
|
||||
PNLCalculationType calc_type = PNLCalculationType.Mid,
|
||||
QuantityConversionData<double>? qty_conversion = null) {
|
||||
//
|
||||
this.key = key;
|
||||
this.default_cpp = default_cpp;
|
||||
this.override_cpp = override_cpp;
|
||||
this.pnl_price = pnl_price;
|
||||
this.bid_price = bid_price;
|
||||
this.ask_price = ask_price;
|
||||
this.last_price = last_price;
|
||||
this.settlement_price = settlement_price;
|
||||
this.sod = sod ?? PositionPriceSizeWithGreeks.empty;
|
||||
this.day = day ?? PositionPriceSizeWithGreeks.empty;
|
||||
this.working = working ?? WorkingOrderData.Empty;
|
||||
this.security = security;
|
||||
this.account_id = account_id;
|
||||
this.account_name = account_name;
|
||||
this.calc_type = calc_type;
|
||||
this.qty_conversion = qty_conversion ?? new();
|
||||
}
|
||||
|
||||
public AccountTuple account => new(account_id, account_name);
|
||||
public string symbol => security?.pnl_symbol() ?? string.Empty;
|
||||
public ExpirationDate expiration =>
|
||||
security?.normal_expirations()?.MinOrDefault(ExpirationDate.None) ?? ExpirationDate.None;
|
||||
public double effective_cpp => override_cpp ?? default_cpp;
|
||||
|
||||
/// Market/Calc
|
||||
public double mid_price => (bid_price + ask_price) / 2;
|
||||
public double pnl_price { get; }
|
||||
|
||||
/// Sod
|
||||
public double sod_pnl => new[] { sod_realized_pnl, sod_unrealized_pnl }.sum_real();
|
||||
public double sod_long_pos => sod.long_pos;
|
||||
public double sod_long_avg_price => sod.long_avg;
|
||||
public double sod_long_avg_pnl => bid_price - sod.long_avg;
|
||||
public double sod_short_pos => sod.short_pos;
|
||||
public double sod_short_avg_price => sod.short_avg;
|
||||
public double sod_short_avg_pnl => sod.short_avg - ask_price;
|
||||
public double sod_net_pos => sod.net_pos;
|
||||
public double sod_net_avg_price => sod.net_avg;
|
||||
public double sod_unrealized_pnl => sod_long_pos > sod_short_pos
|
||||
? (sod_long_pos - sod_short_pos) * effective_cpp * (bid_price - sod_long_avg_price)
|
||||
: (sod_short_pos - sod_long_pos) * effective_cpp * (sod_short_avg_price - ask_price);
|
||||
public double sod_realized_pnl => (sod_short_avg_price - sod_long_avg_price) * effective_cpp * Math.Min(sod_long_pos, sod_short_pos);
|
||||
public double sod_delta => sod.delta;
|
||||
public double sod_gamma => sod.gamma;
|
||||
public double sod_vega => sod.vega;
|
||||
public double sod_theta => sod.theta;
|
||||
public double display_sod_net_pos => qty_conversion.to_display(sod_net_pos);
|
||||
public double display_sod_long_pos => qty_conversion.to_display(sod_long_pos);
|
||||
public double display_sod_short_pos => qty_conversion.to_display(sod_short_pos);
|
||||
|
||||
/// Day
|
||||
public double day_pnl => new[] { day_realized_pnl + day_unrealized_pnl }.sum_real();
|
||||
public double day_long_pos => day.long_pos;
|
||||
public double day_long_avg_price => day.long_avg;
|
||||
public double day_long_avg_pnl => bid_price - day.long_avg;
|
||||
public double day_short_pos => day.short_pos;
|
||||
public double day_short_avg_price => day.short_avg;
|
||||
public double day_short_avg_pnl => day.short_avg - ask_price;
|
||||
public double day_delta => day.delta;
|
||||
public double day_gamma => day.gamma;
|
||||
public double day_vega => day.vega;
|
||||
public double day_theta => day.theta;
|
||||
public bool has_day_trades => day.long_pos > 0 || day.short_pos > 0;
|
||||
public double day_net_pos => day.net_pos;
|
||||
public double day_net_avg => day.net_avg;
|
||||
public double day_unrealized_pnl => day_long_pos > day_short_pos
|
||||
? (day_long_pos - day_short_pos) * effective_cpp * (bid_price - day_long_avg_price)
|
||||
: (day_short_pos - day_long_pos) * effective_cpp * (day_short_avg_price - ask_price);
|
||||
public double day_realized_pnl => (day_short_avg_price - day_long_avg_price) * effective_cpp * Math.Min(day_long_pos, day_short_pos);
|
||||
public double display_day_net_pos => qty_conversion.to_display(day_net_pos);
|
||||
public double display_day_long_pos => qty_conversion.to_display(day_long_pos);
|
||||
public double display_day_short_pos => qty_conversion.to_display(day_short_pos);
|
||||
|
||||
/// Total
|
||||
public double total_pnl => new[] { sod_pnl, day_pnl }.sum_real();
|
||||
public double total_long_pos => new[] { sod.long_pos, day.long_pos }.sum_real();
|
||||
public double total_long_avg_price =>
|
||||
MathUtils.weighted_average(
|
||||
sod_long_avg_price.if_nan(0),
|
||||
sod_long_pos.if_nan(0),
|
||||
day_long_avg_price.if_nan(0),
|
||||
day_long_pos.if_nan(0));
|
||||
public double total_long_avg_pnl => new[] { sod_long_avg_pnl, day_long_avg_pnl }.sum_real();
|
||||
public double total_short_pos => new[] { sod.short_pos, day.short_pos }.sum_real();
|
||||
public double total_short_avg_price =>
|
||||
MathUtils.weighted_average(
|
||||
sod_short_avg_price.if_nan(0),
|
||||
sod_short_pos.if_nan(0),
|
||||
day_short_avg_price.if_nan(0),
|
||||
day_short_pos.if_nan(0));
|
||||
public double total_short_avg_pnl => new[] { sod_short_avg_pnl, day_short_avg_pnl }.sum_real();
|
||||
public double total_net_pos => new[] { sod.long_pos, -sod.short_pos, day.long_pos, -day.short_pos }.Where(n => n.is_real()).Sum();
|
||||
public double total_unrealized_pnl => new[] { sod_unrealized_pnl, day_unrealized_pnl }.sum_real();
|
||||
public double total_realized_pnl => new[] { sod_realized_pnl, day_realized_pnl }.sum_real();
|
||||
public double total_delta => sod.delta.add_real(day.delta);
|
||||
public double total_gamma => sod.gamma.add_real(day.gamma);
|
||||
public double total_vega => sod.vega.add_real(day.vega);
|
||||
public double total_theta => sod.theta.add_real(day.theta);
|
||||
public double display_total_net_pos => qty_conversion.to_display(total_net_pos);
|
||||
public double display_total_long_pos => qty_conversion.to_display(total_long_pos);
|
||||
public double display_total_short_pos => qty_conversion.to_display(total_short_pos);
|
||||
|
||||
/// Working
|
||||
public double working_long_pos => working.long_data.working_total;
|
||||
public double working_long_avg_price => effective_cpp * working.long_data.avg_price;
|
||||
public double working_long_top_price => effective_cpp * working.long_data.top_price;
|
||||
public double working_short_pos => working.short_data.working_total;
|
||||
public double working_short_avg_price => effective_cpp * working.short_data.avg_price;
|
||||
public double working_short_top_price => effective_cpp * working.short_data.top_price;
|
||||
public double working_net_pos => working_long_pos - working_short_pos;
|
||||
public double display_working_net_pos => qty_conversion.to_display(working_net_pos);
|
||||
public double display_working_long_pos => qty_conversion.to_display(working_long_pos);
|
||||
public double display_working_short_pos => qty_conversion.to_display(working_short_pos);
|
||||
|
||||
public static PNLRowData from_pnl_unit(IPNLUnit u) =>
|
||||
new(
|
||||
u.id(),
|
||||
default_cpp: u.security.spec_or_default().CashPerPoint,
|
||||
override_cpp: null,
|
||||
pnl_price: u.theo,
|
||||
bid_price: double.NaN,
|
||||
ask_price: double.NaN,
|
||||
last_price: double.NaN,
|
||||
settlement_price: u.settle_price,
|
||||
// Now computed as the sum: sod_realized_pnl + sod_unrealized_pnl
|
||||
// sod_pnl: u.start_pnl,
|
||||
sod: new() {
|
||||
price_size = new(
|
||||
u.start_long_pos,
|
||||
u.start_long_avg_cost,
|
||||
u.start_short_pos,
|
||||
-u.start_short_avg_cost),
|
||||
greeks = new() {
|
||||
delta = u.start_delta,
|
||||
gamma = u.start_gamma,
|
||||
vega = u.start_vega,
|
||||
theta = u.start_theta
|
||||
}
|
||||
},
|
||||
// Now computed as the sum: day_realized_pnl + day_unrealized_pnl
|
||||
// day_pnl: u.day_pnl,
|
||||
day: new() {
|
||||
price_size = new(
|
||||
u.day_long_pos,
|
||||
u.day_long_avg_cost,
|
||||
u.day_short_pos,
|
||||
-u.day_short_avg_cost),
|
||||
greeks = new() {
|
||||
delta = u.day_delta,
|
||||
gamma = u.day_gamma,
|
||||
vega = u.day_vega,
|
||||
theta = u.day_theta
|
||||
}
|
||||
},
|
||||
working: null,
|
||||
security: u.security,
|
||||
account_id: u.account_id,
|
||||
account_name: u.account,
|
||||
calc_type: PNLCalculationType.Mid,
|
||||
qty_conversion: null);
|
||||
|
||||
public PNLRowData with(
|
||||
SecurityImmutable? security = null,
|
||||
uint? account_id = null,
|
||||
string account_name = null,
|
||||
WorkingOrderData? working = null,
|
||||
PNLCalculationType? calc_type = null,
|
||||
double? bid_price = null,
|
||||
double? ask_price = null) =>
|
||||
new PNLRowData(
|
||||
key,
|
||||
default_cpp,
|
||||
override_cpp,
|
||||
pnl_price,
|
||||
bid_price ?? this.bid_price,
|
||||
ask_price ?? this.ask_price,
|
||||
last_price,
|
||||
settlement_price,
|
||||
sod,
|
||||
day,
|
||||
working ?? this.working,
|
||||
security ?? this.security,
|
||||
account_id ?? this.account_id,
|
||||
account_name ?? this.account_name,
|
||||
calc_type ?? this.calc_type,
|
||||
qty_conversion: qty_conversion);
|
||||
|
||||
public PNLRowData with(SecurityMD smd) {
|
||||
ulong time = 0;
|
||||
if (!smd.md.get_bbo(ref time, out var bid, out var ask)) {
|
||||
return this;
|
||||
}
|
||||
return with(security: smd.security, bid_price: bid.price, ask_price: ask.price);
|
||||
}
|
||||
|
||||
public bool Equals(PNLRowData other) =>
|
||||
key == other.key &&
|
||||
default_cpp == other.default_cpp &&
|
||||
override_cpp == other.override_cpp &&
|
||||
security.HasValue == other.security.HasValue &&
|
||||
account_name == other.account_name &&
|
||||
sod == other.sod &&
|
||||
day == other.day &&
|
||||
bid_price.Equals(other.bid_price) &&
|
||||
ask_price.Equals(other.ask_price) &&
|
||||
last_price.Equals(other.last_price) &&
|
||||
mid_price.Equals(other.mid_price) &&
|
||||
settlement_price.Equals(other.settlement_price) &&
|
||||
calc_type.Equals(other.calc_type) &&
|
||||
working.summary == other.working.summary &&
|
||||
qty_conversion == other.qty_conversion;
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
obj is PNLRowData other && Equals(other);
|
||||
|
||||
// assuming callers will not combine different values with the same key,
|
||||
// the other components shouldn't be included in the hash calculation.
|
||||
public override int GetHashCode() =>
|
||||
key.GetHashCode();
|
||||
|
||||
public static bool operator ==(PNLRowData a, PNLRowData b) => a.Equals(b);
|
||||
public static bool operator !=(PNLRowData a, PNLRowData b) => !a.Equals(b);
|
||||
}
|
||||
|
||||
static class PNLDataExtensions {
|
||||
public static string pnl_symbol(this SecurityImmutable security) {
|
||||
return bts.api.ExchangeSpecificUtilities.get_pnl_symbol(security);
|
||||
}
|
||||
|
||||
// while override_cpp could use double.NaN to indicate the lack of an override,
|
||||
// the nullable double makes it clear that it is an optional value.
|
||||
public static (double default_cpp, double? override_cpp) pnl_cpp_tuple(this PNLUnitImmutable pnl_unit, SecurityImmutable? security) =>
|
||||
security.HasValue ?
|
||||
pnl_cpp_tuple(pnl_unit, security.Value) :
|
||||
(pnl_unit.CashValue, pnl_unit.HasCppOverride ? pnl_unit.CppOverride.Value : (double?)null);
|
||||
|
||||
public static (double default_cpp, double? override_cpp) pnl_cpp_tuple(this PNLUnitImmutable pnl_unit, SecurityImmutable security) {
|
||||
// TODO: actual impl
|
||||
double calced_pnl = bts.api.ExchangeSpecificUtilities.get_cpp(pnl_unit, security);
|
||||
return (calced_pnl, pnl_unit.HasCppOverride ? pnl_unit.CppOverride.Value : (double?)null);
|
||||
}
|
||||
}
|
||||
}
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using bts.api.position;
|
||||
using bts.utils;
|
||||
|
||||
using mbts;
|
||||
using mbts.analytics;
|
||||
using mbts.spark;
|
||||
using mbts.spark.utilities;
|
||||
using mbts.ui;
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Api.Orders;
|
||||
using Spark.Api.Position;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
using PNLKey = bts.AccountSecurityKey;
|
||||
|
||||
namespace bts.shell.pnl {
|
||||
public enum PNLCalculationType {
|
||||
None,
|
||||
Bid,
|
||||
Ask,
|
||||
Opposite,
|
||||
Same,
|
||||
[Description("Cascade")]
|
||||
Waterfall,
|
||||
Last,
|
||||
Mid,
|
||||
Settle
|
||||
}
|
||||
|
||||
readonly struct WorkingOrderData {
|
||||
public readonly WorkingOrderSideData long_data, short_data;
|
||||
|
||||
WorkingOrderData(WorkingOrderSideData long_data, WorkingOrderSideData short_data) {
|
||||
this.long_data = long_data;
|
||||
this.short_data = short_data;
|
||||
}
|
||||
|
||||
public static WorkingOrderData Empty =>
|
||||
new WorkingOrderData(WorkingOrderSideData.EmptyLong, WorkingOrderSideData.EmptyShort);
|
||||
|
||||
public double top_bid =>
|
||||
long_data.data.Count > 0 ?
|
||||
long_data.data.First().Key :
|
||||
double.NaN;
|
||||
|
||||
public double top_ask =>
|
||||
short_data.data.Count > 0 ?
|
||||
short_data.data.First().Key :
|
||||
double.NaN;
|
||||
|
||||
public PositionPriceSize summary =>
|
||||
new PositionPriceSize(long_data.working_total, long_data.avg_price, short_data.working_total, short_data.avg_price);
|
||||
|
||||
public static WorkingOrderData Create(
|
||||
IEnumerable<OrderRecordImmutable> orders, QuantityConversionData<double> qty_conversion) =>
|
||||
Create(orders.Select(o => (o, qty_conversion)));
|
||||
|
||||
public static WorkingOrderData Create(
|
||||
IEnumerable<(OrderRecordImmutable order, QuantityConversionData<double> qty_conversion)> orders) =>
|
||||
orders.Aggregate(Empty, (seed, tup) => seed.Add(tup.order, tup.qty_conversion));
|
||||
|
||||
public WorkingOrderData Add(OrderRecordImmutable order, QuantityConversionData<double> qty_conversion) {
|
||||
if (order.working_quantity() <= 0)
|
||||
return new WorkingOrderData(long_data, short_data);
|
||||
switch (order.side()) {
|
||||
case Side.Buy: return new WorkingOrderData(long_data.Add(order, qty_conversion), short_data);
|
||||
case Side.Sell: return new WorkingOrderData(long_data, short_data.Add(order, qty_conversion));
|
||||
default: throw ExceptionBuilder.Argument.unexpected_case(order.side(), "order.side");
|
||||
}
|
||||
}
|
||||
|
||||
public WorkingOrderData Remove(OrderRecordImmutable order) {
|
||||
if (order.working_quantity() <= 0)
|
||||
return new WorkingOrderData(long_data, short_data);
|
||||
switch (order.side()) {
|
||||
case Side.Buy: return new WorkingOrderData(long_data.Remove(order.Key, order.price()), short_data);
|
||||
case Side.Sell: return new WorkingOrderData(long_data, short_data.Remove(order.Key, order.price()));
|
||||
default: throw ExceptionBuilder.Argument.unexpected_case(order.side(), "order.side");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
readonly struct WorkingOrderSideData {
|
||||
public readonly double avg_price, display_avg_price;
|
||||
public readonly ImmutableSortedDictionary<double, ImmutableDictionary<uint, (OrderRecordImmutable order, QuantityConversionData<double> qty_conversion)>> data;
|
||||
public readonly double working_total;
|
||||
public readonly double display_working_total;
|
||||
|
||||
WorkingOrderSideData(
|
||||
double avg_price,
|
||||
double working_total,
|
||||
double display_avg_price,
|
||||
double display_working_total,
|
||||
ImmutableSortedDictionary<double, ImmutableDictionary<uint, (OrderRecordImmutable, QuantityConversionData<double>)>> data
|
||||
) {
|
||||
this.avg_price = avg_price;
|
||||
this.working_total = working_total;
|
||||
this.display_avg_price = display_avg_price;
|
||||
this.data = data;
|
||||
this.display_working_total = display_working_total;
|
||||
}
|
||||
|
||||
public static WorkingOrderSideData EmptyLong => new(
|
||||
double.NaN, 0, double.NaN, 0,
|
||||
ImmutableSortedDictionary.Create<double, ImmutableDictionary<uint, (OrderRecordImmutable, QuantityConversionData<double>)>>(
|
||||
new ReverseComparer<double>(new OrderPriceComparer())));
|
||||
|
||||
public static WorkingOrderSideData EmptyShort => new(
|
||||
double.NaN, 0, double.NaN, 0,
|
||||
ImmutableSortedDictionary.Create<double, ImmutableDictionary<uint, (OrderRecordImmutable, QuantityConversionData<double>)>>(
|
||||
new OrderPriceComparer()));
|
||||
|
||||
public double top_price =>
|
||||
data.Count > 0 ?
|
||||
data.First().Key :
|
||||
double.NaN;
|
||||
|
||||
public double top_volume =>
|
||||
data.Count > 0 ?
|
||||
data.Values.First().Values.Sum(o => o.order.working_quantity()) :
|
||||
0;
|
||||
|
||||
public double display_top_volume =>
|
||||
data.Count > 0 ?
|
||||
data.Values.First().Values.Sum(o => o.qty_conversion
|
||||
.convert_numeric_type<double>()
|
||||
.to_display(o.order.working_quantity())) :
|
||||
0;
|
||||
|
||||
public WorkingOrderSideData Add(OrderRecordImmutable order_record) =>
|
||||
Add(order_record, new());
|
||||
|
||||
public WorkingOrderSideData Add(
|
||||
OrderRecordImmutable order_record, QuantityConversionData<double> qty_conversion) {
|
||||
var working_qty = order_record.working_quantity();
|
||||
if (working_qty <= 0)
|
||||
throw new ArgumentException(nameof(working_qty));
|
||||
uint order = order_record.Key;
|
||||
var dworking_qty = qty_conversion.to_display(working_qty);
|
||||
double price = order_record.price();
|
||||
if (working_total == 0) {
|
||||
Log.assert(display_working_total == 0);
|
||||
return new WorkingOrderSideData(price, working_qty, display_avg_price, dworking_qty, data.Add(
|
||||
price, ImmutableDictionary<uint, (OrderRecordImmutable, QuantityConversionData<double>)>.Empty.Add(order, (order_record, qty_conversion))));
|
||||
} else return new WorkingOrderSideData(
|
||||
avg_price + ((price - avg_price) * ((double)working_qty / (working_total + working_qty))),
|
||||
working_total + working_qty,
|
||||
display_avg_price + ((price - display_avg_price) * ((double)dworking_qty / (display_working_total + dworking_qty))),
|
||||
display_working_total + dworking_qty,
|
||||
data.SetItem(price, data.TryGetValue(price, out var curr) ?
|
||||
curr.Add(order, (order_record, qty_conversion)) :
|
||||
ImmutableDictionary<uint, (OrderRecordImmutable, QuantityConversionData<double>)>.Empty.Add(order, (order_record, qty_conversion))));
|
||||
}
|
||||
|
||||
public WorkingOrderSideData Remove(uint order, double price) {
|
||||
var tmp_data = data;
|
||||
if (!tmp_data.TryGetValue(price, out var wdata))
|
||||
throw new KeyNotFoundException(nameof(price));
|
||||
if (!wdata.TryGetValue(order, out var worder))
|
||||
throw new KeyNotFoundException(nameof(order));
|
||||
var wqty = worder.order.working_quantity();
|
||||
var dwqty = worder.qty_conversion.to_display(wqty);
|
||||
wdata = wdata.Remove(order);
|
||||
if (wdata.Count == 0)
|
||||
tmp_data = tmp_data.Remove(price);
|
||||
if (tmp_data.Count == 0)
|
||||
return new(
|
||||
double.NaN, 0, double.NaN, 0,
|
||||
ImmutableSortedDictionary.Create<double, ImmutableDictionary<uint, (OrderRecordImmutable, QuantityConversionData<double>)>>(
|
||||
data.KeyComparer));
|
||||
return new(
|
||||
avg_price - ((price - avg_price) * (wqty / (working_total - wqty))),
|
||||
working_total - wqty,
|
||||
display_avg_price - ((price - display_avg_price) * (dwqty / (display_working_total - dwqty))),
|
||||
display_working_total - dwqty,
|
||||
tmp_data);
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
if (data.Count > 0) {
|
||||
var best_order = data.Values.First().Values.First();
|
||||
return OrderUtils.order_collection_summary(
|
||||
best_order.order.price(),
|
||||
display_avg_price,
|
||||
best_order.qty_conversion.to_display(best_order.order.working_quantity()),
|
||||
display_working_total,
|
||||
Security.Defaults.ContractSpecificationImmutable);
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
readonly struct PNLRowData : IEquatable<PNLRowData> {
|
||||
public static readonly Func<PNLRowData, PNLKey> key_fn = d => d.key;
|
||||
public static IComparer<PNLRowData> key_comparer = Comparer<PNLKey>.Default.wrap<PNLKey, PNLRowData>(d => d.key);
|
||||
|
||||
static readonly WaterfallPriceFlags[] _waterfall_preferences = new[] {
|
||||
WaterfallPriceFlags.LastInsideSpread,
|
||||
WaterfallPriceFlags.Mid,
|
||||
WaterfallPriceFlags.LastGTEBid,
|
||||
WaterfallPriceFlags.Bid,
|
||||
WaterfallPriceFlags.LastLTEAsk,
|
||||
WaterfallPriceFlags.Ask,
|
||||
WaterfallPriceFlags.Last,
|
||||
WaterfallPriceFlags.Settle
|
||||
};
|
||||
|
||||
public readonly PNLKey key;
|
||||
public readonly SecurityImmutable? security;
|
||||
public readonly QuantityConversionData<double> qty_conversion;
|
||||
public readonly uint account_id;
|
||||
public readonly string account_name;
|
||||
public readonly PNLCalculationType calc_type;
|
||||
public readonly PositionPriceSizeWithGreeks sod;
|
||||
public readonly PositionPriceSizeWithGreeks day;
|
||||
public readonly WorkingOrderData working;
|
||||
|
||||
public readonly double
|
||||
default_cpp,
|
||||
bid_price,
|
||||
ask_price,
|
||||
last_price,
|
||||
settlement_price;
|
||||
|
||||
public readonly double? override_cpp;
|
||||
|
||||
public PNLRowData(
|
||||
PNLKey key,
|
||||
double default_cpp = 1,
|
||||
double? override_cpp = null,
|
||||
double pnl_price = double.NaN,
|
||||
double bid_price = 0,
|
||||
double ask_price = 0,
|
||||
double last_price = 0,
|
||||
double settlement_price = 0,
|
||||
double sod_pnl = 0,
|
||||
PositionPriceSizeWithGreeks? sod = null,
|
||||
double day_pnl = 0,
|
||||
PositionPriceSizeWithGreeks? day = null,
|
||||
WorkingOrderData? working = null,
|
||||
SecurityImmutable? security = null,
|
||||
uint account_id = 0,
|
||||
string account_name = null,
|
||||
PNLCalculationType calc_type = PNLCalculationType.Mid,
|
||||
QuantityConversionData<double>? qty_conversion = null) {
|
||||
//
|
||||
this.key = key;
|
||||
this.default_cpp = default_cpp;
|
||||
this.override_cpp = override_cpp;
|
||||
this.pnl_price = pnl_price;
|
||||
this.bid_price = bid_price;
|
||||
this.ask_price = ask_price;
|
||||
this.last_price = last_price;
|
||||
this.settlement_price = settlement_price;
|
||||
this.sod_pnl = sod_pnl;
|
||||
this.sod = sod ?? PositionPriceSizeWithGreeks.empty;
|
||||
this.day_pnl = day_pnl;
|
||||
this.day = day ?? PositionPriceSizeWithGreeks.empty;
|
||||
this.working = working ?? WorkingOrderData.Empty;
|
||||
this.security = security;
|
||||
this.account_id = account_id;
|
||||
this.account_name = account_name;
|
||||
this.calc_type = calc_type;
|
||||
this.qty_conversion = qty_conversion ?? new();
|
||||
}
|
||||
|
||||
[Flags]
|
||||
enum WaterfallPriceFlags {
|
||||
None = 0,
|
||||
Bid = 1,
|
||||
Ask = 1 << 1,
|
||||
Last = 1 << 2,
|
||||
Settle = 1 << 3,
|
||||
Mid = Bid | Ask,
|
||||
LastGTEBid = Bid | Last | 1 << 4,
|
||||
LastLTEAsk = Ask | Last | 1 << 5,
|
||||
LastInsideSpread = LastGTEBid | LastLTEAsk,
|
||||
BidGTESettle = Bid | Settle | 1 << 6,
|
||||
AskLTESettle = Ask | Settle | 1 << 7
|
||||
}
|
||||
|
||||
public AccountTuple account => new(account_id, account_name);
|
||||
public string symbol => security?.pnl_symbol() ?? string.Empty;
|
||||
public DateTime expiration =>
|
||||
security?.normal_expirations()?.MinOrDefault(DateTime.MinValue) ?? DateTime.MinValue;
|
||||
public double effective_cpp => override_cpp ?? default_cpp;
|
||||
|
||||
/// Market/Calc
|
||||
public double mid_price => (bid_price + ask_price) / 2;
|
||||
public double pnl_price { get; }
|
||||
|
||||
/// Sod
|
||||
public double sod_pnl { get; }
|
||||
public double sod_long_pos => sod.long_pos;
|
||||
public double sod_long_avg_price => sod.long_avg;
|
||||
public double sod_short_pos => sod.short_pos;
|
||||
public double sod_short_avg_price => sod.short_avg;
|
||||
public double sod_net_pos => sod.net_pos;
|
||||
public double sod_net_avg_price => sod.net_avg;
|
||||
public double sod_delta => sod.delta;
|
||||
public double sod_gamma => sod.gamma;
|
||||
public double sod_vega => sod.vega;
|
||||
public double sod_theta => sod.theta;
|
||||
public double display_sod_net_pos => qty_conversion.to_display(sod_net_pos);
|
||||
public double display_sod_long_pos => qty_conversion.to_display(sod_long_pos);
|
||||
public double display_sod_short_pos => qty_conversion.to_display(sod_short_pos);
|
||||
|
||||
/// Day
|
||||
public double day_pnl { get; }
|
||||
public double day_long_pos => day.long_pos;
|
||||
public double day_long_avg_price => day.long_avg;
|
||||
public double day_short_pos => day.short_pos;
|
||||
public double day_short_avg_price => day.short_avg;
|
||||
public double day_delta => day.delta;
|
||||
public double day_gamma => day.gamma;
|
||||
public double day_vega => day.vega;
|
||||
public double day_theta => day.theta;
|
||||
public bool has_day_trades => day.long_pos > 0 || day.short_pos > 0;
|
||||
public double day_net_pos => day.net_pos;
|
||||
public double day_net_avg => day.net_avg;
|
||||
public double display_day_net_pos => qty_conversion.to_display(day_net_pos);
|
||||
public double display_day_long_pos => qty_conversion.to_display(day_long_pos);
|
||||
public double display_day_short_pos => qty_conversion.to_display(day_short_pos);
|
||||
|
||||
/// Total
|
||||
public double total_pnl => new[] { sod_pnl, day_pnl }.sum_real();
|
||||
public double total_long_pos => new[] { sod.long_pos, day.long_pos }.sum_real();
|
||||
public double total_long_avg_price =>
|
||||
MathUtils.weighted_average(
|
||||
sod_long_avg_price.if_nan(0),
|
||||
sod_long_pos.if_nan(0),
|
||||
day_long_avg_price.if_nan(0),
|
||||
day_long_pos.if_nan(0));
|
||||
public double total_short_pos => new[] { sod.short_pos, day.short_pos }.sum_real();
|
||||
public double total_short_avg_price =>
|
||||
MathUtils.weighted_average(
|
||||
sod_short_avg_price.if_nan(0),
|
||||
sod_short_pos.if_nan(0),
|
||||
day_short_avg_price.if_nan(0),
|
||||
day_short_pos.if_nan(0));
|
||||
public double total_net_pos => new[] { sod.long_pos, -sod.short_pos, day.long_pos, -day.short_pos }.Where(n => n.is_real()).Sum();
|
||||
public double total_delta => sod.delta.add_real(day.delta);
|
||||
public double total_gamma => sod.gamma.add_real(day.gamma);
|
||||
public double total_vega => sod.vega.add_real(day.vega);
|
||||
public double total_theta => sod.theta.add_real(day.theta);
|
||||
public double display_total_net_pos => qty_conversion.to_display(total_net_pos);
|
||||
public double display_total_long_pos => qty_conversion.to_display(total_long_pos);
|
||||
public double display_total_short_pos => qty_conversion.to_display(total_short_pos);
|
||||
|
||||
/// Working
|
||||
public double working_long_pos => working.long_data.working_total;
|
||||
public double working_long_avg_price => effective_cpp * working.long_data.avg_price;
|
||||
public double working_long_top_price => effective_cpp * working.long_data.top_price;
|
||||
public double working_short_pos => working.short_data.working_total;
|
||||
public double working_short_avg_price => effective_cpp * working.short_data.avg_price;
|
||||
public double working_short_top_price => effective_cpp * working.short_data.top_price;
|
||||
public double working_net_pos => working_long_pos - working_short_pos;
|
||||
public double display_working_net_pos => qty_conversion.to_display(working_net_pos);
|
||||
public double display_working_long_pos => qty_conversion.to_display(working_long_pos);
|
||||
public double display_working_short_pos => qty_conversion.to_display(working_short_pos);
|
||||
|
||||
public static PNLRowData from_pnl_unit(IPNLUnit u) =>
|
||||
new(
|
||||
u.id(),
|
||||
default_cpp: 1.0,
|
||||
override_cpp: null,
|
||||
pnl_price: u.theo,
|
||||
bid_price: double.NaN,
|
||||
ask_price: double.NaN,
|
||||
last_price: double.NaN,
|
||||
settlement_price: u.settle_price,
|
||||
sod_pnl: u.start_pnl,
|
||||
sod: new() {
|
||||
price_size = new(
|
||||
u.start_long_pos,
|
||||
u.start_long_avg_cost,
|
||||
u.start_short_pos,
|
||||
u.start_short_avg_cost),
|
||||
greeks = new() {
|
||||
delta = u.start_delta,
|
||||
gamma = u.start_gamma,
|
||||
vega = u.start_vega,
|
||||
theta = u.start_theta
|
||||
}
|
||||
},
|
||||
day_pnl: u.day_pnl,
|
||||
day: new() {
|
||||
price_size = new(
|
||||
u.day_long_pos,
|
||||
u.day_long_avg_cost,
|
||||
u.day_short_pos,
|
||||
u.day_short_avg_cost),
|
||||
greeks = new() {
|
||||
delta = u.day_delta,
|
||||
gamma = u.day_gamma,
|
||||
vega = u.day_vega,
|
||||
theta = u.day_theta
|
||||
}
|
||||
},
|
||||
working: null,
|
||||
security: u.security,
|
||||
account_id: u.account_id,
|
||||
account_name: u.account,
|
||||
calc_type: PNLCalculationType.Mid,
|
||||
qty_conversion: null);
|
||||
|
||||
public PNLRowData with(
|
||||
SecurityImmutable? security = null,
|
||||
uint? account_id = null,
|
||||
string account_name = null,
|
||||
WorkingOrderData? working = null,
|
||||
PNLCalculationType? calc_type = null) =>
|
||||
new PNLRowData(
|
||||
key,
|
||||
default_cpp,
|
||||
override_cpp,
|
||||
pnl_price,
|
||||
bid_price,
|
||||
ask_price,
|
||||
last_price,
|
||||
settlement_price,
|
||||
sod_pnl: sod_pnl,
|
||||
sod,
|
||||
day_pnl: day_pnl,
|
||||
day,
|
||||
working ?? this.working,
|
||||
security ?? this.security,
|
||||
account_id ?? this.account_id,
|
||||
account_name ?? this.account_name,
|
||||
calc_type ?? this.calc_type,
|
||||
qty_conversion: qty_conversion);
|
||||
|
||||
WaterfallPriceFlags _waterfall_flags() {
|
||||
var flags = WaterfallPriceFlags.None;
|
||||
if (!double.IsNaN(bid_price)) flags |= WaterfallPriceFlags.Bid;
|
||||
if (!double.IsNaN(ask_price)) flags |= WaterfallPriceFlags.Ask;
|
||||
if (!double.IsNaN(last_price)) flags |= WaterfallPriceFlags.Last;
|
||||
if (last_price >= bid_price) flags |= WaterfallPriceFlags.LastGTEBid;
|
||||
if (last_price <= ask_price) flags |= WaterfallPriceFlags.LastLTEAsk;
|
||||
if (!double.IsNaN(settlement_price)) flags |= WaterfallPriceFlags.Settle;
|
||||
if (bid_price >= settlement_price) flags |= WaterfallPriceFlags.BidGTESettle;
|
||||
if (ask_price <= settlement_price) flags |= WaterfallPriceFlags.AskLTESettle;
|
||||
return flags;
|
||||
}
|
||||
|
||||
double _waterfall_price() {
|
||||
var flags = _waterfall_flags();
|
||||
// return price for the best match
|
||||
for (int i = 0; i < _waterfall_preferences.Length; i++) {
|
||||
if ((_waterfall_preferences[i] & flags) == _waterfall_preferences[i])
|
||||
return _waterfall_price(_waterfall_preferences[i]);
|
||||
}
|
||||
return double.NaN;
|
||||
}
|
||||
|
||||
double _waterfall_price(WaterfallPriceFlags ltp) {
|
||||
switch (ltp) {
|
||||
case WaterfallPriceFlags.Last:
|
||||
case WaterfallPriceFlags.LastInsideSpread:
|
||||
case WaterfallPriceFlags.LastGTEBid:
|
||||
case WaterfallPriceFlags.LastLTEAsk: return last_price;
|
||||
case WaterfallPriceFlags.Mid: return mid_price;
|
||||
case WaterfallPriceFlags.Bid:
|
||||
case WaterfallPriceFlags.BidGTESettle: return bid_price;
|
||||
case WaterfallPriceFlags.Ask:
|
||||
case WaterfallPriceFlags.AskLTESettle: return ask_price;
|
||||
case WaterfallPriceFlags.Settle: return settlement_price;
|
||||
default: return double.NaN;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(PNLRowData other) =>
|
||||
key == other.key &&
|
||||
default_cpp == other.default_cpp &&
|
||||
override_cpp == other.override_cpp &&
|
||||
security.HasValue == other.security.HasValue &&
|
||||
account_name == other.account_name &&
|
||||
sod == other.sod &&
|
||||
day == other.day &&
|
||||
bid_price.Equals(other.bid_price) &&
|
||||
ask_price.Equals(other.ask_price) &&
|
||||
last_price.Equals(other.last_price) &&
|
||||
mid_price.Equals(other.mid_price) &&
|
||||
settlement_price.Equals(other.settlement_price) &&
|
||||
calc_type.Equals(other.calc_type) &&
|
||||
working.summary == other.working.summary &&
|
||||
qty_conversion == other.qty_conversion;
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
obj is PNLRowData other && Equals(other);
|
||||
|
||||
// assuming callers will not combine different values with the same key,
|
||||
// the other components shouldn't be included in the hash calculation.
|
||||
public override int GetHashCode() =>
|
||||
key.GetHashCode();
|
||||
|
||||
public static bool operator ==(PNLRowData a, PNLRowData b) => a.Equals(b);
|
||||
public static bool operator !=(PNLRowData a, PNLRowData b) => !a.Equals(b);
|
||||
}
|
||||
|
||||
static class PNLDataExtensions {
|
||||
public static string pnl_symbol(this SecurityImmutable security) {
|
||||
return bts.api.ExchangeSpecificUtilities.get_pnl_symbol(security);
|
||||
}
|
||||
|
||||
// while override_cpp could use double.NaN to indicate the lack of an override,
|
||||
// the nullable double makes it clear that it is an optional value.
|
||||
public static (double default_cpp, double? override_cpp) pnl_cpp_tuple(this PNLUnitImmutable pnl_unit, SecurityImmutable? security) =>
|
||||
security.HasValue ?
|
||||
pnl_cpp_tuple(pnl_unit, security.Value) :
|
||||
(pnl_unit.CashValue, pnl_unit.HasCppOverride ? pnl_unit.CppOverride.Value : (double?)null);
|
||||
|
||||
public static (double default_cpp, double? override_cpp) pnl_cpp_tuple(this PNLUnitImmutable pnl_unit, SecurityImmutable security) {
|
||||
// TODO: actual impl
|
||||
double calced_pnl = bts.api.ExchangeSpecificUtilities.get_cpp(pnl_unit, security);
|
||||
return (calced_pnl, pnl_unit.HasCppOverride ? pnl_unit.CppOverride.Value : (double?)null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,8 +38,6 @@ namespace bts.shell.pnl {
|
||||
|
||||
// sod
|
||||
public decimal sod_pnl { get; init; }
|
||||
public decimal sod_realized_pnl { get; init; }
|
||||
public decimal sod_unrealized_pnl { get; init; }
|
||||
public decimal sod_long_pos { get; init; }
|
||||
public decimal sod_short_pos { get; init; }
|
||||
public decimal sod_net_pos => sod_long_pos - sod_short_pos;
|
||||
@@ -53,8 +51,6 @@ namespace bts.shell.pnl {
|
||||
|
||||
// day
|
||||
public decimal day_pnl { get; init; }
|
||||
public decimal day_realized_pnl { get; init; }
|
||||
public decimal day_unrealized_pnl { get; init; }
|
||||
public decimal day_long_pos { get; init; }
|
||||
public decimal day_short_pos { get; init; }
|
||||
public decimal day_net_pos => day_long_pos - day_short_pos;
|
||||
@@ -68,8 +64,6 @@ namespace bts.shell.pnl {
|
||||
|
||||
// total
|
||||
public decimal total_pnl => sod_pnl + day_pnl;
|
||||
public decimal total_realized_pnl => sod_realized_pnl + day_realized_pnl;
|
||||
public decimal total_unrealized_pnl => sod_unrealized_pnl + day_unrealized_pnl;
|
||||
public decimal total_net_pos => total_long_pos - total_short_pos;
|
||||
public decimal total_long_pos => sod_long_pos + day_long_pos;
|
||||
public decimal total_short_pos => sod_short_pos + day_short_pos;
|
||||
@@ -92,8 +86,6 @@ namespace bts.shell.pnl {
|
||||
public bool Equals(PNLNormalizedData other) =>
|
||||
// sod
|
||||
sod_pnl == other.sod_pnl &&
|
||||
sod_realized_pnl == other.sod_realized_pnl &&
|
||||
sod_unrealized_pnl == other.sod_unrealized_pnl &&
|
||||
sod_long_pos == other.sod_long_pos &&
|
||||
sod_short_pos == other.sod_short_pos &&
|
||||
sod_delta == other.sod_delta &&
|
||||
@@ -105,8 +97,6 @@ namespace bts.shell.pnl {
|
||||
|
||||
// day
|
||||
day_pnl == other.day_pnl &&
|
||||
day_realized_pnl == other.day_realized_pnl &&
|
||||
day_unrealized_pnl == other.day_unrealized_pnl &&
|
||||
day_long_pos == other.day_long_pos &&
|
||||
day_short_pos == other.day_short_pos &&
|
||||
day_delta == other.day_delta &&
|
||||
@@ -164,8 +154,6 @@ namespace bts.shell.pnl {
|
||||
new() {
|
||||
// sod
|
||||
sod_pnl = op(a.sod_pnl, b.sod_pnl),
|
||||
sod_realized_pnl = op(a.sod_realized_pnl, b.sod_realized_pnl),
|
||||
sod_unrealized_pnl = op(a.sod_unrealized_pnl, b.sod_unrealized_pnl),
|
||||
sod_long_pos = op(a.sod_long_pos, b.sod_long_pos),
|
||||
sod_short_pos = op(a.sod_short_pos, b.sod_short_pos),
|
||||
sod_delta = op(a.sod_delta, b.sod_delta),
|
||||
@@ -177,8 +165,6 @@ namespace bts.shell.pnl {
|
||||
|
||||
// day
|
||||
day_pnl = op(a.day_pnl, b.day_pnl),
|
||||
day_realized_pnl = op(a.day_realized_pnl, b.day_realized_pnl),
|
||||
day_unrealized_pnl = op(a.day_unrealized_pnl, b.day_unrealized_pnl),
|
||||
day_long_pos = op(a.day_long_pos, b.day_long_pos),
|
||||
day_short_pos = op(a.day_short_pos, b.day_short_pos),
|
||||
day_delta = op(a.day_delta, b.day_delta),
|
||||
|
||||
@@ -39,9 +39,6 @@ namespace bts.shell {
|
||||
class PNLWindow : SparkWindow<PNLSaveState>, ISharedWindow {
|
||||
public const string WINDOW_TYPE = "PNL";
|
||||
public const string WINDOW_TITLE = "P&L Summary";
|
||||
// Cpp overrides aren't respected in pnl calc. Hide the "Override Cpp"
|
||||
// menu item until we fix it.
|
||||
const bool CAN_OVERRIDE_CPP = false;
|
||||
|
||||
static int _window_id_counter = 0;
|
||||
|
||||
@@ -140,10 +137,6 @@ namespace bts.shell {
|
||||
_cached_columns = ImmutableList<DIYGrid.ColumnBase>.Empty.AddRange(_view._grid.Columns);
|
||||
|
||||
_commands = new() {
|
||||
SparkCommands.ShowMarketView.complete(() => {
|
||||
var rows = _vm.selected_rows.null_if_empty() ?? _vm.rows;
|
||||
return SecurityCriteria.from_keys(rows.Select(r => r.security_key.value).Distinct());
|
||||
}),
|
||||
new SparkCommandCommand(
|
||||
"Collapse All", Icons.RightArrow, new Command(() => _vm.set_all_expanded(false))),
|
||||
new SparkCommandCommand(
|
||||
@@ -159,7 +152,7 @@ namespace bts.shell {
|
||||
},
|
||||
new SparkCommandCommand(
|
||||
"Override CPP...", Icons.CurrencyExchange, new Command(_override_cpp)) {
|
||||
show_in_context_menu = CAN_OVERRIDE_CPP,
|
||||
show_in_context_menu = true,
|
||||
show_in_toolbar = false
|
||||
},
|
||||
SparkCommands.window_settings_command(new DialogCommand(_mk_settings_win)),
|
||||
@@ -218,16 +211,13 @@ namespace bts.shell {
|
||||
.ToArray();
|
||||
var calc_type = _vm.calculation_type;
|
||||
var state = _settings_manager.instance_settings;
|
||||
var menu_display = _menu_display_vm?.create();
|
||||
if (state is null) {
|
||||
// don't use defaults if the user manipulated the window state outside of the
|
||||
// settings dialog (e.g., resized column(s) via drag, or changed sort/filter)
|
||||
var defaults = _settings_manager.default_settings;
|
||||
if (calc_type == defaults.calculation_type &&
|
||||
defaults.sorting_criteria.SequenceEqual(sorting_criteria) &&
|
||||
defaults.grid.columns.SequenceEqual(cols) &&
|
||||
defaults.filters.safe_equals(filters) &&
|
||||
(!menu_display.HasValue || menu_display.Value.Equals(defaults.menu_display))) {
|
||||
defaults.grid.columns.SequenceEqual(cols) && defaults.filters.safe_equals(filters)) {
|
||||
// the user's current state still matches the defaults (i.e., no outside
|
||||
// manipulation was performed); return null so this window will use the latest
|
||||
// default settings when restored
|
||||
@@ -244,7 +234,7 @@ namespace bts.shell {
|
||||
state.grid.with(columns: cols, background: _vm.grid_background_color.to_uint()),
|
||||
calc_type,
|
||||
_vm.header_row_display,
|
||||
menu_display: menu_display);
|
||||
menu_display: _menu_display_vm?.create());
|
||||
return new PNLSaveState { use_defaults = false, settings = state };
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace bts.shell {
|
||||
|
||||
static bool _apply(ref PNLSettings settings, IEnumerable<PNLAnimationTriggerData> actual_triggers, IEnumerable<PNLAnimationTriggerData> default_triggers, Func<PNLSettings, PNLAnimationTriggerData[], PNLSettings> set_triggers) {
|
||||
if (_apply(actual_triggers, default_triggers, out var result)) {
|
||||
settings = set_triggers(settings, result.ToArray());
|
||||
settings = set_triggers(settings, actual_triggers.Concat(result).ToArray());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -9,8 +9,6 @@ namespace bts.shell.pnl {
|
||||
|
||||
using ProtoBuf;
|
||||
|
||||
using Spark.Api.Data;
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
@@ -35,8 +33,8 @@ namespace bts.shell.pnl {
|
||||
|
||||
// expiration
|
||||
[ProtoMember(53)]
|
||||
ExpirationDate[] _expiration;
|
||||
public ExpirationDate[] expiration {
|
||||
DateTime[] _expiration;
|
||||
public DateTime[] expiration {
|
||||
get => _expiration.empty_if_null();
|
||||
set => _expiration = value;
|
||||
}
|
||||
@@ -67,24 +65,16 @@ namespace bts.shell.pnl {
|
||||
/// sod
|
||||
[ProtoMember(8)]
|
||||
public DoubleMinMaxState sod_pnl { get; set; }
|
||||
[ProtoMember(54)]
|
||||
public DoubleMinMaxState sod_realized_pnl { get; set; }
|
||||
[ProtoMember(55)]
|
||||
public DoubleMinMaxState sod_unrealized_pnl { get; set; }
|
||||
// sod long
|
||||
[ProtoMember(9)]
|
||||
public DoubleMinMaxState sod_long_pos { get; set; }
|
||||
[ProtoMember(10)]
|
||||
public DoubleMinMaxState sod_long_avg_price { get; set; }
|
||||
[ProtoMember(60)]
|
||||
public DoubleMinMaxState sod_long_avg_pnl { get; set; }
|
||||
// sod short
|
||||
[ProtoMember(11)]
|
||||
public DoubleMinMaxState sod_short_pos { get; set; }
|
||||
[ProtoMember(12)]
|
||||
public DoubleMinMaxState sod_short_avg_price { get; set; }
|
||||
[ProtoMember(61)]
|
||||
public DoubleMinMaxState sod_short_avg_pnl { get; set; }
|
||||
// sod net
|
||||
[ProtoMember(13)]
|
||||
public DoubleMinMaxState sod_net_pos { get; set; }
|
||||
@@ -102,24 +92,16 @@ namespace bts.shell.pnl {
|
||||
/// day
|
||||
[ProtoMember(14)]
|
||||
public DoubleMinMaxState day_pnl { get; set; }
|
||||
[ProtoMember(56)]
|
||||
public DoubleMinMaxState day_realized_pnl { get; set; }
|
||||
[ProtoMember(57)]
|
||||
public DoubleMinMaxState day_unrealized_pnl { get; set; }
|
||||
// day long
|
||||
[ProtoMember(15)]
|
||||
public DoubleMinMaxState day_long_pos { get; set; }
|
||||
[ProtoMember(16)]
|
||||
public DoubleMinMaxState day_long_avg_price { get; set; }
|
||||
[ProtoMember(62)]
|
||||
public DoubleMinMaxState day_long_avg_pnl { get; set; }
|
||||
// day short
|
||||
[ProtoMember(17)]
|
||||
public DoubleMinMaxState day_short_pos { get; set; }
|
||||
[ProtoMember(18)]
|
||||
public DoubleMinMaxState day_short_avg_price { get; set; }
|
||||
[ProtoMember(63)]
|
||||
public DoubleMinMaxState day_short_avg_pnl { get; set; }
|
||||
// day net
|
||||
[ProtoMember(19)]
|
||||
public DoubleMinMaxState day_net_pos { get; set; }
|
||||
@@ -167,24 +149,16 @@ namespace bts.shell.pnl {
|
||||
/// total
|
||||
[ProtoMember(29)]
|
||||
public DoubleMinMaxState total_pnl { get; set; }
|
||||
[ProtoMember(58)]
|
||||
public DoubleMinMaxState total_realized_pnl { get; set; }
|
||||
[ProtoMember(59)]
|
||||
public DoubleMinMaxState total_unrealized_pnl { get; set; }
|
||||
// total long
|
||||
[ProtoMember(30)]
|
||||
public DoubleMinMaxState total_long_pos { get; set; }
|
||||
[ProtoMember(31)]
|
||||
public DoubleMinMaxState total_long_avg_price { get; set; }
|
||||
[ProtoMember(64)]
|
||||
public DoubleMinMaxState total_long_avg_pnl { get; set; }
|
||||
// total short
|
||||
[ProtoMember(32)]
|
||||
public DoubleMinMaxState total_short_pos { get; set; }
|
||||
[ProtoMember(33)]
|
||||
public DoubleMinMaxState total_short_avg_price { get; set; }
|
||||
[ProtoMember(65)]
|
||||
public DoubleMinMaxState total_short_avg_pnl { get; set; }
|
||||
// total net
|
||||
[ProtoMember(34)]
|
||||
public DoubleMinMaxState total_net_pos { get; set; }
|
||||
@@ -225,8 +199,6 @@ namespace bts.shell.pnl {
|
||||
cpp.safe_equals(other.cpp) &&
|
||||
/// sod
|
||||
sod_pnl.safe_equals(other.sod_pnl) &&
|
||||
sod_realized_pnl.safe_equals(other.sod_realized_pnl) &&
|
||||
sod_unrealized_pnl.safe_equals(other.sod_unrealized_pnl) &&
|
||||
sod_long_pos.safe_equals(other.sod_long_pos) &&
|
||||
sod_long_avg_price.safe_equals(other.sod_long_avg_price) &&
|
||||
sod_short_pos.safe_equals(other.sod_short_pos) &&
|
||||
@@ -238,8 +210,6 @@ namespace bts.shell.pnl {
|
||||
sod_theta.safe_equals(other.sod_theta) &&
|
||||
/// day
|
||||
day_pnl.safe_equals(other.day_pnl) &&
|
||||
day_realized_pnl.safe_equals(other.day_realized_pnl) &&
|
||||
day_unrealized_pnl.safe_equals(other.day_unrealized_pnl) &&
|
||||
day_long_pos.safe_equals(other.day_long_pos) &&
|
||||
day_long_avg_price.safe_equals(other.day_long_avg_price) &&
|
||||
day_short_pos.safe_equals(other.day_short_pos) &&
|
||||
@@ -262,8 +232,6 @@ namespace bts.shell.pnl {
|
||||
working_net_pos.safe_equals(other.working_net_pos) &&
|
||||
/// total
|
||||
total_pnl.safe_equals(other.total_pnl) &&
|
||||
total_realized_pnl.safe_equals(other.total_realized_pnl) &&
|
||||
total_unrealized_pnl.safe_equals(other.total_unrealized_pnl) &&
|
||||
total_long_pos.safe_equals(other.total_long_pos) &&
|
||||
total_long_avg_price.safe_equals(other.total_long_avg_price) &&
|
||||
total_short_pos.safe_equals(other.total_short_pos) &&
|
||||
@@ -302,8 +270,6 @@ namespace bts.shell.pnl {
|
||||
bd.add_numeric(fs.cpp, d => d.effective_cpp);
|
||||
/// sod
|
||||
bd.add_numeric(fs.sod_pnl, d => d.sod_pnl);
|
||||
bd.add_numeric(fs.sod_realized_pnl, d => d.sod_realized_pnl);
|
||||
bd.add_numeric(fs.sod_unrealized_pnl, d => d.sod_unrealized_pnl);
|
||||
bd.add_numeric(fs.sod_long_pos, d => d.sod_long_pos);
|
||||
bd.add_numeric(fs.sod_long_avg_price, d => d.sod_long_avg_price);
|
||||
bd.add_numeric(fs.sod_short_pos, d => d.sod_short_pos);
|
||||
@@ -315,8 +281,6 @@ namespace bts.shell.pnl {
|
||||
bd.add_numeric(fs.sod_theta, d => d.sod_theta);
|
||||
/// day
|
||||
bd.add_numeric(fs.day_pnl, d => d.day_pnl);
|
||||
bd.add_numeric(fs.day_realized_pnl, d => d.day_realized_pnl);
|
||||
bd.add_numeric(fs.day_unrealized_pnl, d => d.day_unrealized_pnl);
|
||||
bd.add_numeric(fs.day_long_pos, d => d.day_long_pos);
|
||||
bd.add_numeric(fs.day_long_avg_price, d => d.day_long_avg_price);
|
||||
bd.add_numeric(fs.day_short_pos, d => d.day_short_pos);
|
||||
@@ -335,8 +299,6 @@ namespace bts.shell.pnl {
|
||||
bd.add_numeric(fs.working_net_pos, d => d.working_net_pos);
|
||||
/// total
|
||||
bd.add_numeric(fs.total_pnl, d => d.total_pnl);
|
||||
bd.add_numeric(fs.total_realized_pnl, d => d.total_realized_pnl);
|
||||
bd.add_numeric(fs.total_unrealized_pnl, d => d.total_unrealized_pnl);
|
||||
bd.add_numeric(fs.total_long_pos, d => d.total_long_pos);
|
||||
bd.add_numeric(fs.total_long_avg_price, d => d.total_long_avg_price);
|
||||
bd.add_numeric(fs.total_short_pos, d => d.total_short_pos);
|
||||
|
||||
@@ -9,13 +9,9 @@ using mbts.user.settings;
|
||||
|
||||
using ProtoBuf;
|
||||
|
||||
using Spark.Core;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
@@ -114,22 +110,7 @@ namespace bts.shell.pnl {
|
||||
GridSettings _grid_backing;
|
||||
PNLCellAppearanceProto _grid_cell_appearance_backing;
|
||||
|
||||
static LazyOnce<PNLSettings> defaultProfile;
|
||||
|
||||
static PNLSettings() {
|
||||
defaultProfile = new(() => {
|
||||
var binDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
var store = ShellWindowSettingsDirectoryStore.Create<PNLSettings>(
|
||||
Path.Combine(binDir, "ShellWindowSettings", "Pnl"), "*." + mbts.spark.UserSettings.FileExtensions.PNL);
|
||||
return store.Profiles.GetValueOrDefault("Default")
|
||||
?? store.Profiles.Values.FirstOrDefault()
|
||||
?? historicDefault;
|
||||
});
|
||||
}
|
||||
|
||||
public static PNLSettings Default => defaultProfile.Value;
|
||||
|
||||
static PNLSettings historicDefault =>
|
||||
public static PNLSettings Default =>
|
||||
new PNLSettings {
|
||||
_sorting_criteria = new[] {
|
||||
new SortingCriteria(nameof(Columns.Account), true),
|
||||
@@ -211,10 +192,6 @@ namespace bts.shell.pnl {
|
||||
yield return _trigger($"{nameof(PNLRowData.total_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, font_weight: FontWeights.Bold, column: Columns.TotalPNL));
|
||||
yield return _trigger($"{nameof(PNLRowData.total_net_pos)} > 0", _animation(foreground: BTSColors.MarketData.bid, column: Columns.TotalNetPos));
|
||||
yield return _trigger($"{nameof(PNLRowData.total_net_pos)} < 0", _animation(foreground: BTSColors.MarketData.ask, column: Columns.TotalNetPos));
|
||||
yield return _trigger($"{nameof(PNLRowData.total_realized_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, font_weight: FontWeights.Bold, column: Columns.TotalRealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLRowData.total_realized_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, font_weight: FontWeights.Bold, column: Columns.TotalRealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLRowData.total_unrealized_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, font_weight: FontWeights.Bold, column: Columns.TotalUnrealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLRowData.total_unrealized_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, font_weight: FontWeights.Bold, column: Columns.TotalUnrealizedPNL));
|
||||
// working
|
||||
yield return _trigger($"{nameof(PNLRowData.working_net_pos)} > 0", _animation(foreground: BTSColors.MarketData.bid, column: Columns.WorkingNetPos));
|
||||
yield return _trigger($"{nameof(PNLRowData.working_net_pos)} < 0", _animation(foreground: BTSColors.MarketData.ask, column: Columns.WorkingNetPos));
|
||||
@@ -225,28 +202,16 @@ namespace bts.shell.pnl {
|
||||
get {
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.sod_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, column: Columns.SODPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.sod_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, column: Columns.SODPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.sod_realized_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, column: Columns.SODRealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.sod_realized_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, column: Columns.SODRealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.sod_unrealized_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, column: Columns.SODUnrealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.sod_unrealized_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, column: Columns.SODUnrealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.sod_net_pos)} > 0", _animation(foreground: BTSColors.MarketData.bid, column: Columns.SODNetPos));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.sod_net_pos)} < 0", _animation(foreground: BTSColors.MarketData.ask, column: Columns.SODNetPos));
|
||||
// day
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.day_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, column: Columns.DayPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.day_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, column: Columns.DayPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.day_realized_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, column: Columns.DayRealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.day_realized_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, column: Columns.DayRealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.day_unrealized_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, column: Columns.DayUnrealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.day_unrealized_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, column: Columns.DayUnrealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.day_net_pos)} > 0", _animation(foreground: BTSColors.MarketData.bid, column: Columns.DayNetPos));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.day_net_pos)} < 0", _animation(foreground: BTSColors.MarketData.ask, column: Columns.DayNetPos));
|
||||
// total
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.total_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, column: Columns.TotalPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.total_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, column: Columns.TotalPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.total_realized_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, column: Columns.TotalRealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.total_realized_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, column: Columns.TotalRealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.total_unrealized_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, column: Columns.TotalUnrealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.total_unrealized_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, column: Columns.TotalUnrealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.total_net_pos)} > 0", _animation(foreground: BTSColors.MarketData.bid, column: Columns.TotalNetPos));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.total_net_pos)} < 0", _animation(foreground: BTSColors.MarketData.ask, column: Columns.TotalNetPos));
|
||||
// working
|
||||
@@ -259,28 +224,16 @@ namespace bts.shell.pnl {
|
||||
get {
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.sod_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, column: Columns.SODPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.sod_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, column: Columns.SODPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.sod_realized_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, column: Columns.SODRealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.sod_realized_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, column: Columns.SODRealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.sod_unrealized_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, column: Columns.SODUnrealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.sod_unrealized_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, column: Columns.SODUnrealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.sod_net_pos)} > 0", _animation(foreground: BTSColors.MarketData.bid, column: Columns.SODNetPos));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.sod_net_pos)} < 0", _animation(foreground: BTSColors.MarketData.ask, column: Columns.SODNetPos));
|
||||
// day
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.day_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, column: Columns.DayPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.day_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, column: Columns.DayPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.day_realized_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, column: Columns.DayRealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.day_realized_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, column: Columns.DayRealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.day_unrealized_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, column: Columns.DayUnrealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.day_unrealized_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, column: Columns.DayUnrealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.day_net_pos)} > 0", _animation(foreground: BTSColors.MarketData.bid, column: Columns.DayNetPos));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.day_net_pos)} < 0", _animation(foreground: BTSColors.MarketData.ask, column: Columns.DayNetPos));
|
||||
// total
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.total_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, column: Columns.TotalPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.total_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, column: Columns.TotalPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.total_realized_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, column: Columns.TotalRealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.total_realized_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, column: Columns.TotalRealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.total_unrealized_pnl)} > 0", _animation(foreground: BTSColors.PNL.profit, column: Columns.TotalUnrealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.total_unrealized_pnl)} < 0", _animation(foreground: BTSColors.PNL.loss, column: Columns.TotalUnrealizedPNL));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.total_net_pos)} > 0", _animation(foreground: BTSColors.MarketData.bid, column: Columns.TotalNetPos));
|
||||
yield return _trigger($"{nameof(PNLNormalizedData.total_net_pos)} < 0", _animation(foreground: BTSColors.MarketData.ask, column: Columns.TotalNetPos));
|
||||
// working
|
||||
@@ -439,14 +392,10 @@ namespace bts.shell.pnl {
|
||||
public static GridColumnSettings cpp => new GridColumnSettings(nameof(Columns.CPP), "CPP", false, width: 50, horizontal_alignment: HorizontalAlignment.Right);
|
||||
// sod
|
||||
public static GridColumnSettings sod_pnl => new GridColumnSettings(nameof(Columns.SODPNL), Headers.SOD.PNL, width: Widths.PriceBig, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings sod_realized_pnl => new GridColumnSettings(nameof(Columns.SODRealizedPNL), Headers.SOD.RealizedPNL, width: Widths.PriceBig, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings sod_unrealized_pnl => new GridColumnSettings(nameof(Columns.SODUnrealizedPNL), Headers.SOD.UnrealizedPNL, width: Widths.PriceBig, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings sod_long_pos => new GridColumnSettings(nameof(Columns.SODLongPos), Headers.SOD.Long, false, width: Widths.Qty, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings sod_long_avg_price => new GridColumnSettings(nameof(Columns.SODLongAvgPrice), Headers.SOD.LongAvg, false, width: Widths.Price, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings sod_long_avg_pnl => new(nameof(Columns.SODLongAvgPNL), Headers.SOD.LongAvgPNL, false, width: Widths.Price, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings sod_short_pos => new GridColumnSettings(nameof(Columns.SODShortPos), Headers.SOD.Short, false, width: Widths.Qty, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings sod_short_avg_price => new GridColumnSettings(nameof(Columns.SODShortAvgPrice), Headers.SOD.ShortAvg, false, width: Widths.Price, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings sod_short_avg_pnl => new(nameof(Columns.SODShortAvgPNL), Headers.SOD.ShortAvgPNL, false, width: Widths.Price, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings sod_net_pos => new GridColumnSettings(nameof(Columns.SODNetPos), Headers.SOD.Net, width: Widths.Qty, horizontal_alignment: HorizontalAlignment.Right);
|
||||
|
||||
public static GridColumnSettings sod_delta => new(
|
||||
@@ -479,14 +428,10 @@ namespace bts.shell.pnl {
|
||||
|
||||
// day
|
||||
public static GridColumnSettings day_pnl => new GridColumnSettings(nameof(Columns.DayPNL), Headers.Day.PNL, width: Widths.PriceBig, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings day_realized_pnl => new GridColumnSettings(nameof(Columns.DayRealizedPNL), Headers.Day.RealizedPNL, width: Widths.PriceBig, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings day_unrealized_pnl => new GridColumnSettings(nameof(Columns.DayUnrealizedPNL), Headers.Day.UnrealizedPNL, width: Widths.PriceBig, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings day_long_pos => new GridColumnSettings(nameof(Columns.DayLongPos), Headers.Day.Long, false, width: Widths.Qty, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings day_long_avg_price => new GridColumnSettings(nameof(Columns.DayLongAvgPrice), Headers.Day.LongAvg, false, width: Widths.Price, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings day_long_avg_pnl => new GridColumnSettings(nameof(Columns.DayLongAvgPNL), Headers.Day.LongAvgPNL, false, width: Widths.Price, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings day_short_pos => new GridColumnSettings(nameof(Columns.DayShortPos), Headers.Day.Short, false, width: Widths.Qty, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings day_short_avg_price => new GridColumnSettings(nameof(Columns.DayShortAvgPrice), Headers.Day.ShortAvg, false, width: Widths.Price, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings day_short_avg_pnl => new GridColumnSettings(nameof(Columns.DayShortAvgPNL), Headers.Day.ShortAvgPNL, false, width: Widths.Price, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings day_net_pos => new GridColumnSettings(nameof(Columns.DayNetPos), Headers.Day.Net, width: Widths.Qty, horizontal_alignment: HorizontalAlignment.Right);
|
||||
|
||||
public static GridColumnSettings day_delta => new(
|
||||
@@ -526,14 +471,10 @@ namespace bts.shell.pnl {
|
||||
public static GridColumnSettings working_net_pos => new GridColumnSettings(nameof(Columns.WorkingNetPos), Headers.Working.Net, width: Widths.WorkingQty, horizontal_alignment: HorizontalAlignment.Right);
|
||||
// total
|
||||
public static GridColumnSettings total_pnl => new GridColumnSettings(nameof(Columns.TotalPNL), Headers.Total.PNL, width: Widths.PriceBig, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings total_realized_pnl => new GridColumnSettings(nameof(Columns.TotalRealizedPNL), Headers.Total.RealizedPNL, width: Widths.PriceBig, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings total_unrealized_pnl => new GridColumnSettings(nameof(Columns.TotalUnrealizedPNL), Headers.Total.UnrealizedPNL, width: Widths.PriceBig, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings total_long_pos => new GridColumnSettings(nameof(Columns.TotalLongPos), Headers.Total.Long, false, width: Widths.Qty, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings total_long_avg_price => new GridColumnSettings(nameof(Columns.TotalLongAvgPrice), Headers.Total.LongAvg, false, width: Widths.Price, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings total_long_avg_pnl => new(nameof(Columns.TotalLongAvgPNL), Headers.Total.LongAvgPNL, false, width: Widths.Price, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings total_short_pos => new GridColumnSettings(nameof(Columns.TotalShortPos), Headers.Total.Short, false, width: Widths.Qty, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings total_short_avg_price => new GridColumnSettings(nameof(Columns.TotalShortAvgPrice), Headers.Total.ShortAvg, false, width: Widths.Price, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings total_short_avg_pnl => new(nameof(Columns.TotalShortAvgPNL), Headers.Total.ShortAvgPNL, false, width: Widths.Price, horizontal_alignment: HorizontalAlignment.Right);
|
||||
public static GridColumnSettings total_net_pos => new GridColumnSettings(nameof(Columns.TotalNetPos), Headers.Total.Net, width: Widths.Qty, horizontal_alignment: HorizontalAlignment.Right);
|
||||
|
||||
public static GridColumnSettings total_delta => new(
|
||||
@@ -587,40 +528,28 @@ namespace bts.shell.pnl {
|
||||
|
||||
// pnl
|
||||
yield return sod_pnl;
|
||||
yield return sod_realized_pnl;
|
||||
yield return sod_unrealized_pnl;
|
||||
yield return day_pnl;
|
||||
yield return day_realized_pnl;
|
||||
yield return day_unrealized_pnl;
|
||||
yield return total_pnl;
|
||||
yield return total_realized_pnl;
|
||||
yield return total_unrealized_pnl;
|
||||
|
||||
// sod pos, price
|
||||
yield return sod_long_pos; // hidden
|
||||
yield return sod_long_avg_price; // hidden
|
||||
yield return sod_long_avg_pnl; // hidden
|
||||
yield return sod_short_pos; // hidden
|
||||
yield return sod_short_avg_price; // hidden
|
||||
yield return sod_short_avg_pnl; // hidden
|
||||
yield return sod_net_pos;
|
||||
|
||||
// day pos, price
|
||||
yield return day_long_pos; // hidden
|
||||
yield return day_long_avg_price; // hidden
|
||||
yield return day_long_avg_pnl; // hidden
|
||||
yield return day_short_pos; // hidden
|
||||
yield return day_short_avg_price; // hidden
|
||||
yield return day_short_avg_pnl; // hidden
|
||||
yield return day_net_pos;
|
||||
|
||||
// total pos, price
|
||||
yield return total_long_pos; // hidden
|
||||
yield return total_long_avg_price; // hidden
|
||||
yield return total_long_avg_pnl; // hidden
|
||||
yield return total_short_pos; // hidden
|
||||
yield return total_short_avg_price; // hidden
|
||||
yield return total_short_avg_pnl; // hidden
|
||||
yield return total_net_pos;
|
||||
|
||||
// sod greeks
|
||||
|
||||
@@ -34,8 +34,6 @@ namespace bts.shell.pnl {
|
||||
_cell_map.set_appearances(default_appearances);
|
||||
// sod
|
||||
sod_pnl = _cell_map.add_pnl_decimal(ColumnKeys.SODPNL, d => d.sod_pnl);
|
||||
sod_realized_pnl = _cell_map.add_pnl_decimal(ColumnKeys.SODRealizedPNL, d => d.sod_realized_pnl);
|
||||
sod_unrealized_pnl = _cell_map.add_pnl_decimal(ColumnKeys.SODUnrealizedPNL, d => d.sod_unrealized_pnl);
|
||||
sod_net_pos = _cell_map.add_net_pos(ColumnKeys.SODNetPos, d => d.sod_net_pos);
|
||||
sod_long_pos = _cell_map.add_long_pos(ColumnKeys.SODLongPos, d => d.sod_long_pos);
|
||||
sod_short_pos = _cell_map.add_short_pos(ColumnKeys.SODShortPos, d => d.sod_short_pos);
|
||||
@@ -46,8 +44,6 @@ namespace bts.shell.pnl {
|
||||
|
||||
// day
|
||||
day_pnl = _cell_map.add_pnl(ColumnKeys.DayPNL, d => d.day_pnl);
|
||||
day_realized_pnl = _cell_map.add_pnl_decimal(ColumnKeys.DayRealizedPNL, d => d.day_realized_pnl);
|
||||
day_unrealized_pnl = _cell_map.add_pnl_decimal(ColumnKeys.DayUnrealizedPNL, d => d.day_unrealized_pnl);
|
||||
day_net_pos = _cell_map.add_net_pos(ColumnKeys.DayNetPos, d => d.day_net_pos);
|
||||
day_long_pos = _cell_map.add_long_pos(ColumnKeys.DayLongPos, d => d.day_long_pos);
|
||||
day_short_pos = _cell_map.add_short_pos(ColumnKeys.DayShortPos, d => d.day_short_pos);
|
||||
@@ -62,8 +58,6 @@ namespace bts.shell.pnl {
|
||||
working_short_pos = _cell_map.add_short_pos(ColumnKeys.WorkingShortPos, r => r.working_short_pos);
|
||||
// total
|
||||
total_pnl = _cell_map.add_pnl_decimal(ColumnKeys.TotalPNL, d => d.total_pnl);
|
||||
total_realized_pnl = _cell_map.add_pnl_decimal(ColumnKeys.TotalRealizedPNL, d => d.total_realized_pnl);
|
||||
total_unrealized_pnl = _cell_map.add_pnl_decimal(ColumnKeys.TotalUnrealizedPNL, d => d.total_unrealized_pnl);
|
||||
total_net_pos = _cell_map.add_net_pos(ColumnKeys.TotalNetPos, d => d.total_net_pos);
|
||||
total_long_pos = _cell_map.add_long_pos(ColumnKeys.TotalLongPos, d => d.total_long_pos);
|
||||
total_short_pos = _cell_map.add_short_pos(ColumnKeys.TotalShortPos, d => d.total_short_pos);
|
||||
@@ -94,8 +88,6 @@ namespace bts.shell.pnl {
|
||||
|
||||
// day
|
||||
public PNLCellVM<PNLNormalizedData, decimal> day_pnl { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> day_realized_pnl { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> day_unrealized_pnl { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> day_long_pos { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> day_short_pos { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> day_net_pos { get; }
|
||||
@@ -106,8 +98,6 @@ namespace bts.shell.pnl {
|
||||
|
||||
// sod
|
||||
public PNLCellVM<PNLNormalizedData, decimal> sod_pnl { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> sod_realized_pnl { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> sod_unrealized_pnl { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> sod_long_pos { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> sod_short_pos { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> sod_net_pos { get; }
|
||||
@@ -118,8 +108,6 @@ namespace bts.shell.pnl {
|
||||
|
||||
// total
|
||||
public PNLCellVM<PNLNormalizedData, decimal> total_pnl { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> total_realized_pnl { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> total_unrealized_pnl { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> total_net_pos { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> total_long_pos { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> total_short_pos { get; }
|
||||
|
||||
@@ -6,7 +6,6 @@ using mbts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
|
||||
using Spark.Api.Data;
|
||||
using Spark.Core.Collections;
|
||||
using Spark.Core.Data;
|
||||
|
||||
@@ -50,7 +49,9 @@ namespace bts.shell.pnl {
|
||||
expiration_cell = _cell_map.add(
|
||||
ColumnKeys.Expiration,
|
||||
d => d.expiration,
|
||||
e => e.ToString());
|
||||
e => e == DateTime.MinValue
|
||||
? "N/A"
|
||||
: SecurityFormatter.format_expiration(e));
|
||||
symbol_cell = _cell_map.add(ColumnKeys.Symbol, d => d.symbol);
|
||||
security_cell = _cell_map.add(
|
||||
ColumnKeys.Security,
|
||||
@@ -62,18 +63,14 @@ namespace bts.shell.pnl {
|
||||
cpp = _cell_map.add(ColumnKeys.CPP, d => d.effective_cpp);
|
||||
// sod
|
||||
sod_pnl = _cell_map.add_pnl_double(ColumnKeys.SODPNL, d => d.sod_pnl);
|
||||
sod_realized_pnl = _cell_map.add_pnl_double(ColumnKeys.SODRealizedPNL, d => d.sod_realized_pnl);
|
||||
sod_unrealized_pnl = _cell_map.add_pnl_double(ColumnKeys.SODUnrealizedPNL, d => d.sod_unrealized_pnl);
|
||||
sod_net_pos = _cell_map.add_net_pos(
|
||||
ColumnKeys.SODNetPos, d => d.display_sod_net_pos, fmt_qty);
|
||||
sod_long_pos = _cell_map.add_long_pos(
|
||||
ColumnKeys.SODLongPos, d => d.display_sod_long_pos, fmt_qty);
|
||||
sod_long_avg_price = _cell_map.add_long_price(ColumnKeys.SODLongAvgPrice, d => d.sod_long_avg_price);
|
||||
sod_long_avg_pnl = _cell_map.add_long_price(ColumnKeys.SODLongAvgPNL, d => d.sod_long_avg_pnl);
|
||||
sod_short_pos = _cell_map.add_short_pos(
|
||||
ColumnKeys.SODShortPos, d => d.display_sod_short_pos, fmt_qty);
|
||||
sod_short_avg_price = _cell_map.add_short_price(ColumnKeys.SODShortAvgPrice, d => d.sod_short_avg_price);
|
||||
sod_short_avg_pnl = _cell_map.add_short_price(ColumnKeys.SODShortAvgPNL, d => d.sod_short_avg_pnl);
|
||||
sod_delta = _cell_map.add_pnl_double(ColumnKeys.SODDelta, d => d.sod_delta, fmt_greek);
|
||||
sod_gamma = _cell_map.add_pnl_double(ColumnKeys.SODGamma, d => d.sod_gamma, fmt_greek);
|
||||
sod_vega = _cell_map.add_pnl_double(ColumnKeys.SODVega, d => d.sod_vega, fmt_greek);
|
||||
@@ -81,18 +78,14 @@ namespace bts.shell.pnl {
|
||||
|
||||
// day
|
||||
day_pnl = _cell_map.add_pnl_double(ColumnKeys.DayPNL, d => d.day_pnl);
|
||||
day_realized_pnl = _cell_map.add_pnl_double(ColumnKeys.DayRealizedPNL, d => d.day_realized_pnl);
|
||||
day_unrealized_pnl = _cell_map.add_pnl_double(ColumnKeys.DayUnrealizedPNL, d => d.day_unrealized_pnl);
|
||||
day_net_pos = _cell_map.add_net_pos(
|
||||
ColumnKeys.DayNetPos, d => d.display_day_net_pos, fmt_qty);
|
||||
day_long_pos = _cell_map.add_long_pos(
|
||||
ColumnKeys.DayLongPos, d => d.display_day_long_pos, fmt_qty);
|
||||
day_long_avg_price = _cell_map.add_long_price(ColumnKeys.DayLongAvgPrice, d => d.day_long_avg_price);
|
||||
day_long_avg_pnl = _cell_map.add_long_price(ColumnKeys.DayLongAvgPNL, d => d.day_long_avg_pnl);
|
||||
day_short_pos = _cell_map.add_short_pos(
|
||||
ColumnKeys.DayShortPos, d => d.display_day_short_pos, fmt_qty);
|
||||
day_short_avg_price = _cell_map.add_short_price(ColumnKeys.DayShortAvgPrice, d => d.day_short_avg_price);
|
||||
day_short_avg_pnl = _cell_map.add_short_price(ColumnKeys.DayShortAvgPNL, d => d.day_short_avg_pnl);
|
||||
day_delta = _cell_map.add_pnl_double(ColumnKeys.DayDelta, d => d.day_delta, fmt_greek);
|
||||
day_gamma = _cell_map.add_pnl_double(ColumnKeys.DayGamma, d => d.day_gamma, fmt_greek);
|
||||
day_vega = _cell_map.add_pnl_double(ColumnKeys.DayVega, d => d.day_vega, fmt_greek);
|
||||
@@ -113,18 +106,14 @@ namespace bts.shell.pnl {
|
||||
working_short_avg_price = _cell_map.add_short_price(ColumnKeys.WorkingShortAvgPrice, d => d.working_short_avg_price);
|
||||
// total
|
||||
total_pnl = _cell_map.add_pnl_double(ColumnKeys.TotalPNL, d => d.total_pnl);
|
||||
total_realized_pnl = _cell_map.add_pnl_double(ColumnKeys.TotalRealizedPNL, d => d.total_realized_pnl);
|
||||
total_unrealized_pnl = _cell_map.add_pnl_double(ColumnKeys.TotalUnrealizedPNL, d => d.total_unrealized_pnl);
|
||||
total_net_pos = _cell_map.add_net_pos(
|
||||
ColumnKeys.TotalNetPos, d => d.display_total_net_pos, fmt_qty);
|
||||
total_long_pos = _cell_map.add_long_pos(
|
||||
ColumnKeys.TotalLongPos, d => d.display_total_long_pos, fmt_qty);
|
||||
total_long_avg_price = _cell_map.add_long_price(ColumnKeys.TotalLongAvgPrice, d => d.total_long_avg_price);
|
||||
total_long_avg_pnl = _cell_map.add_long_price(ColumnKeys.TotalLongAvgPNL, d => d.total_long_avg_pnl);
|
||||
total_short_pos = _cell_map.add_short_pos(
|
||||
ColumnKeys.TotalShortPos, d => d.display_total_short_pos, fmt_qty);
|
||||
total_short_avg_price = _cell_map.add_short_price(ColumnKeys.TotalShortAvgPrice, d => d.total_short_avg_price);
|
||||
total_short_avg_pnl = _cell_map.add_short_price(ColumnKeys.TotalShortAvgPNL, d => d.total_short_avg_pnl);
|
||||
total_delta = _cell_map.add_pnl_double(
|
||||
ColumnKeys.TotalDelta, d => d.total_delta, fmt_greek);
|
||||
total_gamma = _cell_map.add_pnl_double(
|
||||
@@ -203,8 +192,6 @@ namespace bts.shell.pnl {
|
||||
var nd = new PNLNormalizedData() {
|
||||
// sod
|
||||
sod_pnl = sod_pnl.value.round_to_decimal(),
|
||||
sod_realized_pnl = sod_realized_pnl.value.round_to_decimal(),
|
||||
sod_unrealized_pnl = sod_unrealized_pnl.value.round_to_decimal(),
|
||||
sod_long_pos = sod_long,
|
||||
sod_short_pos = sod_short,
|
||||
sod_delta = sod_delta,
|
||||
@@ -216,8 +203,6 @@ namespace bts.shell.pnl {
|
||||
|
||||
// day
|
||||
day_pnl = day_pnl.value.round_to_decimal(),
|
||||
day_realized_pnl = day_realized_pnl.value.round_to_decimal(),
|
||||
day_unrealized_pnl = day_unrealized_pnl.value.round_to_decimal(),
|
||||
day_long_pos = day_long,
|
||||
day_short_pos = day_short,
|
||||
day_delta = day_delta,
|
||||
@@ -245,13 +230,13 @@ namespace bts.shell.pnl {
|
||||
public string account_name => data.account_name;
|
||||
public Venue exchange => security?.Exchange ?? Venue.Unset;
|
||||
public string symbol => security.symbol_or_default();
|
||||
public ExpirationDate expiration => data.expiration;
|
||||
public DateTime expiration => data.expiration;
|
||||
public Security.ContractOneofCase security_type => security?.ContractCase ?? Security.ContractOneofCase.None;
|
||||
public SecurityImmutable? security => data.security;
|
||||
// cells
|
||||
public PNLCellVM<PNLRowData, AccountTuple> account_cell { get; }
|
||||
public PNLCellVM<PNLRowData, Venue> exchange_cell { get; }
|
||||
public PNLCellVM<PNLRowData, ExpirationDate> expiration_cell { get; }
|
||||
public PNLCellVM<PNLRowData, DateTime> expiration_cell { get; }
|
||||
public PNLCellVM<PNLRowData, string> symbol_cell { get; }
|
||||
public PNLCellVM<PNLRowData, Security.ContractOneofCase> security_type_cell { get; }
|
||||
public PNLCellVM<PNLRowData, SecurityImmutable?> security_cell { get; }
|
||||
@@ -259,15 +244,11 @@ namespace bts.shell.pnl {
|
||||
public PNLCellVM<PNLRowData, double> cpp { get; }
|
||||
// sod
|
||||
public PNLCellVM<PNLRowData, double> sod_pnl { get; }
|
||||
public PNLCellVM<PNLRowData, double> sod_realized_pnl { get; }
|
||||
public PNLCellVM<PNLRowData, double> sod_unrealized_pnl { get; }
|
||||
public PNLCellVM<PNLRowData, double> sod_net_pos { get; }
|
||||
public PNLCellVM<PNLRowData, double> sod_long_pos { get; }
|
||||
public PNLCellVM<PNLRowData, double> sod_long_avg_price { get; }
|
||||
public PNLCellVM<PNLRowData, double> sod_long_avg_pnl { get; }
|
||||
public PNLCellVM<PNLRowData, double> sod_short_pos { get; }
|
||||
public PNLCellVM<PNLRowData, double> sod_short_avg_price { get; }
|
||||
public PNLCellVM<PNLRowData, double> sod_short_avg_pnl { get; }
|
||||
public PNLCellVM<PNLRowData, double> sod_delta { get; }
|
||||
public PNLCellVM<PNLRowData, double> sod_gamma { get; }
|
||||
public PNLCellVM<PNLRowData, double> sod_vega { get; }
|
||||
@@ -275,15 +256,11 @@ namespace bts.shell.pnl {
|
||||
|
||||
// day
|
||||
public PNLCellVM<PNLRowData, double> day_pnl { get; }
|
||||
public PNLCellVM<PNLRowData, double> day_realized_pnl { get; }
|
||||
public PNLCellVM<PNLRowData, double> day_unrealized_pnl { get; }
|
||||
public PNLCellVM<PNLRowData, double> day_net_pos { get; }
|
||||
public PNLCellVM<PNLRowData, double> day_long_pos { get; }
|
||||
public PNLCellVM<PNLRowData, double> day_long_avg_price { get; }
|
||||
public PNLCellVM<PNLRowData, double> day_long_avg_pnl { get; }
|
||||
public PNLCellVM<PNLRowData, double> day_short_pos { get; }
|
||||
public PNLCellVM<PNLRowData, double> day_short_avg_price { get; }
|
||||
public PNLCellVM<PNLRowData, double> day_short_avg_pnl { get; }
|
||||
public PNLCellVM<PNLRowData, double> day_delta { get; }
|
||||
public PNLCellVM<PNLRowData, double> day_gamma { get; }
|
||||
public PNLCellVM<PNLRowData, double> day_vega { get; }
|
||||
@@ -297,15 +274,11 @@ namespace bts.shell.pnl {
|
||||
public PNLCellVM<PNLRowData, double> working_short_avg_price { get; }
|
||||
// total
|
||||
public PNLCellVM<PNLRowData, double> total_pnl { get; }
|
||||
public PNLCellVM<PNLRowData, double> total_realized_pnl { get; }
|
||||
public PNLCellVM<PNLRowData, double> total_unrealized_pnl { get; }
|
||||
public PNLCellVM<PNLRowData, double> total_net_pos { get; }
|
||||
public PNLCellVM<PNLRowData, double> total_long_pos { get; }
|
||||
public PNLCellVM<PNLRowData, double> total_long_avg_price { get; }
|
||||
public PNLCellVM<PNLRowData, double> total_long_avg_pnl { get; }
|
||||
public PNLCellVM<PNLRowData, double> total_short_pos { get; }
|
||||
public PNLCellVM<PNLRowData, double> total_short_avg_price { get; }
|
||||
public PNLCellVM<PNLRowData, double> total_short_avg_pnl { get; }
|
||||
public PNLCellVM<PNLRowData, double> total_delta { get; }
|
||||
public PNLCellVM<PNLRowData, double> total_gamma { get; }
|
||||
public PNLCellVM<PNLRowData, double> total_vega { get; }
|
||||
|
||||
@@ -17,7 +17,6 @@ namespace bts.shell.pnl {
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Api.Data;
|
||||
using Spark.Api.Orders;
|
||||
using Spark.Core;
|
||||
using Spark.Core.Collections;
|
||||
@@ -120,7 +119,7 @@ namespace bts.shell.pnl {
|
||||
out var symbol_filter_items_observer,
|
||||
out var symbol_filter_items_view);
|
||||
symbol_filter_items_view.CustomSort = Comparer<string>.Default.to_safe().to_non_generic();
|
||||
expiration_filter = DiscreteValuesFilterVM.CreateTableUpdate<PNLRowData, ExpirationDate, ExpirationDate>(
|
||||
expiration_filter = DiscreteValuesFilterVM.CreateTableUpdate<PNLRowData, DateTime, DateTime>(
|
||||
r => r.expiration,
|
||||
exp => exp,
|
||||
out var expiration_filter_items_observer,
|
||||
@@ -227,7 +226,7 @@ namespace bts.shell.pnl {
|
||||
/// security
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, uint[]> account_filter { get; }
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, Venue[]> exchange_filter { get; } = DiscreteValuesFilterVM.Common.exchange<PNLRowData>(r => r.security.exchange_or_default(), nameof(PNLRowVM.exchange));
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, ExpirationDate[]> expiration_filter { get; }
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DateTime[]> expiration_filter { get; }
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, string[]> symbol_filter { get; }
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, string> security_filter { get; } = new RegexFilterVM<PNLRowData>(r => r.security?.ToString(), nameof(PNLRowData.security));
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, string> security_key_filter { get; } = new RegexFilterVM<PNLRowData>(r => r.key.security_id.ToString());
|
||||
@@ -238,14 +237,10 @@ namespace bts.shell.pnl {
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> cpp_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.effective_cpp);
|
||||
/// sod
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> sod_pnl_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.sod_pnl);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> sod_realized_pnl_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.sod_realized_pnl);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> sod_unrealized_pnl_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.sod_unrealized_pnl);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> sod_long_pos_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.sod.long_pos);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> sod_long_avg_price_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.sod_long_avg_price);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> sod_long_avg_pnl_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.sod_long_avg_pnl);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> sod_short_pos_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.sod.short_pos);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> sod_short_avg_price_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.sod_short_avg_price);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> sod_short_avg_pnl_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.sod_short_avg_pnl);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> sod_net_pos_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.sod.net_pos);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> sod_delta_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.sod.delta);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> sod_gamma_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.sod.gamma);
|
||||
@@ -254,14 +249,10 @@ namespace bts.shell.pnl {
|
||||
|
||||
/// day
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> day_pnl_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.day_pnl);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> day_realized_pnl_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.day_realized_pnl);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> day_unrealized_pnl_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.day_unrealized_pnl);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> day_long_pos_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.day_long_pos);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> day_long_avg_price_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.day_long_avg_price);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> day_long_avg_pnl_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.day_long_avg_pnl);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> day_short_pos_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.day_short_pos);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> day_short_avg_price_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.day_short_avg_price);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> day_short_avg_pnl_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.day_short_avg_pnl);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> day_net_pos_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.day_net_pos);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> day_delta_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.day.delta);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> day_gamma_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.day.gamma);
|
||||
@@ -276,14 +267,10 @@ namespace bts.shell.pnl {
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> working_net_pos_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.working_net_pos);
|
||||
/// total
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> total_pnl_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.total_pnl);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> total_realized_pnl_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.total_realized_pnl);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> total_unrealized_pnl_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.total_unrealized_pnl);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> total_long_pos_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.total_long_pos);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> total_long_avg_price_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.total_long_avg_price);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> total_long_avg_pnl_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.total_long_avg_pnl);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> total_short_pos_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.total_short_pos);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> total_short_avg_price_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.total_short_avg_price);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> total_short_avg_pnl_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.total_short_avg_pnl);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> total_net_pos_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.total_net_pos);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> total_delta_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.total_delta);
|
||||
public IDataGridColumnPersistentFilter<PNLRowData, DoubleMinMaxState> total_gamma_filter { get; } = new DoubleMinMax<PNLRowData>(r => r.total_gamma);
|
||||
@@ -323,8 +310,6 @@ namespace bts.shell.pnl {
|
||||
cpp = cpp_filter.get_state(),
|
||||
/// sod
|
||||
sod_pnl = sod_pnl_filter.get_state(),
|
||||
sod_realized_pnl = sod_realized_pnl_filter.get_state(),
|
||||
sod_unrealized_pnl = sod_unrealized_pnl_filter.get_state(),
|
||||
sod_long_pos = sod_long_pos_filter.get_state(),
|
||||
sod_long_avg_price = sod_long_avg_price_filter.get_state(),
|
||||
sod_short_pos = sod_short_pos_filter.get_state(),
|
||||
@@ -336,14 +321,10 @@ namespace bts.shell.pnl {
|
||||
sod_theta = sod_theta_filter.get_state(),
|
||||
/// day
|
||||
day_pnl = day_pnl_filter.get_state(),
|
||||
day_realized_pnl = day_realized_pnl_filter.get_state(),
|
||||
day_unrealized_pnl = day_unrealized_pnl_filter.get_state(),
|
||||
day_long_pos = day_long_pos_filter.get_state(),
|
||||
day_long_avg_price = day_long_avg_price_filter.get_state(),
|
||||
day_long_avg_pnl = day_long_avg_price_filter.get_state(),
|
||||
day_short_pos = day_short_pos_filter.get_state(),
|
||||
day_short_avg_price = day_short_avg_price_filter.get_state(),
|
||||
day_short_avg_pnl = day_short_avg_pnl_filter.get_state(),
|
||||
day_net_pos = day_net_pos_filter.get_state(),
|
||||
day_delta = day_delta_filter.get_state(),
|
||||
day_gamma = day_gamma_filter.get_state(),
|
||||
@@ -352,8 +333,6 @@ namespace bts.shell.pnl {
|
||||
has_day_trades = has_day_trades_filter.get_state(),
|
||||
/// total
|
||||
total_pnl = total_pnl_filter.get_state(),
|
||||
total_realized_pnl = total_realized_pnl_filter.get_state(),
|
||||
total_unrealized_pnl = total_unrealized_pnl_filter.get_state(),
|
||||
total_long_pos = total_long_pos_filter.get_state(),
|
||||
total_long_avg_price = total_long_avg_price_filter.get_state(),
|
||||
total_short_pos = total_short_pos_filter.get_state(),
|
||||
@@ -396,8 +375,6 @@ namespace bts.shell.pnl {
|
||||
cpp_filter.load_state(f.cpp);
|
||||
/// sod
|
||||
sod_pnl_filter.load_state(f.sod_pnl);
|
||||
sod_realized_pnl_filter.load_state(f.sod_realized_pnl);
|
||||
sod_unrealized_pnl_filter.load_state(f.sod_unrealized_pnl);
|
||||
sod_long_pos_filter.load_state(f.sod_long_pos);
|
||||
sod_long_avg_price_filter.load_state(f.sod_long_avg_price);
|
||||
sod_short_pos_filter.load_state(f.sod_short_pos);
|
||||
@@ -406,8 +383,6 @@ namespace bts.shell.pnl {
|
||||
sod_delta_filter.load_state(f.sod_delta);
|
||||
/// day
|
||||
day_pnl_filter.load_state(f.day_pnl);
|
||||
day_realized_pnl_filter.load_state(f.day_realized_pnl);
|
||||
day_unrealized_pnl_filter.load_state(f.day_unrealized_pnl);
|
||||
day_long_pos_filter.load_state(f.day_long_pos);
|
||||
day_long_avg_price_filter.load_state(f.day_long_avg_price);
|
||||
day_short_pos_filter.load_state(f.day_short_pos);
|
||||
@@ -416,8 +391,6 @@ namespace bts.shell.pnl {
|
||||
has_day_trades_filter.load_state(f.has_day_trades);
|
||||
/// total
|
||||
total_pnl_filter.load_state(f.total_pnl);
|
||||
total_realized_pnl_filter.load_state(f.total_realized_pnl);
|
||||
total_unrealized_pnl_filter.load_state(f.total_unrealized_pnl);
|
||||
total_long_pos_filter.load_state(f.total_long_pos);
|
||||
total_long_avg_price_filter.load_state(f.total_long_avg_price);
|
||||
total_short_pos_filter.load_state(f.total_short_pos);
|
||||
@@ -593,14 +566,10 @@ namespace bts.shell.pnl {
|
||||
case ColumnKeys.CPP: return wrap(r => r.cpp);
|
||||
/// SOD
|
||||
case ColumnKeys.SODPNL: return wrap(r => r.sod_pnl);
|
||||
case ColumnKeys.SODRealizedPNL: return wrap(r => r.sod_realized_pnl);
|
||||
case ColumnKeys.SODUnrealizedPNL: return wrap(r => r.sod_unrealized_pnl);
|
||||
case ColumnKeys.SODLongPos: return wrap(r => r.sod_long_pos);
|
||||
case ColumnKeys.SODLongAvgPrice: return wrap(r => r.sod_long_avg_price);
|
||||
case ColumnKeys.SODLongAvgPNL: return wrap(r => r.sod_long_avg_pnl);
|
||||
case ColumnKeys.SODShortPos: return wrap(r => r.sod_short_pos);
|
||||
case ColumnKeys.SODShortAvgPrice: return wrap(r => r.sod_short_avg_price);
|
||||
case ColumnKeys.SODShortAvgPNL: return wrap(r => r.sod_short_avg_pnl);
|
||||
case ColumnKeys.SODNetPos: return wrap(r => r.sod_net_pos);
|
||||
case ColumnKeys.SODDelta: return wrap(r => r.sod_delta);
|
||||
case ColumnKeys.SODGamma: return wrap(r => r.sod_gamma);
|
||||
@@ -608,14 +577,10 @@ namespace bts.shell.pnl {
|
||||
case ColumnKeys.SODTheta: return wrap(r => r.sod_theta);
|
||||
/// Day
|
||||
case ColumnKeys.DayPNL: return wrap(r => r.day_pnl);
|
||||
case ColumnKeys.DayRealizedPNL: return wrap(r => r.day_realized_pnl);
|
||||
case ColumnKeys.DayUnrealizedPNL: return wrap(r => r.day_unrealized_pnl);
|
||||
case ColumnKeys.DayLongPos: return wrap(r => r.day_long_pos);
|
||||
case ColumnKeys.DayLongAvgPrice: return wrap(r => r.day_long_avg_price);
|
||||
case ColumnKeys.DayLongAvgPNL: return wrap(r => r.day_long_avg_pnl);
|
||||
case ColumnKeys.DayShortPos: return wrap(r => r.day_short_pos);
|
||||
case ColumnKeys.DayShortAvgPrice: return wrap(r => r.day_short_avg_price);
|
||||
case ColumnKeys.DayShortAvgPNL: return wrap(r => r.day_short_avg_pnl);
|
||||
case ColumnKeys.DayNetPos: return wrap(r => r.day_net_pos);
|
||||
case ColumnKeys.DayDelta: return wrap(r => r.day_delta);
|
||||
case ColumnKeys.DayGamma: return wrap(r => r.day_gamma);
|
||||
@@ -624,14 +589,10 @@ namespace bts.shell.pnl {
|
||||
case ColumnKeys.HasDayTrades: return wrap(r => r.has_day_trades);
|
||||
/// Total
|
||||
case ColumnKeys.TotalPNL: return wrap(r => r.total_pnl);
|
||||
case ColumnKeys.TotalRealizedPNL: return wrap(r => r.total_realized_pnl);
|
||||
case ColumnKeys.TotalUnrealizedPNL: return wrap(r => r.total_unrealized_pnl);
|
||||
case ColumnKeys.TotalLongPos: return wrap(r => r.total_long_pos);
|
||||
case ColumnKeys.TotalLongAvgPrice: return wrap(r => r.total_long_avg_price);
|
||||
case ColumnKeys.TotalLongAvgPNL: return wrap(r => r.total_long_avg_pnl);
|
||||
case ColumnKeys.TotalShortPos: return wrap(r => r.total_short_pos);
|
||||
case ColumnKeys.TotalShortAvgPrice: return wrap(r => r.total_short_avg_price);
|
||||
case ColumnKeys.TotalShortAvgPNL: return wrap(r => r.total_short_avg_pnl);
|
||||
case ColumnKeys.TotalNetPos: return wrap(r => r.total_net_pos);
|
||||
case ColumnKeys.TotalDelta: return wrap(r => r.total_delta);
|
||||
case ColumnKeys.TotalGamma: return wrap(r => r.total_gamma);
|
||||
@@ -666,13 +627,13 @@ namespace bts.shell.pnl {
|
||||
yield return col_hash.Contains(c.id) ? c.with(is_visible: false) : c;
|
||||
}
|
||||
|
||||
static IObservable<TableUpdate<ExpirationDate, ExpirationDate>> _expirations_source(
|
||||
static IObservable<TableUpdate<DateTime, DateTime>> _expirations_source(
|
||||
IObservable<TableUpdate<PNLRowData, PNLKey>> pnl_source) =>
|
||||
pnl_source
|
||||
.StartWith(TableUpdate<PNLRowData, PNLKey>.mk_empty(PNLRowData.key_fn))
|
||||
.distinct_on(
|
||||
PNLRowData.key_fn, r => r.expiration, e => e, EqualityComparer<ExpirationDate>.Default)
|
||||
.Filter(e => e != ExpirationDate.None);
|
||||
PNLRowData.key_fn, r => r.expiration, e => e, EqualityComparer<DateTime>.Default)
|
||||
.Filter(e => e != DateTime.MinValue);
|
||||
|
||||
// combines the known system symbols
|
||||
static IObservable<TableUpdate<string, string>> _symbols_source(IObservable<TableUpdate<PNLRowData, PNLKey>> pnl_source) =>
|
||||
@@ -746,7 +707,7 @@ namespace bts.shell.pnl {
|
||||
filter.security = SecurityCriteria.from_securities(sec));
|
||||
break;
|
||||
case ColumnKeys.Expiration:
|
||||
try_set_filter_prop<ExpirationDate>(exp_date => filter.exp_date = exp_date);
|
||||
try_set_filter_prop<DateTime>(exp_date => filter.exp_date = exp_date);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
@@ -814,7 +775,7 @@ namespace bts.shell.pnl {
|
||||
case ColumnKeys.Symbol: filter.symbols = new[] { g.Name.ToString() }; break;
|
||||
case ColumnKeys.Exchange: filter.exchanges = new[] { (Venue)g.Name }; break;
|
||||
case ColumnKeys.Expiration: {
|
||||
if (g.Name is ExpirationDate exp) {
|
||||
if (g.Name is DateTime exp) {
|
||||
if (filter.security_criteria is null) {
|
||||
filter.security_criteria = SecurityCriteria.from_expirations(exp);
|
||||
} else {
|
||||
|
||||
@@ -118,8 +118,6 @@ namespace bts.shell.pnl {
|
||||
});
|
||||
// sod
|
||||
sod_pnl = _cell_map.add_pnl(ColumnKeys.SODPNL, d => d.sod_pnl);
|
||||
sod_realized_pnl = _cell_map.add_pnl(ColumnKeys.SODRealizedPNL, d => d.sod_realized_pnl);
|
||||
sod_unrealized_pnl = _cell_map.add_pnl(ColumnKeys.SODUnrealizedPNL, d => d.sod_unrealized_pnl);
|
||||
sod_net_pos = _cell_map.add_net_pos(ColumnKeys.SODNetPos, d => d.display_sod_net_pos);
|
||||
sod_long_pos = _cell_map.add_long_pos(ColumnKeys.SODLongPos, d => d.display_sod_long_pos);
|
||||
sod_short_pos = _cell_map.add_short_pos(ColumnKeys.SODShortPos, d => d.display_sod_short_pos);
|
||||
@@ -130,8 +128,6 @@ namespace bts.shell.pnl {
|
||||
|
||||
// day
|
||||
day_pnl = _cell_map.add_pnl(ColumnKeys.DayPNL, d => d.day_pnl);
|
||||
day_realized_pnl = _cell_map.add_pnl(ColumnKeys.DayRealizedPNL, d => d.day_realized_pnl);
|
||||
day_unrealized_pnl = _cell_map.add_pnl(ColumnKeys.DayUnrealizedPNL, d => d.day_unrealized_pnl);
|
||||
day_net_pos = _cell_map.add_net_pos(ColumnKeys.DayNetPos, d => d.display_day_net_pos);
|
||||
day_long_pos = _cell_map.add_long_pos(ColumnKeys.DayLongPos, d => d.display_day_long_pos);
|
||||
day_short_pos = _cell_map.add_short_pos(ColumnKeys.DayShortPos, d => d.display_day_short_pos);
|
||||
@@ -142,8 +138,6 @@ namespace bts.shell.pnl {
|
||||
|
||||
// total
|
||||
total_pnl = _cell_map.add(ColumnKeys.TotalPNL, d => d.total_pnl, FormattingDelegates.Price<decimal>.Value);
|
||||
total_realized_pnl = _cell_map.add_pnl(ColumnKeys.TotalRealizedPNL, d => d.total_realized_pnl);
|
||||
total_unrealized_pnl = _cell_map.add_pnl(ColumnKeys.TotalUnrealizedPNL, d => d.total_unrealized_pnl);
|
||||
total_net_pos = _cell_map.add(ColumnKeys.TotalNetPos, d => d.display_total_net_pos);
|
||||
total_long_pos = _cell_map.add(ColumnKeys.TotalLongPos, d => d.display_total_long_pos);
|
||||
total_short_pos = _cell_map.add(ColumnKeys.TotalShortPos, d => d.display_total_short_pos);
|
||||
@@ -187,8 +181,6 @@ namespace bts.shell.pnl {
|
||||
|
||||
// sod
|
||||
public PNLCellVM<PNLNormalizedData, decimal> sod_pnl { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> sod_realized_pnl { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> sod_unrealized_pnl { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> sod_net_pos { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> sod_long_pos { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> sod_short_pos { get; }
|
||||
@@ -199,8 +191,6 @@ namespace bts.shell.pnl {
|
||||
|
||||
// day
|
||||
public PNLCellVM<PNLNormalizedData, decimal> day_pnl { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> day_realized_pnl { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> day_unrealized_pnl { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> day_net_pos { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> day_long_pos { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> day_short_pos { get; }
|
||||
@@ -211,8 +201,6 @@ namespace bts.shell.pnl {
|
||||
|
||||
// total
|
||||
public PNLCellVM<PNLNormalizedData, decimal> total_pnl { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> total_realized_pnl { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> total_unrealized_pnl { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> total_net_pos { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> total_long_pos { get; }
|
||||
public PNLCellVM<PNLNormalizedData, decimal> total_short_pos { get; }
|
||||
|
||||
@@ -266,7 +266,6 @@
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
<Setter Property="Margin" Value="4,0,0,0"/>
|
||||
<Setter Property="FontWeight" Value="Bold"/>
|
||||
<Setter Property="Foreground" Value="{u:BTSColor UI.default_text}"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="HeaderRowCellText" TargetType="TextBlock">
|
||||
@@ -571,8 +570,6 @@
|
||||
</TextBlock>
|
||||
<!--SOD-->
|
||||
<c:TextCell c:DIYGrid.ColumnKey="SODPNL" DataContext="{Binding total_aggregate.sod_pnl}" Style="{StaticResource HeaderRowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="SODRealizedPNL" DataContext="{Binding total_aggregate.sod_realized_pnl}" Style="{StaticResource HeaderRowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="SODUnrealizedPNL" DataContext="{Binding total_aggregate.sod_unrealized_pnl}" Style="{StaticResource HeaderRowTextCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="SODNetPos" DataContext="{Binding total_aggregate.sod_net_pos}" Style="{StaticResource TotalRowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="SODLongPos" DataContext="{Binding total_aggregate.sod_long_pos}" Style="{StaticResource TotalRowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="SODShortPos" DataContext="{Binding total_aggregate.sod_short_pos}" Style="{StaticResource TotalRowHyperlinkCell}"/>
|
||||
@@ -583,8 +580,6 @@
|
||||
|
||||
<!--Day-->
|
||||
<c:TextCell c:DIYGrid.ColumnKey="DayPNL" DataContext="{Binding total_aggregate.day_pnl}" Style="{StaticResource HeaderRowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="DayRealizedPNL" DataContext="{Binding total_aggregate.day_realized_pnl}" Style="{StaticResource HeaderRowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="DayUnrealizedPNL" DataContext="{Binding total_aggregate.day_unrealized_pnl}" Style="{StaticResource HeaderRowTextCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="DayNetPos" DataContext="{Binding total_aggregate.day_net_pos}" Style="{StaticResource TotalRowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="DayLongPos" DataContext="{Binding total_aggregate.day_long_pos}" Style="{StaticResource TotalRowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="DayShortPos" DataContext="{Binding total_aggregate.day_short_pos}" Style="{StaticResource TotalRowHyperlinkCell}"/>
|
||||
@@ -603,8 +598,6 @@
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="WorkingShortPos" DataContext="{Binding total_aggregate.working_short_pos}" Style="{StaticResource TotalRowHyperlinkCell}"/>
|
||||
<!--Total-->
|
||||
<c:TextCell c:DIYGrid.ColumnKey="TotalPNL" DataContext="{Binding total_aggregate.total_pnl}" Style="{StaticResource HeaderRowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="TotalRealizedPNL" DataContext="{Binding total_aggregate.total_realized_pnl}" Style="{StaticResource HeaderRowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="TotalUnrealizedPNL" DataContext="{Binding total_aggregate.total_unrealized_pnl}" Style="{StaticResource HeaderRowTextCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="TotalNetPos" DataContext="{Binding total_aggregate.total_net_pos}" Style="{StaticResource TotalRowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="TotalLongPos" DataContext="{Binding total_aggregate.total_long_pos}" Style="{StaticResource TotalRowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="TotalShortPos" DataContext="{Binding total_aggregate.total_short_pos}" Style="{StaticResource TotalRowHyperlinkCell}"/>
|
||||
@@ -639,8 +632,6 @@
|
||||
<TextBlock Text="{Binding selected_rows.Count, StringFormat='Selected ({0})'}" Style="{StaticResource HeaderRowHeaderText}"/>
|
||||
<!--SOD-->
|
||||
<c:TextCell c:DIYGrid.ColumnKey="SODPNL" DataContext="{Binding selected_aggregate.sod_pnl}" Style="{StaticResource HeaderRowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="SODRealizedPNL" DataContext="{Binding selected_aggregate.sod_realized_pnl}" Style="{StaticResource HeaderRowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="SODUnrealizedPNL" DataContext="{Binding selected_aggregate.sod_unrealized_pnl}" Style="{StaticResource HeaderRowTextCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="SODNetPos" DataContext="{Binding selected_aggregate.sod_net_pos}" Style="{StaticResource SelectedTotalRowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="SODLongPos" DataContext="{Binding selected_aggregate.sod_long_pos}" Style="{StaticResource SelectedTotalRowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="SODShortPos" DataContext="{Binding selected_aggregate.sod_short_pos}" Style="{StaticResource SelectedTotalRowHyperlinkCell}"/>
|
||||
@@ -651,8 +642,6 @@
|
||||
|
||||
<!--Day-->
|
||||
<c:TextCell c:DIYGrid.ColumnKey="DayPNL" DataContext="{Binding selected_aggregate.day_pnl}" Style="{StaticResource HeaderRowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="DayRealizedPNL" DataContext="{Binding selected_aggregate.day_realized_pnl}" Style="{StaticResource HeaderRowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="DayUnrealizedPNL" DataContext="{Binding selected_aggregate.day_unrealized_pnl}" Style="{StaticResource HeaderRowTextCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="DayNetPos" DataContext="{Binding selected_aggregate.day_net_pos}" Style="{StaticResource SelectedTotalRowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="DayLongPos" DataContext="{Binding selected_aggregate.day_long_pos}" Style="{StaticResource SelectedTotalRowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="DayShortPos" DataContext="{Binding selected_aggregate.day_short_pos}" Style="{StaticResource SelectedTotalRowHyperlinkCell}"/>
|
||||
@@ -671,8 +660,6 @@
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="WorkingShortPos" DataContext="{Binding selected_aggregate.working_short_pos}" Style="{StaticResource SelectedTotalRowHyperlinkCell}"/>
|
||||
<!--Total-->
|
||||
<c:TextCell c:DIYGrid.ColumnKey="TotalPNL" DataContext="{Binding selected_aggregate.total_pnl}" Style="{StaticResource HeaderRowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="TotalRealizedPNL" DataContext="{Binding selected_aggregate.total_realized_pnl}" Style="{StaticResource HeaderRowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="TotalUnrealizedPNL" DataContext="{Binding selected_aggregate.total_unrealized_pnl}" Style="{StaticResource HeaderRowTextCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="TotalNetPos" DataContext="{Binding selected_aggregate.total_net_pos}" Style="{StaticResource SelectedTotalRowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="TotalLongPos" DataContext="{Binding selected_aggregate.total_long_pos}" Style="{StaticResource SelectedTotalRowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="TotalShortPos" DataContext="{Binding selected_aggregate.total_short_pos}" Style="{StaticResource SelectedTotalRowHyperlinkCell}"/>
|
||||
@@ -804,26 +791,6 @@
|
||||
data_member_path="sod_pnl"
|
||||
Header="SOD PnL"
|
||||
/>
|
||||
<!--SOD Realized PNL-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.sod_realized_pnl_filter, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterTemplate="{StaticResource {x:Static ft:DataGridFilterKnownTemplates.DoubleMinMax}}"
|
||||
c:DataGridFilterProperties.FilterActive="{Binding DataContext.sod_realized_pnl_filter.active, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.sod_realized_pnl_filter.open, Source={u:DirectReference _grid}}"
|
||||
key="SODRealizedPNL"
|
||||
data_member_path="sod_realized_pnl"
|
||||
Header="SOD Realized PnL"
|
||||
/>
|
||||
<!--SOD Unrealized PNL-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.sod_unrealized_pnl_filter, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterTemplate="{StaticResource {x:Static ft:DataGridFilterKnownTemplates.DoubleMinMax}}"
|
||||
c:DataGridFilterProperties.FilterActive="{Binding DataContext.sod_unrealized_pnl_filter.active, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.sod_unrealized_pnl_filter.open, Source={u:DirectReference _grid}}"
|
||||
key="SODUnrealizedPNL"
|
||||
data_member_path="sod_unrealized_pnl"
|
||||
Header="SOD Unrealized PnL"
|
||||
/>
|
||||
<!--SOD Net Pos-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.sod_net_pos_filter, Source={u:DirectReference _grid}}"
|
||||
@@ -852,15 +819,6 @@
|
||||
key="SODLongAvgPrice"
|
||||
data_member_path="sod_long_avg_price"
|
||||
/>
|
||||
<!--SOD Long Avg PNL-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.sod_long_avg_pnl_filter, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterTemplate="{StaticResource {x:Static ft:DataGridFilterKnownTemplates.DoubleMinMax}}"
|
||||
c:DataGridFilterProperties.FilterActive="{Binding DataContext.sod_long_avg_pnl_filter.active, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.sod_long_avg_pnl_filter.open, Source={u:DirectReference _grid}}"
|
||||
key="SODLongAvgPNL"
|
||||
data_member_path="sod_long_avg_pnl"
|
||||
/>
|
||||
<!--SOD Short Pos-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.sod_short_pos_filter, Source={u:DirectReference _grid}}"
|
||||
@@ -879,15 +837,6 @@
|
||||
key="SODShortAvgPrice"
|
||||
data_member_path="sod_short_avg_price"
|
||||
/>
|
||||
<!--SOD Short Avg PNL-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.sod_short_avg_pnl_filter, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterTemplate="{StaticResource {x:Static ft:DataGridFilterKnownTemplates.DoubleMinMax}}"
|
||||
c:DataGridFilterProperties.FilterActive="{Binding DataContext.sod_short_avg_pnl_filter.active, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.sod_short_avg_pnl_filter.open, Source={u:DirectReference _grid}}"
|
||||
key="SODShortAvgPNL"
|
||||
data_member_path="sod_short_avg_pnl"
|
||||
/>
|
||||
<!--SOD Delta-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.sod_delta_filter, Source={u:DirectReference _grid}}"
|
||||
@@ -931,26 +880,6 @@
|
||||
data_member_path="day_pnl"
|
||||
sort_member_path="day_pnl"
|
||||
/>
|
||||
<!--Day Realized PNL-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.day_realized_pnl_filter, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterTemplate="{StaticResource {x:Static ft:DataGridFilterKnownTemplates.DoubleMinMax}}"
|
||||
c:DataGridFilterProperties.FilterActive="{Binding DataContext.day_realized_pnl_filter.active, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.day_realized_pnl_filter.open, Source={u:DirectReference _grid}}"
|
||||
key="DayRealizedPNL"
|
||||
data_member_path="day_realized_pnl"
|
||||
Header="Day Realized PnL"
|
||||
/>
|
||||
<!--Day Unrealized PNL-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.day_unrealized_pnl_filter, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterTemplate="{StaticResource {x:Static ft:DataGridFilterKnownTemplates.DoubleMinMax}}"
|
||||
c:DataGridFilterProperties.FilterActive="{Binding DataContext.day_unrealized_pnl_filter.active, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.day_unrealized_pnl_filter.open, Source={u:DirectReference _grid}}"
|
||||
key="DayUnrealizedPNL"
|
||||
data_member_path="day_unrealized_pnl"
|
||||
Header="Day Unrealized PnL"
|
||||
/>
|
||||
<!--Day Net Pos-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.day_net_pos_filter, Source={u:DirectReference _grid}}"
|
||||
@@ -981,16 +910,6 @@
|
||||
data_member_path="day_long_avg_price"
|
||||
sort_member_path="day_long_avg_price"
|
||||
/>
|
||||
<!--Day Long Avg PNL-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.day_long_avg_pnl_filter, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterTemplate="{StaticResource {x:Static ft:DataGridFilterKnownTemplates.DoubleMinMax}}"
|
||||
c:DataGridFilterProperties.FilterActive="{Binding DataContext.day_long_avg_pnl_filter.active, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.day_long_avg_pnl_filter.open, Source={u:DirectReference _grid}}"
|
||||
key="DayLongAvgPNL"
|
||||
data_member_path="day_long_avg_pnl"
|
||||
sort_member_path="day_long_avg_pnl"
|
||||
/>
|
||||
<!--Day Delta-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.day_delta_filter, Source={u:DirectReference _grid}}"
|
||||
@@ -1093,16 +1012,6 @@
|
||||
data_member_path="day_short_avg_price"
|
||||
sort_member_path="day_short_avg_price"
|
||||
/>
|
||||
<!--Day Short Avg PNL-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.day_short_avg_pnl_filter, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterTemplate="{StaticResource {x:Static ft:DataGridFilterKnownTemplates.DoubleMinMax}}"
|
||||
c:DataGridFilterProperties.FilterActive="{Binding DataContext.day_short_avg_pnl_filter.active, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.day_short_avg_pnl_filter.open, Source={u:DirectReference _grid}}"
|
||||
key="DayShortAvgPNL"
|
||||
data_member_path="day_short_avg_pnl"
|
||||
sort_member_path="day_short_avg_pnl"
|
||||
/>
|
||||
<!--Day Short Pos-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.day_short_pos_filter, Source={u:DirectReference _grid}}"
|
||||
@@ -1181,26 +1090,6 @@
|
||||
key="TotalPNL"
|
||||
data_member_path="total_pnl"
|
||||
/>
|
||||
<!--Total Realized PNL-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.total_realized_pnl_filter, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterTemplate="{StaticResource {x:Static ft:DataGridFilterKnownTemplates.DoubleMinMax}}"
|
||||
c:DataGridFilterProperties.FilterActive="{Binding DataContext.total_realized_pnl_filter.active, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.total_realized_pnl_filter.open, Source={u:DirectReference _grid}}"
|
||||
key="TotalRealizedPNL"
|
||||
data_member_path="total_realized_pnl"
|
||||
Header="Total Realized PnL"
|
||||
/>
|
||||
<!--Total Unrealized PNL-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.total_unrealized_pnl_filter, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterTemplate="{StaticResource {x:Static ft:DataGridFilterKnownTemplates.DoubleMinMax}}"
|
||||
c:DataGridFilterProperties.FilterActive="{Binding DataContext.total_unrealized_pnl_filter.active, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.total_unrealized_pnl_filter.open, Source={u:DirectReference _grid}}"
|
||||
key="TotalUnrealizedPNL"
|
||||
data_member_path="total_unrealized_pnl"
|
||||
Header="Total Unrealized PnL"
|
||||
/>
|
||||
<!--Total Net Pos-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.total_net_pos_filter, Source={u:DirectReference _grid}}"
|
||||
@@ -1231,16 +1120,6 @@
|
||||
data_member_path="total_long_avg_price"
|
||||
sort_member_path="total_long_avg_price"
|
||||
/>
|
||||
<!--Total Long Avg PNL-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.total_long_avg_pnl_filter, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterTemplate="{StaticResource {x:Static ft:DataGridFilterKnownTemplates.DoubleMinMax}}"
|
||||
c:DataGridFilterProperties.FilterActive="{Binding DataContext.total_long_avg_pnl_filter.active, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.total_long_avg_pnl_filter.open, Source={u:DirectReference _grid}}"
|
||||
key="TotalLongAvgPNL"
|
||||
data_member_path="total_long_avg_pnl"
|
||||
sort_member_path="total_long_avg_pnl"
|
||||
/>
|
||||
<!--Total Short Pos-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.total_short_pos_filter, Source={u:DirectReference _grid}}"
|
||||
@@ -1261,16 +1140,6 @@
|
||||
data_member_path="total_short_avg_price"
|
||||
sort_member_path="total_short_avg_price"
|
||||
/>
|
||||
<!--Total Short Avg PNL-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.total_short_avg_pnl_filter, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterTemplate="{StaticResource {x:Static ft:DataGridFilterKnownTemplates.DoubleMinMax}}"
|
||||
c:DataGridFilterProperties.FilterActive="{Binding DataContext.total_short_avg_pnl_filter.active, Source={u:DirectReference _grid}}"
|
||||
c:DataGridFilterProperties.FilterOpen="{Binding DataContext.total_short_avg_pnl_filter.open, Source={u:DirectReference _grid}}"
|
||||
key="TotalShortAvgPNL"
|
||||
data_member_path="total_short_avg_pnl"
|
||||
sort_member_path="total_short_avg_pnl"
|
||||
/>
|
||||
<!--Total Delta-->
|
||||
<pnl:PNLColumn
|
||||
c:DataGridFilterProperties.Filter="{Binding DataContext.total_delta_filter, Source={u:DirectReference _grid}}"
|
||||
@@ -1329,15 +1198,11 @@
|
||||
<c:TextCell c:DIYGrid.ColumnKey="CPP" DataContext="{Binding cpp}" Style="{StaticResource RowTextCell}"/>
|
||||
<!--SOD-->
|
||||
<c:TextCell c:DIYGrid.ColumnKey="SODPNL" DataContext="{Binding sod_pnl}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="SODRealizedPNL" DataContext="{Binding sod_realized_pnl}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="SODUnrealizedPNL" DataContext="{Binding sod_unrealized_pnl}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="SODNetPos" DataContext="{Binding sod_net_pos}" Style="{StaticResource RowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="SODLongPos" DataContext="{Binding sod_long_pos}" Style="{StaticResource RowHyperlinkCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="SODLongAvgPrice" DataContext="{Binding sod_long_avg_price}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="SODLongAvgPNL" DataContext="{Binding sod_long_avg_pnl}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="SODShortPos" DataContext="{Binding sod_short_pos}" Style="{StaticResource RowHyperlinkCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="SODShortAvgPrice" DataContext="{Binding sod_short_avg_price}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="SODShortAvgPNL" DataContext="{Binding sod_short_avg_pnl}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="SODDelta"
|
||||
DataContext="{Binding sod_delta}"
|
||||
@@ -1357,15 +1222,11 @@
|
||||
|
||||
<!--Day-->
|
||||
<c:TextCell c:DIYGrid.ColumnKey="DayPNL" DataContext="{Binding day_pnl}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="DayRealizedPNL" DataContext="{Binding day_realized_pnl}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="DayUnrealizedPNL" DataContext="{Binding day_unrealized_pnl}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="DayNetPos" DataContext="{Binding day_net_pos}" Style="{StaticResource RowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="DayLongPos" DataContext="{Binding day_long_pos}" Style="{StaticResource RowHyperlinkCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="DayLongAvgPrice" DataContext="{Binding day_long_avg_price}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="DayLongAvgPNL" DataContext="{Binding day_long_avg_pnl}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="DayShortPos" DataContext="{Binding day_short_pos}" Style="{StaticResource RowHyperlinkCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="DayShortAvgPrice" DataContext="{Binding day_short_avg_price}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="DayShortAvgPNL" DataContext="{Binding day_short_avg_pnl}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="DayDelta"
|
||||
DataContext="{Binding day_delta}"
|
||||
@@ -1396,9 +1257,6 @@
|
||||
<c:TextCell c:DIYGrid.ColumnKey="LastPrice" DataContext="{Binding last_price}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="SettlementPrice" DataContext="{Binding settlement_price}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="PNLPrice" DataContext="{Binding pnl_price}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="BidPrice" DataContext="{Binding bid_price}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="AskPrice" DataContext="{Binding ask_price}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="MidPrice" DataContext="{Binding mid_price}" Style="{StaticResource RowTextCell}"/>
|
||||
<!--Working-->
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="WorkingNetPos" DataContext="{Binding working_net_pos}" Style="{StaticResource RowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="WorkingLongPos" DataContext="{Binding working_long_pos}" Style="{StaticResource RowHyperlinkCell}"/>
|
||||
@@ -1407,15 +1265,11 @@
|
||||
<c:TextCell c:DIYGrid.ColumnKey="WorkingShortAvgPrice" DataContext="{Binding working_short_avg_price}" Style="{StaticResource RowTextCell}"/>
|
||||
<!--Total-->
|
||||
<c:TextCell c:DIYGrid.ColumnKey="TotalPNL" DataContext="{Binding total_pnl}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="TotalRealizedPNL" DataContext="{Binding total_realized_pnl}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="TotalUnrealizedPNL" DataContext="{Binding total_unrealized_pnl}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="TotalNetPos" DataContext="{Binding total_net_pos}" Style="{StaticResource RowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="TotalLongPos" DataContext="{Binding total_long_pos}" Style="{StaticResource RowHyperlinkCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="TotalLongAvgPrice" DataContext="{Binding total_long_avg_price}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="TotalLongAvgPNL" DataContext="{Binding total_long_avg_pnl}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="TotalShortPos" DataContext="{Binding total_short_pos}" Style="{StaticResource RowHyperlinkCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="TotalShortAvgPrice" DataContext="{Binding total_short_avg_price}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="TotalShortAvgPNL" DataContext="{Binding total_short_avg_pnl}" Style="{StaticResource RowTextCell}"/>
|
||||
<c:TextCell
|
||||
c:DIYGrid.ColumnKey="TotalDelta"
|
||||
DataContext="{Binding total_delta}"
|
||||
@@ -1506,8 +1360,6 @@
|
||||
</Grid>
|
||||
<!--SOD-->
|
||||
<c:TextCell c:DIYGrid.ColumnKey="SODPNL" DataContext="{Binding sod_pnl}" Style="{StaticResource GroupRowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="SODRealizedPNL" DataContext="{Binding sod_realized_pnl}" Style="{StaticResource GroupRowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="SODUnrealizedPNL" DataContext="{Binding sod_unrealized_pnl}" Style="{StaticResource GroupRowTextCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="SODNetPos" DataContext="{Binding sod_net_pos}" Style="{StaticResource GroupRowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="SODLongPos" DataContext="{Binding sod_long_pos}" Style="{StaticResource GroupRowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="SODShortPos" DataContext="{Binding sod_short_pos}" Style="{StaticResource GroupRowHyperlinkCell}"/>
|
||||
@@ -1518,8 +1370,6 @@
|
||||
|
||||
<!--Day-->
|
||||
<c:TextCell c:DIYGrid.ColumnKey="DayPNL" DataContext="{Binding day_pnl}" Style="{StaticResource GroupRowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="DayRealizedPNL" DataContext="{Binding day_realized_pnl}" Style="{StaticResource GroupRowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="DayUnrealizedPNL" DataContext="{Binding day_unrealized_pnl}" Style="{StaticResource GroupRowTextCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="DayNetPos" DataContext="{Binding day_net_pos}" Style="{StaticResource GroupRowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="DayLongPos" DataContext="{Binding day_long_pos}" Style="{StaticResource GroupRowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="DayShortPos" DataContext="{Binding day_short_pos}" Style="{StaticResource GroupRowHyperlinkCell}"/>
|
||||
@@ -1534,8 +1384,6 @@
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="WorkingShortPos" DataContext="{Binding working_short_pos}" Style="{StaticResource GroupRowHyperlinkCell}"/>
|
||||
<!--Total-->
|
||||
<c:TextCell c:DIYGrid.ColumnKey="TotalPNL" DataContext="{Binding total_pnl}" Style="{StaticResource GroupRowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="TotalRealizedPNL" DataContext="{Binding total_realized_pnl}" Style="{StaticResource GroupRowTextCell}"/>
|
||||
<c:TextCell c:DIYGrid.ColumnKey="TotalUnrealizedPNL" DataContext="{Binding total_unrealized_pnl}" Style="{StaticResource GroupRowTextCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="TotalNetPos" DataContext="{Binding total_net_pos}" Style="{StaticResource GroupRowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="TotalLongPos" DataContext="{Binding total_long_pos}" Style="{StaticResource GroupRowHyperlinkCell}"/>
|
||||
<c:HyperlinkCell c:DIYGrid.ColumnKey="TotalShortPos" DataContext="{Binding total_short_pos}" Style="{StaticResource GroupRowHyperlinkCell}"/>
|
||||
|
||||
@@ -1,439 +1,427 @@
|
||||
namespace bts.shell.pnl {
|
||||
using bts.collections;
|
||||
|
||||
using mbts.collections;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.converters;
|
||||
using mbts.ui.dpi;
|
||||
using mbts.ui.extensions;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
enum PNLHeaderRowDisplay {
|
||||
None,
|
||||
Total,
|
||||
SelectedTotal
|
||||
}
|
||||
|
||||
partial class PNLView : UserControl {
|
||||
public static readonly double
|
||||
MinGroupRowHeight = 24.0.RoundLayoutValue(),
|
||||
MinHeaderRowHeight = 24.0.RoundLayoutValue();
|
||||
DIYGridPopupManager _popup_man_backing;
|
||||
|
||||
public enum Columns {
|
||||
Account = 1,
|
||||
// Security
|
||||
Exchange,
|
||||
Symbol,
|
||||
Expiration,
|
||||
SecurityType,
|
||||
Security,
|
||||
SecurityKey,
|
||||
CPP,
|
||||
// SOD
|
||||
SODPNL,
|
||||
SODRealizedPNL,
|
||||
SODUnrealizedPNL,
|
||||
SODLongPos,
|
||||
SODLongAvgPrice,
|
||||
SODLongAvgPNL,
|
||||
SODShortPos,
|
||||
SODShortAvgPrice,
|
||||
SODShortAvgPNL,
|
||||
SODNetPos,
|
||||
SODDelta,
|
||||
SODGamma,
|
||||
SODVega,
|
||||
SODTheta,
|
||||
// Day
|
||||
DayPNL,
|
||||
DayRealizedPNL,
|
||||
DayUnrealizedPNL,
|
||||
DayLongPos,
|
||||
DayLongAvgPrice,
|
||||
DayLongAvgPNL,
|
||||
DayShortPos,
|
||||
DayShortAvgPrice,
|
||||
DayShortAvgPNL,
|
||||
DayDelta,
|
||||
DayGamma,
|
||||
DayVega,
|
||||
DayTheta,
|
||||
DayCalcType,
|
||||
DayNetPos,
|
||||
HasDayTrades,
|
||||
// Raw Day
|
||||
RawDayLongPos,
|
||||
RawDayShortPos,
|
||||
RawDayNetPos,
|
||||
// Working
|
||||
WorkingLongPos,
|
||||
WorkingLongAvgPrice,
|
||||
WorkingShortPos,
|
||||
WorkingShortAvgPrice,
|
||||
WorkingNetPos,
|
||||
// Total
|
||||
TotalPNL,
|
||||
TotalRealizedPNL,
|
||||
TotalUnrealizedPNL,
|
||||
TotalLongPos,
|
||||
TotalLongAvgPrice,
|
||||
TotalLongAvgPNL,
|
||||
TotalShortPos,
|
||||
TotalShortAvgPrice,
|
||||
TotalShortAvgPNL,
|
||||
TotalNetPos,
|
||||
TotalDelta,
|
||||
TotalGamma,
|
||||
TotalVega,
|
||||
TotalTheta,
|
||||
// Market
|
||||
BidPrice,
|
||||
MidPrice,
|
||||
AskPrice,
|
||||
LastPrice,
|
||||
SettlementPrice,
|
||||
PNLPrice
|
||||
}
|
||||
|
||||
public static readonly IValueConverter
|
||||
IncrementalGroupLevelConverter = ValueConverter.create<int, int>(level => level + 1),
|
||||
GroupLevelMarginConverter = ValueConverter.create<int, Thickness>(level => new Thickness(24 * level, 0, 0, 0)),
|
||||
HeaderRowHeightConverter = new RangeBlockConverter<double> { Minimum = MinHeaderRowHeight },
|
||||
ExpandedVisualStateConverter = ValueConverter.create<bool, string>(is_expanded => is_expanded ? "Expanded" : "Collapsed");
|
||||
|
||||
public static readonly IMultiValueConverter
|
||||
TotalHeaderRowDisplayTextConverter = ValueConverter.create<int, int, string>((filtered, total) => $"Total ({(filtered == total ? total.ToString() : $"{filtered}/{total}")})"),
|
||||
CellParamsConverter = ValueConverter.create<object, Columns, PNLCell>((item, col) => new PNLCell(item, col));
|
||||
|
||||
public static readonly RoutedCommand CellClickCommand = new RoutedCommand();
|
||||
|
||||
static readonly string _node_path_separator = $" {SpecialCharacters.Dot} ";
|
||||
|
||||
IDisposable _anchors_hook, _animations_hook;
|
||||
int _anchor_version;
|
||||
|
||||
public PNLView() {
|
||||
SetCurrentValue(AnchorIndexProperty, new AnchorIndex());
|
||||
InitializeComponent();
|
||||
SetBinding(AnchorsProperty, new Binding(nameof(PNLVM.anchors)));
|
||||
_grid.ConnectOnLoaded(() => {
|
||||
if (_grid.try_find_descendent_of_type(out DIYGridRowsPresenter presenter)) {
|
||||
presenter.GroupItemSelectionPivot += on_group_item_selection_pivot;
|
||||
return Disposable.Create(() => presenter.GroupItemSelectionPivot -= on_group_item_selection_pivot);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
void on_group_item_selection_pivot(object sender, GroupItemSelectionPivotEventArgs e) =>
|
||||
e.Handled = e.group_item is PNLRowCollectionViewGroup pnl_group && pnl_group.is_expanded;
|
||||
}
|
||||
|
||||
public new PNLVM DataContext {
|
||||
get => base.DataContext as PNLVM;
|
||||
set => base.DataContext = value;
|
||||
}
|
||||
|
||||
public bool EnableAnimations {
|
||||
get => _animations_hook != null;
|
||||
set {
|
||||
if (EnableAnimations != value) {
|
||||
if (_animations_hook == null) {
|
||||
_animations_hook = AdornerHelper.attach_continuously_on_loaded(
|
||||
() => new GridAnimation.DIYGridAnimationAdorner<Columns>(_grid, _grid.descendants_of_type<DIYGridRowsPresenter>().First()),
|
||||
_grid);
|
||||
} else {
|
||||
_animations_hook.Dispose();
|
||||
_animations_hook = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region AnchorIndex
|
||||
public static readonly DependencyProperty AnchorIndexProperty =
|
||||
WPFHelper.create_dp<AnchorIndex, PNLView>(
|
||||
nameof(AnchorIndex),
|
||||
(o, v) => v?.reset(o?.Anchors));
|
||||
|
||||
public AnchorIndex AnchorIndex {
|
||||
get => GetValue(AnchorIndexProperty) as AnchorIndex;
|
||||
set => SetValue(AnchorIndexProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GroupLevel
|
||||
public static readonly DependencyProperty GroupLevelProperty =
|
||||
DependencyProperty.RegisterAttached(
|
||||
"GroupLevel",
|
||||
typeof(int),
|
||||
typeof(PNLView),
|
||||
new PropertyMetadata(0, (d, e) => {
|
||||
if (d is GroupItem group && e.NewValue is int level)
|
||||
group.SetBinding(DIYGrid.ColumnKeyProperty, new Binding($"{nameof(Anchors)}[{level}]") { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(PNLView), 1) });
|
||||
}));
|
||||
|
||||
public static int GetGroupLevel(DependencyObject d) => (int)d.GetValue(GroupLevelProperty);
|
||||
public static void SetGroupLevel(DependencyObject d, int value) => d.SetValue(GroupLevelProperty, value);
|
||||
|
||||
void _grid_loaded(object sender, RoutedEventArgs e) {
|
||||
// this is a hack to make room for the 'totals row' between the column headers and the regular rows.
|
||||
if (_grid.try_find_descendent_of_type(out DIYGridRowsPresenter rp)) {
|
||||
rp.SetBinding(MarginProperty,
|
||||
BindingHelper.create_multi(
|
||||
ValueConverter.create<PNLHeaderRowDisplay, double, Thickness>((hrd, row_height) => {
|
||||
double top = 0;
|
||||
if ((hrd & PNLHeaderRowDisplay.Total) != 0)
|
||||
top += row_height;
|
||||
if ((hrd & PNLHeaderRowDisplay.SelectedTotal) != 0)
|
||||
top += row_height;
|
||||
return new Thickness(0, top, 0, 0);
|
||||
}),
|
||||
new Binding(nameof(PNLVM.header_row_display)),
|
||||
new Binding {
|
||||
Path = new PropertyPath(DIYGrid.RowHeightProperty),
|
||||
Converter = HeaderRowHeightConverter,
|
||||
Source = _grid
|
||||
}));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Anchors
|
||||
public static readonly DependencyProperty AnchorsProperty =
|
||||
WPFHelper.create_dp<IEnumerable<Columns>, PNLView>(
|
||||
nameof(Anchors),
|
||||
(o, v) => {
|
||||
if (o?._grid?.Columns is not ObservableCollection<DIYGrid.ColumnBase> cols ||
|
||||
o?._grid?.Rows is not ICollectionView rows_view ||
|
||||
v is not INotifyCollectionChanged anchor_notifier ||
|
||||
v is not IReadOnlyList<Columns> anchor_keys) {
|
||||
return;
|
||||
}
|
||||
|
||||
int version = ++o._anchor_version;
|
||||
bool busy = false;
|
||||
var pnl_cols = cols.CastObservable<DIYGrid.ColumnBase, PNLColumn>();
|
||||
o._anchors_hook?.Dispose();
|
||||
o._anchors_hook = Disposable.Create(
|
||||
anchor_notifier.Subscribe((_, __) => {
|
||||
if (busy)
|
||||
return;
|
||||
// invoke async to avoid noisy consecutive resets due to batch changes
|
||||
busy = true;
|
||||
o.Dispatcher.InvokeAsync(() => {
|
||||
sync_anchor_cols();
|
||||
busy = false;
|
||||
});
|
||||
}));
|
||||
o.AnchorIndex?.reset(anchor_keys);
|
||||
sync_anchor_cols();
|
||||
void sync_anchor_cols() {
|
||||
// since reset is invoked asynchronously, need to check we are still the latest version.
|
||||
if (o._anchor_version != version)
|
||||
return;
|
||||
o.AnchorIndex?.reset(anchor_keys);
|
||||
// move all the anchor columns to the left, ordered by anchor position (grouping hierarchy).
|
||||
for (int i = 0; i < anchor_keys.Count; i++) {
|
||||
if (pnl_cols.TryGetFirst(c => c.key == anchor_keys[i], out var match, out int curr_pos)) {
|
||||
match.is_visible = true;
|
||||
if (curr_pos != i) {
|
||||
cols.Move(curr_pos, i);
|
||||
}
|
||||
match.anchor_index = i + 1;
|
||||
}
|
||||
}
|
||||
for (int i = anchor_keys.Count; i < pnl_cols.Count; i++) {
|
||||
pnl_cols[i].anchor_index = null;
|
||||
}
|
||||
using (rows_view.DeferRefresh()) {
|
||||
rows_view.GroupDescriptions.Clear();
|
||||
var anchor_cols = from key in anchor_keys
|
||||
join col in pnl_cols on key equals col.key
|
||||
select new PNLGroupDescription(col);
|
||||
rows_view.GroupDescriptions.AddRange(anchor_cols);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
public IEnumerable<Columns> Anchors {
|
||||
get => GetValue(AnchorsProperty) as IEnumerable<Columns>;
|
||||
set => SetValue(AnchorsProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
DIYGridPopupManager _popup_man {
|
||||
get {
|
||||
if (_popup_man_backing == null) {
|
||||
_popup_man_backing = DIYGridPopupManager.create(this);
|
||||
}
|
||||
return _popup_man_backing;
|
||||
}
|
||||
}
|
||||
|
||||
void _cell_click(PNLCell cell) {
|
||||
Log.Ui.info($"PNLCell Click: {cell}.");
|
||||
try {
|
||||
switch (cell.column) {
|
||||
case Columns.SODNetPos:
|
||||
case Columns.SODLongPos:
|
||||
case Columns.SODShortPos:
|
||||
case Columns.DayNetPos:
|
||||
case Columns.DayLongPos:
|
||||
case Columns.DayShortPos:
|
||||
case Columns.RawDayNetPos:
|
||||
case Columns.RawDayLongPos:
|
||||
case Columns.RawDayShortPos:
|
||||
case Columns.TotalNetPos:
|
||||
case Columns.TotalLongPos:
|
||||
case Columns.TotalShortPos: {
|
||||
var oneof = cell.oneof();
|
||||
if (oneof == null)
|
||||
return;
|
||||
var (vm, context, title, fg) = cell.oneof().Match(_row_fills, _group_fills, _header_fills);
|
||||
_show_auxiliary_popup(vm, context, title, fg);
|
||||
}
|
||||
break;
|
||||
case Columns.WorkingNetPos:
|
||||
case Columns.WorkingLongPos:
|
||||
case Columns.WorkingShortPos: {
|
||||
var (vm, context, title, fg) = cell.oneof().Match(_orderbook_params, _orderbook_params, _orderbook_params);
|
||||
_show_auxiliary_popup(vm, context, title, fg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Log.Ui.warn($"{nameof(PNLView)} error on cell click: {ex}.");
|
||||
}
|
||||
}
|
||||
|
||||
#region Fills
|
||||
(FillsVM vm, string context, string title, Color fg) _row_fills(PNLRowCell cell) {
|
||||
var (title_desc, fg) = _fills_title(cell.column);
|
||||
return (DataContext.mk_fills_vm(cell.row, cell.column), $"{cell.row.account_name} {cell.row.security}", title_desc, fg);
|
||||
}
|
||||
|
||||
(FillsVM vm, string context, string title, Color fg) _group_fills(PNLGroupCell cell) {
|
||||
var (title_desc, fg) = _fills_title(cell.column);
|
||||
return (DataContext.mk_fills_vm(cell.group, cell.column), string.Join(_node_path_separator, cell.group.GroupNamePath), title_desc, fg);
|
||||
}
|
||||
|
||||
(FillsVM vm, string context, string title, Color fg) _header_fills(PNLHeaderRowCell cell) {
|
||||
var (title_desc, fg) = _fills_title(cell.column);
|
||||
return (DataContext.mk_fills_vm(cell.header_row, cell.column), EnumHelper.get_display_name(cell.header_row), title_desc, fg);
|
||||
}
|
||||
|
||||
static (string desc, Color fg) _fills_title(Columns key) {
|
||||
switch (key) {
|
||||
case Columns.SODLongPos: return ("Open Buy Fills", BTSColors.MarketData.bid);
|
||||
case Columns.SODShortPos: return ("Open Sell Fills", BTSColors.MarketData.ask);
|
||||
case Columns.SODNetPos: return ("Open Fills", BTSColors.UI.default_text);
|
||||
case Columns.DayLongPos: return ("Day Buy Fills", BTSColors.MarketData.bid);
|
||||
case Columns.DayShortPos: return ("Day Sell Fills", BTSColors.MarketData.ask);
|
||||
case Columns.DayNetPos: return ("Day Fills", BTSColors.UI.default_text);
|
||||
case Columns.RawDayLongPos: return ("Raw Day Buy Fills", BTSColors.MarketData.bid);
|
||||
case Columns.RawDayShortPos: return ("Raw Day Sell Fills", BTSColors.MarketData.ask);
|
||||
case Columns.RawDayNetPos: return ("Raw Day Fills", BTSColors.UI.default_text);
|
||||
case Columns.TotalLongPos: return ("All Buy Fills", BTSColors.MarketData.bid);
|
||||
case Columns.TotalShortPos: return ("All Sell Fills", BTSColors.MarketData.ask);
|
||||
case Columns.TotalNetPos: return ("All Fills", BTSColors.UI.default_text);
|
||||
default: throw ExceptionBuilder.Argument.unexpected_case(key, nameof(key));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region OrderBook
|
||||
(OrderBookVM vm, string context, string title, Color fg) _orderbook_params(PNLRowCell cell) {
|
||||
var (title_desc, fg) = _orderbook_title(cell.column);
|
||||
return (DataContext.mk_orderbook_vm(cell.row, cell.column), $"{cell.row.account_name} {cell.row.security}", title_desc, fg);
|
||||
}
|
||||
|
||||
(OrderBookVM vm, string context, string title, Color fg) _orderbook_params(PNLGroupCell cell) {
|
||||
var (title_desc, fg) = _orderbook_title(cell.column);
|
||||
return (DataContext.mk_orderbook_vm(cell.group, cell.column), string.Join(_node_path_separator, cell.group.GroupNamePath), title_desc, fg);
|
||||
}
|
||||
|
||||
(OrderBookVM vm, string context, string title, Color fg) _orderbook_params(PNLHeaderRowCell cell) {
|
||||
var (title_desc, fg) = _orderbook_title(cell.column);
|
||||
return (DataContext.mk_orderbook_vm(cell.header_row, cell.column), EnumHelper.get_display_name(cell.header_row), title_desc, fg);
|
||||
}
|
||||
|
||||
static (string desc, Color fg) _orderbook_title(Columns key) {
|
||||
switch (key) {
|
||||
case Columns.WorkingLongPos: return ("Working Buy Orders", BTSColors.MarketData.bid);
|
||||
case Columns.WorkingShortPos: return ("Working Sell Orders", BTSColors.MarketData.ask);
|
||||
case Columns.WorkingNetPos: return ("Working Orders", BTSColors.UI.default_text);
|
||||
default: throw ExceptionBuilder.Argument.unexpected_case(key, nameof(key));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
void _cell_click_executed(object sender, ExecutedRoutedEventArgs e) {
|
||||
if (e.Parameter is PNLCell cell) {
|
||||
_cell_click(cell);
|
||||
} else Log.Ui.warn($"{nameof(PNLView)} '{nameof(_cell_click_executed)}' parameter should be a {typeof(PNLCell)} (actually '{e.Parameter}').");
|
||||
}
|
||||
|
||||
void _on_group_item_mouse_down(object sender, MouseButtonEventArgs e) {
|
||||
if (!e.Handled && sender is FrameworkElement el && el.DataContext is PNLRowCollectionViewGroup group) {
|
||||
if (e.ClickCount == 2) {
|
||||
group.is_expanded = !group.is_expanded;
|
||||
} else if (el.try_find_ancestor_of_type(out DIYGrid grid) && grid.SelectionMode != SelectionMode.Single) {
|
||||
group.is_all_selected = !group.is_all_selected.GetValueOrDefault();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
void _show_auxiliary_popup<T>(T content, string context_desc, string title_desc, Color fg) {
|
||||
var view = new HeaderedContentControl {
|
||||
Content = content,
|
||||
Header = new AuxiliaryDataHeader {
|
||||
context = context_desc,
|
||||
title = title_desc,
|
||||
title_foreground = fg
|
||||
},
|
||||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
VerticalAlignment = VerticalAlignment.Top,
|
||||
Resources = new AuxiliaryDataResources()
|
||||
};
|
||||
view.Style = view.Resources[AuxiliaryDataResources.PopupChildStyleKey] as Style;
|
||||
_popup_man.show(view);
|
||||
}
|
||||
|
||||
class PNLGroupDescription : PropertyGroupDescription, IEquatable<PNLGroupDescription> {
|
||||
public PNLGroupDescription(PNLColumn column) : base(column.data_member_path.Path) =>
|
||||
key = column.key;
|
||||
|
||||
public Columns key { get; }
|
||||
|
||||
public bool Equals(PNLGroupDescription other) =>
|
||||
other != null && key == other.key;
|
||||
|
||||
public override int GetHashCode() =>
|
||||
key.GetHashCode();
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
Equals(obj as PNLGroupDescription);
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace bts.shell.pnl {
|
||||
using bts.collections;
|
||||
|
||||
using mbts.collections;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.converters;
|
||||
using mbts.ui.dpi;
|
||||
using mbts.ui.extensions;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
enum PNLHeaderRowDisplay {
|
||||
None,
|
||||
Total,
|
||||
SelectedTotal
|
||||
}
|
||||
|
||||
partial class PNLView : UserControl {
|
||||
public static readonly double
|
||||
MinGroupRowHeight = 24.0.RoundLayoutValue(),
|
||||
MinHeaderRowHeight = 24.0.RoundLayoutValue();
|
||||
DIYGridPopupManager _popup_man_backing;
|
||||
|
||||
public enum Columns {
|
||||
Account = 1,
|
||||
// Security
|
||||
Exchange,
|
||||
Symbol,
|
||||
Expiration,
|
||||
SecurityType,
|
||||
Security,
|
||||
SecurityKey,
|
||||
CPP,
|
||||
// SOD
|
||||
SODPNL,
|
||||
SODLongPos,
|
||||
SODLongAvgPrice,
|
||||
SODShortPos,
|
||||
SODShortAvgPrice,
|
||||
SODNetPos,
|
||||
SODDelta,
|
||||
SODGamma,
|
||||
SODVega,
|
||||
SODTheta,
|
||||
// Day
|
||||
DayPNL,
|
||||
DayLongPos,
|
||||
DayLongAvgPrice,
|
||||
DayShortAvgPrice,
|
||||
DayShortPos,
|
||||
DayDelta,
|
||||
DayGamma,
|
||||
DayVega,
|
||||
DayTheta,
|
||||
DayCalcType,
|
||||
DayNetPos,
|
||||
HasDayTrades,
|
||||
// Raw Day
|
||||
RawDayLongPos,
|
||||
RawDayShortPos,
|
||||
RawDayNetPos,
|
||||
// Working
|
||||
WorkingLongPos,
|
||||
WorkingLongAvgPrice,
|
||||
WorkingShortPos,
|
||||
WorkingShortAvgPrice,
|
||||
WorkingNetPos,
|
||||
// Total
|
||||
TotalPNL,
|
||||
TotalLongPos,
|
||||
TotalLongAvgPrice,
|
||||
TotalShortPos,
|
||||
TotalShortAvgPrice,
|
||||
TotalNetPos,
|
||||
TotalDelta,
|
||||
TotalGamma,
|
||||
TotalVega,
|
||||
TotalTheta,
|
||||
// Market
|
||||
BidPrice,
|
||||
MidPrice,
|
||||
AskPrice,
|
||||
LastPrice,
|
||||
SettlementPrice,
|
||||
PNLPrice
|
||||
}
|
||||
|
||||
public static readonly IValueConverter
|
||||
IncrementalGroupLevelConverter = ValueConverter.create<int, int>(level => level + 1),
|
||||
GroupLevelMarginConverter = ValueConverter.create<int, Thickness>(level => new Thickness(24 * level, 0, 0, 0)),
|
||||
HeaderRowHeightConverter = new RangeBlockConverter<double> { Minimum = MinHeaderRowHeight },
|
||||
ExpandedVisualStateConverter = ValueConverter.create<bool, string>(is_expanded => is_expanded ? "Expanded" : "Collapsed");
|
||||
|
||||
public static readonly IMultiValueConverter
|
||||
TotalHeaderRowDisplayTextConverter = ValueConverter.create<int, int, string>((filtered, total) => $"Total ({(filtered == total ? total.ToString() : $"{filtered}/{total}")})"),
|
||||
CellParamsConverter = ValueConverter.create<object, Columns, PNLCell>((item, col) => new PNLCell(item, col));
|
||||
|
||||
public static readonly RoutedCommand CellClickCommand = new RoutedCommand();
|
||||
|
||||
static readonly string _node_path_separator = $" {SpecialCharacters.Dot} ";
|
||||
|
||||
IDisposable _anchors_hook, _animations_hook;
|
||||
int _anchor_version;
|
||||
|
||||
public PNLView() {
|
||||
SetCurrentValue(AnchorIndexProperty, new AnchorIndex());
|
||||
InitializeComponent();
|
||||
SetBinding(AnchorsProperty, new Binding(nameof(PNLVM.anchors)));
|
||||
_grid.ConnectOnLoaded(() => {
|
||||
if (_grid.try_find_descendent_of_type(out DIYGridRowsPresenter presenter)) {
|
||||
presenter.GroupItemSelectionPivot += on_group_item_selection_pivot;
|
||||
return Disposable.Create(() => presenter.GroupItemSelectionPivot -= on_group_item_selection_pivot);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
void on_group_item_selection_pivot(object sender, GroupItemSelectionPivotEventArgs e) =>
|
||||
e.Handled = e.group_item is PNLRowCollectionViewGroup pnl_group && pnl_group.is_expanded;
|
||||
}
|
||||
|
||||
public new PNLVM DataContext {
|
||||
get => base.DataContext as PNLVM;
|
||||
set => base.DataContext = value;
|
||||
}
|
||||
|
||||
public bool EnableAnimations {
|
||||
get => _animations_hook != null;
|
||||
set {
|
||||
if (EnableAnimations != value) {
|
||||
if (_animations_hook == null) {
|
||||
_animations_hook = AdornerHelper.attach_continuously_on_loaded(
|
||||
() => new GridAnimation.DIYGridAnimationAdorner<Columns>(_grid, _grid.descendants_of_type<DIYGridRowsPresenter>().First()),
|
||||
_grid);
|
||||
} else {
|
||||
_animations_hook.Dispose();
|
||||
_animations_hook = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region AnchorIndex
|
||||
public static readonly DependencyProperty AnchorIndexProperty =
|
||||
WPFHelper.create_dp<AnchorIndex, PNLView>(
|
||||
nameof(AnchorIndex),
|
||||
(o, v) => v?.reset(o?.Anchors));
|
||||
|
||||
public AnchorIndex AnchorIndex {
|
||||
get => GetValue(AnchorIndexProperty) as AnchorIndex;
|
||||
set => SetValue(AnchorIndexProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GroupLevel
|
||||
public static readonly DependencyProperty GroupLevelProperty =
|
||||
DependencyProperty.RegisterAttached(
|
||||
"GroupLevel",
|
||||
typeof(int),
|
||||
typeof(PNLView),
|
||||
new PropertyMetadata(0, (d, e) => {
|
||||
if (d is GroupItem group && e.NewValue is int level)
|
||||
group.SetBinding(DIYGrid.ColumnKeyProperty, new Binding($"{nameof(Anchors)}[{level}]") { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(PNLView), 1) });
|
||||
}));
|
||||
|
||||
public static int GetGroupLevel(DependencyObject d) => (int)d.GetValue(GroupLevelProperty);
|
||||
public static void SetGroupLevel(DependencyObject d, int value) => d.SetValue(GroupLevelProperty, value);
|
||||
|
||||
void _grid_loaded(object sender, RoutedEventArgs e) {
|
||||
// this is a hack to make room for the 'totals row' between the column headers and the regular rows.
|
||||
if (_grid.try_find_descendent_of_type(out DIYGridRowsPresenter rp)) {
|
||||
rp.SetBinding(MarginProperty,
|
||||
BindingHelper.create_multi(
|
||||
ValueConverter.create<PNLHeaderRowDisplay, double, Thickness>((hrd, row_height) => {
|
||||
double top = 0;
|
||||
if ((hrd & PNLHeaderRowDisplay.Total) != 0)
|
||||
top += row_height;
|
||||
if ((hrd & PNLHeaderRowDisplay.SelectedTotal) != 0)
|
||||
top += row_height;
|
||||
return new Thickness(0, top, 0, 0);
|
||||
}),
|
||||
new Binding(nameof(PNLVM.header_row_display)),
|
||||
new Binding {
|
||||
Path = new PropertyPath(DIYGrid.RowHeightProperty),
|
||||
Converter = HeaderRowHeightConverter,
|
||||
Source = _grid
|
||||
}));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Anchors
|
||||
public static readonly DependencyProperty AnchorsProperty =
|
||||
WPFHelper.create_dp<IEnumerable<Columns>, PNLView>(
|
||||
nameof(Anchors),
|
||||
(o, v) => {
|
||||
if (o?._grid?.Columns is not ObservableCollection<DIYGrid.ColumnBase> cols ||
|
||||
o?._grid?.Rows is not ICollectionView rows_view ||
|
||||
v is not INotifyCollectionChanged anchor_notifier ||
|
||||
v is not IReadOnlyList<Columns> anchor_keys) {
|
||||
return;
|
||||
}
|
||||
|
||||
int version = ++o._anchor_version;
|
||||
bool busy = false;
|
||||
var pnl_cols = cols.CastObservable<DIYGrid.ColumnBase, PNLColumn>();
|
||||
o._anchors_hook?.Dispose();
|
||||
o._anchors_hook = Disposable.Create(
|
||||
anchor_notifier.Subscribe((_, __) => {
|
||||
if (busy)
|
||||
return;
|
||||
// invoke async to avoid noisy consecutive resets due to batch changes
|
||||
busy = true;
|
||||
o.Dispatcher.InvokeAsync(() => {
|
||||
sync_anchor_cols();
|
||||
busy = false;
|
||||
});
|
||||
}));
|
||||
o.AnchorIndex?.reset(anchor_keys);
|
||||
sync_anchor_cols();
|
||||
void sync_anchor_cols() {
|
||||
// since reset is invoked asynchronously, need to check we are still the latest version.
|
||||
if (o._anchor_version != version)
|
||||
return;
|
||||
o.AnchorIndex?.reset(anchor_keys);
|
||||
// move all the anchor columns to the left, ordered by anchor position (grouping hierarchy).
|
||||
for (int i = 0; i < anchor_keys.Count; i++) {
|
||||
if (pnl_cols.TryGetFirst(c => c.key == anchor_keys[i], out var match, out int curr_pos)) {
|
||||
match.is_visible = true;
|
||||
if (curr_pos != i) {
|
||||
cols.Move(curr_pos, i);
|
||||
}
|
||||
match.anchor_index = i + 1;
|
||||
}
|
||||
}
|
||||
for (int i = anchor_keys.Count; i < pnl_cols.Count; i++) {
|
||||
pnl_cols[i].anchor_index = null;
|
||||
}
|
||||
using (rows_view.DeferRefresh()) {
|
||||
rows_view.GroupDescriptions.Clear();
|
||||
var anchor_cols = from key in anchor_keys
|
||||
join col in pnl_cols on key equals col.key
|
||||
select new PNLGroupDescription(col);
|
||||
rows_view.GroupDescriptions.AddRange(anchor_cols);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
public IEnumerable<Columns> Anchors {
|
||||
get => GetValue(AnchorsProperty) as IEnumerable<Columns>;
|
||||
set => SetValue(AnchorsProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
DIYGridPopupManager _popup_man {
|
||||
get {
|
||||
if (_popup_man_backing == null) {
|
||||
_popup_man_backing = DIYGridPopupManager.create(this);
|
||||
}
|
||||
return _popup_man_backing;
|
||||
}
|
||||
}
|
||||
|
||||
void _cell_click(PNLCell cell) {
|
||||
Log.Ui.info($"PNLCell Click: {cell}.");
|
||||
try {
|
||||
switch (cell.column) {
|
||||
case Columns.SODNetPos:
|
||||
case Columns.SODLongPos:
|
||||
case Columns.SODShortPos:
|
||||
case Columns.DayNetPos:
|
||||
case Columns.DayLongPos:
|
||||
case Columns.DayShortPos:
|
||||
case Columns.RawDayNetPos:
|
||||
case Columns.RawDayLongPos:
|
||||
case Columns.RawDayShortPos:
|
||||
case Columns.TotalNetPos:
|
||||
case Columns.TotalLongPos:
|
||||
case Columns.TotalShortPos: {
|
||||
var oneof = cell.oneof();
|
||||
if (oneof == null)
|
||||
return;
|
||||
var (vm, context, title, fg) = cell.oneof().Match(_row_fills, _group_fills, _header_fills);
|
||||
_show_auxiliary_popup(vm, context, title, fg);
|
||||
}
|
||||
break;
|
||||
case Columns.WorkingNetPos:
|
||||
case Columns.WorkingLongPos:
|
||||
case Columns.WorkingShortPos: {
|
||||
var (vm, context, title, fg) = cell.oneof().Match(_orderbook_params, _orderbook_params, _orderbook_params);
|
||||
_show_auxiliary_popup(vm, context, title, fg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Log.Ui.warn($"{nameof(PNLView)} error on cell click: {ex}.");
|
||||
}
|
||||
}
|
||||
|
||||
#region Fills
|
||||
(FillsVM vm, string context, string title, Color fg) _row_fills(PNLRowCell cell) {
|
||||
var (title_desc, fg) = _fills_title(cell.column);
|
||||
return (DataContext.mk_fills_vm(cell.row, cell.column), $"{cell.row.account_name} {cell.row.security}", title_desc, fg);
|
||||
}
|
||||
|
||||
(FillsVM vm, string context, string title, Color fg) _group_fills(PNLGroupCell cell) {
|
||||
var (title_desc, fg) = _fills_title(cell.column);
|
||||
return (DataContext.mk_fills_vm(cell.group, cell.column), string.Join(_node_path_separator, cell.group.GroupNamePath), title_desc, fg);
|
||||
}
|
||||
|
||||
(FillsVM vm, string context, string title, Color fg) _header_fills(PNLHeaderRowCell cell) {
|
||||
var (title_desc, fg) = _fills_title(cell.column);
|
||||
return (DataContext.mk_fills_vm(cell.header_row, cell.column), EnumHelper.get_display_name(cell.header_row), title_desc, fg);
|
||||
}
|
||||
|
||||
static (string desc, Color fg) _fills_title(Columns key) {
|
||||
switch (key) {
|
||||
case Columns.SODLongPos: return ("Open Buy Fills", BTSColors.MarketData.bid);
|
||||
case Columns.SODShortPos: return ("Open Sell Fills", BTSColors.MarketData.ask);
|
||||
case Columns.SODNetPos: return ("Open Fills", BTSColors.UI.default_text);
|
||||
case Columns.DayLongPos: return ("Day Buy Fills", BTSColors.MarketData.bid);
|
||||
case Columns.DayShortPos: return ("Day Sell Fills", BTSColors.MarketData.ask);
|
||||
case Columns.DayNetPos: return ("Day Fills", BTSColors.UI.default_text);
|
||||
case Columns.RawDayLongPos: return ("Raw Day Buy Fills", BTSColors.MarketData.bid);
|
||||
case Columns.RawDayShortPos: return ("Raw Day Sell Fills", BTSColors.MarketData.ask);
|
||||
case Columns.RawDayNetPos: return ("Raw Day Fills", BTSColors.UI.default_text);
|
||||
case Columns.TotalLongPos: return ("All Buy Fills", BTSColors.MarketData.bid);
|
||||
case Columns.TotalShortPos: return ("All Sell Fills", BTSColors.MarketData.ask);
|
||||
case Columns.TotalNetPos: return ("All Fills", BTSColors.UI.default_text);
|
||||
default: throw ExceptionBuilder.Argument.unexpected_case(key, nameof(key));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region OrderBook
|
||||
(OrderBookVM vm, string context, string title, Color fg) _orderbook_params(PNLRowCell cell) {
|
||||
var (title_desc, fg) = _orderbook_title(cell.column);
|
||||
return (DataContext.mk_orderbook_vm(cell.row, cell.column), $"{cell.row.account_name} {cell.row.security}", title_desc, fg);
|
||||
}
|
||||
|
||||
(OrderBookVM vm, string context, string title, Color fg) _orderbook_params(PNLGroupCell cell) {
|
||||
var (title_desc, fg) = _orderbook_title(cell.column);
|
||||
return (DataContext.mk_orderbook_vm(cell.group, cell.column), string.Join(_node_path_separator, cell.group.GroupNamePath), title_desc, fg);
|
||||
}
|
||||
|
||||
(OrderBookVM vm, string context, string title, Color fg) _orderbook_params(PNLHeaderRowCell cell) {
|
||||
var (title_desc, fg) = _orderbook_title(cell.column);
|
||||
return (DataContext.mk_orderbook_vm(cell.header_row, cell.column), EnumHelper.get_display_name(cell.header_row), title_desc, fg);
|
||||
}
|
||||
|
||||
static (string desc, Color fg) _orderbook_title(Columns key) {
|
||||
switch (key) {
|
||||
case Columns.WorkingLongPos: return ("Working Buy Orders", BTSColors.MarketData.bid);
|
||||
case Columns.WorkingShortPos: return ("Working Sell Orders", BTSColors.MarketData.ask);
|
||||
case Columns.WorkingNetPos: return ("Working Orders", BTSColors.UI.default_text);
|
||||
default: throw ExceptionBuilder.Argument.unexpected_case(key, nameof(key));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
void _cell_click_executed(object sender, ExecutedRoutedEventArgs e) {
|
||||
if (e.Parameter is PNLCell cell) {
|
||||
_cell_click(cell);
|
||||
} else Log.Ui.warn($"{nameof(PNLView)} '{nameof(_cell_click_executed)}' parameter should be a {typeof(PNLCell)} (actually '{e.Parameter}').");
|
||||
}
|
||||
|
||||
void _on_group_item_mouse_down(object sender, MouseButtonEventArgs e) {
|
||||
if (!e.Handled && sender is FrameworkElement el && el.DataContext is PNLRowCollectionViewGroup group) {
|
||||
if (e.ClickCount == 2) {
|
||||
group.is_expanded = !group.is_expanded;
|
||||
} else if (el.try_find_ancestor_of_type(out DIYGrid grid) && grid.SelectionMode != SelectionMode.Single) {
|
||||
group.is_all_selected = !group.is_all_selected.GetValueOrDefault();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
void _show_auxiliary_popup<T>(T content, string context_desc, string title_desc, Color fg) {
|
||||
var view = new HeaderedContentControl {
|
||||
Content = content,
|
||||
Header = new AuxiliaryDataHeader {
|
||||
context = context_desc,
|
||||
title = title_desc,
|
||||
title_foreground = fg
|
||||
},
|
||||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
VerticalAlignment = VerticalAlignment.Top,
|
||||
Resources = new AuxiliaryDataResources()
|
||||
};
|
||||
view.Style = view.Resources[AuxiliaryDataResources.PopupChildStyleKey] as Style;
|
||||
_popup_man.show(view);
|
||||
}
|
||||
|
||||
class PNLGroupDescription : PropertyGroupDescription, IEquatable<PNLGroupDescription> {
|
||||
public PNLGroupDescription(PNLColumn column) : base(column.data_member_path.Path) =>
|
||||
key = column.key;
|
||||
|
||||
public Columns key { get; }
|
||||
|
||||
public bool Equals(PNLGroupDescription other) =>
|
||||
other != null && key == other.key;
|
||||
|
||||
public override int GetHashCode() =>
|
||||
key.GetHashCode();
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
Equals(obj as PNLGroupDescription);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -237,7 +237,7 @@ namespace BCG {
|
||||
PNLRollOverDataUnit u;
|
||||
if (_roll_over_data != null && (u = _roll_over_data.getValue(exp, strike, true)) != null) {
|
||||
cp_row[(int)NMSheetColumnName.vol_change] = tp.vol - u.vol;
|
||||
cp_row[(int)NMSheetColumnName.straddle_change] = ((tp.vol - u.vol) * tp.cvega * 2.0 * 100.0) / tp.driver;
|
||||
cp_row[(int)NMSheetColumnName.straddle_change] = (tp.vol - u.vol) * tp.cvega * 2.0 * 100.0;
|
||||
} else {
|
||||
cp_row[(int)NMSheetColumnName.vol_change] = Double.NaN;
|
||||
cp_row[(int)NMSheetColumnName.straddle_change] = Double.NaN;
|
||||
|
||||
@@ -14,103 +14,23 @@ using mbts.analytics;
|
||||
using bts.api.analytics;
|
||||
|
||||
namespace mbts.spark {
|
||||
public class ClientArchivedVolRequest {
|
||||
public readonly int id;
|
||||
public readonly ArchivedTheoRetrieval ret;
|
||||
public ClientArchivedVolRequest(Int32 id, ArchivedTheoRetrieval ret) {
|
||||
this.id = id;
|
||||
this.ret = ret;
|
||||
}
|
||||
private static int _id = 0;
|
||||
public static int get_new_id() {
|
||||
int rv = 0;
|
||||
lock (typeof(ClientArchivedVolRequest)) {
|
||||
rv = ++_id;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public override string ToString() {
|
||||
return $"id: {id} sym: {ret.SecTup.Symbol} vol_time: {ret.SaveTime}";
|
||||
}
|
||||
}
|
||||
// This is created by the NMSheetSingleOptionMainDataSource - it downloads the
|
||||
// archived theos and provides access to it
|
||||
public class NMSheetArchivedVolProvider : IDisposable {
|
||||
private readonly ThreadedBlackboard _bb;
|
||||
private readonly NMSheetSymbol _sym;
|
||||
private readonly bts.api.SecurityTuple _sec_tup;
|
||||
private Action _cb = () => { };
|
||||
private readonly ITag<SystemContractData> _sc_tag = SparkTags.SystemContractsTag;
|
||||
private readonly ITag<NMSheetSettings> _settings_tag;
|
||||
private readonly ITag<Tuple<ClientArchivedVolRequest, bts.api.analytics.ArchivedTheoList>>
|
||||
_response_tag = SparkTags.ResponseArchivedVols;
|
||||
private bool _waiting_for_reponse = false;
|
||||
private ClientArchivedVolRequest _last_req;
|
||||
bts.api.analytics.ArchivedTheoList _cached_data = null;
|
||||
private Nullable<ArchivedTheoListImmutable> _cached_data;
|
||||
|
||||
public NMSheetArchivedVolProvider(string req_id, ThreadedBlackboard bb,
|
||||
NMSheetSymbol symbol,
|
||||
Action cb) {
|
||||
bts.Log.Ui.info($"NMSheetArchivedVolProvider req_id: {req_id} symbol: {symbol}");
|
||||
_bb = bb;
|
||||
_sym = symbol;
|
||||
_sec_tup = new bts.api.SecurityTuple() {
|
||||
Venue = _sym.option_exchange,
|
||||
Type = SecurityType.Option,
|
||||
Symbol = _sym.option_name
|
||||
};
|
||||
_last_req = new ClientArchivedVolRequest(
|
||||
0,
|
||||
new ArchivedTheoRetrieval() {
|
||||
SaveTime = 0,
|
||||
SecTup = _sec_tup
|
||||
});
|
||||
_cb = cb;
|
||||
_settings_tag = SparkTags.TC2Tags.NMSheetSettingsTag(req_id);
|
||||
_bb.subscribe(_sc_tag);
|
||||
_bb.subscribe(_settings_tag);
|
||||
_bb.subscribe(_response_tag);
|
||||
_bb.data_callback += _on_data;
|
||||
_check_and_send_request(true);
|
||||
}
|
||||
|
||||
private static UInt64 _get_vol_time(NMSheetSettings settings) {
|
||||
NMSheetSettingLayout.VolDay vol_day = settings.setting_layout.vol_day;
|
||||
TimeSpan vol_time = settings.setting_layout.vol_time;
|
||||
DateTime date = DateTime.Today.Date;
|
||||
switch (vol_day) {
|
||||
case NMSheetSettingLayout.VolDay.DayBeforeYesterday:
|
||||
date = date.Subtract(TimeSpan.FromDays(2));
|
||||
break;
|
||||
case NMSheetSettingLayout.VolDay.Yesterday:
|
||||
date = date.Subtract(TimeSpan.FromDays(1));
|
||||
break;
|
||||
case NMSheetSettingLayout.VolDay.Today:
|
||||
break;
|
||||
}
|
||||
DateTime dt = date.Add(vol_time);
|
||||
var rv = VolSurfaceUtilityFunctions.get_unix_epoch_msecs(dt);
|
||||
bts.Log.Ui.info($"NMSheetArchivedVolProvider._get_vol_time vol_day: {vol_day} " +
|
||||
$"vol_time: {vol_time} dt: {dt} epoch_md: {rv}");
|
||||
return rv;
|
||||
}
|
||||
|
||||
private void _check_and_send_request(bool force = false) {
|
||||
NMSheetSettings settings = _bb.read_state(_settings_tag);
|
||||
if (settings != null && settings.setting_layout != null) {
|
||||
UInt64 vol_time = _get_vol_time(settings);
|
||||
if (force || _last_req.ret.SaveTime != vol_time) {
|
||||
_last_req = new ClientArchivedVolRequest(
|
||||
ClientArchivedVolRequest.get_new_id(),
|
||||
new ArchivedTheoRetrieval() {
|
||||
SaveTime = vol_time,
|
||||
SecTup = _sec_tup
|
||||
});
|
||||
_waiting_for_reponse = true;
|
||||
bts.Log.Gen.info($"NMSheetArchivedVolProvider._check_and_send_request req: {_last_req}");
|
||||
_bb.post(SparkTags.RequestArchivedVols, _last_req);
|
||||
}
|
||||
}
|
||||
_bb.subscribe(SparkTags.ArchivedTheos);
|
||||
_bb.data_callback += _on_data;
|
||||
}
|
||||
|
||||
private void _compute_and_post() {
|
||||
@@ -118,34 +38,22 @@ namespace mbts.spark {
|
||||
}
|
||||
|
||||
private void _on_data(object tag, object data) {
|
||||
if (_settings_tag.Equals(tag)) {
|
||||
_check_and_send_request();
|
||||
} else if (_response_tag.Equals(tag)) {
|
||||
if (_waiting_for_reponse) {
|
||||
Tuple<ClientArchivedVolRequest, bts.api.analytics.ArchivedTheoList> resp =
|
||||
_bb.read_state(_response_tag);
|
||||
if (resp != null) {
|
||||
ClientArchivedVolRequest responsed_req = resp.Item1;
|
||||
if (responsed_req.id == _last_req.id) {
|
||||
// got we were looking for
|
||||
_cached_data = resp.Item2;
|
||||
_waiting_for_reponse = false;
|
||||
bts.Log.Gen.info($"NMSheetArchivedVolProvider._on_data recvd data, req: {_last_req}");
|
||||
_compute_and_post();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (_sc_tag.Equals(tag)) {
|
||||
// just listen to archihved theos and fire callback
|
||||
if (tag.Equals(SparkTags.ArchivedTheos)) {
|
||||
_cached_data = new Nullable<ArchivedTheoListImmutable>((ArchivedTheoListImmutable)data);
|
||||
_compute_and_post();
|
||||
}
|
||||
else if (_sc_tag.Equals(tag)) {
|
||||
_compute_and_post();
|
||||
}
|
||||
}
|
||||
|
||||
public OptionContractKeyedData<PNLRollOverDataUnit> get_all_data() {
|
||||
SystemContractData sc_data = _bb.read_state(_sc_tag);
|
||||
if (_cached_data != null && sc_data != null) {
|
||||
if (sc_data != null && _cached_data != null && _cached_data.HasValue) {
|
||||
OptionContractKeyedData<PNLRollOverDataUnit> rv =
|
||||
new OptionContractKeyedData<PNLRollOverDataUnit>();
|
||||
foreach (var v in _cached_data.SecTheo) {
|
||||
foreach (var v in _cached_data.Value.SecTheo) {
|
||||
var sec_md = sc_data.get_sec_md(v.Id);
|
||||
try {
|
||||
if (sec_md != null) {
|
||||
|
||||
+28
-9
@@ -1,5 +1,7 @@
|
||||
namespace BCG {
|
||||
partial class NMSheetControl {
|
||||
namespace BCG
|
||||
{
|
||||
partial class NMSheetControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
@@ -9,9 +11,11 @@
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing) {
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
_logical_dispose(disposing);
|
||||
if (disposing && (components != null)) {
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
|
||||
}
|
||||
@@ -24,7 +28,8 @@
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent() {
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this._menu_panel = new System.Windows.Forms.Panel();
|
||||
this._button_minimize_spreads = new System.Windows.Forms.Button();
|
||||
@@ -67,6 +72,7 @@
|
||||
this._toolstripmenuitem_task_manage_templates = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this._toolstripseperator_task_eye = new System.Windows.Forms.ToolStripSeparator();
|
||||
this._toolstrip_menuitem_save_data_to_file = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this._toolstrip_menuitem_save_ivs = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this._toolstripseperator_export_data = new System.Windows.Forms.ToolStripSeparator();
|
||||
this._toolstripmenuitem_card = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this._toolstripseperator_expirations = new System.Windows.Forms.ToolStripSeparator();
|
||||
@@ -293,7 +299,8 @@
|
||||
this._toolstripmenuitem_atm,
|
||||
this._toolseperator_atm,
|
||||
};
|
||||
if (_api_tasking_enabled) {
|
||||
if (_api_tasking_enabled)
|
||||
{
|
||||
right_click_menu.AddRange(new System.Collections.Generic.List<System.Windows.Forms.ToolStripItem>() {
|
||||
this._toolstripmenuitem_task_eye,
|
||||
// no quoter
|
||||
@@ -307,7 +314,8 @@
|
||||
// this._toolstripmenuitem_task_override_size,
|
||||
// });
|
||||
// }
|
||||
if (_api_tasking_enabled) {
|
||||
if (_api_tasking_enabled)
|
||||
{
|
||||
right_click_menu.AddRange(new System.Collections.Generic.List<System.Windows.Forms.ToolStripItem>() {
|
||||
this._toolstripmenuitem_task_eye_switch_all_off,
|
||||
// We can do this from the algo studio now
|
||||
@@ -317,6 +325,7 @@
|
||||
right_click_menu.AddRange(new System.Collections.Generic.List<System.Windows.Forms.ToolStripItem>() {
|
||||
// this._toolstripseperator_task_eye,
|
||||
this._toolstrip_menuitem_save_data_to_file,
|
||||
this._toolstrip_menuitem_save_ivs,
|
||||
this._toolstripseperator_export_data,
|
||||
this._toolstripmenuitem_card,
|
||||
this._toolstripseperator_expirations,
|
||||
@@ -324,7 +333,8 @@
|
||||
this._toolstripmenuitem_minimize_spreads,
|
||||
this._toolstripseperator_filter,
|
||||
});
|
||||
if (_api_tasking_enabled) {
|
||||
if (_api_tasking_enabled)
|
||||
{
|
||||
right_click_menu.AddRange(new System.Collections.Generic.List<System.Windows.Forms.ToolStripItem>() {
|
||||
this._toolstripmenuitem_filter,
|
||||
this._toolseperator_quotesets
|
||||
@@ -497,6 +507,13 @@
|
||||
this._toolstripseperator_task_eye.Name = "_toolstripseperator_task_eye";
|
||||
this._toolstripseperator_task_eye.Size = new System.Drawing.Size(213, 6);
|
||||
//
|
||||
// _toolstrip_menuitem_save_ivs
|
||||
//
|
||||
this._toolstrip_menuitem_save_ivs.Name = "_toolstrip_menuitem_save_ivs";
|
||||
this._toolstrip_menuitem_save_ivs.Size = new System.Drawing.Size(216, 22);
|
||||
this._toolstrip_menuitem_save_ivs.Text = "Save IVs";
|
||||
//
|
||||
//
|
||||
// _toolstrip_menuitem_save_data_to_file
|
||||
//
|
||||
this._toolstrip_menuitem_save_data_to_file.Name = "_toolstrip_menuitem_save_data_to_file";
|
||||
@@ -581,7 +598,8 @@
|
||||
this._toolstripmenuitem_settings_volchange,
|
||||
this._toolstripmenuitem_settings_straddle
|
||||
};
|
||||
if (_api_tasking_enabled) {
|
||||
if (_api_tasking_enabled)
|
||||
{
|
||||
sheet_settings_items.AddRange(new System.Collections.Generic.List<System.Windows.Forms.ToolStripItem>() {
|
||||
this._toolseperator_task_ee,
|
||||
this._toolstripmenuitem_settings_show_task_ee_data,
|
||||
@@ -900,6 +918,7 @@
|
||||
private System.Windows.Forms.ToolStripSeparator _toolstripseparator_task_size;
|
||||
private System.Windows.Forms.ToolStripMenuItem _toolstripmenuitem_task_undo_size_override;
|
||||
private System.Windows.Forms.ToolStripMenuItem _toolstrip_menuitem_save_data_to_file;
|
||||
private System.Windows.Forms.ToolStripMenuItem _toolstrip_menuitem_save_ivs;
|
||||
private System.Windows.Forms.ToolStripSeparator _toolstripseperator_export_data;
|
||||
private System.Windows.Forms.Button _button_theo_acceptance_confirmation;
|
||||
private System.Windows.Forms.ToolStripMenuItem _toolstripmenuitem_filter_strikes_with_pos_edge;
|
||||
|
||||
@@ -20,6 +20,8 @@ using System.Collections;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading;
|
||||
using bts.api.orderman;
|
||||
using bts;
|
||||
using mbts.analytics;
|
||||
|
||||
namespace BCG {
|
||||
public partial class NMSheetControl : UserControl {
|
||||
@@ -252,7 +254,7 @@ namespace BCG {
|
||||
/// windows timer
|
||||
_windows_timer = new System.Windows.Forms.Timer(components);
|
||||
_windows_timer.Enabled = true;
|
||||
_windows_timer.Interval = 20;
|
||||
_windows_timer.Interval = 100;
|
||||
_windows_timer.Tick += _windows_timer_tick;
|
||||
_toolstripmenuitem_card.Visible = false;
|
||||
/// status bar
|
||||
@@ -317,6 +319,9 @@ namespace BCG {
|
||||
_set_new_settings(_settings);
|
||||
_theo_grid.theo_grid.scroll_to_point(Point.Empty);
|
||||
};
|
||||
_toolstrip_menuitem_save_ivs.Click += (s, e) => {
|
||||
_threaded_bb.post(SparkTags.TC2Tags.ArchiveIVsTag, _nmsheet_symbol_list[0]);
|
||||
};
|
||||
_toolstripmenuitem_filter_strikes_in_tasks.Click += (s, e) => {
|
||||
_settings.setting_filter.filter_ee_task_strikes = !_settings.setting_filter.filter_ee_task_strikes;
|
||||
_set_new_settings(_settings);
|
||||
@@ -612,7 +617,7 @@ namespace BCG {
|
||||
cell.col == NMSheetColumnName.put_ask_price || cell.col == NMSheetColumnName.put_ask_size) {
|
||||
_launch_order_entry_window(cell, _is_control_down() ? OrderEntryWindow.Ladder : OrderEntryWindow.Ticket);
|
||||
} else if (cell.col == NMSheetColumnName.call_theo || cell.col == NMSheetColumnName.put_theo ||
|
||||
cell.col == NMSheetColumnName.straddle || cell.col == NMSheetColumnName.strike) {
|
||||
cell.col == NMSheetColumnName.straddle || cell.col == NMSheetColumnName.strike) {
|
||||
if (cell.call_selected)
|
||||
_add_spread_leg(cell.expiration, cell.strike, true, false, leg_size, state);
|
||||
if (cell.put_selected)
|
||||
@@ -717,9 +722,9 @@ namespace BCG {
|
||||
|
||||
private void _windows_timer_tick(object sender, EventArgs e) {
|
||||
_publish_activation_state();
|
||||
//_threaded_bb.sec_thread_dowork();
|
||||
// this computes the data and then paints it
|
||||
_check_and_propagate_data();
|
||||
_poll_theo_acceptance_button();
|
||||
//_poll_theo_acceptance_button();
|
||||
_refresh_statusbar_data(false);
|
||||
}
|
||||
|
||||
@@ -780,21 +785,31 @@ namespace BCG {
|
||||
#region Coalescer NMSheetData interaction
|
||||
|
||||
private DateTime _last_data_draw_time = DateTime.MinValue;
|
||||
private const double _min_draw_period_ms = 333.3;
|
||||
private const double _min_draw_period_ms = 500;
|
||||
private NMSheetGeometricLayout _last_geo_lo_info = null;
|
||||
private VolSurfaceTimer _vs_timer = new VolSurfaceTimer();
|
||||
// this is where we assemble the data (in _coalescer.get_data())
|
||||
// and then painted in _respond_to_data
|
||||
private void _check_and_propagate_data() {
|
||||
if (is_visible) {
|
||||
if ((DateTime.Now - _last_data_draw_time).Milliseconds >= Math.Max(_settings.setting_grid_internal.grid_paint_throttle_ms, _min_draw_period_ms)) {
|
||||
_vs_timer.start();
|
||||
NMSheetData new_sheet_data = _coalescer.get_data();
|
||||
_vs_timer.stop();
|
||||
Log.Gen.info($"NMSheetControl._check_and_propagate_data get_data time: {_vs_timer.last_interval_time_ms} msecs symbols: {_title_prefix} tid: {System.Threading.Thread.CurrentThread.ManagedThreadId}");
|
||||
if (new_sheet_data != null) {
|
||||
_last_data_draw_time = DateTime.Now;
|
||||
_sheet_data = new_sheet_data;
|
||||
_vs_timer.start();
|
||||
_respond_to_data();
|
||||
_vs_timer.stop();
|
||||
Log.Gen.info($"NMSheetControl._check_and_propagate_data _respond_to_data time: {_vs_timer.last_interval_time_ms} msecs symbols: {_title_prefix} tid: {System.Threading.Thread.CurrentThread.ManagedThreadId}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// this is the painting
|
||||
private void _respond_to_data() {
|
||||
if (_sheet_data != null) {
|
||||
_set_driver_control_display();
|
||||
|
||||
@@ -1,244 +1,243 @@
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.api.orderman;
|
||||
using bts.shell;
|
||||
using bts.utils;
|
||||
|
||||
using mbts;
|
||||
using mbts.spark;
|
||||
using mbts.ui.controls;
|
||||
|
||||
using Spark.Api.Orders;
|
||||
using Spark.Core;
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using OrderPair = System.ValueTuple<bts.api.SecurityImmutable?, bts.api.orderman.OrderRecordImmutable>;
|
||||
using TickDisplaySettingsImmutable = bts.api.domain.TickDisplaySettingsImmutable;
|
||||
|
||||
namespace bts.spark {
|
||||
internal class Activity {
|
||||
public SecurityImmutable? security;
|
||||
public string message;
|
||||
public ILogViewerCategory category;
|
||||
}
|
||||
|
||||
class OrderActivitySummarizer : IDisposable {
|
||||
readonly IBus _bus;
|
||||
IReadOnlyDictionary<uint, SecurityMD> _security = new Dictionary<uint, SecurityMD>();
|
||||
IDisposable _dispose;
|
||||
static readonly IEqualityComparer<OrderRecordImmutable> _id_comparer =
|
||||
bts.utils.EqualityComparer.Create<OrderRecordImmutable, uint>(a => a.Key);
|
||||
|
||||
public OrderActivitySummarizer(IBus bus, IObservable<TableUpdate<OrderRecordTuple, uint>> orders) {
|
||||
_bus = bus;
|
||||
_dispose = Disposable.Create(
|
||||
bus.subscribe(SparkTags.SecuritiesTag).Subscribe(sec => _security = sec),
|
||||
orders.Subscribe(orders_updated));
|
||||
}
|
||||
|
||||
public void Dispose() => Disposable.dispose(ref _dispose);
|
||||
|
||||
#region formatting
|
||||
|
||||
SecurityImmutable? try_get_security(uint security_key) {
|
||||
if (_security.TryGetValue(security_key, out SecurityMD md)) {
|
||||
return md.security;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static string format_order_success(
|
||||
uint key, double price, double size, Side side, ContractSpecificationImmutable? spec) =>
|
||||
$"({key}) {side.ToString().ToLower()} {size} @ {spec.format(price)}";
|
||||
|
||||
string format_order_fail(
|
||||
double price,
|
||||
double size,
|
||||
Side side,
|
||||
ContractSpecificationImmutable? spec,
|
||||
string error) =>
|
||||
$"Failed to {side.ToString().ToLower()} {size} @ {spec.format(price)}. {error}";
|
||||
|
||||
string format_cancel_success(OrderRecordImmutable order, ContractSpecificationImmutable? spec) {
|
||||
return $"({order.Key}) Canceled {order.short_description(spec)}, was working {order.working_quantity()}";
|
||||
}
|
||||
string format_cancel_error(OrderRecordImmutable order, ContractSpecificationImmutable? spec, string error) {
|
||||
return $"({order.Key}) Failed to cancel {order.short_description(spec)}: {error}";
|
||||
}
|
||||
public static string format_fill_summary(OrderRecordImmutable before, OrderRecordImmutable after) =>
|
||||
_format_fill_summary(_header(after.Key), before, after);
|
||||
|
||||
public static string format_fill_summary(OrderRecordImmutable before, OrderRecordImmutable after, SecurityImmutable? security) =>
|
||||
_format_fill_summary(_header(after.Key, security), before, after);
|
||||
|
||||
public static string format_status_change(uint key, OrderStatus old_status, OrderStatus new_status) =>
|
||||
_format_status_change(_header(key), key, old_status, new_status);
|
||||
|
||||
public static string format_status_change(uint key, OrderStatus old_status, OrderStatus new_status, SecurityImmutable? security) =>
|
||||
_format_status_change(_header(key, security), key, old_status, new_status);
|
||||
|
||||
// since changes are naggled, transition changes aren't always detected (e.g. a new order changes before observers are notified of its existence), so old_status might be null.
|
||||
public static string format_status_change(uint key, OrderStatus? old_status, OrderStatus new_status, SecurityImmutable? security) {
|
||||
string header = _header(key, security);
|
||||
return old_status.HasValue ?
|
||||
_format_status_change(header, key, old_status.Value, new_status) :
|
||||
_format_status_change(header, key, new_status);
|
||||
}
|
||||
|
||||
public static string order_completion_debrief(
|
||||
OrderRecordImmutable order,
|
||||
SecurityImmutable? security,
|
||||
TickDisplaySettingsImmutable qty_display) =>
|
||||
_format_order_completion(
|
||||
_header(order.Key, security), order, security?.ContractSpec, qty_display);
|
||||
|
||||
public static string modified_description(OrderRecordImmutable old_order, OrderRecordImmutable new_order, ContractSpecificationImmutable? spec) {
|
||||
double old_price = old_order.State.Price, new_price = new_order.State.Price;
|
||||
double old_size = old_order.State.quantity();
|
||||
double new_size = new_order.State.quantity();
|
||||
uint old_attached_target_key = old_order.attached_target_order_key(), new_attached_target_key = new_order.attached_target_order_key();
|
||||
return StringBuilderEx.join(prefix, change_descs());
|
||||
//
|
||||
string prefix() => $"({old_order.Key}) Changed";
|
||||
IEnumerable<string> change_descs() {
|
||||
if (old_price != new_price)
|
||||
yield return $"price from {spec.format(old_price)} to {spec.format(new_price)}";
|
||||
if (old_size != new_size)
|
||||
yield return $"size from {old_size} to {new_size}, working {new_order.working_quantity()}";
|
||||
if (old_attached_target_key != new_attached_target_key)
|
||||
yield return $"attached target from {old_attached_target_key} to {new_attached_target_key}";
|
||||
}
|
||||
}
|
||||
|
||||
static string _header(uint key) => $"({key})";
|
||||
static string _header(uint key, SecurityImmutable? security) => $"({key}) {security.display_name()}";
|
||||
|
||||
static string _format_fill_summary(string header, OrderRecordImmutable before, OrderRecordImmutable after) {
|
||||
int fb = (int)before.State.FilledQuantity;
|
||||
int fa = (int)after.State.FilledQuantity;
|
||||
return $"{header} {after.Def.Side.past_tense()} {(fa - fb)} ({fa} total), still working {after.working_quantity()}";
|
||||
}
|
||||
|
||||
static string _format_status_change(string header, uint key, OrderStatus new_status) =>
|
||||
$"{header} Status changed to {new_status}";
|
||||
|
||||
static string _format_status_change(string header, uint key, OrderStatus old_status, OrderStatus new_status) =>
|
||||
$"{header} Status changed from {old_status} to {new_status}";
|
||||
|
||||
static string _format_order_completion(
|
||||
string header,
|
||||
OrderRecordImmutable order,
|
||||
ContractSpecificationImmutable? spec,
|
||||
TickDisplaySettingsImmutable qty_display) {
|
||||
var filled_qty_str = qty_display.format(order.filled_quantity());
|
||||
return $"{header} Completed: {order.side().past_tense()} {filled_qty_str}, " +
|
||||
$"@ {spec.spec_or_default().format(order.avg_price())} (avg)";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
void orders_updated(TableUpdate<OrderRecordTuple, uint> update) {
|
||||
|
||||
foreach (var o in update.added) {
|
||||
if (!string.IsNullOrEmpty(o.order.State.LastMsg) && o.order.State.Created.ToDateTime().Date == DateTime.Today) {
|
||||
if (o.security.HasValue) {
|
||||
log_status(ActivityLogCategory.warn, o.security.Value, o.order.State.LastMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var order in update.changes) {
|
||||
var neworder = order.New.order;
|
||||
var oldorder = order.Old.order;
|
||||
var security = order.New.security ?? order.Old.security;
|
||||
//
|
||||
// description
|
||||
var mod_desc = modified_description(oldorder, neworder, security?.ContractSpec);
|
||||
if (!string.IsNullOrEmpty(mod_desc)) {
|
||||
log_status(ActivityLogCategory.modify, security, mod_desc);
|
||||
}
|
||||
//
|
||||
// filled quantity
|
||||
if (oldorder.State.FilledQuantity != neworder.State.FilledQuantity && !neworder.has_parent()) {
|
||||
log_status(ActivityLogCategory.fill, security, format_fill_summary(oldorder, neworder));
|
||||
}
|
||||
|
||||
//
|
||||
// status
|
||||
if (oldorder.State.Status != neworder.State.Status && !neworder.has_parent()) {
|
||||
log_status(ActivityLogCategory.modify, security,
|
||||
format_status_change(neworder.Key, oldorder.State.Status, neworder.State.Status));
|
||||
}
|
||||
|
||||
// last msg
|
||||
if (oldorder.State.LastMsg != neworder.State.LastMsg) {
|
||||
if (security.HasValue) {
|
||||
log_status(ActivityLogCategory.warn, security, neworder.State.LastMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void log_status(ILogViewerCategory category, SecurityImmutable? security, string msg) {
|
||||
_bus.post(SparkTags.LogActivity, new Activity { security = security, message = msg, category = category });
|
||||
}
|
||||
|
||||
internal void on_send_order(
|
||||
OrderDefinitionImmutable order, double price, double size, uint? key, string error) {
|
||||
var security = try_get_security(order.SecurityKey);
|
||||
log_status(ActivityLogCategory.order, security, key.HasValue ?
|
||||
format_order_success(key.Value, price, size, order.Side, security?.ContractSpec) :
|
||||
format_order_fail(price, size, order.Side, security?.ContractSpec, error));
|
||||
}
|
||||
|
||||
internal void on_cancel_order(OrderRecordImmutable order, bool success, string error) {
|
||||
var security = try_get_security(order.Def.SecurityKey);
|
||||
log_status(ActivityLogCategory.cancel, security, success ?
|
||||
format_cancel_success(order, security?.ContractSpec) :
|
||||
format_cancel_error(order, security?.ContractSpec, error));
|
||||
}
|
||||
|
||||
internal void update_order(
|
||||
OrderRecordImmutable order, double price, double size, bool algo_changed) =>
|
||||
_log_order_update(order, price, size, algo_changed, "change from");
|
||||
|
||||
internal void update_order_failed(OrderRecordImmutable order, double price, double size, bool algo_changed) =>
|
||||
_log_order_update(order, price, size, algo_changed, "failed to change from");
|
||||
|
||||
void _log_order_update(
|
||||
OrderRecordImmutable order,
|
||||
double price,
|
||||
double size,
|
||||
bool algo_changed,
|
||||
string change_desc_prefix
|
||||
) {
|
||||
if (price == order.price() && size == order.working_quantity() && !algo_changed) {
|
||||
// nothing actually changed
|
||||
return;
|
||||
}
|
||||
const string algo_change_text = "change algo parameters";
|
||||
var security = try_get_security(order.Def.SecurityKey);
|
||||
var change_descs = new List<string>(1);
|
||||
|
||||
var price_display = TickUtils.get_tick(security, price).to_api_tick_display_settingsi();
|
||||
var price_qty_change_desc = OrdersExtensions.update_description(
|
||||
order, price, size, price_display);
|
||||
|
||||
if (!price_qty_change_desc.is_null_or_empty()) {
|
||||
change_descs.Add(price_qty_change_desc);
|
||||
}
|
||||
if (algo_changed) {
|
||||
change_descs.Add(algo_change_text);
|
||||
}
|
||||
|
||||
var desc = $"({order.Key}) {change_desc_prefix} {"; ".join(change_descs)}";
|
||||
log_status(ActivityLogCategory.modify, security, desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.api.orderman;
|
||||
using bts.shell;
|
||||
using bts.utils;
|
||||
|
||||
using mbts;
|
||||
using mbts.spark;
|
||||
using mbts.ui.controls;
|
||||
|
||||
using Spark.Api.Orders;
|
||||
using Spark.Core;
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using OrderPair = System.ValueTuple<bts.api.SecurityImmutable?, bts.api.orderman.OrderRecordImmutable>;
|
||||
using TickDisplaySettingsImmutable = bts.api.domain.TickDisplaySettingsImmutable;
|
||||
|
||||
namespace bts.spark {
|
||||
internal class Activity {
|
||||
public SecurityImmutable? security;
|
||||
public string message;
|
||||
public ILogViewerCategory category;
|
||||
}
|
||||
|
||||
class OrderActivitySummarizer : IDisposable {
|
||||
readonly IBus _bus;
|
||||
IReadOnlyDictionary<uint, SecurityMD> _security = new Dictionary<uint, SecurityMD>();
|
||||
IDisposable _dispose;
|
||||
static readonly IEqualityComparer<OrderRecordImmutable> _id_comparer =
|
||||
bts.utils.EqualityComparer.Create<OrderRecordImmutable, uint>(a => a.Key);
|
||||
|
||||
public OrderActivitySummarizer(IBus bus, IObservable<TableUpdate<OrderRecordTuple, uint>> orders) {
|
||||
_bus = bus;
|
||||
_dispose = Disposable.Create(
|
||||
bus.subscribe(SparkTags.SecuritiesTag).Subscribe(sec => _security = sec),
|
||||
orders.Subscribe(orders_updated));
|
||||
}
|
||||
|
||||
public void Dispose() => Disposable.dispose(ref _dispose);
|
||||
|
||||
#region formatting
|
||||
|
||||
SecurityImmutable? try_get_security(uint security_key) {
|
||||
if (_security.TryGetValue(security_key, out SecurityMD md)) {
|
||||
return md.security;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static string format_order_success(
|
||||
uint key, double price, double size, Side side, ContractSpecificationImmutable? spec) =>
|
||||
$"({key}) {side.ToString().ToLower()} {size} @ {spec.format(price)}";
|
||||
|
||||
string format_order_fail(
|
||||
double price,
|
||||
double size,
|
||||
Side side,
|
||||
ContractSpecificationImmutable? spec,
|
||||
string error) =>
|
||||
$"Failed to {side.ToString().ToLower()} {size} @ {spec.format(price)}. {error}";
|
||||
|
||||
string format_cancel_success(OrderRecordImmutable order, ContractSpecificationImmutable? spec) {
|
||||
return $"({order.Key}) Canceled {order.short_description(spec)}, was working {order.working_quantity()}";
|
||||
}
|
||||
string format_cancel_error(OrderRecordImmutable order, ContractSpecificationImmutable? spec, string error) {
|
||||
return $"({order.Key}) Failed to cancel {order.short_description(spec)}: {error}";
|
||||
}
|
||||
public static string format_fill_summary(OrderRecordImmutable before, OrderRecordImmutable after) =>
|
||||
_format_fill_summary(_header(after.Key), before, after);
|
||||
|
||||
public static string format_fill_summary(OrderRecordImmutable before, OrderRecordImmutable after, SecurityImmutable? security) =>
|
||||
_format_fill_summary(_header(after.Key, security), before, after);
|
||||
|
||||
public static string format_status_change(uint key, OrderStatus old_status, OrderStatus new_status) =>
|
||||
_format_status_change(_header(key), key, old_status, new_status);
|
||||
|
||||
public static string format_status_change(uint key, OrderStatus old_status, OrderStatus new_status, SecurityImmutable? security) =>
|
||||
_format_status_change(_header(key, security), key, old_status, new_status);
|
||||
|
||||
// since changes are naggled, transition changes aren't always detected (e.g. a new order changes before observers are notified of its existence), so old_status might be null.
|
||||
public static string format_status_change(uint key, OrderStatus? old_status, OrderStatus new_status, SecurityImmutable? security) {
|
||||
string header = _header(key, security);
|
||||
return old_status.HasValue ?
|
||||
_format_status_change(header, key, old_status.Value, new_status) :
|
||||
_format_status_change(header, key, new_status);
|
||||
}
|
||||
|
||||
public static string order_completion_debrief(
|
||||
OrderRecordImmutable order,
|
||||
SecurityImmutable? security,
|
||||
TickDisplaySettingsImmutable qty_display) =>
|
||||
_format_order_completion(
|
||||
_header(order.Key, security), order, security?.ContractSpec, qty_display);
|
||||
|
||||
public static string modified_description(OrderRecordImmutable old_order, OrderRecordImmutable new_order, ContractSpecificationImmutable? spec) {
|
||||
double old_price = old_order.State.Price, new_price = new_order.State.Price;
|
||||
uint old_size = old_order.State.Quantity, new_size = new_order.State.Quantity;
|
||||
uint old_attached_target_key = old_order.attached_target_order_key(), new_attached_target_key = new_order.attached_target_order_key();
|
||||
return StringBuilderEx.join(prefix, change_descs());
|
||||
//
|
||||
string prefix() => $"({old_order.Key}) Changed";
|
||||
IEnumerable<string> change_descs() {
|
||||
if (old_price != new_price)
|
||||
yield return $"price from {spec.format(old_price)} to {spec.format(new_price)}";
|
||||
if (old_size != new_size)
|
||||
yield return $"size from {old_size} to {new_size}, working {new_order.working_quantity()}";
|
||||
if (old_attached_target_key != new_attached_target_key)
|
||||
yield return $"attached target from {old_attached_target_key} to {new_attached_target_key}";
|
||||
}
|
||||
}
|
||||
|
||||
static string _header(uint key) => $"({key})";
|
||||
static string _header(uint key, SecurityImmutable? security) => $"({key}) {security.display_name()}";
|
||||
|
||||
static string _format_fill_summary(string header, OrderRecordImmutable before, OrderRecordImmutable after) {
|
||||
int fb = (int)before.State.FilledQuantity;
|
||||
int fa = (int)after.State.FilledQuantity;
|
||||
return $"{header} {after.Def.Side.past_tense()} {(fa - fb)} ({fa} total), still working {after.working_quantity()}";
|
||||
}
|
||||
|
||||
static string _format_status_change(string header, uint key, OrderStatus new_status) =>
|
||||
$"{header} Status changed to {new_status}";
|
||||
|
||||
static string _format_status_change(string header, uint key, OrderStatus old_status, OrderStatus new_status) =>
|
||||
$"{header} Status changed from {old_status} to {new_status}";
|
||||
|
||||
static string _format_order_completion(
|
||||
string header,
|
||||
OrderRecordImmutable order,
|
||||
ContractSpecificationImmutable? spec,
|
||||
TickDisplaySettingsImmutable qty_display) {
|
||||
var filled_qty_str = qty_display.format(order.filled_quantity());
|
||||
return $"{header} Completed: {order.side().past_tense()} {filled_qty_str}, " +
|
||||
$"@ {spec.spec_or_default().format(order.avg_price())} (avg)";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
void orders_updated(TableUpdate<OrderRecordTuple, uint> update) {
|
||||
|
||||
foreach (var o in update.added) {
|
||||
if (!string.IsNullOrEmpty(o.order.State.LastMsg) && o.order.State.Created.ToDateTime().Date == DateTime.Today) {
|
||||
if (o.security.HasValue) {
|
||||
log_status(ActivityLogCategory.warn, o.security.Value, o.order.State.LastMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var order in update.changes) {
|
||||
var neworder = order.New.order;
|
||||
var oldorder = order.Old.order;
|
||||
var security = order.New.security ?? order.Old.security;
|
||||
//
|
||||
// description
|
||||
var mod_desc = modified_description(oldorder, neworder, security?.ContractSpec);
|
||||
if (!string.IsNullOrEmpty(mod_desc)) {
|
||||
log_status(ActivityLogCategory.modify, security, mod_desc);
|
||||
}
|
||||
//
|
||||
// filled quantity
|
||||
if (oldorder.State.FilledQuantity != neworder.State.FilledQuantity && !neworder.has_parent()) {
|
||||
log_status(ActivityLogCategory.fill, security, format_fill_summary(oldorder, neworder));
|
||||
}
|
||||
|
||||
//
|
||||
// status
|
||||
if (oldorder.State.Status != neworder.State.Status && !neworder.has_parent()) {
|
||||
log_status(ActivityLogCategory.modify, security,
|
||||
format_status_change(neworder.Key, oldorder.State.Status, neworder.State.Status));
|
||||
}
|
||||
|
||||
// last msg
|
||||
if (oldorder.State.LastMsg != neworder.State.LastMsg) {
|
||||
if (security.HasValue) {
|
||||
log_status(ActivityLogCategory.warn, security, neworder.State.LastMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void log_status(ILogViewerCategory category, SecurityImmutable? security, string msg) {
|
||||
_bus.post(SparkTags.LogActivity, new Activity { security = security, message = msg, category = category });
|
||||
}
|
||||
|
||||
internal void on_send_order(
|
||||
OrderDefinitionImmutable order, double price, double size, uint? key, string error) {
|
||||
var security = try_get_security(order.SecurityKey);
|
||||
log_status(ActivityLogCategory.order, security, key.HasValue ?
|
||||
format_order_success(key.Value, price, size, order.Side, security?.ContractSpec) :
|
||||
format_order_fail(price, size, order.Side, security?.ContractSpec, error));
|
||||
}
|
||||
|
||||
internal void on_cancel_order(OrderRecordImmutable order, bool success, string error) {
|
||||
var security = try_get_security(order.Def.SecurityKey);
|
||||
log_status(ActivityLogCategory.cancel, security, success ?
|
||||
format_cancel_success(order, security?.ContractSpec) :
|
||||
format_cancel_error(order, security?.ContractSpec, error));
|
||||
}
|
||||
|
||||
internal void update_order(
|
||||
OrderRecordImmutable order, double price, double size, bool algo_changed) =>
|
||||
_log_order_update(order, price, size, algo_changed, "change from");
|
||||
|
||||
internal void update_order_failed(OrderRecordImmutable order, double price, double size, bool algo_changed) =>
|
||||
_log_order_update(order, price, size, algo_changed, "failed to change from");
|
||||
|
||||
void _log_order_update(
|
||||
OrderRecordImmutable order,
|
||||
double price,
|
||||
double size,
|
||||
bool algo_changed,
|
||||
string change_desc_prefix
|
||||
) {
|
||||
if (price == order.price() && size == order.working_quantity() && !algo_changed) {
|
||||
// nothing actually changed
|
||||
return;
|
||||
}
|
||||
const string algo_change_text = "change algo parameters";
|
||||
var security = try_get_security(order.Def.SecurityKey);
|
||||
var change_descs = new List<string>(1);
|
||||
|
||||
var price_display = TickUtils.get_tick(security, price).to_api_tick_display_settingsi();
|
||||
var price_qty_change_desc = OrdersExtensions.update_description(
|
||||
order, price, size, price_display);
|
||||
|
||||
if (!price_qty_change_desc.is_null_or_empty()) {
|
||||
change_descs.Add(price_qty_change_desc);
|
||||
}
|
||||
if (algo_changed) {
|
||||
change_descs.Add(algo_change_text);
|
||||
}
|
||||
|
||||
var desc = $"({order.Key}) {change_desc_prefix} {"; ".join(change_descs)}";
|
||||
log_status(ActivityLogCategory.modify, security, desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace mbts.spark {
|
||||
namespace mbts.spark {
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.api.core;
|
||||
@@ -662,7 +662,7 @@ namespace mbts.spark {
|
||||
if (o.State.Price == price) return true;
|
||||
var wq = o.working_quantity();
|
||||
if (wq > 0) {
|
||||
return await orders_model.update_order(o, price, o.State.quantity());
|
||||
return await orders_model.update_order(o, price, o.State.Quantity);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -64,5 +64,9 @@ namespace System.Reactive.Linq {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static IObservable<TResult> SelectInline<T, TResult>(
|
||||
this IObservable<T> source, Func<T, TResult> selector) =>
|
||||
Observable.Create<TResult>(o => source.Subscribe(v => o.OnNext(selector(v))));
|
||||
}
|
||||
}
|
||||
@@ -36,9 +36,8 @@ namespace mbts {
|
||||
}
|
||||
|
||||
public static bool is_unexpired(bts.api.SecurityTuple st, DateTime exp_date) {
|
||||
if (st.Venue == Venue.Cboe || st.Venue == Venue.Glbx) {
|
||||
// server is already getting teh righ contracts
|
||||
return true;
|
||||
if (st.Venue == Venue.Cboe) {
|
||||
return exp_date.Date >= DateTime.Now.Date;
|
||||
}
|
||||
TimeSpan exp_time = get_exp_time(st);
|
||||
DateTime full_exp_utc = exp_date.ToUniversalTime().Date.Add(exp_time);
|
||||
@@ -47,8 +46,12 @@ namespace mbts {
|
||||
}
|
||||
|
||||
public static bool is_unexpired(bts.api.SecurityImmutable sec) {
|
||||
if (sec.security_tuple().Venue == Venue.Cboe || sec.security_tuple().Venue == Venue.Glbx)
|
||||
return true;
|
||||
if (sec.security_tuple().Venue == Venue.Cboe || sec.security_tuple().Venue == Venue.Glbx) {
|
||||
var exp = sec.to_sec_exp().expiration;
|
||||
bool is_unexp = exp.Date >= DateTime.Now.Date;
|
||||
// Log.Gen.info($"SecurityExpirationMapper.is_unexpired exp: {exp} is_unexp: {is_unexp}");
|
||||
return is_unexp;
|
||||
}
|
||||
var sec_type = sec.security_type();
|
||||
switch (sec_type) {
|
||||
case bts.api.SecurityType.Future:
|
||||
|
||||
Binary file not shown.
@@ -1,59 +0,0 @@
|
||||
#nullable enable
|
||||
using bts.collections;
|
||||
|
||||
using Spark.Core;
|
||||
using Spark.Core.Protobuf;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace bts.shell;
|
||||
|
||||
static class ShellWindowSettingsDirectoryStore {
|
||||
public static ShellWindowSettingsDirectoryStore<T> Create<T>(string path, string searchPattern) =>
|
||||
new(path, searchPattern);
|
||||
}
|
||||
|
||||
class ShellWindowSettingsDirectoryStore<T> {
|
||||
readonly LazyOnce<Dictionary<string, SingleFileStore>> profiles;
|
||||
|
||||
public ShellWindowSettingsDirectoryStore(string path, string searchPattern) =>
|
||||
profiles = new(() => {
|
||||
try {
|
||||
return Directory.EnumerateFiles(path, searchPattern).Select(SingleFileStore.FromPath).ToDictionary(sfs => sfs.Name);
|
||||
} catch (Exception ex) {
|
||||
Log.Ui.error($"Failed to enumerate {typeof(T)} settings files in '{path}'. {ex}");
|
||||
}
|
||||
return new(0);
|
||||
});
|
||||
|
||||
public IReadOnlyDictionary<string, T?> Profiles =>
|
||||
MappedDictionary.create(profiles.Value, sfs => sfs.Value);
|
||||
|
||||
class SingleFileStore {
|
||||
LazyOnce<T?> value;
|
||||
|
||||
public SingleFileStore(string path) {
|
||||
Name = Path.GetFileNameWithoutExtension(path);
|
||||
value = new(LoadValue);
|
||||
|
||||
T? LoadValue() {
|
||||
try {
|
||||
using var f = File.OpenRead(path);
|
||||
return ProtobufSerializationHelper.deserialize<T>(f);
|
||||
} catch (Exception ex) {
|
||||
Log.Ui.error($"Failed to load {typeof(T)} file '{path}'. {ex}");
|
||||
}
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public static SingleFileStore FromPath(string path) =>
|
||||
new(path);
|
||||
|
||||
public string Name { get; }
|
||||
public T? Value => value.Value;
|
||||
}
|
||||
}
|
||||
@@ -77,10 +77,6 @@
|
||||
<EmbeddedResource Include="Sounds/whistle.wav" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="ShellWindowSettings/**" CopyToOutputDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="diagnostic" AfterTargets="PreBuildEvent" />
|
||||
|
||||
</Project>
|
||||
@@ -353,11 +353,8 @@ namespace mbts.spark {
|
||||
|
||||
public static ITag<Nothing> ShowGlobalAlertsTag { get; } = _mk_tag<Nothing>();
|
||||
|
||||
public static ITag<ClientArchivedVolRequest> RequestArchivedVols { get; } = _mk_tag<ClientArchivedVolRequest>();
|
||||
|
||||
public static ITag<Tuple<ClientArchivedVolRequest, bts.api.analytics.ArchivedTheoList>>
|
||||
ResponseArchivedVols { get; } =
|
||||
_mk_tag<Tuple<ClientArchivedVolRequest, bts.api.analytics.ArchivedTheoList>>();
|
||||
public static ITag<ArchivedTheoListImmutable>
|
||||
ArchivedTheos { get; } = _mk_tag<ArchivedTheoListImmutable>();
|
||||
|
||||
static SparkTag<T> _mk_tag<T>([CallerMemberName] string name = null) =>
|
||||
new(name ?? throw new ArgumentNullException(nameof(name)));
|
||||
@@ -373,6 +370,7 @@ namespace mbts.spark {
|
||||
public class Nothing { Nothing() { } }
|
||||
|
||||
public class TC2Tags {
|
||||
public static ITag<NMSheetSymbol> ArchiveIVsTag {get;} = _mk_tag<NMSheetSymbol>();
|
||||
public static ITag<NMSheetAllTaskingData> TaskData { get; } =
|
||||
_mk_tag<NMSheetAllTaskingData>();
|
||||
// Data request for a sheet
|
||||
@@ -386,6 +384,11 @@ namespace mbts.spark {
|
||||
public static ITag<ExpStrikeKeyedData<TheoPoint>> LiveTheosTag((string, Venue) symbol) =>
|
||||
_mk_tag<ExpStrikeKeyedData<TheoPoint>, (string, Venue)>(symbol);
|
||||
|
||||
// these are the theos at time of the vol save (we use it to extrapolate the theos prices for the spreads)
|
||||
public static ITag<ExpStrikeKeyedData<TheoPoint>> VolSaveEventTheosTag((string, Venue) symbol) =>
|
||||
_mk_tag<ExpStrikeKeyedData<TheoPoint>, (string, Venue)>(symbol);
|
||||
|
||||
|
||||
// Aggregated version of the above
|
||||
public static ITag<IReadOnlyDictionary<(string, Venue), ExpStrikeKeyedData<TheoPoint>>>
|
||||
AllLiveTheosTag { get; } =
|
||||
|
||||
@@ -254,9 +254,9 @@ namespace mbts.ui {
|
||||
public static class PNL {
|
||||
public static BTSColor foreground => UI.default_foreground;
|
||||
public static BTSColor anchor => Colors.Gold;
|
||||
public static BTSColor profit => BTSCoreColors.spring_green;
|
||||
public static BTSColor profit => Colors.Green;
|
||||
public static BTSColor net_zero => BTSCoreColors.gray;
|
||||
public static BTSColor loss => BTSCoreColors.fire_brick;
|
||||
public static BTSColor loss => BTSCoreColors.venetian_red;
|
||||
public static BTSColor header_row_background => 0xffaaaaaa;
|
||||
// group background colors
|
||||
public static BTSColor group_row_background1 => 0x19141420;
|
||||
@@ -276,8 +276,8 @@ namespace mbts.ui {
|
||||
}
|
||||
|
||||
public static Color anchor_color => Colors.Gold;
|
||||
public static Color profit_color => profit;
|
||||
public static Color loss_color => loss;
|
||||
public static Color profit_color => Colors.Green;
|
||||
public static Color loss_color => BTSCoreColors.venetian_red;
|
||||
public static Color header_row_background_color => 0xffaaaaaa.argb_color();
|
||||
// group background colors
|
||||
public static Color group_row_background_color1 => group_row_background1;
|
||||
|
||||
@@ -83,7 +83,6 @@
|
||||
public static BTSColor green => 0xff00c000;
|
||||
public static BTSColor green_p_light => 0xff99ee90;
|
||||
public static BTSColor green_dark_light => 0xff255d25;
|
||||
public static BTSColor spring_green => 0xff00fb76;
|
||||
public static BTSColor light_sea_green => 0xff17b794;
|
||||
public static BTSColor very_light_malachite_green => 0xff52e887;
|
||||
public static BTSColor may_green => 0xff43a23c;
|
||||
@@ -101,7 +100,6 @@
|
||||
public static BTSColor red_light_dark => 0xffd69a9a;
|
||||
public static BTSColor red_light_dark_saturated => 0xffd67e7e;
|
||||
public static BTSColor permanent_geranium_lake => 0xffde3429;
|
||||
public static BTSColor fire_brick => 0xffb1373a;
|
||||
public static BTSColor fire_opal => 0xfff05454;
|
||||
public static BTSColor paradise_pink => 0xffe94560;
|
||||
public static BTSColor tulip => 0xffff878d;
|
||||
|
||||
+20
-20
@@ -1,20 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.utils {
|
||||
public class ReverseComparer<T> : IComparer<T> {
|
||||
private readonly IComparer<T> _wrapped;
|
||||
|
||||
public ReverseComparer(IComparer<T> wrapped) {
|
||||
_wrapped = wrapped;
|
||||
}
|
||||
|
||||
public int Compare(T x, T y) {
|
||||
// reverse operands
|
||||
return _wrapped.Compare(y, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace mbts.utils {
|
||||
public class ReverseComparer<T> : IComparer<T> {
|
||||
private readonly IComparer<T> _wrapped;
|
||||
|
||||
public ReverseComparer(IComparer<T> wrapped) {
|
||||
_wrapped = wrapped;
|
||||
}
|
||||
|
||||
public int Compare(T x, T y) {
|
||||
// reverse operands
|
||||
return _wrapped.Compare(y, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,15 +209,11 @@ namespace mbts.ui.controls {
|
||||
this.prefix = prefix;
|
||||
|
||||
public string PNL => $"{prefix} PNL";
|
||||
public string RealizedPNL => $"{prefix} R PNL";
|
||||
public string UnrealizedPNL => $"{prefix} U PNL";
|
||||
public string Net => $"{prefix} {PNLHeaders.Net}";
|
||||
public string Long => $"{prefix} {PNLHeaders.Long}";
|
||||
public string LongAvg => $"{Long} {AvgPrice}";
|
||||
public string LongAvgPNL => $"{Long} {AvgPrice} PNL";
|
||||
public string Short => $"{prefix} {PNLHeaders.Short}";
|
||||
public string ShortAvg => $"{Short} {AvgPrice}";
|
||||
public string ShortAvgPNL => $"{Short} {AvgPrice} PNL";
|
||||
public string Delta => $"{prefix} {PNLHeaders.Delta}";
|
||||
public string Gamma => $"{prefix} {PNLHeaders.Gamma}";
|
||||
public string Vega => $"{prefix} {PNLHeaders.Vega}";
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
using mbts.ui;
|
||||
|
||||
using Spark.Api.Data;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -136,20 +134,6 @@ namespace mbts.spark.filters {
|
||||
}
|
||||
}
|
||||
|
||||
public void add_exp_date(
|
||||
ExpirationDate dt, Func<TRow, ExpirationDate?> selector, bool null_passes_filter = false) {
|
||||
// Use local fns to provide context in stack trace
|
||||
_predicates.Add(null_passes_filter ? null_pass_impl : null_fail_impl);
|
||||
|
||||
bool null_fail_impl(TRow r) =>
|
||||
selector(r) == dt;
|
||||
|
||||
bool null_pass_impl(TRow r) {
|
||||
var rdt = selector(r);
|
||||
return !rdt.HasValue || rdt == dt;
|
||||
}
|
||||
}
|
||||
|
||||
public Func<TRow, bool> to_predicate() =>
|
||||
_predicates.Count == 0 ? null : new Func<TRow, bool>(o => _predicates.All(p => p(o)));
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
|
||||
using Spark.Api.Data;
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
namespace mbts.ui;
|
||||
|
||||
using mbts.ui.shell;
|
||||
|
||||
using Spark.Api.Data;
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
|
||||
static class DisplayTranslatorExtensions {
|
||||
public static IDisposable connect_owner<T>(
|
||||
this IDisplayTranslator<T> display_translator,
|
||||
IRaiseNotifyPropertyChanged owner,
|
||||
params string[] properties
|
||||
) {
|
||||
if (display_translator is null)
|
||||
throw new ArgumentNullException(nameof(display_translator));
|
||||
if (owner is null)
|
||||
throw new ArgumentNullException(nameof(owner));
|
||||
display_translator.value_changed += on_value_changed;
|
||||
return Disposable.Create(() => display_translator.value_changed -= on_value_changed);
|
||||
void on_value_changed() {
|
||||
for (int i = 0; i < properties.Length; i++)
|
||||
owner.raise_notify_property_changed(properties[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
using bts.utils;
|
||||
|
||||
using mbts.ui.shell;
|
||||
|
||||
using Spark.Core;
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
namespace mbts.ui {
|
||||
interface IDisplayTranslator<T> {
|
||||
T display_value { get; set; }
|
||||
T actual_value { get; set; }
|
||||
event Action value_changed;
|
||||
}
|
||||
|
||||
enum QuantityConversionOpType {
|
||||
None,
|
||||
MultiplyActual,
|
||||
DivideActual
|
||||
}
|
||||
|
||||
readonly struct QuantityConversionData<T> : IEquatable<QuantityConversionData<T>>
|
||||
where T : INumber<T> {
|
||||
public QuantityConversionData(T value, QuantityConversionOpType op) {
|
||||
this.value = value;
|
||||
this.op = op;
|
||||
}
|
||||
|
||||
public enum OpType {
|
||||
None,
|
||||
MultiplyActual,
|
||||
DivideActual
|
||||
}
|
||||
|
||||
public T value { get; }
|
||||
public QuantityConversionOpType op { get; }
|
||||
|
||||
public QuantityConversionData<TResult> convert_numeric_type<TResult>()
|
||||
where TResult : INumber<TResult> =>
|
||||
new(NumericCastConverter<T, TResult>.convert(value), op);
|
||||
|
||||
public bool Equals(QuantityConversionData<T> other) =>
|
||||
value == other.value &&
|
||||
op == other.op;
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
obj is QuantityConversionData<T> other && Equals(other);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
EqualityComparer.auto_phase(value.GetHashCode(), op.GetHashCode());
|
||||
|
||||
public static bool operator ==(QuantityConversionData<T> x, QuantityConversionData<T> y) =>
|
||||
x.Equals(y);
|
||||
|
||||
public static bool operator !=(QuantityConversionData<T> x, QuantityConversionData<T> y) =>
|
||||
!x.Equals(y);
|
||||
}
|
||||
|
||||
static class DisplayQuantityMultiplier {
|
||||
public static DisplayQuantityMultiplier<uint> create_uint() => new(
|
||||
DisplayTranslatorExtensions.to_display,
|
||||
DisplayTranslatorExtensions.from_display);
|
||||
|
||||
public static DisplayQuantityMultiplier<double> create_double() => new(
|
||||
DisplayTranslatorExtensions.to_display,
|
||||
DisplayTranslatorExtensions.from_display);
|
||||
}
|
||||
|
||||
class DisplayQuantityMultiplier<T> : IDisplayTranslator<T> where T : struct, INumber<T> {
|
||||
readonly Func<QuantityConversionData<T>, T, T> _to_display, _from_display;
|
||||
readonly IEqualityComparer<T> _comparer;
|
||||
T _actual_value;
|
||||
QuantityConversionData<T> _conversion_data;
|
||||
|
||||
public DisplayQuantityMultiplier(
|
||||
Func<QuantityConversionData<T>, T, T> to_display,
|
||||
Func<QuantityConversionData<T>, T, T> from_display,
|
||||
IEqualityComparer<T> comparer = null,
|
||||
T actual_value = default,
|
||||
QuantityConversionData<T> conversion_data = default) {
|
||||
//
|
||||
_to_display = to_display ?? throw new ArgumentNullException(nameof(to_display));
|
||||
_from_display = from_display ?? throw new ArgumentNullException(nameof(from_display));
|
||||
_comparer = comparer ?? EqualityComparer<T>.Default;
|
||||
_actual_value = actual_value;
|
||||
_conversion_data = conversion_data;
|
||||
}
|
||||
|
||||
public event Action value_changed;
|
||||
|
||||
public T actual_value {
|
||||
get => _actual_value;
|
||||
set {
|
||||
if (!_comparer.Equals(_actual_value, value)) {
|
||||
_actual_value = value;
|
||||
value_changed?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T display_value {
|
||||
get => _to_display(_conversion_data, _actual_value);
|
||||
set => actual_value = _from_display(_conversion_data, value);
|
||||
}
|
||||
|
||||
public QuantityConversionData<T> conversion_data {
|
||||
get => _conversion_data;
|
||||
set {
|
||||
if (_conversion_data != value) {
|
||||
_conversion_data = value;
|
||||
value_changed?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class OptionalDisplayQuantityMultiplier<T> : IDisplayTranslator<T?> where T : struct, INumber<T> {
|
||||
T? _actual_value;
|
||||
QuantityConversionData<T> _conversion_data;
|
||||
|
||||
public event Action value_changed;
|
||||
|
||||
public T? actual_value {
|
||||
get => _actual_value;
|
||||
set {
|
||||
if (_actual_value != value) {
|
||||
_actual_value = value;
|
||||
value_changed?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T? display_value {
|
||||
get => _actual_value.HasValue ?
|
||||
_conversion_data.to_display(_actual_value.Value) : _actual_value;
|
||||
set => actual_value = value.HasValue ?
|
||||
_conversion_data.from_display(value.Value) : value;
|
||||
}
|
||||
|
||||
public QuantityConversionData<T> conversion_data {
|
||||
get => _conversion_data;
|
||||
set {
|
||||
if (_conversion_data != value) {
|
||||
_conversion_data = value;
|
||||
value_changed?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class DisplayTranslatorExtensions {
|
||||
public static IDisposable connect_owner<T>(
|
||||
this IDisplayTranslator<T> display_translator,
|
||||
IRaiseNotifyPropertyChanged owner,
|
||||
params string[] properties
|
||||
) {
|
||||
if (display_translator is null)
|
||||
throw new ArgumentNullException(nameof(display_translator));
|
||||
if (owner is null)
|
||||
throw new ArgumentNullException(nameof(owner));
|
||||
display_translator.value_changed += on_value_changed;
|
||||
return Disposable.Create(() => display_translator.value_changed -= on_value_changed);
|
||||
void on_value_changed() {
|
||||
for (int i = 0; i < properties.Length; i++)
|
||||
owner.raise_notify_property_changed(properties[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static IObservable<T> subscribe_actual_value<T>(
|
||||
this IDisplayTranslator<T> display_translator) =>
|
||||
subscribe_actual_value(display_translator, EqualityComparer<T>.Default);
|
||||
|
||||
public static IObservable<T> subscribe_actual_value<T>(
|
||||
this IDisplayTranslator<T> display_translator, IEqualityComparer<T> comparer) {
|
||||
if (comparer is null)
|
||||
throw new ArgumentNullException(nameof(comparer));
|
||||
return Observable.Create<T>(o => {
|
||||
var curr = display_translator.actual_value;
|
||||
o.OnNext(curr);
|
||||
display_translator.value_changed += on_value_changed;
|
||||
return Disposable.Create(() => display_translator.value_changed -= on_value_changed);
|
||||
void on_value_changed() {
|
||||
var next = display_translator.actual_value;
|
||||
if (!comparer.Equals(curr, next))
|
||||
o.OnNext(curr = next);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static T to_display<T>(
|
||||
this QuantityConversionData<T> quantity_conversion_data, T actual_value)
|
||||
where T : INumber<T> =>
|
||||
quantity_conversion_data.op switch {
|
||||
QuantityConversionOpType.DivideActual =>
|
||||
actual_value.safe_divide(quantity_conversion_data.value),
|
||||
QuantityConversionOpType.MultiplyActual =>
|
||||
actual_value * quantity_conversion_data.value,
|
||||
_ => actual_value,
|
||||
};
|
||||
|
||||
public static T from_display<T>(
|
||||
this QuantityConversionData<T> quantity_conversion_data, T display_value)
|
||||
where T : INumber<T> =>
|
||||
quantity_conversion_data.op switch {
|
||||
QuantityConversionOpType.DivideActual => display_value * quantity_conversion_data.value,
|
||||
QuantityConversionOpType.MultiplyActual =>
|
||||
display_value.safe_divide(quantity_conversion_data.value),
|
||||
_ => display_value,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
#nullable enable
|
||||
namespace Spark.Api.MarketData;
|
||||
|
||||
using System;
|
||||
|
||||
public readonly struct Bbo : IEquatable<Bbo> {
|
||||
public readonly double BidPrice;
|
||||
public readonly double BidQuantity;
|
||||
public readonly double AskPrice;
|
||||
public readonly double AskQuantity;
|
||||
|
||||
public Bbo(double bidPrice, double bidQuantity, double askPrice, double askQuantity) {
|
||||
BidPrice = bidPrice;
|
||||
BidQuantity = bidQuantity;
|
||||
AskPrice = askPrice;
|
||||
AskQuantity = askQuantity;
|
||||
}
|
||||
|
||||
public static Bbo Empty => new(double.NaN, double.NaN, double.NaN, double.NaN);
|
||||
|
||||
public bool Equals(Bbo other) =>
|
||||
BidPrice.Equals(other.BidPrice) &&
|
||||
BidQuantity.Equals(other.BidQuantity) &&
|
||||
AskPrice.Equals(other.AskPrice) &&
|
||||
AskQuantity.Equals(other.AskQuantity);
|
||||
|
||||
public override bool Equals(object? obj) =>
|
||||
obj is Bbo other && Equals(other);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
HashCode.Combine(BidPrice, BidQuantity, AskPrice, AskQuantity);
|
||||
|
||||
public override string ToString() =>
|
||||
$"({BidQuantity}) {BidPrice} {AskPrice} ({AskQuantity})";
|
||||
|
||||
public static bool operator ==(Bbo left, Bbo right) =>
|
||||
left.Equals(right);
|
||||
|
||||
public static bool operator !=(Bbo left, Bbo right) =>
|
||||
!left.Equals(right);
|
||||
|
||||
public static implicit operator (double, double, double, double)(Bbo bbo) =>
|
||||
(bbo.BidPrice, bbo.BidQuantity, bbo.AskPrice, bbo.AskQuantity);
|
||||
|
||||
public static implicit operator Bbo((double, double, double, double) bboTup) =>
|
||||
(bboTup.Item1, bboTup.Item2, bboTup.Item3, bboTup.Item4);
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
#nullable enable
|
||||
namespace Spark.Api.MarketData;
|
||||
|
||||
using mbts;
|
||||
using mbts.co2;
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
class BookStore {
|
||||
readonly uint numDepthLevels;
|
||||
readonly Dictionary<uint, PollableBook> books = new(0);
|
||||
IReadOnlyDictionary<uint, SecurityMD> securityMds = new Dictionary<uint, SecurityMD>(0);
|
||||
|
||||
public BookStore(uint numDepthLevels = NativePriceHelpers.COCONUT_MAX_DEPTH) =>
|
||||
this.numDepthLevels = numDepthLevels;
|
||||
|
||||
public BookStore(IReadOnlyDictionary<uint, SecurityMD> securityMds, uint numDepthLevels = NativePriceHelpers.COCONUT_MAX_DEPTH) {
|
||||
this.securityMds = securityMds;
|
||||
this.numDepthLevels = numDepthLevels;
|
||||
}
|
||||
|
||||
public void OnSecurityMds(IReadOnlyDictionary<uint, SecurityMD> securityMds) {
|
||||
this.securityMds = securityMds;
|
||||
books.Clear();
|
||||
}
|
||||
|
||||
public PollableBook? GetPollableBook(uint id) {
|
||||
if (!books.TryGetValue(id, out var book)) {
|
||||
if (securityMds.TryGetValue(id, out var smd)) {
|
||||
book = new(smd, numDepthLevels);
|
||||
books.Add(id, book);
|
||||
}
|
||||
}
|
||||
return book;
|
||||
}
|
||||
|
||||
public BookTuple? GetBook(uint id, bool poll = true) {
|
||||
var pb = GetPollableBook(id);
|
||||
if (poll) {
|
||||
pb?.poll_changes();
|
||||
}
|
||||
return pb?.to_book_tuple();
|
||||
}
|
||||
}
|
||||
@@ -22,13 +22,6 @@ namespace Spark.Api.MarketData {
|
||||
public SecurityImmutable security { get; }
|
||||
public uint security_id => security.Id;
|
||||
public Book book { get; }
|
||||
public Bbo bbo {
|
||||
get {
|
||||
(double bidp, double bidq) = book.bids.Count > 0 ? (book.bids[0].price, book.bids[0].size) : (double.NaN, double.NaN);
|
||||
(double askp, double askq) = book.asks.Count > 0 ? (book.asks[0].price, book.asks[0].size) : (double.NaN, double.NaN);
|
||||
return new(bidp, bidq, askp, askq);
|
||||
}
|
||||
}
|
||||
|
||||
public TickDisplaySettingsImmutable quantity_display =>
|
||||
_quantity_display ?? Security.Defaults.quantity_display_settingsi;
|
||||
|
||||
@@ -180,6 +180,38 @@ namespace bts.md {
|
||||
}
|
||||
}
|
||||
|
||||
class PollableBook {
|
||||
readonly SecurityMD _security_md;
|
||||
readonly uint _num_depth_levels;
|
||||
ulong _last_update_time = 0;
|
||||
// Reuse the same arrays as an optimization to avoid reallocating memory on each poll.
|
||||
// Note: this will break if the code isn't called in a thread-safe manner.
|
||||
NativePriceSize[] _bids;
|
||||
NativePriceSize[] _asks;
|
||||
|
||||
public PollableBook(SecurityMD security_md, uint num_depth_levels) {
|
||||
_security_md = security_md;
|
||||
_num_depth_levels = num_depth_levels;
|
||||
_bids = new NativePriceSize[_num_depth_levels];
|
||||
_asks = new NativePriceSize[_num_depth_levels];
|
||||
}
|
||||
|
||||
public BookTuple to_book_tuple() {
|
||||
var book = new Book(
|
||||
_security_md.security.Id, _to_book_side(_bids), _to_book_side(_asks));
|
||||
return new(_security_md.security, book, _security_md.quantity_display);
|
||||
}
|
||||
|
||||
public bool poll_changes() =>
|
||||
_security_md.md.get_depth(
|
||||
ref _last_update_time, ref _bids, ref _asks, _num_depth_levels);
|
||||
|
||||
static List<PriceSize> _to_book_side(NativePriceSize[] native_book_side) =>
|
||||
native_book_side
|
||||
.Select(nps => new PriceSize(nps.size, nps.direct_size, nps.implied_size, nps.price))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
class PollablePriceTicker {
|
||||
readonly SecurityMD _security_md;
|
||||
ulong _bbo_poll_time = 0;
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
#nullable enable
|
||||
namespace Spark.Api.MarketData;
|
||||
|
||||
using bts;
|
||||
using bts.api.core;
|
||||
|
||||
using mbts;
|
||||
|
||||
using Spark.Core.Reactive;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading;
|
||||
|
||||
public static class MarketDataExtensions {
|
||||
public static IObservable<TableUpdate<TResult, TKey>>? JoinBbo<T, TResult, TKey>(
|
||||
this IObservable<TableUpdate<T, TKey>> source,
|
||||
IObservable<IReadOnlyDictionary<uint, SecurityMD>> securities,
|
||||
Func<T, uint> getSecId,
|
||||
Func<T, Bbo, TResult> getResult,
|
||||
Func<TResult, TKey> getResultKey,
|
||||
TimeSpan? pollInterval = null
|
||||
) where TKey : IEquatable<TKey> {
|
||||
return source.JoinBooks(securities, getSecId, GetResult, getResultKey, pollInterval, 1);
|
||||
|
||||
TResult GetResult(T value, BookTuple book) =>
|
||||
getResult(value, book.bbo);
|
||||
}
|
||||
|
||||
public static IObservable<TableUpdate<(T, BookTuple), TKey>> JoinBooks<T, TKey>(
|
||||
this IObservable<TableUpdate<T, TKey>> source,
|
||||
IObservable<IReadOnlyDictionary<uint, SecurityMD>> securities,
|
||||
Func<T, uint> getSecId,
|
||||
TimeSpan? pollInterval = null,
|
||||
uint? numDepthLevels = null
|
||||
) where TKey : IEquatable<TKey> {
|
||||
// Get key function from the first update. This is for convenience (one
|
||||
// less arg), and guarentees the key is consistent with the source data.
|
||||
bool isKeyInitialized = false;
|
||||
Func<T, TKey> keyFn = _ => throw new NotImplementedException(
|
||||
"Key function expected from first update in source sequence");
|
||||
return source.SelectInline(
|
||||
s => {
|
||||
if (!isKeyInitialized) {
|
||||
isKeyInitialized = true;
|
||||
Interlocked.Exchange(ref keyFn, Log.notnull(s.key_extractor));
|
||||
}
|
||||
return s;
|
||||
})
|
||||
.JoinBooks(securities, getSecId, (v, b) => (v, b), getKey, pollInterval, numDepthLevels);
|
||||
|
||||
TKey getKey((T v, BookTuple) tup) =>
|
||||
keyFn(tup.v);
|
||||
}
|
||||
|
||||
public static IObservable<TableUpdate<TResult, TKey>> JoinBooks<T, TResult, TKey>(
|
||||
this IObservable<TableUpdate<T, TKey>> source,
|
||||
IObservable<IReadOnlyDictionary<uint, SecurityMD>> securities,
|
||||
Func<T, uint> getSecId,
|
||||
Func<T, BookTuple, TResult> getResult,
|
||||
Func<TResult, TKey> getResultKey,
|
||||
TimeSpan? pollInterval = null,
|
||||
uint? numDepthLevels = null
|
||||
) where TKey : IEquatable<TKey> {
|
||||
pollInterval ??= TimeSpan.FromSeconds(0.1);
|
||||
numDepthLevels ??= 5;
|
||||
return source.CombineLatest(securities.Select(smds => new BookStore(smds)))
|
||||
.Sample(pollInterval.Value)
|
||||
.Scan(TableUpdate<TResult, TKey>.mk_empty(getResultKey), Accumulate);
|
||||
|
||||
TableUpdate<TResult, TKey> Accumulate(TableUpdate<TResult, TKey> lastOut, (TableUpdate<T, TKey>, BookStore) lastIn) {
|
||||
var (table, bookStore) = lastIn;
|
||||
if (table is null || bookStore is null) {
|
||||
return lastOut;
|
||||
}
|
||||
var bd = lastOut.to_builder();
|
||||
var getKey = Log.notnull(table.key_extractor);
|
||||
var dirtyKeys = table.added.Concat(table.changes.New()).ToHashSet(getKey);
|
||||
lock (bookStore) {
|
||||
foreach (var secGroup in table.state.Values.GroupBy(getSecId)) {
|
||||
var pbook = bookStore.GetPollableBook(secGroup.Key);
|
||||
if (pbook is null) {
|
||||
continue;
|
||||
}
|
||||
bool isBookDirty = pbook.poll_changes();
|
||||
var book = pbook.to_book_tuple();
|
||||
var dirtyVals = secGroup.AsEnumerable();
|
||||
if (!isBookDirty) {
|
||||
dirtyVals = dirtyVals.Where(v => dirtyKeys.Contains(getKey(v)));
|
||||
}
|
||||
foreach (var v in dirtyVals) {
|
||||
var result = getResult(v, book);
|
||||
bd.add_or_update(result);
|
||||
}
|
||||
}
|
||||
return bd.to_table();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
#nullable enable
|
||||
|
||||
namespace Spark.Api.MarketData;
|
||||
|
||||
using bts.md;
|
||||
|
||||
using mbts;
|
||||
using mbts.co2;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
class PollableBook {
|
||||
readonly SecurityMD _security_md;
|
||||
readonly uint _num_depth_levels;
|
||||
ulong _last_update_time = 0;
|
||||
// Reuse the same arrays as an optimization to avoid reallocating memory on each poll.
|
||||
// Note: this will break if the code isn't called in a thread-safe manner.
|
||||
NativePriceSize[] _bids;
|
||||
NativePriceSize[] _asks;
|
||||
|
||||
public PollableBook(SecurityMD security_md, uint num_depth_levels = NativePriceHelpers.COCONUT_MAX_DEPTH) {
|
||||
_security_md = security_md;
|
||||
_num_depth_levels = num_depth_levels;
|
||||
_bids = new NativePriceSize[_num_depth_levels];
|
||||
_asks = new NativePriceSize[_num_depth_levels];
|
||||
}
|
||||
|
||||
public ulong last_update_time => _last_update_time;
|
||||
|
||||
public BookTuple to_book_tuple() {
|
||||
var book = new Book(
|
||||
_security_md.security.Id, _to_book_side(_bids), _to_book_side(_asks));
|
||||
return new(_security_md.security, book, _security_md.quantity_display);
|
||||
}
|
||||
|
||||
public bool poll_changes() =>
|
||||
_security_md.md.get_depth(
|
||||
ref _last_update_time, ref _bids, ref _asks, _num_depth_levels);
|
||||
|
||||
static List<PriceSize> _to_book_side(NativePriceSize[] native_book_side) =>
|
||||
native_book_side
|
||||
.Select(nps => new PriceSize(nps.size, nps.direct_size, nps.implied_size, nps.price))
|
||||
.ToList();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace bts.api.orderman {
|
||||
|
||||
public static class OrderUtilities {
|
||||
public static NativeOrderStateImmutable? native_order_state(this OrderStateImmutable order) {
|
||||
switch(order.CustomCase) {
|
||||
case OrderState.CustomOneofCase.Market:
|
||||
return order.Market.NativeState;
|
||||
case OrderState.CustomOneofCase.Limit:
|
||||
return order.Limit.NativeState;
|
||||
case OrderState.CustomOneofCase.Stop:
|
||||
return order.Stop.NativeState;
|
||||
case OrderState.CustomOneofCase.StopLimit:
|
||||
return order.StopLimit.NativeState;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,20 +37,6 @@ namespace Spark.Api.Orders {
|
||||
public static double fill_ratio(this OrderStateImmutable state) =>
|
||||
state.filled_quantity() / state.quantity();
|
||||
|
||||
public static NativeOrderStateImmutable? native_order_state(this OrderStateImmutable order) {
|
||||
switch(order.CustomCase) {
|
||||
case OrderState.CustomOneofCase.Market:
|
||||
return order.Market.NativeState;
|
||||
case OrderState.CustomOneofCase.Limit:
|
||||
return order.Limit.NativeState;
|
||||
case OrderState.CustomOneofCase.Stop:
|
||||
return order.Stop.NativeState;
|
||||
case OrderState.CustomOneofCase.StopLimit:
|
||||
return order.StopLimit.NativeState;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static double filled_quantity(this OrderRecordImmutable order) =>
|
||||
@@ -269,7 +255,7 @@ namespace Spark.Api.Orders {
|
||||
}
|
||||
|
||||
public static string short_description(this OrderRecordImmutable order, ContractSpecificationImmutable? spec) =>
|
||||
$"{(order.HasDef ? order.Def.Side.ToString() : "(unknown-side)")} {(order.HasState ? $@"{order.State.quantity()} @ {spec.format(order.State.Price)}" : "(unknown-price) @ (unknown-quantity)")}";
|
||||
$"{(order.HasDef ? order.Def.Side.ToString() : "(unknown-side)")} {(order.HasState ? ($@"{spec.format(order.State.Price)} @ {order.State.Quantity}") : "(unknown-price) @ (unknown-quantity)")}";
|
||||
|
||||
public static string short_description(
|
||||
SecurityImmutable security, Side side, double price, double quantity) {
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
namespace bts.shell.pnl;
|
||||
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
|
||||
using mbts.spark;
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Api.Data;
|
||||
using Spark.Api.Orders;
|
||||
using Spark.Api.Position;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
readonly struct WorkingOrderData {
|
||||
public readonly WorkingOrderSideData long_data, short_data;
|
||||
|
||||
WorkingOrderData(WorkingOrderSideData long_data, WorkingOrderSideData short_data) {
|
||||
this.long_data = long_data;
|
||||
this.short_data = short_data;
|
||||
}
|
||||
|
||||
public static WorkingOrderData Empty =>
|
||||
new(WorkingOrderSideData.EmptyLong, WorkingOrderSideData.EmptyShort);
|
||||
|
||||
public double top_bid =>
|
||||
long_data.data.Count > 0 ?
|
||||
long_data.data.First().Key :
|
||||
double.NaN;
|
||||
|
||||
public double top_ask =>
|
||||
short_data.data.Count > 0 ?
|
||||
short_data.data.First().Key :
|
||||
double.NaN;
|
||||
|
||||
public PositionPriceSize summary =>
|
||||
new(long_data.working_total, long_data.avg_price, short_data.working_total, short_data.avg_price);
|
||||
|
||||
public static WorkingOrderData Create(
|
||||
IEnumerable<OrderRecordImmutable> orders, QuantityConversionData<double> qty_conversion) =>
|
||||
Create(orders.Select(o => (o, qty_conversion)));
|
||||
|
||||
public static WorkingOrderData Create(
|
||||
IEnumerable<(OrderRecordImmutable order, QuantityConversionData<double> qty_conversion)> orders) =>
|
||||
orders.Aggregate(Empty, (seed, tup) => seed.Add(tup.order, tup.qty_conversion));
|
||||
|
||||
public WorkingOrderData Add(OrderRecordImmutable order, QuantityConversionData<double> qty_conversion) {
|
||||
if (order.working_quantity() <= 0) {
|
||||
return new(long_data, short_data);
|
||||
}
|
||||
return order.side() switch {
|
||||
Side.Buy => new(long_data.Add(order, qty_conversion), short_data),
|
||||
Side.Sell => new(long_data, short_data.Add(order, qty_conversion)),
|
||||
_ => throw ExceptionBuilder.Argument.unexpected_case(order.side(), "order.side"),
|
||||
};
|
||||
}
|
||||
|
||||
public WorkingOrderData Remove(OrderRecordImmutable order) {
|
||||
if (order.working_quantity() <= 0) {
|
||||
return new(long_data, short_data);
|
||||
}
|
||||
return order.side() switch {
|
||||
Side.Buy => new(long_data.Remove(order.Key, order.price()), short_data),
|
||||
Side.Sell => new(long_data, short_data.Remove(order.Key, order.price())),
|
||||
_ => throw ExceptionBuilder.Argument.unexpected_case(order.side(), "order.side"),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
namespace bts.shell.pnl;
|
||||
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
|
||||
using mbts.spark;
|
||||
using mbts.utils;
|
||||
|
||||
using Spark.Api.Data;
|
||||
using Spark.Api.Orders;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
|
||||
public readonly struct WorkingOrderSideData {
|
||||
public readonly double avg_price, display_avg_price;
|
||||
public readonly ImmutableSortedDictionary<double, ImmutableDictionary<uint, (OrderRecordImmutable order, QuantityConversionData<double> qty_conversion)>> data;
|
||||
public readonly double working_total;
|
||||
public readonly double display_working_total;
|
||||
|
||||
WorkingOrderSideData(
|
||||
double avg_price,
|
||||
double working_total,
|
||||
double display_avg_price,
|
||||
double display_working_total,
|
||||
ImmutableSortedDictionary<double, ImmutableDictionary<uint, (OrderRecordImmutable, QuantityConversionData<double>)>> data
|
||||
) {
|
||||
this.avg_price = avg_price;
|
||||
this.working_total = working_total;
|
||||
this.display_avg_price = display_avg_price;
|
||||
this.data = data;
|
||||
this.display_working_total = display_working_total;
|
||||
}
|
||||
|
||||
public static WorkingOrderSideData EmptyLong => new(
|
||||
double.NaN, 0, double.NaN, 0,
|
||||
ImmutableSortedDictionary.Create<double, ImmutableDictionary<uint, (OrderRecordImmutable, QuantityConversionData<double>)>>(
|
||||
new ReverseComparer<double>(new OrderPriceComparer())));
|
||||
|
||||
public static WorkingOrderSideData EmptyShort => new(
|
||||
double.NaN, 0, double.NaN, 0,
|
||||
ImmutableSortedDictionary.Create<double, ImmutableDictionary<uint, (OrderRecordImmutable, QuantityConversionData<double>)>>(
|
||||
new OrderPriceComparer()));
|
||||
|
||||
public double top_price =>
|
||||
data.Count > 0 ?
|
||||
data.First().Key :
|
||||
double.NaN;
|
||||
|
||||
public double top_volume =>
|
||||
data.Count > 0 ?
|
||||
data.Values.First().Values.Sum(o => o.order.working_quantity()) :
|
||||
0;
|
||||
|
||||
public double display_top_volume =>
|
||||
data.Count > 0 ?
|
||||
data.Values.First().Values.Sum(o => o.qty_conversion
|
||||
.convert_numeric_type<double>()
|
||||
.to_display(o.order.working_quantity())) :
|
||||
0;
|
||||
|
||||
public WorkingOrderSideData Add(OrderRecordImmutable order_record) =>
|
||||
Add(order_record, new());
|
||||
|
||||
public WorkingOrderSideData Add(
|
||||
OrderRecordImmutable order_record, QuantityConversionData<double> qty_conversion) {
|
||||
var working_qty = order_record.working_quantity();
|
||||
if (working_qty <= 0)
|
||||
throw new ArgumentException(nameof(working_qty));
|
||||
uint order = order_record.Key;
|
||||
var dworking_qty = qty_conversion.to_display(working_qty);
|
||||
double price = order_record.price();
|
||||
if (working_total == 0) {
|
||||
Log.assert(display_working_total == 0);
|
||||
return new WorkingOrderSideData(price, working_qty, display_avg_price, dworking_qty, data.Add(
|
||||
price, ImmutableDictionary<uint, (OrderRecordImmutable, QuantityConversionData<double>)>.Empty.Add(order, (order_record, qty_conversion))));
|
||||
} else return new WorkingOrderSideData(
|
||||
avg_price + ((price - avg_price) * ((double)working_qty / (working_total + working_qty))),
|
||||
working_total + working_qty,
|
||||
display_avg_price + ((price - display_avg_price) * ((double)dworking_qty / (display_working_total + dworking_qty))),
|
||||
display_working_total + dworking_qty,
|
||||
data.SetItem(price, data.TryGetValue(price, out var curr) ?
|
||||
curr.Add(order, (order_record, qty_conversion)) :
|
||||
ImmutableDictionary<uint, (OrderRecordImmutable, QuantityConversionData<double>)>.Empty.Add(order, (order_record, qty_conversion))));
|
||||
}
|
||||
|
||||
public WorkingOrderSideData Remove(uint order, double price) {
|
||||
var tmp_data = data;
|
||||
if (!tmp_data.TryGetValue(price, out var wdata))
|
||||
throw new KeyNotFoundException(nameof(price));
|
||||
if (!wdata.TryGetValue(order, out var worder))
|
||||
throw new KeyNotFoundException(nameof(order));
|
||||
var wqty = worder.order.working_quantity();
|
||||
var dwqty = worder.qty_conversion.to_display(wqty);
|
||||
wdata = wdata.Remove(order);
|
||||
if (wdata.Count == 0)
|
||||
tmp_data = tmp_data.Remove(price);
|
||||
if (tmp_data.Count == 0)
|
||||
return new(
|
||||
double.NaN, 0, double.NaN, 0,
|
||||
ImmutableSortedDictionary.Create<double, ImmutableDictionary<uint, (OrderRecordImmutable, QuantityConversionData<double>)>>(
|
||||
data.KeyComparer));
|
||||
return new(
|
||||
avg_price - ((price - avg_price) * (wqty / (working_total - wqty))),
|
||||
working_total - wqty,
|
||||
display_avg_price - ((price - display_avg_price) * (dwqty / (display_working_total - dwqty))),
|
||||
display_working_total - dwqty,
|
||||
tmp_data);
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
if (data.Count > 0) {
|
||||
if (display_working_total == 0) {
|
||||
return string.Empty;
|
||||
}
|
||||
var spec = Security.Defaults.ContractSpecificationImmutable;
|
||||
var best_order = data.Values.First().Values.First();
|
||||
var best_price_volume = best_order.qty_conversion.to_display(best_order.order.working_quantity());
|
||||
var best_price = best_order.order.price();
|
||||
return display_working_total == best_price_volume ?
|
||||
$"{best_price_volume} @ {spec.format(best_price)}" :
|
||||
$"{best_price_volume} ({display_working_total}) @ {spec.format(best_price)}";
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
namespace Spark.Api.Data;
|
||||
|
||||
using mbts.ui;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
|
||||
public class DisplayQuantityMultiplier<T> : IDisplayTranslator<T> where T : struct, INumber<T> {
|
||||
readonly Func<QuantityConversionData<T>, T, T> _to_display, _from_display;
|
||||
readonly IEqualityComparer<T> _comparer;
|
||||
T _actual_value;
|
||||
QuantityConversionData<T> _conversion_data;
|
||||
|
||||
public DisplayQuantityMultiplier(
|
||||
Func<QuantityConversionData<T>, T, T> to_display,
|
||||
Func<QuantityConversionData<T>, T, T> from_display,
|
||||
IEqualityComparer<T> comparer = null,
|
||||
T actual_value = default,
|
||||
QuantityConversionData<T> conversion_data = default) {
|
||||
//
|
||||
_to_display = to_display ?? throw new ArgumentNullException(nameof(to_display));
|
||||
_from_display = from_display ?? throw new ArgumentNullException(nameof(from_display));
|
||||
_comparer = comparer ?? EqualityComparer<T>.Default;
|
||||
_actual_value = actual_value;
|
||||
_conversion_data = conversion_data;
|
||||
}
|
||||
|
||||
public event Action value_changed;
|
||||
|
||||
public T actual_value {
|
||||
get => _actual_value;
|
||||
set {
|
||||
if (!_comparer.Equals(_actual_value, value)) {
|
||||
_actual_value = value;
|
||||
value_changed?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T display_value {
|
||||
get => _to_display(_conversion_data, _actual_value);
|
||||
set => actual_value = _from_display(_conversion_data, value);
|
||||
}
|
||||
|
||||
public QuantityConversionData<T> conversion_data {
|
||||
get => _conversion_data;
|
||||
set {
|
||||
if (_conversion_data != value) {
|
||||
_conversion_data = value;
|
||||
value_changed?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class OptionalDisplayQuantityMultiplier<T> : IDisplayTranslator<T?> where T : struct, INumber<T> {
|
||||
T? _actual_value;
|
||||
QuantityConversionData<T> _conversion_data;
|
||||
|
||||
public event Action value_changed;
|
||||
|
||||
public T? actual_value {
|
||||
get => _actual_value;
|
||||
set {
|
||||
if (_actual_value != value) {
|
||||
_actual_value = value;
|
||||
value_changed?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T? display_value {
|
||||
get => _actual_value.HasValue ?
|
||||
_conversion_data.to_display(_actual_value.Value) : _actual_value;
|
||||
set => actual_value = value.HasValue ?
|
||||
_conversion_data.from_display(value.Value) : value;
|
||||
}
|
||||
|
||||
public QuantityConversionData<T> conversion_data {
|
||||
get => _conversion_data;
|
||||
set {
|
||||
if (_conversion_data != value) {
|
||||
_conversion_data = value;
|
||||
value_changed?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class DisplayQuantityMultiplier {
|
||||
public static DisplayQuantityMultiplier<uint> create_uint() => new(
|
||||
DisplayTranslatorExtensions.to_display,
|
||||
DisplayTranslatorExtensions.from_display);
|
||||
|
||||
public static DisplayQuantityMultiplier<double> create_double() => new(
|
||||
DisplayTranslatorExtensions.to_display,
|
||||
DisplayTranslatorExtensions.from_display);
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
namespace Spark.Api.Data;
|
||||
|
||||
using bts.api;
|
||||
|
||||
using mbts.utils;
|
||||
|
||||
using System;
|
||||
|
||||
public enum ExpirationDateType {
|
||||
None = 0,
|
||||
FixedDate = 1,
|
||||
Perpetual = 2
|
||||
}
|
||||
|
||||
public readonly struct ExpirationDate : IEquatable<ExpirationDate>, IComparable<ExpirationDate> {
|
||||
public ExpirationDate(DateTime value, ExpirationDateType type) {
|
||||
Value = value;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public static ExpirationDate None => new(default, ExpirationDateType.None);
|
||||
public static ExpirationDate Perpetual => new(default, ExpirationDateType.Perpetual);
|
||||
public static ExpirationDate FixedDate(DateTime dateTime) => new(dateTime, ExpirationDateType.FixedDate);
|
||||
|
||||
public DateTime Value { get; }
|
||||
public ExpirationDateType Type { get; }
|
||||
|
||||
static ComparerBuilder<ExpirationDate> comparer = new ComparerBuilder<ExpirationDate>() {
|
||||
ed => ed.Type,
|
||||
ed => ed.Value
|
||||
};
|
||||
|
||||
public int CompareTo(ExpirationDate other) =>
|
||||
comparer.Compare(this, other);
|
||||
|
||||
public bool Equals(ExpirationDate other) =>
|
||||
Value == other.Value && Type == other.Type;
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
obj is ExpirationDate other && Equals(other);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
HashCode.Combine(Value.GetHashCode(), (int)Type);
|
||||
|
||||
public override string ToString() =>
|
||||
ToString(DateFormat.DayMonthAbvDiff2000);
|
||||
|
||||
public string ToString(DateFormat dateFormat) =>
|
||||
Type switch {
|
||||
ExpirationDateType.None => "None",
|
||||
ExpirationDateType.FixedDate => DateFormatter.Format(Value, dateFormat),
|
||||
ExpirationDateType.Perpetual => "Perp",
|
||||
_ => "Invalid",
|
||||
};
|
||||
|
||||
public static bool operator ==(ExpirationDate left, ExpirationDate right) =>
|
||||
left.Equals(right);
|
||||
|
||||
public static bool operator !=(ExpirationDate left, ExpirationDate right) =>
|
||||
!left.Equals(right);
|
||||
|
||||
public static bool operator <(ExpirationDate left, ExpirationDate right) =>
|
||||
comparer.Compare(left, right) < 0;
|
||||
|
||||
public static bool operator >(ExpirationDate left, ExpirationDate right) =>
|
||||
comparer.Compare(left, right) > 0;
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
using bts.utils;
|
||||
|
||||
using Spark.Core.Disposables;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
namespace Spark.Api.Data;
|
||||
|
||||
public interface IDisplayTranslator<T> {
|
||||
T display_value { get; set; }
|
||||
T actual_value { get; set; }
|
||||
event Action value_changed;
|
||||
}
|
||||
|
||||
public static class DisplayTranslatorExtensions {
|
||||
public static IObservable<T> subscribe_actual_value<T>(
|
||||
this IDisplayTranslator<T> display_translator) =>
|
||||
subscribe_actual_value(display_translator, EqualityComparer<T>.Default);
|
||||
|
||||
public static IObservable<T> subscribe_actual_value<T>(
|
||||
this IDisplayTranslator<T> display_translator, IEqualityComparer<T> comparer) {
|
||||
if (comparer is null)
|
||||
throw new ArgumentNullException(nameof(comparer));
|
||||
return Observable.Create<T>(o => {
|
||||
var curr = display_translator.actual_value;
|
||||
o.OnNext(curr);
|
||||
display_translator.value_changed += on_value_changed;
|
||||
return Disposable.Create(() => display_translator.value_changed -= on_value_changed);
|
||||
void on_value_changed() {
|
||||
var next = display_translator.actual_value;
|
||||
if (!comparer.Equals(curr, next))
|
||||
o.OnNext(curr = next);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static T to_display<T>(
|
||||
this QuantityConversionData<T> quantity_conversion_data, T actual_value)
|
||||
where T : INumber<T> =>
|
||||
quantity_conversion_data.op switch {
|
||||
QuantityConversionOpType.DivideActual =>
|
||||
actual_value.safe_divide(quantity_conversion_data.value),
|
||||
QuantityConversionOpType.MultiplyActual =>
|
||||
actual_value * quantity_conversion_data.value,
|
||||
_ => actual_value,
|
||||
};
|
||||
|
||||
public static T from_display<T>(
|
||||
this QuantityConversionData<T> quantity_conversion_data, T display_value)
|
||||
where T : INumber<T> =>
|
||||
quantity_conversion_data.op switch {
|
||||
QuantityConversionOpType.DivideActual => display_value * quantity_conversion_data.value,
|
||||
QuantityConversionOpType.MultiplyActual =>
|
||||
display_value.safe_divide(quantity_conversion_data.value),
|
||||
_ => display_value,
|
||||
};
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
namespace Spark.Api.Data;
|
||||
|
||||
using Spark.Core;
|
||||
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
public enum QuantityConversionOpType {
|
||||
None,
|
||||
MultiplyActual,
|
||||
DivideActual
|
||||
}
|
||||
|
||||
public readonly struct QuantityConversionData<T> : IEquatable<QuantityConversionData<T>>
|
||||
where T : INumber<T> {
|
||||
public QuantityConversionData(T value, QuantityConversionOpType op) {
|
||||
this.value = value;
|
||||
this.op = op;
|
||||
}
|
||||
|
||||
public T value { get; }
|
||||
public QuantityConversionOpType op { get; }
|
||||
|
||||
public QuantityConversionData<TResult> convert_numeric_type<TResult>()
|
||||
where TResult : INumber<TResult> =>
|
||||
new(NumericCastConverter<T, TResult>.convert(value), op);
|
||||
|
||||
public bool Equals(QuantityConversionData<T> other) =>
|
||||
value == other.value &&
|
||||
op == other.op;
|
||||
|
||||
public override bool Equals(object obj) =>
|
||||
obj is QuantityConversionData<T> other && Equals(other);
|
||||
|
||||
public override int GetHashCode() =>
|
||||
HashCode.Combine(value, op);
|
||||
|
||||
public static bool operator ==(QuantityConversionData<T> x, QuantityConversionData<T> y) =>
|
||||
x.Equals(y);
|
||||
|
||||
public static bool operator !=(QuantityConversionData<T> x, QuantityConversionData<T> y) =>
|
||||
!x.Equals(y);
|
||||
}
|
||||
@@ -5,7 +5,6 @@ namespace mbts.spark {
|
||||
|
||||
using ProtoBuf;
|
||||
|
||||
using Spark.Api.Data;
|
||||
using Spark.Core.Collections;
|
||||
using Spark.Core.Protobuf;
|
||||
|
||||
@@ -28,9 +27,6 @@ namespace mbts.spark {
|
||||
internal static SecurityCriteria from_keys(IEnumerable<uint> keys) =>
|
||||
new(new[] { new SecurityCriteriaClause(security_keys: keys.ToArray()) });
|
||||
|
||||
internal static SecurityCriteria from_expirations(params ExpirationDate[] exp_dates) =>
|
||||
new(new[] { new SecurityCriteriaClause(expirations: exp_dates) });
|
||||
|
||||
internal static SecurityCriteria from_expirations(params DateTime[] exp_dates) =>
|
||||
from_expirations(exp_dates.AsEnumerable());
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace mbts.spark {
|
||||
|
||||
using ProtoBuf;
|
||||
|
||||
using Spark.Api.Data;
|
||||
using Spark.Core.Collections;
|
||||
using Spark.Core.Protobuf;
|
||||
|
||||
@@ -18,12 +17,12 @@ namespace mbts.spark {
|
||||
Venue[]? exchanges = null,
|
||||
SecurityType[]? security_types = null,
|
||||
string[]? symbols = null,
|
||||
ExpirationDate[]? expirations = null,
|
||||
DateTime[]? expirations = null,
|
||||
uint[]? security_keys = null,
|
||||
string? pretty_name = null,
|
||||
double[]? strikes = null,
|
||||
PutOrCall[]? callputs = null,
|
||||
string[]? names = null
|
||||
string[]? names= null
|
||||
) {
|
||||
this.exchanges = exchanges;
|
||||
this.security_types = security_types;
|
||||
@@ -33,7 +32,7 @@ namespace mbts.spark {
|
||||
this.pretty_name = pretty_name;
|
||||
this.strikes = strikes;
|
||||
this.callputs = callputs;
|
||||
this.names = names;
|
||||
this.names=names;
|
||||
}
|
||||
|
||||
public static SecurityCriteriaClause from_securities(
|
||||
@@ -59,18 +58,12 @@ namespace mbts.spark {
|
||||
return new SecurityCriteriaClause(security_keys: keys, pretty_name: pretty_name);
|
||||
}
|
||||
|
||||
public static SecurityCriteriaClause from_expirations(IEnumerable<DateTime> expirations) {
|
||||
return expirations is null
|
||||
public static SecurityCriteriaClause from_expirations(IEnumerable<DateTime> expirations) =>
|
||||
expirations is null
|
||||
? new()
|
||||
: from_expirations(expirations.Select(convert).ToArray());
|
||||
: from_expirations(expirations as DateTime[] ?? expirations.ToArray());
|
||||
|
||||
static ExpirationDate convert(DateTime e) =>
|
||||
Security.is_perpetual_exp(e)
|
||||
? ExpirationDate.Perpetual
|
||||
: ExpirationDate.FixedDate(e);
|
||||
}
|
||||
|
||||
public static SecurityCriteriaClause from_expirations(params ExpirationDate[] expirations) =>
|
||||
public static SecurityCriteriaClause from_expirations(params DateTime[] expirations) =>
|
||||
new(expirations: expirations);
|
||||
|
||||
[ProtoMember(1)]
|
||||
@@ -86,7 +79,7 @@ namespace mbts.spark {
|
||||
public string[]? symbols { get; }
|
||||
|
||||
// Not stored in protobuf (yet)
|
||||
public ExpirationDate[]? expirations { get; }
|
||||
public DateTime[]? expirations { get; }
|
||||
|
||||
[ProtoMember(5)]
|
||||
public uint[]? security_keys { get; }
|
||||
|
||||
@@ -3,8 +3,6 @@ namespace mbts.spark {
|
||||
using bts.api;
|
||||
using bts.collections;
|
||||
|
||||
using Spark.Api.Data;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -182,7 +180,7 @@ namespace mbts.spark {
|
||||
Venue[]? exchanges = null,
|
||||
SecurityType[]? security_types = null,
|
||||
string[]? symbols = null,
|
||||
ExpirationDate[]? expirations = null,
|
||||
DateTime[]? expirations = null,
|
||||
uint[]? security_keys = null,
|
||||
string? pretty_name = null,
|
||||
double[]? strikes = null,
|
||||
|
||||
@@ -567,9 +567,6 @@ namespace mbts {
|
||||
public static double round(this bts.api.domain.TickFactorsImmutable tick, double input) =>
|
||||
_round_tick(tick.tick_unit_frac(), input);
|
||||
|
||||
public static void round(this bts.api.domain.TickFactorsImmutable tick, ref double input) =>
|
||||
input = _round_tick(tick.tick_unit_frac(), input);
|
||||
|
||||
public static double round(this RegionalTickFactors regional_tick, double input) {
|
||||
if (DoubleHelper.IsNaNOrInfinity(input)) {
|
||||
return input;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace bts.api {
|
||||
public static security_key key(Security s) { return s.Id; }
|
||||
|
||||
public static bool is_perpetual_exp(DateTime exp) =>
|
||||
exp.Year < 2000 || exp.Year > 2099;
|
||||
exp.Year < 2000 || exp.Year > 2999;
|
||||
|
||||
public static class Defaults {
|
||||
public static ContractSpecification ContractSpecification =>
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
namespace bts.api {
|
||||
using Spark.Core.Collections;
|
||||
using mbts.utils;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
class SecurityComparer : IComparer<Security>, IComparer<SecurityImmutable> {
|
||||
static readonly SecurityComparer _instance = new();
|
||||
@@ -24,24 +25,182 @@ namespace bts.api {
|
||||
}
|
||||
|
||||
public static int compare(SecurityImmutable x, SecurityImmutable y) {
|
||||
var xlegs = new ContractLegEnumerable(x);
|
||||
var ylegs = new ContractLegEnumerable(y);
|
||||
using var xen = xlegs.GetEnumerator();
|
||||
using var yen = ylegs.GetEnumerator();
|
||||
int c = 0;
|
||||
while (xen.MoveNext()) {
|
||||
if (!yen.MoveNext()) {
|
||||
return 1;
|
||||
}
|
||||
c = new ComparisonCriteria(xen.Current).CompareTo(new(yen.Current));
|
||||
if (c != 0) {
|
||||
return c;
|
||||
int c = non_deterministic_impl();
|
||||
if (c == 0) {
|
||||
c = x.ToString().CompareTo(y.ToString());
|
||||
if (c == 0) {
|
||||
c = x.Id.CompareTo(y.Id);
|
||||
}
|
||||
}
|
||||
if (yen.MoveNext()) {
|
||||
return -1;
|
||||
return c;
|
||||
|
||||
// this has been observed to be non-determinisitc with certain ICE securities
|
||||
// (it is determenistic with other exchanges..as far as we know).
|
||||
int non_deterministic_impl() {
|
||||
// | Type 1 | Type 2 | Comp Hierarchy |
|
||||
// |------------------------------------------|
|
||||
// | SPOT | SPOT | sym, curr |
|
||||
// | SPOT | FUT | sym, curr |
|
||||
// | SPOT | OPT | SPOT < OPT |
|
||||
// | SPOT | SPREAD | * SPOT < SPREAD |
|
||||
// | SPOT | SYNTH | * SPOT < SYNTH |
|
||||
// | FUT | FUT | sym, exp, curr |
|
||||
// | FUT | OPT | * FUT < OPT |
|
||||
// | FUT | SPREAD | * FUT < SPREAD |
|
||||
// | FUT | SYNTH | * FUT < SYNTH |
|
||||
// | OPT | OPT | sym, exp, curr, k, c/p |
|
||||
// | OPT | SPREAD | OPT <=> first leg |
|
||||
// | OPT | SYNTH | OPT <=> first leg |
|
||||
// | SPREAD | SPREAD | legs <=> legs |
|
||||
// | SPREAD | SYNTH | legs <=> legs |
|
||||
//
|
||||
// * comp result is constant (there is no comp hierarchy)
|
||||
|
||||
return x.ContractCase switch {
|
||||
Security.ContractOneofCase.Future =>
|
||||
y.ContractCase switch {
|
||||
Security.ContractOneofCase.Spot =>
|
||||
new ComparerBuilder<SecurityImmutable> {
|
||||
s => s.Symbol,
|
||||
s => s.Currency
|
||||
}.Compare(x, y),
|
||||
Security.ContractOneofCase.Future =>
|
||||
new ComparerBuilder<SecurityImmutable> {
|
||||
s => s.Symbol,
|
||||
s => s.Future.expiration_date()
|
||||
}.Compare(x, y),
|
||||
Security.ContractOneofCase.Option or
|
||||
Security.ContractOneofCase.Spread or
|
||||
Security.ContractOneofCase.Synthetic => -1,
|
||||
_ => 1,
|
||||
},
|
||||
Security.ContractOneofCase.Spot =>
|
||||
y.ContractCase switch {
|
||||
Security.ContractOneofCase.Spot or
|
||||
Security.ContractOneofCase.Future =>
|
||||
new ComparerBuilder<SecurityImmutable> {
|
||||
s => s.Symbol,
|
||||
s => s.Currency
|
||||
}.Compare(x, y),
|
||||
_ => -1,
|
||||
},
|
||||
Security.ContractOneofCase.Option or
|
||||
Security.ContractOneofCase.Spread or
|
||||
Security.ContractOneofCase.Synthetic =>
|
||||
y.ContractCase switch {
|
||||
Security.ContractOneofCase.Spread or
|
||||
Security.ContractOneofCase.Synthetic or
|
||||
Security.ContractOneofCase.Option => compare_flat_legs(),
|
||||
_ => 1,
|
||||
},
|
||||
Security.ContractOneofCase.None =>
|
||||
y.ContractCase == Security.ContractOneofCase.None ? 0 : -1,
|
||||
_ => throw new InvalidOperationException(),
|
||||
};
|
||||
}
|
||||
return 0;
|
||||
|
||||
int compare_flat_legs() {
|
||||
var xlegs = new ContractLegEnumerable(x).ToList();
|
||||
var ylegs = new ContractLegEnumerable(y).ToList();
|
||||
int max = Math.Min(xlegs.Count, ylegs.Count);
|
||||
for (int i = 0; i < max; i++) {
|
||||
var xleg = xlegs[i];
|
||||
var yleg = ylegs[i];
|
||||
int comp = _compare(
|
||||
xleg.Security, xleg.signed_quantity(),
|
||||
yleg.Security, yleg.signed_quantity());
|
||||
if (comp != 0) {
|
||||
return comp;
|
||||
}
|
||||
}
|
||||
return xlegs.Count.CompareTo(ylegs.Count);
|
||||
}
|
||||
}
|
||||
|
||||
public static int compare(string x_sym, FutureContract x, string y_sym, FutureContract y) {
|
||||
int sym_comp = x_sym.CompareTo(y_sym);
|
||||
return sym_comp == 0 ? x.expiration_date().CompareTo(y.expiration_date()) : sym_comp;
|
||||
}
|
||||
|
||||
public static int compare(string x_sym, FutureContractImmutable x, string y_sym, FutureContractImmutable y) {
|
||||
int sym_comp = x_sym.CompareTo(y_sym);
|
||||
return sym_comp == 0 ? x.expiration_date().CompareTo(y.expiration_date()) : sym_comp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares option/future securities
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentException"/>
|
||||
static int _compare(SecurityImmutable x, double xqty, SecurityImmutable y, double yqty) {
|
||||
static bool is_valid_sec_type(SecurityImmutable sec) =>
|
||||
sec.ContractCase switch {
|
||||
Security.ContractOneofCase.Spot or
|
||||
Security.ContractOneofCase.Future or
|
||||
Security.ContractOneofCase.Option => true,
|
||||
_ => false
|
||||
};
|
||||
if (!is_valid_sec_type(x)) {
|
||||
throw new ArgumentException("Security not of type Option or Future", nameof(x));
|
||||
}
|
||||
if (!is_valid_sec_type(y)) {
|
||||
throw new ArgumentException("Security not of type Option or Future", nameof(y));
|
||||
}
|
||||
|
||||
// symbol
|
||||
int comp = string.Compare(x.Symbol, y.Symbol);
|
||||
if (comp != 0) {
|
||||
return comp;
|
||||
}
|
||||
|
||||
// expiration
|
||||
var xexp = x.security_expiration();
|
||||
var yexp = y.security_expiration();
|
||||
if (xexp.HasValue) {
|
||||
if (!yexp.HasValue) {
|
||||
return -1;
|
||||
}
|
||||
comp = xexp.Value.CompareTo(yexp.Value);
|
||||
if (comp != 0) {
|
||||
return comp;
|
||||
}
|
||||
} else if (yexp.HasValue) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// strike
|
||||
var xk = x.strike();
|
||||
var yk = y.strike();
|
||||
if (double.IsNaN(xk) != double.IsNaN(yk)) {
|
||||
return double.IsNaN(xk) ? -1 : 1;
|
||||
}
|
||||
if (!double.IsNaN(xk)) {
|
||||
comp = xk.CompareTo(yk);
|
||||
if (comp != 0) {
|
||||
return comp;
|
||||
}
|
||||
}
|
||||
|
||||
// security type
|
||||
comp = x.ContractCase.CompareTo(y.ContractCase);
|
||||
if (comp != 0) {
|
||||
return comp;
|
||||
}
|
||||
|
||||
// quantity
|
||||
comp = xqty.CompareTo(yqty);
|
||||
if (comp != 0) {
|
||||
return comp;
|
||||
}
|
||||
|
||||
// venue
|
||||
comp = x.Exchange.CompareTo(y.Exchange);
|
||||
if (comp != 0) {
|
||||
return comp;
|
||||
}
|
||||
|
||||
// id
|
||||
comp = x.Id.CompareTo(y.Id);
|
||||
return comp;
|
||||
}
|
||||
|
||||
int IComparer<Security>.Compare(Security x, Security y) =>
|
||||
@@ -49,65 +208,5 @@ namespace bts.api {
|
||||
|
||||
int IComparer<SecurityImmutable>.Compare(SecurityImmutable x, SecurityImmutable y) =>
|
||||
compare(x, y);
|
||||
|
||||
readonly struct ComparisonCriteria : IComparable<ComparisonCriteria> {
|
||||
readonly SecurityImmutable security;
|
||||
readonly double legQty;
|
||||
|
||||
public ComparisonCriteria(SecurityImmutable security) {
|
||||
this.security = security;
|
||||
legQty = 1;
|
||||
}
|
||||
|
||||
public ComparisonCriteria(ContractLegImmutable leg) {
|
||||
security = leg.Security;
|
||||
legQty = leg.signed_quantity();
|
||||
}
|
||||
|
||||
public string Symbol => security.Symbol;
|
||||
public DateTime? Expiration => security.ContractCase switch {
|
||||
Security.ContractOneofCase.Future => security.Future.expiration_date(),
|
||||
Security.ContractOneofCase.Option => security.Option.expiration_date(),
|
||||
_ => null,
|
||||
};
|
||||
public string Currency => security.Currency;
|
||||
public double? Strike => security.HasOption ? security.Option.Strike : null;
|
||||
public PutOrCall? CallPut => security.HasOption ? security.Option.CallPut : null;
|
||||
public Venue Exchange => security.Exchange;
|
||||
public uint Id => security.Id;
|
||||
|
||||
public int CompareTo(ComparisonCriteria other) {
|
||||
var c = string.Compare(Symbol, other.Symbol);
|
||||
if (c != 0) {
|
||||
return c;
|
||||
}
|
||||
c = NullCheckComparer.Compare(Expiration, other.Expiration);
|
||||
if (c != 0) {
|
||||
return c;
|
||||
}
|
||||
c = string.Compare(Currency, other.Currency);
|
||||
if (c != 0) {
|
||||
return c;
|
||||
}
|
||||
c = NullCheckComparer.Compare(Strike, other.Strike);
|
||||
if (c != 0) {
|
||||
return c;
|
||||
}
|
||||
c = NullCheckComparer.Compare(CallPut, other.CallPut);
|
||||
if (c != 0) {
|
||||
return c;
|
||||
}
|
||||
c = NullCheckComparer.Compare(Exchange, other.Exchange);
|
||||
if (c != 0) {
|
||||
return c;
|
||||
}
|
||||
c = legQty.CompareTo(other.legQty);
|
||||
if (c != 0) {
|
||||
return c;
|
||||
}
|
||||
c = Id.CompareTo(other.Id);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
namespace bts.api {
|
||||
using Spark.Api.Data;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -39,20 +37,15 @@ namespace bts.api {
|
||||
};
|
||||
}
|
||||
|
||||
public static IEnumerable<ExpirationDate> normal_expirations(this SecurityImmutable security) {
|
||||
return security.ContractCase switch {
|
||||
Security.ContractOneofCase.Spot => new[] { ExpirationDate.None },
|
||||
Security.ContractOneofCase.Future => new[] { future_exp(security.Future.expiration_date()) },
|
||||
Security.ContractOneofCase.Option => new[] { ExpirationDate.FixedDate(security.Option.expiration_date()) },
|
||||
public static IEnumerable<DateTime> normal_expirations(this SecurityImmutable security) =>
|
||||
security.ContractCase switch {
|
||||
Security.ContractOneofCase.Future => new[] { security.Future.expiration_date() },
|
||||
Security.ContractOneofCase.Option => new[] { security.Option.expiration_date() },
|
||||
Security.ContractOneofCase.Spread => security.Spread.Legs.SelectMany(l => l.Security.normal_expirations()),
|
||||
Security.ContractOneofCase.Synthetic => security.Synthetic.Legs.SelectMany(l => l.Security.normal_expirations()),
|
||||
_ => Enumerable.Empty<ExpirationDate>()
|
||||
_ => Enumerable.Empty<DateTime>()
|
||||
};
|
||||
|
||||
static ExpirationDate future_exp(DateTime exp_date) =>
|
||||
Security.is_perpetual_exp(exp_date) ? ExpirationDate.Perpetual : ExpirationDate.FixedDate(exp_date);
|
||||
}
|
||||
|
||||
public static ProductImmutable product(this SecurityImmutable security) =>
|
||||
new(new() {
|
||||
Exchange = security.Exchange,
|
||||
@@ -75,7 +68,7 @@ namespace bts.api {
|
||||
public static DateTime expiration_date(this FutureContractImmutable future) =>
|
||||
new((int)future.ExpirationYear, (int)future.ExpirationMonth, (int)future.ExpirationDay);
|
||||
|
||||
internal static ExpirationDate earliest_expiration(this SecurityImmutable security) =>
|
||||
internal static DateTime earliest_expiration(this SecurityImmutable security) =>
|
||||
security.normal_expirations().Min();
|
||||
|
||||
public static double strike(this SecurityImmutable security) =>
|
||||
@@ -142,7 +135,6 @@ namespace bts.api {
|
||||
domain.SecurityType.Future => SecurityType.Future,
|
||||
domain.SecurityType.Option => SecurityType.Option,
|
||||
domain.SecurityType.Spread => SecurityType.Spread,
|
||||
domain.SecurityType.Synthetic => SecurityType.Synthetic,
|
||||
domain.SecurityType.Unspecified => SecurityType.Unset,
|
||||
_ => throw new NotImplementedException(),
|
||||
};
|
||||
@@ -153,7 +145,6 @@ namespace bts.api {
|
||||
SecurityType.Future => domain.SecurityType.Future,
|
||||
SecurityType.Option => domain.SecurityType.Option,
|
||||
SecurityType.Spread => domain.SecurityType.Spread,
|
||||
SecurityType.Synthetic => domain.SecurityType.Synthetic,
|
||||
SecurityType.Unset => domain.SecurityType.Unspecified,
|
||||
_ => throw new NotImplementedException(),
|
||||
};
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
namespace bts.api {
|
||||
using Spark.Api.Data;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
@@ -108,10 +106,8 @@
|
||||
string? symbol = null,
|
||||
Security.ContractOneofCase? type = null,
|
||||
DateFormat date_format = DateFormat.DayMonthAbvDiff2000) {
|
||||
var exp_type = Security.is_perpetual_exp(exp_date)
|
||||
? ExpirationDateType.Perpetual
|
||||
: ExpirationDateType.FixedDate;
|
||||
var result = new ExpirationDate(exp_date, exp_type).ToString(date_format);
|
||||
var result = Security.is_perpetual_exp(exp_date) ?
|
||||
"Perp" : DateFormatter.Format(exp_date, date_format);
|
||||
if (symbol is not null) {
|
||||
result = symbol + " " + result;
|
||||
}
|
||||
|
||||
+149
-149
@@ -1,149 +1,149 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace bts.collections {
|
||||
class OperableHierarchicalCollectionModel<TRow, T, TKey> where TKey : IEquatable<TKey> where TRow : IHierarchicalRow<T> {
|
||||
readonly Func<T, TRow> _row_factory;
|
||||
readonly Func<T, TKey> _key;
|
||||
SortedTree<TRow, TKey> _tree;
|
||||
IComparer<TRow> _comparer;
|
||||
Func<TRow, bool> _filter;
|
||||
IEnumerable<INode<TRow>> _cached_filtered = Enumerable.Empty<INode<TRow>>();
|
||||
|
||||
public OperableHierarchicalCollectionModel(Func<T, TRow> row_factory, Func<T, TKey> key, Func<T, TKey> parent_key, TKey no_parent_key, IComparer<TRow> comparer) {
|
||||
_row_factory = row_factory;
|
||||
_tree = new SortedTree<TRow, TKey>(_comparer = comparer, el => key(el.value), el => parent_key(el.value), no_parent_key);
|
||||
_key = key;
|
||||
}
|
||||
|
||||
public IComparer<TRow> comparer {
|
||||
get => _comparer;
|
||||
set {
|
||||
_tree = _tree.Resort(_comparer = value);
|
||||
_cached_filtered = null;
|
||||
}
|
||||
}
|
||||
public Func<TRow, bool> filter {
|
||||
get => _filter;
|
||||
set {
|
||||
_filter = value;
|
||||
_cached_filtered = null;
|
||||
_refresh_hierarchical_props();
|
||||
}
|
||||
}
|
||||
public IEnumerable<TRow> rows {
|
||||
get {
|
||||
return _root_nodes.SelectMany(impl);
|
||||
IEnumerable<TRow> impl(INode<TRow> n) {
|
||||
yield return n.value;
|
||||
if (n.value.is_expanded) {
|
||||
foreach (var _n in n.inner.SelectMany(impl))
|
||||
yield return _n;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<TRow> all_rows {
|
||||
get {
|
||||
return _root_nodes.SelectMany(impl);
|
||||
IEnumerable<TRow> impl(INode<TRow> n) {
|
||||
yield return n.value;
|
||||
foreach (var _n in n.inner.SelectMany(impl))
|
||||
yield return _n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int total_row_count { get; private set; }
|
||||
|
||||
IEnumerable<INode<TRow>> _root_nodes =>
|
||||
_filter == null ? _tree.RootNodes : (_cached_filtered ??= _tree.RootNodes.filtered(_filter));
|
||||
|
||||
public IEnumerable<TRow> GetAllRows(bool excludeFiltered = false) =>
|
||||
excludeFiltered ? all_rows : _tree;
|
||||
// collapse
|
||||
public void collapse_row(TKey key) => _toggle_is_expanded(key, false);
|
||||
public void collapse_all() => _toggle_is_expanded(false);
|
||||
// expand
|
||||
public void expand_row(TKey key) => _toggle_is_expanded(key, true);
|
||||
public void expand_all() => _toggle_is_expanded(true);
|
||||
// lookups
|
||||
public bool try_get_row(TKey key, out TRow row) {
|
||||
if (_tree.TryGetNode(key, out var node)) {
|
||||
row = node.value;
|
||||
return true;
|
||||
}
|
||||
row = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
public TRow get_parent(TKey key) {
|
||||
if (try_get_row(key, out TRow r)) {
|
||||
return _tree.GetParent(r).value;
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
||||
public IEnumerable<TRow> get_descendent_rows(TKey key) {
|
||||
if (_tree.TryGetNode(key, out var n)) {
|
||||
yield return n.value;
|
||||
foreach (var v in n.inner_values())
|
||||
yield return v;
|
||||
}
|
||||
}
|
||||
|
||||
// update
|
||||
public void update(IEnumerable<T> added, IEnumerable<T> changed, IEnumerable<TKey> removed) {
|
||||
foreach (var k in removed) {
|
||||
if (_tree.Remove(k))
|
||||
total_row_count--;
|
||||
}
|
||||
foreach (var v in changed) {
|
||||
_tree.TryReplace(_key(v), r => { r.on_value_changed(v); return r; });
|
||||
}
|
||||
foreach (var v in added) {
|
||||
if (_tree.Insert(_row_factory(v)))
|
||||
total_row_count++;
|
||||
}
|
||||
_cached_filtered = null;
|
||||
_refresh_hierarchical_props();
|
||||
}
|
||||
|
||||
void _refresh_hierarchical_props() {
|
||||
foreach (var n in _root_nodes)
|
||||
impl(n, 0);
|
||||
void impl(INode<TRow> n, int depth_level) {
|
||||
if (n.value.depth_level != depth_level) {
|
||||
n.value.on_depth_level_changed(depth_level);
|
||||
}
|
||||
using (var en = n.inner.GetEnumerator()) {
|
||||
if (en.MoveNext()) {
|
||||
if (!n.value.is_parent)
|
||||
n.value.on_is_parent_changed(true);
|
||||
depth_level++;
|
||||
do impl(en.Current, depth_level);
|
||||
while (en.MoveNext());
|
||||
} else if (n.value.is_parent)
|
||||
n.value.on_is_parent_changed(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _toggle_is_expanded(TKey key, bool is_expanded) =>
|
||||
_tree.TryReplace(key, r => {
|
||||
if (r.is_expanded != is_expanded)
|
||||
r.on_is_expanded_changed(is_expanded);
|
||||
return r;
|
||||
});
|
||||
|
||||
void _toggle_is_expanded(bool is_expanded) {
|
||||
foreach (var row in _tree)
|
||||
if (row.is_expanded != is_expanded)
|
||||
row.on_is_expanded_changed(is_expanded);
|
||||
}
|
||||
|
||||
T _value_selector(TRow row) => row.value;
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace bts.collections {
|
||||
class OperableHierarchicalCollectionModel<TRow, T, TKey> where TKey : IEquatable<TKey> where TRow : IHierarchicalRow<T> {
|
||||
readonly Func<T, TRow> _row_factory;
|
||||
readonly Func<T, TKey> _key;
|
||||
SortedTree<TRow, TKey> _tree;
|
||||
IComparer<TRow> _comparer;
|
||||
Func<TRow, bool> _filter;
|
||||
List<INode<TRow>> _cached_filtered = new List<INode<TRow>>();
|
||||
|
||||
public OperableHierarchicalCollectionModel(Func<T, TRow> row_factory, Func<T, TKey> key, Func<T, TKey> parent_key, TKey no_parent_key, IComparer<TRow> comparer) {
|
||||
_row_factory = row_factory;
|
||||
_tree = new SortedTree<TRow, TKey>(_comparer = comparer, el => key(el.value), el => parent_key(el.value), no_parent_key);
|
||||
_key = key;
|
||||
}
|
||||
|
||||
public IComparer<TRow> comparer {
|
||||
get => _comparer;
|
||||
set {
|
||||
_tree = _tree.Resort(_comparer = value);
|
||||
_cached_filtered = null;
|
||||
}
|
||||
}
|
||||
public Func<TRow, bool> filter {
|
||||
get => _filter;
|
||||
set {
|
||||
_filter = value;
|
||||
_cached_filtered = null;
|
||||
_refresh_hierarchical_props();
|
||||
}
|
||||
}
|
||||
public IEnumerable<TRow> rows {
|
||||
get {
|
||||
return _root_nodes.SelectMany(impl);
|
||||
IEnumerable<TRow> impl(INode<TRow> n) {
|
||||
yield return n.value;
|
||||
if (n.value.is_expanded) {
|
||||
foreach (var _n in n.inner.SelectMany(impl))
|
||||
yield return _n;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<TRow> all_rows {
|
||||
get {
|
||||
return _root_nodes.SelectMany(impl);
|
||||
IEnumerable<TRow> impl(INode<TRow> n) {
|
||||
yield return n.value;
|
||||
foreach (var _n in n.inner.SelectMany(impl))
|
||||
yield return _n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int total_row_count { get; private set; }
|
||||
|
||||
IEnumerable<INode<TRow>> _root_nodes =>
|
||||
_filter == null ? _tree.RootNodes : _cached_filtered ?? (_cached_filtered = _tree.RootNodes.filtered(_filter).sorted_hard(_comparer));
|
||||
|
||||
public IEnumerable<TRow> GetAllRows(bool excludeFiltered = false) =>
|
||||
excludeFiltered ? all_rows : _tree;
|
||||
// collapse
|
||||
public void collapse_row(TKey key) => _toggle_is_expanded(key, false);
|
||||
public void collapse_all() => _toggle_is_expanded(false);
|
||||
// expand
|
||||
public void expand_row(TKey key) => _toggle_is_expanded(key, true);
|
||||
public void expand_all() => _toggle_is_expanded(true);
|
||||
// lookups
|
||||
public bool try_get_row(TKey key, out TRow row) {
|
||||
if (_tree.TryGetNode(key, out var node)) {
|
||||
row = node.value;
|
||||
return true;
|
||||
}
|
||||
row = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
public TRow get_parent(TKey key) {
|
||||
if (try_get_row(key, out TRow r)) {
|
||||
return _tree.GetParent(r).value;
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
||||
public IEnumerable<TRow> get_descendent_rows(TKey key) {
|
||||
if (_tree.TryGetNode(key, out var n)) {
|
||||
yield return n.value;
|
||||
foreach (var v in n.inner_values())
|
||||
yield return v;
|
||||
}
|
||||
}
|
||||
|
||||
// update
|
||||
public void update(IEnumerable<T> added, IEnumerable<T> changed, IEnumerable<TKey> removed) {
|
||||
foreach (var k in removed) {
|
||||
if (_tree.Remove(k))
|
||||
total_row_count--;
|
||||
}
|
||||
foreach (var v in changed) {
|
||||
_tree.TryReplace(_key(v), r => { r.on_value_changed(v); return r; });
|
||||
}
|
||||
foreach (var v in added) {
|
||||
if (_tree.Insert(_row_factory(v)))
|
||||
total_row_count++;
|
||||
}
|
||||
_cached_filtered = null;
|
||||
_refresh_hierarchical_props();
|
||||
}
|
||||
|
||||
void _refresh_hierarchical_props() {
|
||||
foreach (var n in _root_nodes)
|
||||
impl(n, 0);
|
||||
void impl(INode<TRow> n, int depth_level) {
|
||||
if (n.value.depth_level != depth_level) {
|
||||
n.value.on_depth_level_changed(depth_level);
|
||||
}
|
||||
using (var en = n.inner.GetEnumerator()) {
|
||||
if (en.MoveNext()) {
|
||||
if (!n.value.is_parent)
|
||||
n.value.on_is_parent_changed(true);
|
||||
depth_level++;
|
||||
do impl(en.Current, depth_level);
|
||||
while (en.MoveNext());
|
||||
} else if (n.value.is_parent)
|
||||
n.value.on_is_parent_changed(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _toggle_is_expanded(TKey key, bool is_expanded) =>
|
||||
_tree.TryReplace(key, r => {
|
||||
if (r.is_expanded != is_expanded)
|
||||
r.on_is_expanded_changed(is_expanded);
|
||||
return r;
|
||||
});
|
||||
|
||||
void _toggle_is_expanded(bool is_expanded) {
|
||||
foreach (var row in _tree)
|
||||
if (row.is_expanded != is_expanded)
|
||||
row.on_is_expanded_changed(is_expanded);
|
||||
}
|
||||
|
||||
T _value_selector(TRow row) => row.value;
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,6 @@
|
||||
this IObservable<T> source, Func<T, TResult> bootstrap_selector, Func<T, TResult> selector) =>
|
||||
Observable.Create<TResult>(o => {
|
||||
object locker = new();
|
||||
var local_bootstrap_selector = bootstrap_selector;
|
||||
return source.Subscribe(v => {
|
||||
// The preliminary null-check for `bootstrapper` is performed outside of the lock.
|
||||
//
|
||||
@@ -46,13 +45,13 @@
|
||||
//
|
||||
// If `bootstrapper is not null`, the use of a lock becomes neccessary to ensure that
|
||||
// the observer is only bootstrapped once.
|
||||
if (local_bootstrap_selector is null) {
|
||||
if (bootstrap_selector is null) {
|
||||
o.OnNext(selector(v));
|
||||
return;
|
||||
}
|
||||
lock (locker) {
|
||||
o.OnNext((local_bootstrap_selector ?? selector)(v));
|
||||
local_bootstrap_selector = null;
|
||||
o.OnNext((bootstrap_selector ?? selector)(v));
|
||||
bootstrap_selector = null;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -211,10 +210,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
public static IObservable<TResult> SelectInline<T, TResult>(
|
||||
this IObservable<T> source, Func<T, TResult> selector) =>
|
||||
Observable.Create<TResult>(o => source.Subscribe(v => o.OnNext(selector(v))));
|
||||
|
||||
/// <summary>
|
||||
/// Uses each element of a source observable to create an inner observable of <typeparamref name="TResult"/>, unlike <see cref="Observable.SelectMany{TSource, TResult}(IObservable{TSource}, Func{TSource, IObservable{TResult}})"/>,
|
||||
/// each inner sequence is terminated when the next one begins.
|
||||
|
||||
@@ -322,7 +322,7 @@ namespace bts.api.core {
|
||||
Log.DataFlow.diag($"Create Filter {typeof(T).Name}");
|
||||
|
||||
return source.CombineLatest(predicate, (upd, pred) => (upd, pred)).Subscribe(tup => {
|
||||
bool pred_changed = tup.pred != pred_cache && pred_cache is not null;
|
||||
bool pred_changed = tup.pred == pred_cache && pred_cache is not null;
|
||||
pred_cache = tup.pred;
|
||||
unfiltered_cache = tup.upd;
|
||||
if (pred_changed && filtered_cache is not null) {
|
||||
|
||||
@@ -13,7 +13,6 @@ namespace bts.websocket_core {
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using Spark.Api.Data;
|
||||
using Spark.Api.MarketData;
|
||||
using Spark.Api.Orders;
|
||||
using Spark.Core.Collections;
|
||||
@@ -253,9 +252,7 @@ namespace bts.websocket_core {
|
||||
exchanges,
|
||||
types,
|
||||
symbols?.getuprarr(),
|
||||
expiration is null
|
||||
? Array.Empty<ExpirationDate>()
|
||||
: Array.ConvertAll(expiration, ExpirationDate.FixedDate),
|
||||
expiration,
|
||||
null,
|
||||
null,
|
||||
strikes,
|
||||
|
||||
@@ -7,11 +7,6 @@ include(${CMAKE_SOURCE_DIR}/cmake/Protobuf.cmake)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateDefaultConfig.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/cmake/PrintList.cmake)
|
||||
|
||||
configure_file(
|
||||
"${CMAKE_SOURCE_DIR}/cmake/version.h.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/version.h"
|
||||
)
|
||||
|
||||
if (DEFINED DOTNET_BINARY_DIR OR DEFINED DOTNET_WINDOWS_BINARY_DIR)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/AddCopyBinariesTarget.cmake)
|
||||
endif()
|
||||
|
||||
@@ -770,14 +770,14 @@ bts::api::orderman::RoutingRecord AdminServiceUtils::get_routing_record(
|
||||
case api::VENUE_BINANCE_USDS_FUTURES: {
|
||||
rv.set_session("binance_usds_futures_1");
|
||||
rv.set_account(account_ptr->name());
|
||||
rv.set_operator_id(user_ptr->name());
|
||||
rv.set_account(user_ptr->name());
|
||||
out_result.set_is_success(true);
|
||||
return rv;
|
||||
}
|
||||
case api::VENUE_BINANCE: {
|
||||
rv.set_session("binance_1");
|
||||
rv.set_account(account_ptr->name());
|
||||
rv.set_operator_id(user_ptr->name());
|
||||
rv.set_account(user_ptr->name());
|
||||
out_result.set_is_success(true);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ message VolSurfaceUsageList {
|
||||
}
|
||||
|
||||
message ArchivedSecurityTheo {
|
||||
uint32 id = 10;
|
||||
uint32 id = 10[ (bts.api.key) = true ];
|
||||
double driver = 20;
|
||||
double vol = 30;
|
||||
double theo = 40;
|
||||
@@ -49,7 +49,7 @@ message ArchivedSecurityTheo {
|
||||
}
|
||||
|
||||
message ArchivedTheoList {
|
||||
uint64 save_time = 10;
|
||||
uint64 save_time = 10[ (bts.api.key) = true ];
|
||||
// these are sec_tups that are part of this save
|
||||
repeated bts.api.SecurityTuple sec_tups = 20;
|
||||
repeated ArchivedSecurityTheo sec_theo = 30;
|
||||
@@ -195,8 +195,10 @@ service AnalyticsService {
|
||||
|
||||
/// theos
|
||||
rpc archive_theos(ArchivedTheoList) returns (bts.api.ResultMessage);
|
||||
rpc clean_and_archive_theos(ArchivedTheoList) returns (bts.api.ResultMessage);
|
||||
// finds the archived_theo closest to this point
|
||||
rpc get_archived_theos(ArchivedTheoRetrieval) returns (ArchivedTheoList);
|
||||
rpc archived_theos(bts.api.VoidMessage) returns (stream ArchivedTheoList);
|
||||
|
||||
/// reports
|
||||
rpc get_new_report_id(bts.api.VoidMessage)
|
||||
|
||||
Loaded 100 of 165 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user