Throttling the driver prices for performance
This commit is contained in:
1 parent
7d66d7847f
commit
1a0d2e59ab
2 files changed
+12
-4
No files matched your search
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using mbts.analytics;
|
||||
using bts.api;
|
||||
using bts;
|
||||
using bts.proto;
|
||||
|
||||
namespace mbts.spark {
|
||||
using DriverMD = Tuple<SecurityImmutable, VolSurfaceMDUnit>;
|
||||
@@ -20,6 +21,8 @@ namespace mbts.spark {
|
||||
SparkTags.SystemContractsTag;
|
||||
private OptionDriverPriceMap _last_published;
|
||||
private readonly PerfStatsLogger _logger;
|
||||
private readonly TimeSpan _fire_period = TimeSpan.FromMilliseconds(300);
|
||||
private DateTime _last_fire_time = DateTime.MinValue;
|
||||
|
||||
public SingleOptionDriverPricePublisher(SecurityTuple sec_tup,
|
||||
ThreadedBlackboard bb) {
|
||||
@@ -39,12 +42,15 @@ namespace mbts.spark {
|
||||
|
||||
private void _on_bb_data(object tag, object data) {
|
||||
if (_in_bb_exp_params_tag == tag || _in_bb_contracts_tag == tag) {
|
||||
_compute_and_fire();
|
||||
_on_bb_timer();
|
||||
}
|
||||
}
|
||||
|
||||
private void _on_bb_timer() {
|
||||
_compute_and_fire();
|
||||
if (DateTime.Now - _last_fire_time >= _fire_period) {
|
||||
_last_fire_time = DateTime.Now;
|
||||
_compute_and_fire();
|
||||
}
|
||||
}
|
||||
|
||||
private void _compute_and_fire() {
|
||||
@@ -82,8 +88,9 @@ namespace mbts.spark {
|
||||
// compares the new values to the previous
|
||||
private bool _is_different(IDictionary<SecurityExpiration, DriverMD> new_dic) {
|
||||
Func<DriverMD, DriverMD, bool> is_dmd_diff = (d1, d2) => {
|
||||
return !d1.Item1.Equals(d2.Item1) ||
|
||||
!d1.Item2.Equals(d2.Item2);
|
||||
bool eq = d1.Item1.Id == d2.Item1.Id &&
|
||||
d1.Item2.Equals(d2.Item2);
|
||||
return !eq;
|
||||
};
|
||||
new_dic.Difference(_last_published.exp_price_map, out var ex_left, out var ex_right, out var overlap);
|
||||
return ex_left.Count() != 0 || ex_right.Count() != 0 ||
|
||||
|
||||
@@ -60,6 +60,7 @@ namespace mbts.analytics {
|
||||
public bool Equals(VolSurfaceMDUnit other) {
|
||||
if (other != null)
|
||||
return
|
||||
VolSurfaceUtilityFunctions.compare_doubles(mark_price, other.mark_price) &&
|
||||
VolSurfaceUtilityFunctions.compare_doubles(bid_price, other.bid_price) &&
|
||||
bid_size == other.bid_size &&
|
||||
VolSurfaceUtilityFunctions.compare_doubles(ask_price, other.ask_price) &&
|
||||
|
||||
Reference in new issue
Block a user