merge from master
This commit is contained in:
commit
d4ee0cfc97
26 files changed
+1624
-548
No files matched your search
@@ -1,29 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bts.api
|
||||
{
|
||||
public interface ITag { }
|
||||
// It is important that ITag<T> is a distinct type from ITag
|
||||
public interface ITag<T> { }
|
||||
public interface ISubscribe
|
||||
{
|
||||
IObservable<T> subscribe<T>(ITag tag);
|
||||
IObservable<T> subscribe<T>(ITag<T> tag);
|
||||
}
|
||||
|
||||
public interface IPost
|
||||
{
|
||||
void post<T>(ITag tag, T data);
|
||||
void post<T>(ITag<T> tag, T data);
|
||||
}
|
||||
|
||||
public interface IBus : IPost, ISubscribe
|
||||
{
|
||||
//string[] missing_pieces();
|
||||
}
|
||||
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bts.api
|
||||
{
|
||||
public interface ITag { }
|
||||
// It is important that ITag<T> is a distinct type from ITag
|
||||
public interface ITag<T> { }
|
||||
public interface ISubscribe
|
||||
{
|
||||
IObservable<T> subscribe<T>(ITag tag);
|
||||
IObservable<T> subscribe<T>(ITag<T> tag);
|
||||
}
|
||||
|
||||
public interface IPost
|
||||
{
|
||||
void post<T>(ITag tag, T data);
|
||||
void post<T>(ITag<T> tag, T data);
|
||||
}
|
||||
|
||||
public interface IBus : IPost, ISubscribe
|
||||
{
|
||||
//string[] missing_pieces();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,7 +20,7 @@ namespace bts.core
|
||||
if (inst.TryGetValue(tag, out ISubject<T> result)) {
|
||||
return result;
|
||||
}
|
||||
result = new Subject<T>();
|
||||
result = new ReplaySubject<T>(1);
|
||||
inst[tag] = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
using bts.api;
|
||||
using bts.spark;
|
||||
using mbts.co2;
|
||||
using mbts.collections;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using static mbts.spark.SparkTags;
|
||||
using static mbts.ui.shell.ProtoBufSerializationHelper;
|
||||
using mbts.collections.extensions;
|
||||
using System.Collections.ObjectModel;
|
||||
using ProtoBuf;
|
||||
using mbts.ui;
|
||||
using System.IO;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace mbts.spark {
|
||||
internal class ContractPickerModel : ViewModelBase {
|
||||
|
||||
|
||||
public ContractPickerModel(IBus bus) {
|
||||
_bus = bus;
|
||||
_subs.Add(_bus.subscribe(SecuritiesTag).Subscribe(on_securities_changed));
|
||||
|
||||
add_criteria_command = new DelegateCommand(_ => {
|
||||
security_criteria.Add(new SecurityCriteria()
|
||||
{
|
||||
pretty_name = criteria_input_name,
|
||||
exchanges = selected_exchanges.ToArray(),
|
||||
security_types = selected_security_types.ToArray(),
|
||||
symbols = selected_symbols.ToArray(),
|
||||
security_keys = selected_securities.ToArray()
|
||||
});
|
||||
criteria_input_name = string.Empty;
|
||||
});
|
||||
|
||||
remove_criteria_command = new DelegateCommand(_ =>
|
||||
{
|
||||
security_criteria.Remove(selected_security_criteria);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private readonly IBus _bus;
|
||||
private IList<IDisposable> _subs = new List<IDisposable>();
|
||||
|
||||
|
||||
internal void exchange_selection_changed(IEnumerable<Venue> exchanges)
|
||||
{
|
||||
selected_exchanges = exchanges.ToList();
|
||||
symbols.sync_with(UserSymbol.get_all()
|
||||
.Where(s => exchanges.Contains(s.exchange))
|
||||
.Select(s => s.symbol)
|
||||
.Distinct()
|
||||
.ToList());
|
||||
_update_securities();
|
||||
|
||||
// test on click -- verify our func works
|
||||
var results = all_securities.Select(all => all.Value.security).Where(x => _security_in_criteria(x)).ToList();
|
||||
}
|
||||
|
||||
internal void security_type_selection_changed(IEnumerable<SecurityType> security_types)
|
||||
{
|
||||
selected_security_types = security_types.ToList();
|
||||
_update_securities();
|
||||
|
||||
// test on click -- verify our func works
|
||||
var results = all_securities.Select(all => all.Value.security).Where(x => _security_in_criteria(x)).ToList();
|
||||
}
|
||||
|
||||
internal void symbol_selection_changed(IEnumerable<string> symbols)
|
||||
{
|
||||
selected_symbols = symbols.ToList();
|
||||
_update_securities();
|
||||
|
||||
// test on click -- verify our func works
|
||||
var results = all_securities.Select(all => all.Value.security).Where(x => _security_in_criteria(x)).ToList();
|
||||
}
|
||||
|
||||
internal void security_selection_changed(IEnumerable<SecurityImmutable> secs)
|
||||
{
|
||||
selected_securities = secs.Select(s => s.Id).ToList();
|
||||
|
||||
// test on click -- verify our func works
|
||||
var results = all_securities.Select(all => all.Value.security).Where( x => _security_in_criteria(x)).ToList();
|
||||
}
|
||||
|
||||
private void on_securities_changed(IReadOnlyDictionary<uint, SecurityMD> changed_securities)
|
||||
{
|
||||
all_securities = changed_securities;
|
||||
securities.sync_with(changed_securities
|
||||
.Select(entry => entry.Value.security)
|
||||
);
|
||||
_update_securities();
|
||||
}
|
||||
internal void criteria_selection_changed(SecurityCriteria changed_criteria)
|
||||
{
|
||||
// this is currently not changing the selected item in the main listboxes, need to investigate
|
||||
if (changed_criteria != null)
|
||||
{
|
||||
// need security key to description lookup here
|
||||
SecurityCriteriaChangedEventsArgs args = new SecurityCriteriaChangedEventsArgs();
|
||||
args.securities = all_securities.Where(s => changed_criteria.security_keys.Contains(s.Key)).Select(sec => sec.Value.security).ToArray();
|
||||
args.criteria = changed_criteria;
|
||||
|
||||
on_security_criteria_changed(args);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void on_security_criteria_changed(SecurityCriteriaChangedEventsArgs e)
|
||||
{
|
||||
security_criteria_changed?.Invoke(this, e);
|
||||
}
|
||||
|
||||
public List<Venue> all_exchanges { get; } = new List<Venue> { Venue.Glbx, Venue.Cboe };//UserSymbol.get_all().Select(x => x.exchange).Distinct().ToList();
|
||||
public List<Venue> selected_exchanges = new List<Venue>();
|
||||
|
||||
public IEnumerable<SecurityType> security_types { get; } = EnumHelper.get_values_except(SecurityType.Option, SecurityType.Unset);
|
||||
public List<SecurityType> selected_security_types = new List<SecurityType>();
|
||||
|
||||
public ObservableCollection<string> symbols { get; } = new ObservableCollection<string>(UserSymbol.get_all().Select(s => s.symbol).Distinct());
|
||||
public List<string> selected_symbols = new List<string>();
|
||||
|
||||
private IReadOnlyDictionary<uint, SecurityMD> all_securities = new Dictionary<uint, SecurityMD>();
|
||||
public List<uint> selected_securities = new List<uint>();
|
||||
public ObservableCollection<SecurityImmutable> securities { get; } = new ObservableCollection<SecurityImmutable>();
|
||||
|
||||
public ICommand add_criteria_command { get; }
|
||||
public ICommand remove_criteria_command { get; }
|
||||
public ObservableCollection<SecurityCriteria> security_criteria { get; } = new ObservableCollection<SecurityCriteria>();
|
||||
|
||||
private SecurityCriteria _selected_security_criteria = new SecurityCriteria();
|
||||
public SecurityCriteria selected_security_criteria
|
||||
{
|
||||
get { return _selected_security_criteria; }
|
||||
set
|
||||
{
|
||||
_selected_security_criteria = value;
|
||||
RaisePropertyChanged("selected_security_criteria");
|
||||
}
|
||||
}
|
||||
|
||||
private string _criteria_input_name;
|
||||
public string criteria_input_name {
|
||||
get { return _criteria_input_name; }
|
||||
set { _criteria_input_name = value;
|
||||
RaisePropertyChanged("criteria_input_name");
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler<SecurityCriteriaChangedEventsArgs> security_criteria_changed;
|
||||
|
||||
|
||||
|
||||
private void _update_securities()
|
||||
{
|
||||
securities.sync_with(all_securities
|
||||
.Select(all => all.Value.security)
|
||||
// exchange filtering
|
||||
.Where(sec => selected_exchanges.Count == 0 || selected_exchanges
|
||||
.Any(exchange => exchange == sec.Exchange))
|
||||
// type filtering
|
||||
.Where(sec => selected_security_types.Count == 0 || selected_security_types
|
||||
.Any(sec_type => sec_type == sec.security_type()))
|
||||
// symbol filtering
|
||||
.Where(sec => selected_symbols.Count == 0 || selected_symbols
|
||||
.Any(sym => sym == sec.Symbol))
|
||||
);
|
||||
|
||||
// test of serializing/de to/from protobuf
|
||||
MemoryStream test = new MemoryStream();
|
||||
get_state(test);
|
||||
test.Position = 0;
|
||||
try_deserialize(test, out ShellSerializationHeader header);
|
||||
try_deserialize(test, out StartupData data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private bool _security_in_criteria(SecurityImmutable sec_item)
|
||||
{
|
||||
// Mock criteria to test against
|
||||
var item1 = new SecurityCriteria()
|
||||
{
|
||||
exchanges = new Venue[] { },
|
||||
security_types = new SecurityType[] { },
|
||||
symbols = new string[] { },
|
||||
security_keys = new uint[] { 176868 }
|
||||
};
|
||||
var item2 = new SecurityCriteria()
|
||||
{
|
||||
exchanges = new Venue[] { },
|
||||
security_types = new SecurityType[] { SecurityType.Future },
|
||||
symbols = new string[] {"GE"},
|
||||
security_keys = new uint[] { }
|
||||
};
|
||||
SecurityCriteria[] a = new SecurityCriteria[] { item1, item2 };
|
||||
|
||||
List<bool> criteria_results = new List<bool>(a.Length + 1);
|
||||
criteria_results.Add(false);
|
||||
foreach (SecurityCriteria x in a)
|
||||
{
|
||||
bool iteration_result = (x.exchanges.Length == 0 || x.exchanges.Any(exchange => exchange == sec_item.Exchange))
|
||||
&& (x.security_types.Length == 0 || x.security_types.Any(sec_type => sec_type == sec_item.security_type()))
|
||||
&& (x.symbols.Length == 0 || x.symbols.Any(sym => sym == sec_item.Symbol))
|
||||
&& (x.security_keys.Length == 0 || x.security_keys.Any(sec_key => sec_key == sec_item.Id));
|
||||
criteria_results.Add(iteration_result);
|
||||
}
|
||||
bool final_result = criteria_results.Any(r => r);
|
||||
return final_result;
|
||||
|
||||
|
||||
|
||||
//var overall_predicate = PredicateBuilder.True<SecurityImmutable>();
|
||||
//foreach (SecurityCriteria entry in a)
|
||||
//{
|
||||
// var inner_exchange_predicate = PredicateBuilder.False<SecurityImmutable>();
|
||||
// foreach (Venue v in entry.exchanges)
|
||||
// {
|
||||
// Venue temp_v = v;
|
||||
// inner_exchange_predicate = inner_exchange_predicate.Or(p => p.Exchange == temp_v);
|
||||
// }
|
||||
// //predicate = predicate.And(exchange_predicate);
|
||||
|
||||
// var inner_type_predicate = PredicateBuilder.False<SecurityImmutable>();
|
||||
// foreach (SecurityType s_type in entry.security_types)
|
||||
// {
|
||||
// SecurityType temp_s = s_type;
|
||||
// inner_type_predicate = inner_type_predicate.Or(p => p.security_type() == temp_s);
|
||||
// }
|
||||
|
||||
// var entry_predicate = PredicateBuilder.True<SecurityImmutable>();
|
||||
// entry_predicate = entry_predicate.And(inner_exchange_predicate).And(inner_type_predicate);
|
||||
// overall_predicate = overall_predicate.Or(entry_predicate);
|
||||
//}
|
||||
//return entry_predicate.Compile();
|
||||
|
||||
}
|
||||
|
||||
public void get_state(Stream save_here)
|
||||
{
|
||||
// Mock data to be saved
|
||||
var x = new SecurityCriteria()
|
||||
{
|
||||
exchanges = selected_exchanges.ToArray(),
|
||||
security_types = selected_security_types.ToArray(),
|
||||
symbols = selected_symbols.ToArray(),
|
||||
security_keys = selected_securities.ToArray()
|
||||
};
|
||||
SecurityCriteria[] a = new SecurityCriteria[] { x };
|
||||
|
||||
//ProtoBufSerializationHelper.serialize(save_here, new ShellSerializationHeader { name = SAVE_NAME, version = VERSION });
|
||||
//ProtoBufSerializationHelper.serialize(save_here, new StartupData(a));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Disposable.dispose(_subs);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
internal class SecurityCriteriaChangedEventsArgs : EventArgs
|
||||
{
|
||||
public SecurityCriteria criteria { get; set; }
|
||||
public SecurityImmutable[] securities { get; set; }
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
public class StartupData
|
||||
{
|
||||
public const int Version = 1;
|
||||
public StartupData() { }
|
||||
public StartupData(SecurityCriteria[] security_criteria)
|
||||
{
|
||||
this.security_criteria = security_criteria;
|
||||
}
|
||||
[ProtoMember(1)]
|
||||
public SecurityCriteria[] security_criteria;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<UserControl x:Class="mbts.spark.ContractPickerView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
x:ClassModifier="internal"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="600">
|
||||
<DockPanel>
|
||||
<Grid Grid.IsSharedSizeScope="True" DockPanel.Dock="Top" ShowGridLines="True" Background="Bisque">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition SharedSizeGroup="share_col_width" Width="Auto" />
|
||||
<ColumnDefinition SharedSizeGroup="share_col_width" Width="Auto" />
|
||||
<ColumnDefinition SharedSizeGroup="share_col_width" Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Row="0" Grid.Column="0" Content="Exchanges"/>
|
||||
<Label Grid.Row="0" Grid.Column="1" Content="Types"/>
|
||||
<Label Grid.Row="0" Grid.Column="2" Content="Symbols"/>
|
||||
<Label Grid.Row="0" Grid.Column="3" Content="Instruments"/>
|
||||
<ListBox x:Name="_exchanges" Grid.Row ="1" Grid.Column="0" SelectionMode="Extended" ItemsSource="{Binding all_exchanges}" Height="200" VerticalAlignment="Top" ></ListBox>
|
||||
<ListBox x:Name="_security_types" Grid.Row ="1" Grid.Column="1" SelectionMode="Extended" ItemsSource="{Binding security_types}" Height="200" VerticalAlignment="Top"></ListBox>
|
||||
<ListBox x:Name="_symbols" Grid.Row ="1" Grid.Column="2" SelectionMode="Extended" ItemsSource="{Binding symbols}" Height="200" VerticalAlignment="Top"></ListBox>
|
||||
<ListBox x:Name="_securities" Grid.Row ="1" Grid.Column="3" SelectionMode="Extended" ItemsSource="{Binding securities}" Height="200" Width="200" VerticalAlignment="Top" ></ListBox>
|
||||
<Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox Grid.Row="0" Grid.Column="0" Text="{Binding criteria_input_name}" Width="100"></TextBox>
|
||||
<Button Grid.Row="0" Grid.Column="1" Command="{Binding add_criteria_command}" HorizontalAlignment="Right">Add</Button>
|
||||
<ListBox x:Name="_criteria" Grid.Row="1" Grid.Column="0" ItemsSource="{Binding security_criteria}" SelectedItem="{Binding selected_security_criteria}" Height="50"></ListBox>
|
||||
<Button Grid.Row="1" Grid.Column="1" Command="{Binding remove_criteria_command}" HorizontalAlignment="Right">Remove</Button>
|
||||
</Grid>
|
||||
<UniformGrid Grid.Row="3" Rows="1" Columns="2" DockPanel.Dock="Bottom">
|
||||
<Button>OK</Button>
|
||||
<Button>Cancel</Button>
|
||||
</UniformGrid>
|
||||
</Grid>
|
||||
</DockPanel>
|
||||
|
||||
</UserControl>
|
||||
@@ -0,0 +1,139 @@
|
||||
using mbts.ui;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using System.IO;
|
||||
using bts.api;
|
||||
using System.ComponentModel.Composition;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for ContractPickerView.xaml
|
||||
/// </summary>
|
||||
partial class ContractPickerView : UserControl
|
||||
{
|
||||
|
||||
public ContractPickerView(ContractPickerModel context)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.DataContext = context;
|
||||
|
||||
_exchanges.SelectionChanged += exchanges_changed;
|
||||
_security_types.SelectionChanged += security_types_changed;
|
||||
_symbols.SelectionChanged += symbols_changed;
|
||||
_securities.SelectionChanged += securities_changed;
|
||||
_criteria.SelectionChanged += criteria_changed;
|
||||
context.security_criteria_changed += security_criteria_changed;
|
||||
}
|
||||
|
||||
private void security_criteria_changed(object sender, SecurityCriteriaChangedEventsArgs e)
|
||||
{
|
||||
if (e != null)
|
||||
{
|
||||
_exchanges.SelectedItems.Clear();
|
||||
foreach (var exch in e.criteria.exchanges)
|
||||
{
|
||||
_exchanges.SelectedItems.Add(exch);
|
||||
}
|
||||
_security_types.SelectedItems.Clear();
|
||||
foreach (var sec_type in e.criteria.security_types)
|
||||
{
|
||||
_security_types.SelectedItems.Add(sec_type);
|
||||
}
|
||||
_symbols.SelectedItems.Clear();
|
||||
foreach (var sym in e.criteria.symbols)
|
||||
{
|
||||
_symbols.SelectedItems.Add(sym);
|
||||
}
|
||||
_securities.SelectedItems.Clear();
|
||||
foreach (var sec in e.securities)
|
||||
{
|
||||
_securities.SelectedItems.Add(sec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void symbols_changed(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
((ContractPickerModel)DataContext).symbol_selection_changed(_symbols.SelectedItems.Cast<string>());
|
||||
}
|
||||
|
||||
private void security_types_changed(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
((ContractPickerModel)DataContext).security_type_selection_changed(_security_types.SelectedItems.Cast<SecurityType>());
|
||||
}
|
||||
|
||||
private void exchanges_changed(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
((ContractPickerModel)DataContext).exchange_selection_changed(_exchanges.SelectedItems.Cast<Venue>());
|
||||
}
|
||||
|
||||
private void securities_changed(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
((ContractPickerModel)DataContext).security_selection_changed(_securities.SelectedItems.Cast<SecurityImmutable>());
|
||||
}
|
||||
|
||||
private void criteria_changed(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
((ContractPickerModel)DataContext).criteria_selection_changed(_criteria.SelectedItem as SecurityCriteria);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//[Export (typeof(IShellModule))]
|
||||
public class TempModule : IShellModule {
|
||||
private IBus _bus;
|
||||
|
||||
[ImportingConstructor]
|
||||
public TempModule(IBus bus) {
|
||||
_bus = bus;
|
||||
}
|
||||
|
||||
public ImageSource icon => Icons.Abacus;
|
||||
|
||||
public string name => "test";
|
||||
|
||||
public int priority => 1;
|
||||
|
||||
public IShellWindow launch_ui => null;
|
||||
|
||||
public Task<IShellWindow> create(Stream load_stream) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void get_state(Stream save_here) {
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void load_state(Stream state = null) {
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void start() {
|
||||
//var vm = new ContractPickerModel(_bus);
|
||||
//var view = new ContractPickerView(vm);
|
||||
//return ShellWindow.create(this, "test", view, vm.get_state, Icons.Abacus);
|
||||
|
||||
var x = new Window {
|
||||
Content = new ContractPickerView(new ContractPickerModel(_bus))
|
||||
};
|
||||
x.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using bts.api;
|
||||
using ProtoBuf;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
[ProtoContract]
|
||||
public class SecurityCriteria
|
||||
{
|
||||
public SecurityCriteria() { }
|
||||
|
||||
[ProtoMember(1)]
|
||||
public string pretty_name;
|
||||
|
||||
[ProtoMember(2)]
|
||||
public Venue[] exchanges;
|
||||
|
||||
[ProtoMember(3)]
|
||||
public SecurityType[] security_types;
|
||||
|
||||
[ProtoMember(4)]
|
||||
public string[] symbols;
|
||||
|
||||
[ProtoMember(5)]
|
||||
public uint[] security_keys;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return pretty_name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ using mbts;
|
||||
using System.Reactive.Linq;
|
||||
using security_key = System.UInt32;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
|
||||
namespace mbts.spark
|
||||
{
|
||||
@@ -94,6 +95,19 @@ namespace mbts.spark
|
||||
}
|
||||
Logger.log(bts.log.Level.Info, bts.log.Subsystem.gen, String.Format("MDSource publishing {0} securities", rv.Count));
|
||||
_bus.post(SparkTags.SecuritiesTag, rv);
|
||||
|
||||
if (rv.Count > 2000) temporary_bullshit(rv);
|
||||
}
|
||||
|
||||
private void temporary_bullshit(Dictionary<uint, SecurityMD> rv) {
|
||||
using (var file = new StreamWriter(File.OpenWrite("securities.fs"))) {
|
||||
foreach (var md in rv.Values) {
|
||||
var s = md.security;
|
||||
//let s = { symbol = "es"; exchange = Glbx; security_type = Spread; full_name = "esz1" }
|
||||
var str = $"{{ symbol=\"{s.Symbol}\"; exchange={s.Exchange}; security_type={s.security_type()}; full_name=\"{s.ToString("")}\" }}";
|
||||
file.WriteLine(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,11 @@ namespace bts.api {
|
||||
public int CompareTo(SecurityImmutable other) {
|
||||
return Id.CompareTo(other.Id);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.ToString("");
|
||||
}
|
||||
public string ToString(string format, IFormatProvider formatProvider=null) {
|
||||
return Format(this, string.IsNullOrEmpty(format) ? _standard_format : Parse(format));
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -41,12 +41,11 @@ public:
|
||||
_aggregated_hedged_reduction(0),
|
||||
_out_quantity(0)
|
||||
{}
|
||||
// when the user changes the spread price
|
||||
void update_target_spread_price(Price new_target_spread_price)
|
||||
{ _in_target_spread_price = new_target_spread_price; }
|
||||
// when the user changes the spread price
|
||||
void update_target_leg_quantity(Quantity new_target_leg_quantity)
|
||||
{ _in_target_leg_quantity = new_target_leg_quantity; }
|
||||
void update_target_price_quantity(Price new_target_spread_price, Quantity new_target_leg_quantity)
|
||||
{
|
||||
_in_target_spread_price = new_target_spread_price;
|
||||
_in_target_leg_quantity = new_target_leg_quantity;
|
||||
}
|
||||
// called when a fill happens for this leg. this increases the filled counter.
|
||||
// this is needed to know the "remainder quantity" needed to price this leg
|
||||
void add_filled_quantity(Quantity filled_qty)
|
||||
@@ -63,6 +62,7 @@ public:
|
||||
_out_price = new_out_price;
|
||||
_out_quantity = new_out_quantity;
|
||||
}
|
||||
void clear_out_price_quantity () {update_out_price_quantity (Price (0), Quantity (0));}
|
||||
// const accessor functions
|
||||
Price target_spread_price() const { return _in_target_spread_price; }
|
||||
Quantity target_leg_quantity() const { return _in_target_leg_quantity; }
|
||||
@@ -84,5 +84,6 @@ public:
|
||||
}
|
||||
}
|
||||
bool target_reached () const {return remaining_to_fill().value() == 0; }
|
||||
bool active_order () const {return _out_quantity.value() > 0;}
|
||||
};
|
||||
}}
|
||||
@@ -22,6 +22,7 @@ SingleLegQuoter::SingleLegQuoter(ISpreaderManager& spreader,
|
||||
_n_spreader_legs (n_spreader_legs),
|
||||
_order (child_order),
|
||||
_price_quantity_state(QuoteLegPriceQuantityState(spread_order_price, Quantity(SpreaderUtils::get_leg_quantity_from_spreader_quantity (this_leg_property, spread_order_quantity)))),
|
||||
_is_permenantly_cancelled (false),
|
||||
_worker(nullptr)
|
||||
//_time_stamp (0) // TODO
|
||||
{
|
||||
@@ -62,11 +63,13 @@ void SingleLegQuoter::update_order_price_quantity(Price price, Quantity quantity
|
||||
}
|
||||
void SingleLegQuoter::cancel_order()
|
||||
{
|
||||
_is_permenantly_cancelled = true;
|
||||
LOG(OrderMan, Diag, "SingleLegQuoter::cancel_order key: {}, state: {}", _order.order_key().value(), _worker->state_text());
|
||||
_worker->cancel ();
|
||||
}
|
||||
void SingleLegQuoter::terminate ()
|
||||
{
|
||||
_is_permenantly_cancelled = true;
|
||||
LOG(OrderMan, Diag, "SingleLegQuoter::terminate key: {}, state: {}", _order.order_key().value(), _worker->state_text());
|
||||
_worker->terminate ();
|
||||
}
|
||||
@@ -79,7 +82,7 @@ bool SingleLegQuoter::is_active_order() const
|
||||
{
|
||||
QuoterState state = _worker->state();
|
||||
return state == QuoterState::WAITING_FOR_FIRST_ACK || state == QuoterState::WAITING_FOR_FIRST_ACK_CANCELLED ||
|
||||
state == QuoterState::WORKING || state == QuoterState::WAITING_FOR_CANCEL_ACK_FINAL || state == QuoterState::WAITING_FOR_CANCEL_ACK_CONTINUE;
|
||||
state == QuoterState::WORKING || state == QuoterState::WAITING_FOR_CANCEL_ACK;
|
||||
}
|
||||
bool SingleLegQuoter::is_terminal_state () const {return _worker->state() == QuoterState::END;}
|
||||
bool SingleLegQuoter::accept_modifications() const { return _worker->state() == QuoterState::WAITING_FOR_SIZE || _worker->state() == QuoterState::WORKING; }
|
||||
@@ -148,7 +151,7 @@ void SingleLegQuoter::_transform_to_START ()
|
||||
}
|
||||
void SingleLegQuoter::_transform_to_WAITING_FOR_SIZE ()
|
||||
{
|
||||
bts_assert (_worker->state() == QuoterState::START || _worker->state() == QuoterState::WAITING_FOR_CANCEL_ACK_CONTINUE);
|
||||
bts_assert (_worker->state() == QuoterState::START || _worker->state() == QuoterState::END);
|
||||
_switch_state (&_waiting_for_size_state_worker);
|
||||
}
|
||||
void SingleLegQuoter::_transform_to_WAITING_FOR_FIRST_ACK ()
|
||||
@@ -166,15 +169,10 @@ void SingleLegQuoter::_transform_to_WORKING()
|
||||
bts_assert (_worker->state() == QuoterState::WAITING_FOR_FIRST_ACK);
|
||||
_switch_state (&_working_state_worker);
|
||||
}
|
||||
void SingleLegQuoter::_transform_to_WAITING_FOR_CANCEL_ACK_FINAL()
|
||||
void SingleLegQuoter::_transform_to_WAITING_FOR_CANCEL_ACK()
|
||||
{
|
||||
bts_assert (_worker->state() == QuoterState::WORKING || _worker->state() == QuoterState::WAITING_FOR_FIRST_ACK);
|
||||
_switch_state (&_waiting_for_cancel_ack_final_state_worker);
|
||||
}
|
||||
void SingleLegQuoter::_transform_to_WAITING_FOR_CANCEL_ACK_CONTINUE()
|
||||
{
|
||||
bts_assert (_worker->state() == QuoterState::WORKING);
|
||||
_switch_state (&_waiting_for_cancel_ack_continue_state_worker);
|
||||
bts_assert (_worker->state() == QuoterState::WORKING || _worker->state() == QuoterState::WAITING_FOR_FIRST_ACK_CANCELLED);
|
||||
_switch_state (&_waiting_for_cancel_ack_state_worker);
|
||||
}
|
||||
void SingleLegQuoter::_transform_to_END()
|
||||
{
|
||||
|
||||
@@ -13,9 +13,8 @@
|
||||
#include "server/sparkd/spreader/quoter/quoter_states/QuoterWaitingForSizeStateWorker.h"
|
||||
#include "server/sparkd/spreader/quoter/quoter_states/QuoterWaitingForFirstAckWorker.h"
|
||||
#include "server/sparkd/spreader/quoter/quoter_states/QuoterWaitingForFirstAckCancelledWorker.h"
|
||||
#include "server/sparkd/spreader/quoter/quoter_states/QuoterWaitingForCancelAckFinalStateWorker.h"
|
||||
#include "server/sparkd/spreader/quoter/quoter_states/QuoterWaitingForCancelAckStateWorker.h"
|
||||
#include "server/sparkd/spreader/quoter/quoter_states/QuoterWorkingStateWorker.h"
|
||||
#include "server/sparkd/spreader/quoter/quoter_states/QuoterWaitingForCancelAckReturnStateWorker.h"
|
||||
#include "server/sparkd/spreader/quoter/quoter_states/QuoterEndStateWorker.h"
|
||||
|
||||
namespace bts {
|
||||
@@ -54,15 +53,15 @@ private:
|
||||
std::vector<PQPair> _aux_comp_data;
|
||||
QuoteLegPriceQuantityState _price_quantity_state;
|
||||
bts::TimeStamp _time_stamp;
|
||||
bool _is_permenantly_cancelled;
|
||||
// state workers
|
||||
IQuoterStateWorker* _worker;
|
||||
QuoterStartStateWorker _start_state_worker;
|
||||
QuoterWaitingForSizeStateWorker _waiting_for_size_state_worker;
|
||||
QuoterWaitingForFirstAckWorker _waiting_for_first_ack_state_worker;
|
||||
QuoterWaitingForFirstAckCancelledWorker _waiting_for_first_ack_cancelled_state_worker;
|
||||
QuoterWaitingForCancelAckFinalStateWorker _waiting_for_cancel_ack_final_state_worker;
|
||||
QuoterWaitingForCancelAckStateWorker _waiting_for_cancel_ack_state_worker;
|
||||
QuoterWorkingStateWorker _working_state_worker;
|
||||
QuoterWaitingForCancelAckReturnStateWorker _waiting_for_cancel_ack_continue_state_worker;
|
||||
QuoterEndStateWorker _end_state_worker;
|
||||
public:
|
||||
SingleLegQuoter(ISpreaderManager& order_bridge,
|
||||
@@ -75,7 +74,29 @@ public:
|
||||
~SingleLegQuoter()
|
||||
{
|
||||
}
|
||||
//1. leave the start state and actually starts processing
|
||||
// market data
|
||||
void init();
|
||||
//2. called by the spreader a change in
|
||||
// order status(or fills) is reported
|
||||
// by the exchange
|
||||
void update_order_status(const SpreaderOrderUpdateMessage& u);
|
||||
//3. called when the market data associated
|
||||
// with this security is changed
|
||||
void on_book(orderman::TickToTradeCorID cid,size_t leg_index, const bts::orderman::Book&);
|
||||
//4. called when the hedge order is cancelled, either
|
||||
// manually or automatically
|
||||
void cancel_order();
|
||||
//5. the quoter forgets everything and goes to the end state
|
||||
void terminate ();
|
||||
//6. time update
|
||||
void on_time(const bts::TimeStamp&);
|
||||
//7. this is called by the spreader when a quoting fill
|
||||
// (ie not hedging fill) happens on one of the quoting
|
||||
// legs
|
||||
void update_other_leg_fills(size_t leg_index, Quantity filled_quantity);
|
||||
//8. called when the user modified the spreader order price or quantity
|
||||
void update_order_price_quantity(Price price, Quantity quantity);
|
||||
// true if the quoter has an active working order. the order can
|
||||
// be in an unknown state, but as long as an order has been sent
|
||||
// and it has not reached a terminal state, its considered "active"
|
||||
@@ -83,38 +104,21 @@ public:
|
||||
// returns true if the quoter is in the final state, from which
|
||||
// it will never come back
|
||||
bool is_terminal_state () const;
|
||||
// the quoter returns true if it is in a state where orders
|
||||
// the quoter returns true if it is in a state where orders
|
||||
// can be modified
|
||||
bool accept_modifications() const;
|
||||
// called by the spreader a change in order status (or fills) is
|
||||
// reported by the exchange
|
||||
void update_order_status(const SpreaderOrderUpdateMessage& order_update_message);
|
||||
// called when the market data associated
|
||||
// with this security is changed
|
||||
void on_book(orderman::TickToTradeCorID cid,size_t leg_index, const bts::orderman::Book&);
|
||||
// this is called by the spreader when a quoting fill
|
||||
// (ie not hedging fill) happens on one of the quoting
|
||||
// legs
|
||||
void update_other_leg_fills(size_t leg_index, Quantity filled_quantity);
|
||||
// called when the user modified the spreader order price or quantity
|
||||
void update_order_price_quantity(Price price, Quantity quantity);
|
||||
// called when the hedge order is cancelled, either
|
||||
// manually or automatically
|
||||
void cancel_order();
|
||||
// the quoter forgets everything and goes to the end state
|
||||
void terminate ();
|
||||
// for test reasons
|
||||
void on_time(const bts::TimeStamp&);
|
||||
QuoterState test_only_func_state() { return _worker->state (); }
|
||||
const QuoteLegPriceQuantityState& test_only_func_price_quantity_state () const {return _price_quantity_state;}
|
||||
bool accept_modifications() const;
|
||||
friend QuoterStartStateWorker;
|
||||
friend QuoterWaitingForSizeStateWorker;
|
||||
friend QuoterWaitingForFirstAckWorker;
|
||||
friend QuoterWaitingForFirstAckCancelledWorker;
|
||||
friend QuoterWaitingForCancelAckFinalStateWorker;
|
||||
friend QuoterWaitingForCancelAckStateWorker;
|
||||
friend QuoterWorkingStateWorker;
|
||||
friend QuoterWaitingForCancelAckReturnStateWorker;
|
||||
friend QuoterEndStateWorker;
|
||||
public:
|
||||
// test only functions
|
||||
QuoterState test_only_func_quoter_state() const { return _worker->state (); }
|
||||
const QuoteLegPriceQuantityState& test_only_func_price_quantity_state () const {return _price_quantity_state;}
|
||||
bool test_only_func_ended_by_spreader () const {return _is_permenantly_cancelled;}
|
||||
private:
|
||||
void _incorporate_other_leg_fill (size_t leg_index, Quantity filled_quantity);
|
||||
// this is the function that computes the quoting price and the
|
||||
@@ -131,8 +135,7 @@ private:
|
||||
void _transform_to_WAITING_FOR_FIRST_ACK ();
|
||||
void _transform_to_WAITING_FOR_FIRST_ACK_CANCELLED();
|
||||
void _transform_to_WORKING();
|
||||
void _transform_to_WAITING_FOR_CANCEL_ACK_FINAL();
|
||||
void _transform_to_WAITING_FOR_CANCEL_ACK_CONTINUE();
|
||||
void _transform_to_WAITING_FOR_CANCEL_ACK();
|
||||
void _transform_to_END();
|
||||
void _switch_state (IQuoterStateWorker* new_state);
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <boost/container/flat_map.hpp>
|
||||
#include "lib/config/protos/MarketData.pb.h"
|
||||
#include "lib/md/Structure/PriceSize.h"
|
||||
#include "lib/domain_model/Security.h"
|
||||
#include "server/sparkd/orderman/md/Book.h"
|
||||
#include "server/sparkd/spreader/LegPropertyData.h"
|
||||
#include "server/sparkd/spreader/QuoteLegPriceQuantityState.h"
|
||||
@@ -78,28 +79,6 @@ public:
|
||||
}
|
||||
bts_assert(false);
|
||||
}
|
||||
// finds the size of the target leg based on the size of the source leg
|
||||
// (to keep their relative ratios intact)
|
||||
// ex: for a spread s1.l1+s2.l2, size N in l2 (so l2 is the source)
|
||||
// corresponds to s1 * N / s2 size on l1 (target).
|
||||
// so if we get an N lot fill in l2, we send a hedge on l1
|
||||
// sized s1 * N / s2
|
||||
static double get_equivelant_size (const LegPropertyData& source_leg, Quantity source_leg_quantity,
|
||||
const LegPropertyData& target_leg)
|
||||
{
|
||||
double rv = std::abs(target_leg.size_multiplier () * source_leg_quantity.value () / source_leg.size_multiplier ());
|
||||
rv = std::round(rv);
|
||||
return rv;
|
||||
}
|
||||
// given the quantity of the spreader order, determines the quality
|
||||
// of the leg
|
||||
static double get_leg_quantity_from_spreader_quantity(const LegPropertyData& leg, Quantity spreader_order_quantity)
|
||||
{
|
||||
double rv = std::abs (leg.size_multiplier () * spreader_order_quantity.value());
|
||||
rv = std::round (rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
/*******************************Orders*********************************/
|
||||
/**********************************************************************/
|
||||
@@ -200,8 +179,29 @@ public:
|
||||
return false;
|
||||
}
|
||||
/**********************************************************************/
|
||||
/**********************Quoting Pricing Calculation*********************/
|
||||
/**************************Price/Size Calculation**********************/
|
||||
/**********************************************************************/
|
||||
// finds the size of the target leg based on the size of the source leg
|
||||
// (to keep their relative ratios intact)
|
||||
// ex: for a spread s1.l1+s2.l2, size N in l2 (so l2 is the source)
|
||||
// corresponds to s1 * N / s2 size on l1 (target).
|
||||
// so if we get an N lot fill in l2, we send a hedge on l1
|
||||
// sized s1 * N / s2
|
||||
static double get_equivelant_size (const LegPropertyData& source_leg, Quantity source_leg_quantity,
|
||||
const LegPropertyData& target_leg)
|
||||
{
|
||||
double rv = std::abs(target_leg.size_multiplier () * source_leg_quantity.value () / source_leg.size_multiplier ());
|
||||
rv = std::round(rv);
|
||||
return rv;
|
||||
}
|
||||
// given the quantity of the spreader order, determines the quality
|
||||
// of the leg
|
||||
static double get_leg_quantity_from_spreader_quantity(const LegPropertyData& leg, Quantity spreader_order_quantity)
|
||||
{
|
||||
double rv = std::abs (leg.size_multiplier () * spreader_order_quantity.value());
|
||||
rv = std::round (rv);
|
||||
return rv;
|
||||
}
|
||||
// calculates the computed price and quantity for a quoting
|
||||
// leg given the data for the other leg
|
||||
static void compute_price_quantity_2_legs(Price target_spread_price, Quantity this_leg_target_quantity,
|
||||
@@ -213,18 +213,26 @@ public:
|
||||
// from traversing the other book, for the requires size
|
||||
Price other_leg_price; Quantity other_leg_quantity;
|
||||
// this is the size ratio of the other leg vs this leg
|
||||
double size_ratio = abs(other_leg_data.size_multiplier() / this_leg_data.size_multiplier());
|
||||
double other_leg_target_quantity = size_ratio * other_leg_data.leg_params().quote_params().lean_quantity_ratio() * this_leg_target_quantity.value();
|
||||
double effective_mult = std::abs(other_leg_data.leg_params().quote_params().lean_quantity_ratio() * other_leg_data.size_multiplier() / this_leg_data.size_multiplier());
|
||||
// to be conservative round the required size up
|
||||
double other_leg_target_quantity = std::round(effective_mult * this_leg_target_quantity.value());
|
||||
SpreaderUtils::traverse_depth_for_quantity(other_leg_book, SpreaderUtils::invert_side (other_leg_data.trading_side()), Quantity(other_leg_target_quantity), other_leg_price, other_leg_quantity);
|
||||
quantity = Quantity (static_cast<double>(other_leg_quantity.value())/size_ratio);
|
||||
price = Price((target_spread_price.value() - other_leg_price.value() * other_leg_data.price_multiplier())/this_leg_data.price_multiplier());
|
||||
double out_quantity = std::round(other_leg_quantity.value() / effective_mult);
|
||||
quantity = Quantity (out_quantity);
|
||||
double out_price = (target_spread_price.value() - other_leg_price.value() * other_leg_data.price_multiplier())/this_leg_data.price_multiplier();
|
||||
out_price = bts::securities::raw_round_to_quote_price (out_price, this_leg_data.tick_size(), this_leg_data.trading_side());
|
||||
price = Price(out_price);
|
||||
}
|
||||
static void compute_hedge_price_size_2_legs (Price spread_price,
|
||||
const LegPropertyData& quote_filled_leg, Price quote_fill_price, Quantity quote_fill_quantity,
|
||||
const LegPropertyData& hedge_leg, Price& out_hedge_price, Quantity& out_hedge_quantity)
|
||||
{
|
||||
out_hedge_quantity = Quantity (quote_fill_quantity.value() * (hedge_leg.size_multiplier() / quote_filled_leg.size_multiplier()));
|
||||
out_hedge_price = Price((spread_price.value() - quote_fill_price.value() * quote_filled_leg.price_multiplier())/hedge_leg.price_multiplier());
|
||||
double out_hedge_quantity_d = std::abs(quote_fill_quantity.value() * (hedge_leg.size_multiplier() / quote_filled_leg.size_multiplier()));
|
||||
out_hedge_quantity_d = std::round(out_hedge_quantity_d);
|
||||
out_hedge_quantity = Quantity (out_hedge_quantity_d);
|
||||
double out_hedge_price_d = (spread_price.value() - quote_fill_price.value() * quote_filled_leg.price_multiplier())/hedge_leg.price_multiplier();
|
||||
out_hedge_price_d = bts::securities::raw_round_to_quote_price (out_hedge_price_d, hedge_leg.tick_size(), hedge_leg.trading_side());
|
||||
out_hedge_price = Price(out_hedge_price_d);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "server/sparkd/orderman/md/Book.h"
|
||||
#include "server/sparkd/spreader/quoter/quoter_states/QuoterEndStateWorker.h"
|
||||
#include "server/sparkd/spreader/quoter/quoter_states/QuoterState.h"
|
||||
#include "server/sparkd/spreader/SingleLegQuoter.h"
|
||||
|
||||
namespace bts{
|
||||
namespace orderman{
|
||||
@@ -9,7 +10,10 @@ namespace orderman{
|
||||
QuoterState QuoterEndStateWorker::state () const {return QuoterState::END;}
|
||||
void QuoterEndStateWorker::build_once (SingleLegQuoter* quoter)
|
||||
{
|
||||
_quoter = quoter;
|
||||
bool is_final = quoter->_is_permenantly_cancelled || quoter->_price_quantity_state.target_reached ();
|
||||
if (!is_final)
|
||||
// zeroing out any working state
|
||||
quoter->_transform_to_WAITING_FOR_SIZE ();
|
||||
}
|
||||
void QuoterEndStateWorker::init ()
|
||||
{
|
||||
|
||||
@@ -15,7 +15,6 @@ class SingleLegQuoter;
|
||||
class QuoterEndStateWorker : public IQuoterStateWorker
|
||||
{
|
||||
private:
|
||||
SingleLegQuoter* _quoter;
|
||||
const std::string _state_text;
|
||||
public:
|
||||
QuoterEndStateWorker () : _state_text ("END") {}
|
||||
|
||||
@@ -49,7 +49,7 @@ void QuoterStartStateWorker::other_leg_quoter_fill (size_t leg_index, Quantity f
|
||||
}
|
||||
void QuoterStartStateWorker::update_spreader_order (Price price, Quantity quantity)
|
||||
{
|
||||
_quoter->_price_quantity_state.update_out_price_quantity (price, quantity);
|
||||
_quoter->_price_quantity_state.update_target_price_quantity (price, quantity);
|
||||
_analyze_and_act ();
|
||||
}
|
||||
void QuoterStartStateWorker::_analyze_and_act ()
|
||||
|
||||
@@ -9,8 +9,7 @@ enum class QuoterState
|
||||
WAITING_FOR_FIRST_ACK,
|
||||
WAITING_FOR_FIRST_ACK_CANCELLED,
|
||||
WORKING,
|
||||
WAITING_FOR_CANCEL_ACK_FINAL,
|
||||
WAITING_FOR_CANCEL_ACK_CONTINUE,
|
||||
WAITING_FOR_CANCEL_ACK,
|
||||
END
|
||||
};
|
||||
}}
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
#include "server/sparkd/spreader/SpreaderOrderUpdateMessage.h"
|
||||
#include "server/sparkd/orderman/md/Book.h"
|
||||
#include "server/sparkd/spreader/quoter/quoter_states/QuoterWaitingForCancelAckFinalStateWorker.h"
|
||||
#include "server/sparkd/spreader/quoter/quoter_states/QuoterState.h"
|
||||
#include "server/sparkd/spreader/SingleLegQuoter.h"
|
||||
#include "server/sparkd/spreader/SpreaderOrderUpdateMessage.h"
|
||||
|
||||
namespace bts{
|
||||
namespace orderman{
|
||||
|
||||
QuoterState QuoterWaitingForCancelAckFinalStateWorker::state () const {return QuoterState::WAITING_FOR_CANCEL_ACK_FINAL;}
|
||||
void QuoterWaitingForCancelAckFinalStateWorker::build_once (SingleLegQuoter* quoter)
|
||||
{
|
||||
_quoter = quoter;
|
||||
}
|
||||
void QuoterWaitingForCancelAckFinalStateWorker::init ()
|
||||
{
|
||||
bts_assert_msg (false, "QuoterWaitingForCancelAckFinalStateWorker::init is an illegal operation");
|
||||
}
|
||||
void QuoterWaitingForCancelAckFinalStateWorker::on_order_update (const SpreaderOrderUpdateMessage& u)
|
||||
{
|
||||
bts_assert (u.acknowledged());
|
||||
_quoter->_price_quantity_state.add_filled_quantity (u.last_update_filled_quantity());
|
||||
if (u.terminal_status())
|
||||
_quoter->_transform_to_END ();
|
||||
}
|
||||
void QuoterWaitingForCancelAckFinalStateWorker::on_book (bts::orderman::TickToTradeCorID, size_t, const bts::orderman::Book&)
|
||||
{}
|
||||
void QuoterWaitingForCancelAckFinalStateWorker::cancel()
|
||||
{}
|
||||
void QuoterWaitingForCancelAckFinalStateWorker::terminate()
|
||||
{
|
||||
_quoter->_transform_to_END ();
|
||||
}
|
||||
void QuoterWaitingForCancelAckFinalStateWorker::on_time(const TimeStamp&)
|
||||
{
|
||||
// TODO check threshold
|
||||
}
|
||||
void QuoterWaitingForCancelAckFinalStateWorker::other_leg_quoter_fill (size_t leg_index, Quantity filled_quantity)
|
||||
{
|
||||
_quoter->_incorporate_other_leg_fill (leg_index, filled_quantity);
|
||||
}
|
||||
void QuoterWaitingForCancelAckFinalStateWorker::update_spreader_order (Price price, Quantity quantity)
|
||||
{
|
||||
_quoter->_price_quantity_state.update_out_price_quantity (price, quantity);
|
||||
}
|
||||
}}
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
#include "server/sparkd/spreader/SpreaderOrderUpdateMessage.h"
|
||||
#include "server/sparkd/orderman/md/Book.h"
|
||||
#include "server/sparkd/spreader/quoter/quoter_states/QuoterWaitingForCancelAckReturnStateWorker.h"
|
||||
#include "server/sparkd/spreader/quoter/quoter_states/QuoterState.h"
|
||||
#include "server/sparkd/spreader/SingleLegQuoter.h"
|
||||
#include "server/sparkd/spreader/SpreaderOrderUpdateMessage.h"
|
||||
|
||||
namespace bts{
|
||||
namespace orderman{
|
||||
|
||||
QuoterState QuoterWaitingForCancelAckReturnStateWorker::state () const {return QuoterState::WAITING_FOR_CANCEL_ACK_CONTINUE;}
|
||||
void QuoterWaitingForCancelAckReturnStateWorker::build_once (SingleLegQuoter* quoter)
|
||||
{
|
||||
_quoter = quoter;
|
||||
}
|
||||
void QuoterWaitingForCancelAckReturnStateWorker::init ()
|
||||
{
|
||||
bts_assert_msg (false, "QuoterWaitingForCancelAckReturnStateWorker::init is an illegal operation");
|
||||
}
|
||||
void QuoterWaitingForCancelAckReturnStateWorker::on_order_update (const SpreaderOrderUpdateMessage& u)
|
||||
{
|
||||
bts_assert (u.acknowledged());
|
||||
_quoter->_price_quantity_state.add_filled_quantity (u.last_update_filled_quantity());
|
||||
if (u.terminal_status())
|
||||
{
|
||||
// order is in terminal status, this is most likely a fill,
|
||||
// though in any case there is no action to take
|
||||
// TODO : get new order from spreader
|
||||
_quoter->_transform_to_WAITING_FOR_SIZE ();
|
||||
}
|
||||
else
|
||||
_analyze_and_act ();
|
||||
}
|
||||
void QuoterWaitingForCancelAckReturnStateWorker::on_book (bts::orderman::TickToTradeCorID, size_t, const bts::orderman::Book&)
|
||||
{}
|
||||
void QuoterWaitingForCancelAckReturnStateWorker::cancel()
|
||||
{
|
||||
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK_FINAL ();
|
||||
}
|
||||
void QuoterWaitingForCancelAckReturnStateWorker::terminate()
|
||||
{
|
||||
_quoter->_transform_to_END ();
|
||||
}
|
||||
void QuoterWaitingForCancelAckReturnStateWorker::on_time(const TimeStamp&)
|
||||
{}
|
||||
void QuoterWaitingForCancelAckReturnStateWorker::other_leg_quoter_fill (size_t leg_index, Quantity filled_quantity)
|
||||
{
|
||||
_quoter->_incorporate_other_leg_fill (leg_index, filled_quantity);
|
||||
_analyze_and_act ();
|
||||
}
|
||||
void QuoterWaitingForCancelAckReturnStateWorker::update_spreader_order (Price price, Quantity quantity)
|
||||
{
|
||||
_quoter->_price_quantity_state.update_out_price_quantity (price, quantity);
|
||||
_analyze_and_act ();
|
||||
}
|
||||
void QuoterWaitingForCancelAckReturnStateWorker::_analyze_and_act ()
|
||||
{
|
||||
if (_quoter->_price_quantity_state.target_reached())
|
||||
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK_FINAL ();
|
||||
}
|
||||
|
||||
}}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "server/sparkd/orderman/utils/orderman_utils.h"
|
||||
#include "lib/utils/bts_chrono.h"
|
||||
#include "server/sparkd/spreader/quoter/quoter_states/QuoterState.h"
|
||||
#include "server/sparkd/spreader/quoter/IQuoterStateWorker.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
class SpreaderOrderUpdateMessage;
|
||||
class Book;
|
||||
class SingleLegQuoter;
|
||||
// if the market dissapears from a working order and the target
|
||||
// has not been reached, then working->waiting_for_cancel_ack_return
|
||||
// happen. here it waits for the cancels and goes back to working_for_size
|
||||
class QuoterWaitingForCancelAckReturnStateWorker : public IQuoterStateWorker
|
||||
{
|
||||
private:
|
||||
SingleLegQuoter* _quoter;
|
||||
const std::string _state_text;
|
||||
public:
|
||||
QuoterWaitingForCancelAckReturnStateWorker () : _state_text ("WAITING_FOR_CANCEL_ACK_CONTINUE") {}
|
||||
QuoterState state () const override;
|
||||
const std::string& state_text () const override {return _state_text;}
|
||||
void build_once (SingleLegQuoter* quoter) override;
|
||||
void init () override;
|
||||
void on_order_update (const SpreaderOrderUpdateMessage& order_update) override;
|
||||
void on_book (bts::orderman::TickToTradeCorID corid, size_t leg_id, const bts::orderman::Book& book) override;
|
||||
void cancel() override;
|
||||
void terminate() override;
|
||||
void on_time(const TimeStamp& ts) override;
|
||||
void other_leg_quoter_fill (size_t leg_id, Quantity fill_quantity) override;
|
||||
void update_spreader_order (Price price, Quantity quantity) override;
|
||||
private:
|
||||
void _analyze_and_act ();
|
||||
};
|
||||
}}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
#include "server/sparkd/spreader/SpreaderOrderUpdateMessage.h"
|
||||
#include "server/sparkd/orderman/md/Book.h"
|
||||
#include "server/sparkd/spreader/quoter/quoter_states/QuoterWaitingForCancelAckStateWorker.h"
|
||||
#include "server/sparkd/spreader/quoter/quoter_states/QuoterState.h"
|
||||
#include "server/sparkd/spreader/SingleLegQuoter.h"
|
||||
#include "server/sparkd/spreader/SpreaderOrderUpdateMessage.h"
|
||||
|
||||
namespace bts{
|
||||
namespace orderman{
|
||||
|
||||
QuoterState QuoterWaitingForCancelAckStateWorker::state () const {return QuoterState::WAITING_FOR_CANCEL_ACK;}
|
||||
void QuoterWaitingForCancelAckStateWorker::build_once (SingleLegQuoter* quoter)
|
||||
{
|
||||
_quoter = quoter;
|
||||
}
|
||||
void QuoterWaitingForCancelAckStateWorker::init ()
|
||||
{
|
||||
bts_assert_msg (false, "QuoterWaitingForCancelAckStateWorker::init is an illegal operation");
|
||||
}
|
||||
void QuoterWaitingForCancelAckStateWorker::on_order_update (const SpreaderOrderUpdateMessage& u)
|
||||
{
|
||||
bts_assert (u.acknowledged());
|
||||
_quoter->_price_quantity_state.add_filled_quantity (u.last_update_filled_quantity());
|
||||
if (u.terminal_status())
|
||||
{
|
||||
_quoter->_price_quantity_state.clear_out_price_quantity ();
|
||||
_quoter->_transform_to_END ();
|
||||
}
|
||||
}
|
||||
void QuoterWaitingForCancelAckStateWorker::on_book (bts::orderman::TickToTradeCorID, size_t, const bts::orderman::Book&)
|
||||
{}
|
||||
void QuoterWaitingForCancelAckStateWorker::cancel()
|
||||
{}
|
||||
void QuoterWaitingForCancelAckStateWorker::terminate()
|
||||
{
|
||||
_quoter->_transform_to_END ();
|
||||
}
|
||||
void QuoterWaitingForCancelAckStateWorker::on_time(const TimeStamp&)
|
||||
{
|
||||
// TODO check threshold
|
||||
}
|
||||
void QuoterWaitingForCancelAckStateWorker::other_leg_quoter_fill (size_t leg_index, Quantity filled_quantity)
|
||||
{
|
||||
_quoter->_incorporate_other_leg_fill (leg_index, filled_quantity);
|
||||
}
|
||||
void QuoterWaitingForCancelAckStateWorker::update_spreader_order (Price price, Quantity quantity)
|
||||
{
|
||||
_quoter->_price_quantity_state.update_target_price_quantity (price, quantity);
|
||||
}
|
||||
}}
|
||||
+2
-2
@@ -12,13 +12,13 @@ class Book;
|
||||
class SingleLegQuoter;
|
||||
// this state is reached when the cancel has been sent
|
||||
// and it is waiting for the cancelled ack
|
||||
class QuoterWaitingForCancelAckFinalStateWorker : public IQuoterStateWorker
|
||||
class QuoterWaitingForCancelAckStateWorker : public IQuoterStateWorker
|
||||
{
|
||||
private:
|
||||
SingleLegQuoter* _quoter;
|
||||
const std::string _state_text;
|
||||
public:
|
||||
QuoterWaitingForCancelAckFinalStateWorker () : _state_text ("WAITING_FOR_CANCEL_ACK_FINAL") {}
|
||||
QuoterWaitingForCancelAckStateWorker () : _state_text ("WAITING_FOR_CANCEL_ACK") {}
|
||||
public:
|
||||
QuoterState state () const override;
|
||||
const std::string& state_text () const override {return _state_text;}
|
||||
+7
-3
@@ -22,12 +22,16 @@ void QuoterWaitingForFirstAckCancelledWorker::on_order_update (const SpreaderOrd
|
||||
bts_assert (u.acknowledged());
|
||||
_quoter->_price_quantity_state.add_filled_quantity (u.last_update_filled_quantity());
|
||||
if (u.terminal_status())
|
||||
{
|
||||
_quoter->_price_quantity_state.clear_out_price_quantity ();
|
||||
_quoter->_transform_to_END ();
|
||||
}
|
||||
else
|
||||
{
|
||||
// got an ack, now cancel the order
|
||||
_quoter->_order.cancel();
|
||||
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK_FINAL ();
|
||||
// TODO: commenting out for the unit tests (no real order)
|
||||
//_quoter->_order.cancel();
|
||||
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK ();
|
||||
}
|
||||
}
|
||||
void QuoterWaitingForFirstAckCancelledWorker::on_book (bts::orderman::TickToTradeCorID, size_t, const bts::orderman::Book&)
|
||||
@@ -46,6 +50,6 @@ void QuoterWaitingForFirstAckCancelledWorker::other_leg_quoter_fill (size_t leg_
|
||||
}
|
||||
void QuoterWaitingForFirstAckCancelledWorker::update_spreader_order (Price price, Quantity quantity)
|
||||
{
|
||||
_quoter->_price_quantity_state.update_out_price_quantity (price, quantity);
|
||||
_quoter->_price_quantity_state.update_target_price_quantity (price, quantity);
|
||||
}
|
||||
}}
|
||||
@@ -22,7 +22,10 @@ void QuoterWaitingForFirstAckWorker::on_order_update (const SpreaderOrderUpdateM
|
||||
bts_assert (u.acknowledged());
|
||||
_quoter->_price_quantity_state.add_filled_quantity (u.last_update_filled_quantity());
|
||||
if (u.terminal_status())
|
||||
{
|
||||
_quoter->_price_quantity_state.clear_out_price_quantity ();
|
||||
_quoter->_transform_to_END ();
|
||||
}
|
||||
else
|
||||
_quoter->_transform_to_WORKING ();
|
||||
}
|
||||
@@ -45,7 +48,7 @@ void QuoterWaitingForFirstAckWorker::other_leg_quoter_fill (size_t leg_index, Qu
|
||||
}
|
||||
void QuoterWaitingForFirstAckWorker::update_spreader_order (Price price, Quantity quantity)
|
||||
{
|
||||
_quoter->_price_quantity_state.update_out_price_quantity (price, quantity);
|
||||
_quoter->_price_quantity_state.update_target_price_quantity (price, quantity);
|
||||
_analyze_and_act ();
|
||||
}
|
||||
void QuoterWaitingForFirstAckWorker::_analyze_and_act ()
|
||||
|
||||
@@ -45,10 +45,10 @@ void QuoterWaitingForSizeStateWorker::other_leg_quoter_fill (size_t leg_index, Q
|
||||
}
|
||||
void QuoterWaitingForSizeStateWorker::update_spreader_order (Price price, Quantity quantity)
|
||||
{
|
||||
_quoter->_price_quantity_state.update_out_price_quantity (price, quantity);
|
||||
_quoter->_price_quantity_state.update_target_price_quantity (price, quantity);
|
||||
_longpath_analyze_and_act (bts::orderman::NullTickToTradeCorID);
|
||||
}
|
||||
void QuoterWaitingForSizeStateWorker::_longpath_analyze_and_act (bts::orderman::TickToTradeCorID corid)
|
||||
void QuoterWaitingForSizeStateWorker::_longpath_analyze_and_act (bts::orderman::TickToTradeCorID)
|
||||
{
|
||||
if (_quoter->_price_quantity_state.target_reached())
|
||||
{
|
||||
@@ -63,8 +63,9 @@ void QuoterWaitingForSizeStateWorker::_longpath_analyze_and_act (bts::orderman::
|
||||
{
|
||||
_quoter->_price_quantity_state.update_out_price_quantity(out_price, out_quantity);
|
||||
LOG(OrderMan, Diag, "QuoterWaitingForSizeStateWorker key: {}, sending order, price: {} quantity: {}",
|
||||
_quoter->_order.order_key().value(), out_price.value(), out_quantity.value());
|
||||
_quoter->_order.create(corid, _quoter->_price_quantity_state.out_price(), _quoter->_price_quantity_state.out_quantity());
|
||||
_quoter->_order.order_key().value(), out_price.value(), out_quantity.value());
|
||||
// TODO
|
||||
//_quoter->_order.create(corid, _quoter->_price_quantity_state.out_price(), _quoter->_price_quantity_state.out_quantity());
|
||||
_quoter->_transform_to_WAITING_FOR_FIRST_ACK ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ void QuoterWorkingStateWorker::on_book (bts::orderman::TickToTradeCorID corid, s
|
||||
void QuoterWorkingStateWorker::cancel()
|
||||
{
|
||||
_quoter->_order.cancel ();
|
||||
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK_FINAL ();
|
||||
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK ();
|
||||
}
|
||||
void QuoterWorkingStateWorker::terminate()
|
||||
{
|
||||
@@ -48,7 +48,7 @@ void QuoterWorkingStateWorker::other_leg_quoter_fill (size_t leg_index, Quantity
|
||||
}
|
||||
void QuoterWorkingStateWorker::update_spreader_order (Price price, Quantity quantity)
|
||||
{
|
||||
_quoter->_price_quantity_state.update_out_price_quantity (price, quantity);
|
||||
_quoter->_price_quantity_state.update_target_price_quantity (price, quantity);
|
||||
_longpath_analyze_and_act (bts::orderman::NullTickToTradeCorID);
|
||||
}
|
||||
void QuoterWorkingStateWorker::_longpath_analyze_and_act (bts::orderman::TickToTradeCorID corid)
|
||||
@@ -60,7 +60,7 @@ void QuoterWorkingStateWorker::_longpath_analyze_and_act (bts::orderman::TickToT
|
||||
// ii. fills in other legs causing reduction here
|
||||
// iii. quantity reduction in the spreader order by the user
|
||||
_quoter->_order.cancel ();
|
||||
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK_FINAL ();
|
||||
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK ();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -72,7 +72,7 @@ void QuoterWorkingStateWorker::_longpath_analyze_and_act (bts::orderman::TickToT
|
||||
{
|
||||
// no size could be computed, go to wait state
|
||||
_quoter->_order.cancel ();
|
||||
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK_CONTINUE ();
|
||||
_quoter->_transform_to_WAITING_FOR_CANCEL_ACK();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user