Merge branch 'master' of bitbucket.org:bluetradesys/spark into algos2

This commit is contained in:
Kevin Darby committed 2019-02-11 11:39:36 -05:00
commit 83104ebaa9
24 files changed
+357 -70

No files matched your search

+15
View File
@@ -1,5 +1,20 @@
# Release Notes
## 1.5.0
### User Visible Changes
#### User Interface Improvements
- Removed security key field from most grids
- Removed trade key field from time and sales grid
- Fixed the "Since Open" time filter to use the exchange open time rather than 8:30 AM
- Fixed the floating order book so that rows are no longer
highlighted after an order is modified
#### SDK
- Improved SDK documentation and usability
### Internal Changes
- Improved robustness of limit system test
- Extensive market data refactoring allow for security definition updates
## 1.4.11
### New Features
- Floating Order Book
@@ -96,7 +96,7 @@ namespace bts.shell {
public static GridColumnSettings day_change => new GridColumnSettings(col_id(Columns.DayChange), DefaultColumnHeaders.DayChange, width: DefaultColumnWidths.Price, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
public static GridColumnSettings session_low => new GridColumnSettings(col_id(Columns.SessionLow), DefaultColumnHeaders.SessionLow, width: DefaultColumnWidths.Price, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
public static GridColumnSettings session_high => new GridColumnSettings(col_id(Columns.SessionHigh), DefaultColumnHeaders.SessionHigh, width: DefaultColumnWidths.Price, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, width: DefaultColumnWidths.SecurityKey);
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, is_visible: false, width: DefaultColumnWidths.SecurityKey);
@@ -38,7 +38,6 @@ namespace mbts.spark {
price_filter.load_state(filters.price);
size_filter.load_state(filters.size);
aggressor_filter.load_state(filters.aggressor_sides);
trade_key_filter.load_state(filters.trade_key);
security_key_filter.load_state(filters.security_key);
}
// Columns
@@ -47,7 +46,6 @@ namespace mbts.spark {
add_column(TimeAndSalesView.Columns.Price, DefaultColumnHeaders.Price, DefaultColumnWidths.Price, nameof(Row.price), price_filter, DataGridFilterKnownTemplates.DoubleMinMax, System.Windows.HorizontalAlignment.Right);
add_column(TimeAndSalesView.Columns.Size, DefaultColumnHeaders.Size, DefaultColumnWidths.Size, nameof(Row.size), size_filter, DataGridFilterKnownTemplates.UIntMinMax, System.Windows.HorizontalAlignment.Right);
add_column(TimeAndSalesView.Columns.Aggressor, DefaultColumnHeaders.Aggressor, DefaultColumnWidths.Aggressor, nameof(Row.aggressor_side), aggressor_filter, DataGridFilterKnownTemplates.EnumValues);
add_column(TimeAndSalesView.Columns.TradeKey, DefaultColumnHeaders.TradeKey, DefaultColumnWidths.TradeKey, nameof(Row.trade_key), trade_key_filter, DataGridFilterKnownTemplates.Regex);
add_column(TimeAndSalesView.Columns.SecurityKey, DefaultColumnHeaders.SecurityKey, DefaultColumnWidths.SecurityKey, nameof(Row.security_key), security_key_filter, DataGridFilterKnownTemplates.Regex);
void add_column(TimeAndSalesView.Columns col_key, string header, double width, string sort_member_path, IDataGridColumnFilter filter, string filter_template, System.Windows.HorizontalAlignment h_alignment = System.Windows.HorizontalAlignment.Left) =>
columns.Add(new TimeAndSalesColumn(
@@ -66,7 +64,7 @@ namespace mbts.spark {
_resources.AddRange(
show_ladder,
DataGridFilterHelper.hook_filters(
rows_view, time_filter, security_filter, price_filter, size_filter, aggressor_filter, trade_key_filter, security_key_filter),
rows_view, time_filter, security_filter, price_filter, size_filter, aggressor_filter, security_key_filter),
settings_manager.subscribe_current().OnDispatcher().Subscribe(grid_settings_manager)
);
rows_view.set_sort_descriptions(startup_data.sorting_criterion, columns);
@@ -103,7 +101,6 @@ namespace mbts.spark {
public IDataGridColumnPersistentFilter<Row, UIntMinMaxState> size_filter { get; } = new UIntMinMax<Row>(r => r.size, nameof(Row.size));
public IDataGridColumnPersistentFilter<Row, AggressorSide[]> aggressor_filter { get; } = DiscreteValuesFilterVM.Create<Row, AggressorSide>(EnumHelper.get_values<AggressorSide>().ToArray(), r => r.aggressor_side, nameof(Row.aggressor_side));
public IDataGridColumnPersistentFilter<Row, string> security_key_filter { get; } = new RegexFilterVM<Row>(r => r.security_key.ToString(), nameof(Row.security_key));
public IDataGridColumnPersistentFilter<Row, string> trade_key_filter { get; } = new RegexFilterVM<Row>(r => r.trade_key.ToString(), nameof(Row.trade_key));
FilterStates _get_filter_states() =>
new FilterStates {
@@ -111,7 +108,6 @@ namespace mbts.spark {
security = security_filter.get_state(),
price = price_filter.get_state(),
size = size_filter.get_state(),
trade_key = trade_key_filter.get_state(),
security_key = security_key_filter.get_state(),
aggressor_sides = aggressor_filter.get_state()
};
@@ -175,7 +171,6 @@ namespace mbts.spark {
case TimeAndSalesView.Columns.Price: return _price_text;
case TimeAndSalesView.Columns.Size: return _size_text;
case TimeAndSalesView.Columns.Aggressor: return _aggressor_text;
case TimeAndSalesView.Columns.TradeKey: return _trade_key_text;
case TimeAndSalesView.Columns.SecurityKey: return _security_key_text;
default: return null;
}
@@ -7,7 +7,7 @@ namespace mbts.ui.spark {
/// Interaction logic for TimeAndSalesView.xaml
/// </summary>
partial class TimeAndSalesView : UserControl {
public enum Columns { Time, Security, Price, Size, OrderType, TradeKey, SecurityKey, Aggressor }
public enum Columns { Time, Security, Price, Size, OrderType, SecurityKey, Aggressor }
public TimeAndSalesView() =>
InitializeComponent();
@@ -84,8 +84,7 @@ namespace bts.shell {
public static GridColumnSettings price => new GridColumnSettings(col_id(Columns.Price), DefaultColumnHeaders.Price, width: DefaultColumnWidths.Price, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
public static GridColumnSettings size => new GridColumnSettings(col_id(Columns.Size), DefaultColumnHeaders.Size, width: DefaultColumnWidths.Size, horizontal_alignment: System.Windows.HorizontalAlignment.Right);
public static GridColumnSettings aggressor => new GridColumnSettings(col_id(Columns.Aggressor), DefaultColumnHeaders.Aggressor, width: DefaultColumnWidths.Aggressor);
public static GridColumnSettings trade_key => new GridColumnSettings(col_id(Columns.TradeKey), DefaultColumnHeaders.TradeKey, width: DefaultColumnWidths.TradeKey);
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, width: DefaultColumnWidths.SecurityKey);
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, is_visible:false, width: DefaultColumnWidths.SecurityKey);
public static IEnumerable<SortingCriteria> default_sorting_criterion {
get {
@@ -100,7 +99,6 @@ namespace bts.shell {
yield return price;
yield return size;
yield return aggressor;
yield return trade_key;
yield return security_key;
}
}
@@ -117,8 +115,8 @@ namespace bts.shell {
public DoubleMinMaxState price;
[ProtoMember(4)]
public UIntMinMaxState size;
[ProtoMember(5)]
public string trade_key;
// [ProtoMember(5)]
// ProtoMember 5 cannot be used further
[ProtoMember(6)]
public string security_key;
[ProtoMember(7)]
@@ -66,7 +66,7 @@ namespace bts.shell {
public static GridColumnSettings description => new GridColumnSettings(col_id(Columns.Description), DefaultColumnHeaders.Description, width: DefaultColumnWidths.Description);
public static GridColumnSettings n_legs => new GridColumnSettings(col_id(Columns.n_legs), DefaultColumnHeaders.N_Legs, width: DefaultColumnWidths.N_Legs);
public static GridColumnSettings n_working_orders => new GridColumnSettings(col_id(Columns.n_working_orders), DefaultColumnHeaders.N_Working_Orders, width: DefaultColumnWidths.N_Working_Orders);
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, width: DefaultColumnWidths.SecurityKey);
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, is_visible: false, width: DefaultColumnWidths.SecurityKey);
public static IEnumerable<SortingCriteria> default_sorting_criterion {
get {
@@ -86,7 +86,7 @@ namespace bts.shell {
public static GridColumnSettings fill_kind => new GridColumnSettings(col_id(Columns.FillKind), DefaultColumnHeaders.FillKind, width: DefaultColumnWidths.FillKind);
public static GridColumnSettings fill_key => new GridColumnSettings(col_id(Columns.FillKey), DefaultColumnHeaders.FillKey, width: DefaultColumnWidths.FillKey);
public static GridColumnSettings order_key => new GridColumnSettings(col_id(Columns.OrderKey), DefaultColumnHeaders.OrderKey, width: DefaultColumnWidths.OrderKey);
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, width: DefaultColumnWidths.SecurityKey);
public static GridColumnSettings security_key => new GridColumnSettings(col_id(Columns.SecurityKey), DefaultColumnHeaders.SecurityKey, is_visible: false, width: DefaultColumnWidths.SecurityKey);
public static IEnumerable<SortingCriteria> default_sorting_criterion {
get {
yield return new SortingCriteria(fill_time.id, false);
@@ -130,7 +130,10 @@ namespace mbts.spark {
public ICommand modify_order_quantity => _modify_order_quantity ??
(_modify_order_quantity = new DelegateCommand(
(desired_quantity) => _owner.modify_order_quantity(this, (uint)desired_quantity),
(desired_quantity) => {
_owner.modify_order_quantity(this, (uint)desired_quantity);
_unselect_me();
},
(desired_quantity) =>
(desired_quantity != null && this.status == OrderStatus.Working && (uint)desired_quantity != this.quantity)
|| is_qty_dirty
@@ -139,12 +142,20 @@ namespace mbts.spark {
public ICommand modify_order_price => _modify_order_price ??
(_modify_order_price = new DelegateCommand(
(desired_price) => _owner.modify_order_price(this, (double)desired_price),
(desired_price) => {
_owner.modify_order_price(this, (double)desired_price);
_unselect_me();
},
(desired_price) =>
(desired_price != null && this.status == OrderStatus.Working && (double)desired_price != this.price)
|| is_price_dirty
)
);
);
private void _unselect_me() {
this.is_selected = false;
_owner.current_row = null;
}
// These fns present a way for the orderbook to avoid noisy, intermittent collection changes during "Expand/Collapse All" ops,
// when incremental changes are ignored in favor of a full reset, after 'is_expanded' is updated for all rows.
@@ -76,7 +76,19 @@ namespace mbts.spark {
public ObservableAppendCollection<DIYGrid.ColumnBase> columns { get; }
public ObservableCollection<DIYGrid.ColumnBase> core_columns => _columns;
public ObservableCollection<OrderBookRowVM> rows => _row_collection;
public OrderBookRowVM current_row { get => _current_row.Value; set => _current_row.Value = value ?? _selected_rows.FirstOrDefault(); }
public OrderBookRowVM current_row {
get => _current_row.Value;
set {
_current_row.Value = value;
// this is so that when the current_row is set to null from
// the row_vm, we propagate the change up to the OrderBookWindow
// so that the cancel and modify commands can_execute is updated.
// Note that this is really only for if/when the edit_xxx columns
// from the mini-ob are present in regular orderbook, else this is
// a no-op.
selected_order_changed?.Invoke(current_order);
}
}
public OrderRecordImmutable? current_order => current_row?.order;
public IEnumerable<OrderRecordImmutable> selected_orders => _selected_rows.Select(r => r.order);
public _GridSettingsManager grid_settings_manager { get; }
@@ -167,11 +167,9 @@ namespace mbts.spark {
}
private void _vm_selected_order_changed(OrderRecordImmutable? e) {
if (e.HasValue) {
_modify_order_command.raiseCanExecuteChanged();
_cancel_selected_orders_command.raiseCanExecuteChanged();
_recreate_selected_orders_command.raiseCanExecuteChanged();
}
}
}
}
@@ -112,7 +112,7 @@ namespace bts.shell {
public static GridColumnSettings last_price => new GridColumnSettings(Columns.LastPrice.ToString(), "Last Filled", width: DIYGrid.DefaultColumnWidths.LastPrice, horizontal_alignment: HorizontalAlignment.Right);
public static GridColumnSettings status => new GridColumnSettings(Columns.Status.ToString(), "Status", width: 80);
public static GridColumnSettings last_message => new GridColumnSettings(Columns.LastMessage.ToString(), "Last Message", width: DIYGrid.DefaultColumnWidths.LastMessage);
public static GridColumnSettings security_key => new GridColumnSettings(Columns.SecurityKey.ToString(), DIYGrid.DefaultColumnHeaders.SecurityKey, width: DIYGrid.DefaultColumnWidths.SecurityKey);
public static GridColumnSettings security_key => new GridColumnSettings(Columns.SecurityKey.ToString(), DIYGrid.DefaultColumnHeaders.SecurityKey, is_visible: false, width: DIYGrid.DefaultColumnWidths.SecurityKey);
public static GridColumnSettings order_key => new GridColumnSettings(Columns.OrderKey.ToString(), DIYGrid.DefaultColumnHeaders.OrderKey, width: DIYGrid.DefaultColumnWidths.OrderKey);
public static GridColumnSettings parent_key => new GridColumnSettings(Columns.ParentKey.ToString(), "Parent Key", width: DIYGrid.DefaultColumnWidths.ParentKey);
@@ -51,7 +51,7 @@ namespace bts.proto {
static class DateTimeProviderExtensions {
public static DateTime get_date_time(this DateTimeProvider dtp) {
switch (dtp.mode) {
case DateTimeProviderMode.CMEOpen: return MarketSchedule.get_cme_gen_open();
case DateTimeProviderMode.CMEOpen: return MarketSchedule.get_start_of_trading_day();
case DateTimeProviderMode.Today: return DateTime.Today;
case DateTimeProviderMode.Explicit:
default: return dtp.explicit_date.GetValueOrDefault();
@@ -36,7 +36,6 @@ namespace mbts.ui.controls {
Symbol = 78,
Time = 112,
TimeInForce = 47,
TradeKey = 76,
User = 53,
Aggressor = 80,
Volume = 74,
@@ -71,7 +70,6 @@ namespace mbts.ui.controls {
ImpliedSize = "Qty (I)",
Symbol = "Symbol",
TimeInForce = "TIF",
TradeKey = "Trade Key",
User = "User",
Time = "Time",
Aggressor = "Aggressor",
@@ -14,7 +14,7 @@ namespace mbts.spark.filters {
TimeFilterMode _mode;
TimeTextTuple _begin, _end;
DateTime? _begin_dt, _end_dt;
readonly DateTime _cme_open = MarketSchedule.get_cme_gen_open();
readonly DateTime _cme_open = MarketSchedule.get_start_of_trading_day();
public TimeFilterVM(Func<TRow, DateTime> get_row_val, string prop_name) : base(get_row_val, prop_name) =>
_set_default_values();
@@ -28,31 +28,10 @@ namespace mbts.spark {
static readonly int sod_hh = (int)config.Configuration.get<bts.config.SODTime>().sod_hh;
static readonly int sod_mm = (int)config.Configuration.get<bts.config.SODTime>().sod_mm;
static readonly TimeZoneInfo central_tzi = TimeZoneInfo.FindSystemTimeZoneById(cst_id);
static readonly DateTime _start_of_trading_day_utc;
static readonly DateTime _adjusted_central_sod;
static readonly DateTime unadjusted_central_sod = TimeZoneInfo.ConvertTimeFromUtc(
DateTime.UtcNow.Date.Add(new TimeSpan(sod_hh, sod_mm, 0)),
central_tzi
);
static MarketSchedule() {
var cme_schedule = config.Configuration.get<bts.md.CMETradingSchedule>();
_cme_gen_open_hrs = cme_schedule?.gen_open_hour ?? 8.5;
_adjusted_central_sod = !central_tzi.IsDaylightSavingTime(unadjusted_central_sod) ? unadjusted_central_sod.AddHours(1) : unadjusted_central_sod;
// Note that this isn't the acutal start of the trading day
// but it's close enough for pnl purposes.
// In reality, instruments have different schedules
// if now is less than the current sod, then we me move the sod back a day to account for the trading day start
if (_adjusted_central_sod >= TimeZoneInfo.ConvertTime(DateTime.Now, central_tzi)) {
_adjusted_central_sod = _adjusted_central_sod.AddDays(-1);
}
var local_time_zone_sod = TimeZoneInfo.ConvertTime(_adjusted_central_sod, central_tzi, TimeZoneInfo.Local);
_start_of_trading_day_utc = local_time_zone_sod.ToUniversalTime();
}
// for object initializers
public MarketSchedule() { }
@@ -73,6 +52,27 @@ namespace mbts.spark {
return last_open;
}
// DateTime? used here b/c we can't set a default parameter with DateTime.Now
// since it's not a compile-time constant
public static DateTime get_start_of_trading_day(DateTime? target_datetime = null, DateTimeKind dtk = DateTimeKind.Local ) {
if (target_datetime == null) target_datetime = DateTime.Now;
var dst_adjusted_central_sod = new DateTimeOffset(
new DateTime(target_datetime.Value.Date.Add(new TimeSpan(sod_hh, sod_mm, 0)).Ticks, DateTimeKind.Unspecified),
central_tzi.BaseUtcOffset
);
// if we're not currently past the start of the trading day, then the start must be yesterday
var temp = dst_adjusted_central_sod;
if (temp >= TimeZoneInfo.ConvertTime(target_datetime.Value, central_tzi)) {
temp = dst_adjusted_central_sod.AddDays(-1);
}
var local_time_zone_sod = TimeZoneInfo.ConvertTime(temp.DateTime, central_tzi, TimeZoneInfo.Local);
if (dtk == DateTimeKind.Utc) {
return local_time_zone_sod.ToUniversalTime();
}
return local_time_zone_sod;
}
public static DateTime get_utctimestamp_as_localtime(string s) {
return DateTimeOffset.ParseExact(s, "yyyyMMddHHmmssffffff", null, System.Globalization.DateTimeStyles.AssumeUniversal).ToLocalTime().LocalDateTime;
}
+30 -14
View File
@@ -1,8 +1,31 @@
# BTS Spark
Our offering consists of a client UI [Spark Client](https://www.bluetradingsystems.com/images/Images/spark/02.06.19/Ladder.png), a high performance professional futures front end, connected via our proprietary protocol over TCP to our Spark Server, which in turn connects to execution venues via their native protocols (typically FIX/TCP for execution and some proprietary protocol over UDP multicast for market data).
![alt text](https://www.bluetradingsystems.com/images/Images/api/API.png)
# BTS Spark Client SDK
#### Getting Started
We currently offer two API extension points. This repository, our BTS **Spark Client SDK** allows users to control our Spark Server externally, that is, out of process, using the exact same protocol our own Spark Client does. In other words, a client application developed via the Spark Client SDK, say a VB .NET UI, would be able to provide any functionality our own UI provides.
## Git
We currently offer bindings for the Spark protocol to C++, C# and Excel clients. Since the underlying transport is TCP, clients developed via the Spark Client SDK can be located anywhere in the world, as long as they can reach the Spark Server via TCP. We do require a VPN or a secure network, since the Spark Protocol is currently not yet encrypted.
Our second API extension point is intended for users that require adding functionality to our Spark Server. If you are interested in extending the server process through custom order types, market data sources, or execution gateways, please see the [Spark Server SDK](https://github.com/BlueTradingSystems/spark_sdk).
### In Depth
* [Interface Overview](doc/Overview.md)
* [Threading Notes](doc/Threading.md)
## Getting Started
### Git
* First clone the spark_client_sdk repo
@@ -11,7 +34,7 @@
```
## Build
### Build
* Use msbuild to target windows / .net 4.71
* Install studio here if you don't have it: https://visualstudio.microsoft.com/downloads/
* Use VSCode for editing, it's better: https://code.visualstudio.com/
@@ -24,7 +47,7 @@ spark_client_sdk\src\spark_sdk> msbuild
* spark_sdk binaries will be produced in the bin\Debug directory
## Connecting to Spark Server
### Connecting to Spark Server
* Start your exe using the -ConfigServer parameter to point at a running Spark Server
```
@@ -35,7 +58,7 @@ spark_client_sdk\src\spark_sdk> msbuild
include: "http://location:8000/config/"
```
## Examples
### Examples
* Make sure you can connect to a running server
* run spark_sdk.exe with no parameters to see help
```
@@ -58,22 +81,15 @@ Arguments:
* [Driver](src/spark_sdk/samples/SDKMain.cs)
## Excel
### Excel
```
spark_sdk\bin\Debug\net471> start spark_excel-addin64-packed.xll
```
* This will start excel and load the bts addin
* Check the [```excel```](excel/) directory for an example spreadsheet
## Notes
* Our client side API is based on Google's protocol buffers; the message types are all protos. https://developers.google.com/protocol-buffers/
* We extended the protoc compiler to generate c#, c++, excel and js bindings to the services provided by our server process (https://github.com/BlueTradingSystems/spark_sdk)
* ### Dotnet core
### Dotnet core
* Right now we only support c# Windows 10 clients, but the package targets both net471 and .net core 2.1.6, so in theory one could run a .net core or c++ client on linux with a little work.
+103
View File
@@ -0,0 +1,103 @@
## Spark Client SDK Overview
The high level description of our order entry interface is as follows:
```
service OrderService {
// RPCs
rpc create_order(Create) returns (Response)
rpc cancel_order(Cancel) returns (Response)
rpc update_order(Update) returns (Response)
// Streams
rpc orders (OrdersSub) returns (stream OrderRecord);
rpc fills (FillsSub) returns (stream Fill);
}
```
This description uses the Google Protocol Buffers syntax to define the server interface (we use our own little compiler to generate bindings to this interface in C#, C++ and Excel). Using this server interface we can create, cancel or update orders, using the Remote Procedure Calls (RPCs) defined these orders can be exchange native orders or our own high level algo orders, or new order types created by users via the Spark Server SDK). We can monitor order state by subscribing to the orders stream above, which produces a a stream of OrderRecord objects, each capturing the latest state of a particular order, as it goes through it life cycle.
An OrderRecord looks like this:
```
message OrderRecord {
uint32 key;
uint32 parent_key;
OrderDefinition def;
OrderState state;
}
```
We have an order key, a possibly null parent order key, an OrderDefinition record, which defines the basic elements of the order, namely its type, side, security, account, etc, and an OrderState record, which captures the latest state of the order:
```
message OrderState {
// Standard order state, shared by all order types
OrderStatus status ;
double price ;
uint32 quantity ;
uint32 filled_quantity;
double last_price;
double avg_price;
string last_msg;
google.protobuf.Timestamp created;
google.protobuf.Timestamp last_change;
// Custom order state, specific to the order type in question
oneof custom {
// native order types
MarketOrderState market;
LimitOrderState limit;
StopOrderState stop;
StopLimitOrderState stop_limit;
// algo order types
IcebergOrderState iceberg;
SpreaderOrderState spreader;
TimeBoxOrderState time_box;
TickOrderState tick;
LeanOrderState lean;
JoinOrderState join;
TopOrderState top;evident
TriggerOrderState trigger;
CoverOrderState cover;
OffsetOrderState offset;
DynamicOrderState dynamic;
}
}
```
This OrderState record consists of a common part, applicable to all order types, and a custom part that is specific to the particular order type the record is associated with. Most of the standard fields should be self-explanatory, the latest price, the latest quantity, the filled quantity, etc. The status enumerate field tells you which state the order is in. We currently define the following states:
```
enum OrderStatus {
// The order has been constructed but not acted on. Inactive orders
// can be abandoned without consequences. This state should only be
// used internally by the order manager, i.e. it should never appear
// in externally visible orders.
ORDER_STATUS_INACTIVE = 0;
// The order is currently working, i.e. its algorithm is operating.
ORDER_STATUS_WORKING = 1;
// The order has completed successfully and accomplished its
// goal. This is a terminal state.
ORDER_STATUS_COMPLETED = 2;
// The order was terminated orderly before it had a chance to
// complete. This is a terminal state.
ORDER_STATUS_CANCELED = 3;
// The order has encountered an unexpected condition from which it
// cannot recover. This a terminal state.
ORDER_STATUS_ERROR = 4;
// The last known state for this order was ORDER_STATUS_WORKING, but
// since then the execution gateway has signaled a disconnect. This
// is not a terminal state.
ORDER_STATUS_DISCONNECTED = 5;
// The order is initializiYou can ng. It cannot be modified at this
point.
ORDER_STATUS_PENDING_WORKING = 6;
// The order is invalid and was rejected by Spark (not the
// exchange), on creation. This is a terminal state.
ORDER_STATUS_REJECTED_BY_SPARK= 7;
}
```
### Threading
Check out our API Threading Doc [here](Threading.md).
+74
View File
@@ -0,0 +1,74 @@
# Client API Threading
BTS API provides two types of calls. There are RPC (remote procedure calls) which accept an argument and return a value and there are streams of tabular data which we call subscriptions. All communication to and from the server happens on a connection thread owned by the ServiceContext object and data must be marshaled back to the right context when the call is complete.
## RPC
### C#
All API calls provide both a synchronous and [asynchronous](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/async) version. If you are calling the API from a WPF or Windows Forms application you should always prefer the async version of the method because it will efficiently make the call and resume execution on the correct thread without blocking or lagging user interactions. The synchronous calls are intended for use in console applications where nothing else needs use of the thread until the data is available.
The async version of the method will return a `Result<T>` type which is used to signal if an error occurred during the call. You should test the Result.success to see if the call succeeded before using Result.value.
```csharp
var s = context.locate<api.user.AuthService>();
var result = await s.get_users_async(new GetUsersRequest());
if (result.success) {
Console.WriteLine(result.value);
}
else {
Console.WriteLine($"Error {result.error_message}");
}
```
### C++
All C++ API calls also provide both a blocking synchronous version and a callback based asynchronous version. In the asynchronous case the callback will execute on the ServiceContext thread and you will need to handle marshaling that data to the appropriate thread. Just like in c# the callback will receive a `Result<T>` which will indicate success or failure. `Result.value` returns an `std::shared_ptr` so you have control over the lifetime of the value.
## Subscriptions
BTS provides streaming updates for some types of data. These updates are incremental in nature and will provide a snapshot of the current state on a new subscription. Streaming updates use the [ReactiveX library](http://reactivex.io) to manage subscribing and unsubscribing. This library provides a rich set of operators that you can use to slide and dice the data streams based on your specific application requirements.
### C#
The subscription callback will arrive on the ServiceContext thread but it can be easily marshaled to the thread of your choice using the [ObserveOn](http://reactivex.io/documentation/operators/observeon.html) operator. For a WPF or Windows Forms application the most common use of this will be [ObserveOnDispatcher]() which will simply execute the callback in the context of the original calling thread. By your choice of where to place the `ObserveOnDispatcher` call in your reactive call chain you can choose whether other operators execute before after switching threads.
In this example the `Where` and `SelectMany` operators will execute on `ServiceContext` connection thread and only the resulting matches will be marshaled across to the calling thread. It is safe to unsubscribe by disposing `sub` from any thread.
```csharp
var orders = context.locate<OrderService>();
ObservableCollection<OrderRecord> orders_with_errors;
IDisposable sub =
orders
.subscribe_orders()
.SelectMany(update => update.added)
.Where(o => o.State.Status == OrderStatus.Error)
.ObserveOnDispatcher()
.Subscribe(o => {
orders_with_errors.Add(o);
});
```
### C++
The C++ subscription callbacks use the [RxCpp](https://github.com/ReactiveX/RxCpp) library which implements the [ReactiveX](http://reactivex.io) operators. The subscribe call will return an `rxcpp::composite_subscription` which implements [RAII](https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization) and will unsubscribe when it is destroyed.
```cpp
#include "lib/api/public/ServiceContext.h"
#include "lib/api/services/OrderService.client.pb.h"
#include <rxcpp/rx.hpp>
#include <google/protobuf/util/json_util.h>
//...
bts::api::ServiceContext ctx;
auto client = ctx.locate<bts::api::orderman::OrderService>();
auto sub =
client.subscribe_orders().subscribe([=](const bts::api::orderman::OrdersUpdate& update) {
std::string result;
for(const auto& order : update.added()) {
auto status = google::protobuf::util::MessageToJsonString(*order, &result, {});
std::cout << "New order: " << result << std::endl;
}
});
```
+1
View File
@@ -61,6 +61,7 @@
<None Include="$(OutputPath)\net471\spark_excel_example_2018.xlsm" pack="true" PackagePath=".\excel\spark_excel_example_2018.xlsm" />
<None Include="$(OutputPath)\net471\spark_excel-addin64-packed.xll" pack="true" PackagePath=".\excel\spark_excel-addin64-packed.xll" />
<None Include="$(OutputPath)\net471\spark_excel-addin64.dna" pack="true" PackagePath=".\excel\spark_excel-addin64.dna" />
<None Include="doc/**" pack="true" PackagePath=".\doc\" />
</ItemGroup>
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences" Condition= " '$(SparkRoot)' != '' ">
@@ -124,10 +124,16 @@ namespace bts.tests
over_limit_order_key = over_limit_order_result.value.OrderKey;
no_limit_order_key = no_limit_order_result.value.OrderKey;
bool waiting_for_orders = true;
var orders = _order_service.subscribei_orders().Subscribe(ords =>
{
waiting_for_orders = false;
IEnumerable<OrderRecordImmutable> filtered_orders = ords.all.Where(x => x.Key == under_limit_order_key || x.Key == over_limit_order_key || x.Key == no_limit_order_key);
Assert.IsTrue(filtered_orders.Count() == 3, "There should be 3 matching orders... there are not");
foreach(var o in filtered_orders)
{
if(o.Key == under_limit_order_key) {
@@ -142,6 +148,9 @@ namespace bts.tests
}
});
while(waiting_for_orders) {
await Task.Delay(100);
}
// Restore the Limits to the original values
bool success = false;
-1
View File
@@ -6,7 +6,6 @@ cp -r $2/files/* $1
for filename in $1/*; do
if [[ $filename == *.xz ]]; then
echo Decompressing $filename
unxz $filename
fi
done
+25 -8
View File
@@ -1,8 +1,23 @@
# BTS Spark SDK
# BTS Spark
#### Getting Started
Our offering consists of a client UI ([Spark Client](https://www.bluetradingsystems.com/bts-spark#ladder-algo-screen)), a high performance professional futures front end, connected via our proprietary protocol over TCP to our Spark Server, which in turn connects to execution venues via their native protocols (typically FIX/TCP for execution and some proprietary protocol over UDP multicast for market data).
## Docker
![alt text](https://www.bluetradingsystems.com/images/Images/api/API.png)
# BTS Spark Server SDK
This API extension point is intended for users that require adding functionality to our Spark Server. Using the **Spark Server SDK** users can create [new order types](https://github.com/BlueTradingSystems/spark_sdk/blob/master/examples/order_plugin_example.cpp), [new market data sources](https://github.com/BlueTradingSystems/spark_sdk/blob/master/examples/md_publisher_example.cpp) and soon new execution gateways. In this case users implement the new functionality in C++, producing a shared library that is loaded at run time by our Spark Server.
If you are interested in sending orders or otherwise controlling a spark server remotely please see the BTS [Spark Client SDK](https://github.com/BlueTradingSystems/spark_client_sdk) repo.
### In Depth
* [Spark Algo Descriptions](doc/algos.md)
## Getting Started
### Docker
We use docker to provide a full dev environment with all the tools users need to develop their own algos.
@@ -35,7 +50,7 @@ $ docker start --attach -i bts_sdk
* If you prefer to run docker as a daemon, check out [``~/spark_sdk/sdk_shell.sh``](sdk_shell.sh)
## Git
### Git
* We assume the git you are using is git-lfs compatible; if you're using the git that comes with our docker, you're all set.
@@ -50,7 +65,7 @@ $ cd spark_sdk
```
## Development
### Development
Look at [examples/md_publisher_example.cpp](examples/md_publisher_example.cpp) to look at how to build a custom market data producer
@@ -62,7 +77,7 @@ run ```build_examples.sh``` to make sure you can build the examples, this will p
$ cd ~/spark_sdk/examples
$ ./build_examples.sh
```
### Server Layout
#### Server Layout
* Spark servers reside on a port, usually 8000, but your production instance could be on a different $PORT
##### SDK Package Layout
@@ -75,8 +90,10 @@ $ ./build_examples.sh
* Production binaries are in ``/sparkbin`` inside the docker container
* Production algo plugins should go into the ``/sparkbin/plugins`` directory
### Recorded market data
* If you want to see prices, before you start sparkd, you'll have to extract the futures.coconut.tar.gz found at the root of the sdk repo and place futures.coconut in ``~/sparkdata/data/replay/``
#### Recorded market data
* We first check for http://mdreplay/spark/futures.coconut
* Then fall back to ``./data_files/ relative to the sparkd binary``
## Debugging
+40
View File
@@ -0,0 +1,40 @@
# BTS Basic Algos
## Lean
The goal of the lean order is to watch the opposite-inside market size and cross when that sizegoes below the threshold (this also implies a cross if that size goes to zero and the markettrades away from you)If the market trades toward you, you can opt into several different behaviors
##### Parameters
* Cross Thresh - size thresh in absolute or ratio terms
* Max Chase Ticks - max levels to pay up, in ticks
## Join
The goal of the join order is to watch the opposite-inside market and join when the market flips (that is, when the best offer becomes the best bid) and has at least threshold size.
##### Parameters
* Join Thresh - size thresh in absolute or ratio terms
## Top
The goal of the top order is to not trade by yourself, but the intent at the time of order entry is toget filled.If the order is on the market (say current bid price) AND the quantity on that bid price is belowtop thresh then cancel the order else remain working.
##### Parameters
* Top Thresh - size thresh in absolute or ratio terms
## Cover
A Cover order’s purpose is to fire a hedge order (of any type) in response to fills from it’s childorder on the opposite side of the market N ticks away
##### Parameters
* Profit Ticks - ticks above or below fill price to place profit / cover order
## OCO
An OCO order’s purpose is to join a 'stop' or 'other' order to a main order wherein when one of these is cancelled, both cancel, or when one is filled, the other order's size is debited in the amount of the fill.
Composing this order with Cover simulates scalping functionality
##### Parameters
* Stop Ticks - ticks below or above main order to place stop / other order
+1
View File
@@ -25,6 +25,7 @@ ln -sf $1/server $1/sdk/lib
mkdir $1/sdk/examples
cp $2/examples/* $1/sdk/examples
cp $2/doc/* $1/sdk/doc
cp $2/sdk_shell.sh $1/sdk/sdk_shell.sh
cp $2/update_github.sh $1/sdk/update_github.sh
cp $2/README.md $1/sdk/README.md