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

This commit is contained in:
Jake Norbut committed 2019-05-07 08:26:15 -05:00
commit af8b559fa6
18 files changed
+170 -77

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@ zola_path=$(readlink -f "../../externals/linux/bin/zola/zola")
mkdir -p $temp_path
cp -r ./* $temp_path
cp -r ../../src/sdk/doc/* $temp_path/content/bts_spark_sdk/Server/
cd $temp_path
$zola_path build -u '/docs/' -o $1 >$tmpfile 2>&1
+5
View File
@@ -4,6 +4,11 @@ weight = 3
sort_by = "weight"
insert_anchor_links = "right"
+++
## 1.6.2
### User Visible Changes
### Exchange simulator
- Exchange simulator now now produce position in queue data
## 1.6.0
### User Visible Changes
#### New Features
@@ -97,7 +97,7 @@ namespace mbts.spark {
public event Action visible_columns_changed;
public IEnumerable<ColumnType> visible_columns =>
public IEnumerable<ColumnType> visible_column_types =>
columns.Where(c => c.settings.show)
.Select(c => c.column_type);
@@ -260,6 +260,7 @@ namespace mbts.spark {
#endregion
Column[] columns { get; set; } = new Column[0];
IEnumerable<Column> _visible_columns => columns.Where(c => c.settings.show);
public void drag_out_of_bounds() =>
_tactile_adorner?.drag_out_of_bounds();
@@ -337,7 +338,7 @@ namespace mbts.spark {
#region Column Utility Methods
Column _column_for_point(Point point) =>
columns.FirstOrDefault(c => c.x_right > point.X, columns.Length > 0 ? columns[columns.Length - 1] : Column.Empty);
_visible_columns.FirstOrDefault(c => c.x_right > point.X, columns.Length > 0 ? columns[columns.Length - 1] : Column.Empty);
double _column_start(ColumnType col_type) =>
columns.TakeWhile(c => c.column_type != col_type).Sum(c => c.settings.width);
@@ -922,4 +923,4 @@ namespace mbts.spark {
}
}
}
}
}
@@ -38,6 +38,14 @@ namespace mbts.spark {
font_weight = FontWeights.SemiBold.ToOpenTypeWeight()
};
public static LadderColumnSettings DefaultPiqColumnSettings => new LadderColumnSettings {
show = false,
width = 50,
font_family = "Segoe UI",
font_size = 10,
font_weight = FontWeights.SemiBold.ToOpenTypeWeight()
};
[ProtoMember(1)]
public bool show { get; set; }
[ProtoMember(2)]
@@ -250,7 +258,7 @@ namespace mbts.spark {
ask_column = LadderColumnSettings.Default,
price_column = LadderColumnSettings.Default,
last_column = LadderColumnSettings.Default,
piq_column = LadderColumnSettings.Default;
piq_column = LadderColumnSettings.DefaultPiqColumnSettings;
orders_column.background = BTSColors.LadderSpecial.default_column_background;
bid_column.foreground = 0xFFFFFF;
bid_column.background = BTSColors.MarketData.bid;
@@ -15,7 +15,7 @@ namespace mbts.spark {
InitializeComponent();
_column_headers_presenter.Columns = new GridViewColumnCollection();
_ladder.visible_columns_changed += () => _column_headers_presenter.Columns.SetItems(
_ladder.visible_columns.Select(t => ColumnFactory.create(_ladder, t)));
_ladder.visible_column_types.Select(t => ColumnFactory.create(_ladder, t)));
this.vm = vm;
DataContext = vm;
DataContextChanged += datacontext_changed;
+56
View File
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using bts.api.core;
using bts.md;
using CommandLine;
using System.Linq;
namespace bts {
[Verb("mbo", HelpText="MBO diagnostic command")]
public class MBOCommandOptions {
[Option('k', "key", Required = true)]
public UInt32 key { get; set; }
[Option('s', "side", Default = api.Side.Undefined)]
public api.Side side { get; set; }
}
public class MBOCommand {
public static int Run(MBOCommandOptions o) {
dump_mbo(o.key, o.side);
return 0;
}
static void dump_mbo(UInt32 key, api.Side side) {
using (var ctx = new ServiceContext()) {
var mbo = ctx.locate<MBOService>();
var data = mbo.get_orders_for_security(new MBOSecurityQuery { SecurityId = key });
Console.WriteLine($"Order data for {data.SecurityId}");
IEnumerable<OrderPosition> orders = data.Bid;
switch(side) {
case api.Side.Undefined:
orders = data.Ask.Concat(data.Bid);
break;
case api.Side.Buy:
orders = data.Bid;
break;
case api.Side.Sell:
orders = data.Ask;
break;
}
var price = 0.0;
foreach(var e in orders) {
if (e.Price != price) {
price = e.Price;
Console.WriteLine("================");
}
Console.WriteLine(e);
}
}
}
}
}
+8 -8
View File
@@ -132,6 +132,14 @@ namespace bts {
foreach (var m in all_markets(ctx)) {
ConsoleEx.WriteLine(m.security.security_desc(), ConsoleColor.White);
var tick = m.security.ContractSpec.LowTick;
if (m.ask.HasValue) {
for (var x = 0; x < o.depth; ++x) {
var price = m.ask.Value.price() + (tick * x);
ConsoleEx.WriteLine($"Sell {o.quantity} at {price}", ConsoleColor.Red);
orders.create_order_async(mkorder(m.security.Id, price, o.quantity, Side.Sell));
System.Threading.Thread.Sleep(o.sleep);
}
}
if (m.bid.HasValue) {
// start at bid and place 1 order at 10 levels
for (var x=0; x < o.depth; ++x) {
@@ -141,14 +149,6 @@ namespace bts {
System.Threading.Thread.Sleep(o.sleep);
}
}
if (m.ask.HasValue) {
for (var x = 0; x < o.depth; ++x) {
var price = m.ask.Value.price() + (tick * x);
ConsoleEx.WriteLine($"Sell {o.quantity} at {price}", ConsoleColor.Red);
orders.create_order_async(mkorder(m.security.Id, price, o.quantity, Side.Sell));
System.Threading.Thread.Sleep(o.sleep);
}
}
}
return 3;
}
+1 -30
View File
@@ -17,16 +17,9 @@ namespace bts {
[Option(nameof(admin))]
public bool admin { get; set; }
[Option(nameof(mbo))]
public bool mbo { get; set; }
[Option("key")]
public UInt32 key { get; set; }
[Option("side")]
public api.Side side { get; set; }
}
[Verb("servicetest", HelpText="Scratch space for testing services")]
public class ServiceTest {
public static int Run(ServiceTestOptions o) {
if (o.synthetic) {
@@ -38,9 +31,6 @@ namespace bts {
if (o.admin) {
admin_test();
}
if (o.mbo) {
mbo_test(o);
}
return 0;
}
@@ -51,25 +41,6 @@ namespace bts {
return "";
}
private static void mbo_test(ServiceTestOptions o) {
var key = o.key;
var side = o.side;
using (var ctx = new ServiceContext()) {
var mbo = ctx.locate<MBOService>();
var data = mbo.get_orders_for_security(new MBOSecurityQuery { SecurityId = key });
Console.WriteLine($"Order data for {data.SecurityId}");
var vector = side == api.Side.Buy ? data.Bid : data.Ask;
var price = 0.0;
foreach(var e in vector) {
if (e.Price != price) {
price = e.Price;
Console.WriteLine("================");
}
Console.WriteLine(e);
}
}
}
private static void synthetic_test() {
using (var ctx = new ServiceContext()) {
+21 -2
View File
@@ -26,8 +26,26 @@ namespace sparkcmd {
mbts.utils.BTSNativeMethods.provide_command_line(args, args.Length);
// note: this can be made to infer the options type list from the list of delegates
return Parser.Default
.ParseArguments<ConfigcheckOptions,ScriptClientOptions,TailServiceOptions,ServiceTestOptions,SettingsManagerOptions,TestCommandOptions,OrderStressOptions >(args)
.MapResult<ConfigcheckOptions,ScriptClientOptions,TailServiceOptions,ServiceTestOptions,SettingsManagerOptions,TestCommandOptions,OrderStressOptions,int>(
.ParseArguments<
ConfigcheckOptions,
ScriptClientOptions,
TailServiceOptions,
ServiceTestOptions,
SettingsManagerOptions,
TestCommandOptions,
OrderStressOptions,
MBOCommandOptions
>(args)
.MapResult<
ConfigcheckOptions,
ScriptClientOptions,
TailServiceOptions,
ServiceTestOptions,
SettingsManagerOptions,
TestCommandOptions,
OrderStressOptions,
MBOCommandOptions,
int>(
Configcheck.Run,
ScriptClientCommand.Run,
TailService.Run,
@@ -35,6 +53,7 @@ namespace sparkcmd {
SettingsManagerCommand.Run,
TestCommand.Run,
OrderStress.Run,
MBOCommand.Run,
errors => 1);
}
}
+5 -10
View File
@@ -1,21 +1,16 @@
<license version="1.0">
<type>production</type>
<customer>
<name>Blue Trading Systems</name>
<name>Blue Trading Systems OF 9420-2</name>
</customer>
<period>
<since>2018-08-30</since>
<till>2019-10-16</till>
<since>2019-05-02</since>
<till>2020-05-13</till>
</period>
<dotNetProducts>
<product id="41" name="FIX Analyser" />
</dotNetProducts>
<dotNetCheckSum>6O68+aAtrLqRaXxY9hLigajhC2ZunVeIev3NbyEXFjHk61WFrNmRTjy6tEduDtFUvGXvS6VUW3VXASaMTLrRgYteZBzfp7+dFTfVIVbzv6cn7c7dnSxWCGO5zPrjXw9cxMXlFz9cshyue6U/DRR5J36ThOhgt2kpY/OP9cgXWJo=</dotNetCheckSum>
<products>
<product id="1" name="OnixS FIX Engine for C++" />
<product id="4" name="CME Market Data Handler for C++" />
<product id="7" name="ICE iMpact Multicast Price Feed Handler for C++" />
<product id="13" name="NYSE ArcaBook Multicast for Equities Handler for C++" />
<product id="67" name="Eurex Market and Reference Data Interfaces (EMDI, RDI) Handler for C++" />
</products>
<checksum>18F98ED1E0A87B4B11DA322403D7BDDD</checksum>
<checksum>5E50A1DACD94D7C1BECD316EEAE5AB02</checksum>
</license>
+1 -1
View File
@@ -6,7 +6,7 @@ namespace cmd {
int RunSim::execute(std::vector<std::string> const &)
{
sim::start_exchange_sim();
sim::start_exchange_sim(nullptr);
return 0;
}
@@ -20,6 +20,7 @@
#include "lib/domain_model/Security.pb.h"
#include "lib/md/relay/RelayRecorder.h"
#include "lib/md/IntPrice.h"
#include "lib/md/MBOProcessor.h"
#include <set>
@@ -124,7 +125,7 @@ struct MDPlayer : md::IRelayWriter
};
int start_exchange_sim()
int start_exchange_sim(md::MBOWriter* mbo)
{
try
{
@@ -137,7 +138,7 @@ int start_exchange_sim()
std::istringstream str{str_settings};
FIX::SessionSettings settings( str );
ex_sim::ExchangeSimApplication application;
ex_sim::ExchangeSimApplication application(mbo);
FIX::FileStoreFactory storeFactory( settings );
FIX::FileLogFactory logFactory( settings );
FIX::SocketAcceptor acceptor( application, storeFactory, settings, logFactory );
+2 -1
View File
@@ -3,8 +3,9 @@
#include <memory>
namespace bts {
namespace md { class MBOWriter; }
namespace sim {
int start_exchange_sim();
int start_exchange_sim(md::MBOWriter*);
}}
@@ -10,12 +10,14 @@
#include "lib/md/Shm/FixedSecurity.h"
#include "lib/md/Shm/MDStructure.h"
#include "lib/md/get_symbols.h"
#include "lib/md/MBOProcessor.h"
#include "lib/utils/Dispatcher.h"
#include "lib/utils/datetime.h"
#include "server/sparkd/exchange_sim/book/Order.h"
#include "server/sparkd/exchange_sim/book/OrderMatcher.h"
#include "server/sparkd/exchange_sim/book/book_transform.h"
#include "lib/persistence/SqliteStore.h"
#include "lib/orderman/orderman_utils/fix_order_codec.h"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <fmt/format.h>
@@ -97,14 +99,20 @@ struct ExchangeSimApplication::MDConsumerRec {
utils::TimeStamp last_read;
};
inline FIX::OrderID exchange_key(const std::string& clOrdID) {
return FIX::OrderID(clOrdID.substr(3));
}
struct ExchangeSimApplication::PImpl {
PImpl()
PImpl(md::MBOWriter* mbo)
: producer(co2::PLATFORM_SIM),
md_sn(1),
timer(utils::Dispatcher::background(), 200,
[=]() { producer.heartbeat(); }),
do_merge_with_md(config::get<config::ExchangeSim>().merge_with_md()),
store(new persistence::SqliteStore("ex_sim_orders")) {}
store(new persistence::SqliteStore("ex_sim_orders")),
lock(),
mbo(mbo) {}
IDGenerator m_generator;
md::MDProducer producer;
@@ -116,9 +124,10 @@ struct ExchangeSimApplication::PImpl {
bool do_merge_with_md;
std::unique_ptr<persistence::IStore> store;
std::mutex lock;
md::MBOWriter* mbo;
};
ExchangeSimApplication::ExchangeSimApplication() : me(new PImpl()) {
ExchangeSimApplication::ExchangeSimApplication(md::MBOWriter* mbo) : me(new PImpl(mbo)) {
auto previous_book = me->store->retrieve_all();
auto all = me->store->retrieve_all()["books"];
@@ -355,7 +364,7 @@ void ExchangeSimApplication::updateOrder(const Order &order, char status) {
FIX::TargetSubID(order.sender_sub_id());
FIX42::ExecutionReport fixOrder;
fixOrder.set(FIX::OrderID("12345678901234567"));
fixOrder.set(exchange_key(order.clordid()));
fixOrder.set(FIX::ExecID(me->m_generator.genExecutionID()));
fixOrder.set(FIX::ExecTransType(FIX::ExecTransType_NEW));
fixOrder.set(FIX::ExecType(status));
@@ -405,7 +414,7 @@ void ExchangeSimApplication::rejectOrder(
FIX::SenderCompID senderCompID(target.getValue());
FIX42::ExecutionReport fixOrder;
fixOrder.set(FIX::OrderID("12345678901234567"));
fixOrder.set(exchange_key(clOrdID.getString()));
fixOrder.set(FIX::ExecID(me->m_generator.genExecutionID()));
fixOrder.set(FIX::ExecTransType(FIX::ExecTransType_NEW));
fixOrder.set(FIX::ExecType(FIX::ExecType_REJECTED));
@@ -480,7 +489,7 @@ void ExchangeSimApplication::update_md(std::string const &sec_desc) {
handle.update_direct(utils::TimeStamp::now(), bids_temp, asks_temp, me->md_sn++);
auto new_trades = matcher.get_new_trades();
for (auto &t : new_trades)
for (auto &t : new_trades) {
handle.add_trade(
utils::TimeStamp::now(),
md::PriceSize_from_double<ex_sim::precision>(t.price.value() * price_factor,t.quantity.value()),
@@ -488,6 +497,29 @@ void ExchangeSimApplication::update_md(std::string const &sec_desc) {
t.bid_aggressor ? co2::AGGRESSOR_SIDE_BUY
: ( t.ask_aggressor ? co2::AGGRESSOR_SIDE_SELL
: co2::AGGRESSOR_SIDE_NONE) );
}
// publish mbo
auto mbo = me->mbo;
if (mbo) {
// get the list of trades
auto ob = matcher.get_order_book(nullptr);
auto snap = mbo->allocate_snapshot();
for (const auto& order : ob.order()) {
auto ek = exchange_key(order.clordid());
md::SnapshotOrder sno {
md::ExchangeOrderKey(std::atoll(ek.getString().c_str())),
md::IntPrice_from_double<precision>(order.price() * price_factor),
(int)order.open_quantity() };
if (order.side() == api::SIDE_BUY) {
snap->bids.push_back(sno);
}
else if (order.side() == api::SIDE_SELL) {
snap->asks.push_back(sno);
}
}
mbo->publish_snapshot(SecurityKey(it->second.key()), &snap);
}
}
}
@@ -43,7 +43,7 @@ GCC_DIAG_OFF("-Wignored-qualifiers")
namespace bts {
namespace api {class Security;}
namespace md {class MDConsumerHandle;}
namespace md {class MDConsumerHandle; class MBOWriter;}
namespace ex_sim {
static const int precision = 9;
class Order;
@@ -55,7 +55,7 @@ class ExchangeSimApplication
public FIX::MessageCracker
{
public:
ExchangeSimApplication();
ExchangeSimApplication(md::MBOWriter*);
~ExchangeSimApplication();
void merge_with_md_book();
@@ -83,13 +83,17 @@ void OrderMatcher::add_or_merge(Order const &o, std::vector<Order> *out) {
auto range = find_level(*side,o.price());
for (auto it = range.first; it != range.second; it++)
if (it->owner() == o.owner()) {
auto no_const = const_cast<Order *>(&(*it));
no_const->set_open_quantity(it->open_quantity() + o.quantity());
// If the last order at this level is the same owner we can update it
if (range.first != range.second) {
auto last = range.second;
last--;
if (last->owner() == o.owner()) {
auto no_const = const_cast<Order *>(&(*last));
no_const->set_open_quantity(last->open_quantity() + o.quantity());
match(out);
return;
}
}
add_new(o,out);
}
@@ -232,14 +236,14 @@ Book OrderMatcher::get_book() const {
return result;
}
OrderBook OrderMatcher::get_order_book(std::string const&exclude_owner) const
OrderBook OrderMatcher::get_order_book(const char* exclude_owner) const
{
OrderBook result;
for (auto &b : me->bids)
if (b.owner() != exclude_owner)
if (exclude_owner == nullptr || b.owner() != exclude_owner)
*result.add_order() = b;
for (auto &a : me->asks)
if (a.owner() != exclude_owner)
if (exclude_owner == nullptr || a.owner() != exclude_owner)
*result.add_order() = a;
return result;
}
@@ -30,7 +30,7 @@ class OrderMatcher {
Quantity by_quantity,
std::string const& order_owner);
Book get_book() const;
OrderBook get_order_book(std::string const&exclude_owner) const;
OrderBook get_order_book(const char*) const;
Order const *get_order(std::string const &clorid);
+1 -1
View File
@@ -152,7 +152,7 @@ void run_market_datapublishers(MBOWriter* mbo) {
}));
if (config::get<MarketDataConfig>().use_sim()) {
threading::make_thread("ExchangeSim", []() { sim::start_exchange_sim(); })
threading::make_thread("ExchangeSim", [mbo]() { sim::start_exchange_sim(mbo); })
.detach();
}
boot_sleep();