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

This commit is contained in:
Kevin Darby committed 2017-10-10 17:23:09 -04:00
commit f8cec19198
7 files changed
+62 -50

No files matched your search

+4 -4
View File
@@ -39,7 +39,7 @@ namespace mbts.spark {
_high = backing(nameof(high), "");
_low = backing(nameof(low), "");
_change = backing(nameof(change), "");
_last = backing(nameof(last), "");
_open = backing(nameof(open), "");
_volume = backing(nameof(volume), 0ul);
// calculator
@@ -95,10 +95,10 @@ namespace mbts.spark {
var spec = security.ContractSpec;
_high.set(spec.format(md.session_high));
_low.set(spec.format(md.session_low));
_open.set(spec.format(md.open_price));
ulong unused = 0;
md.get_last_trade(ref unused, out NativePriceSize last, out DateTime time, out ulong volume);
_change.set(spec.format(last.price - md.settlement_price));
_last.set(spec.format(last.price));
_volume.set(volume);
}
}
@@ -111,8 +111,8 @@ namespace mbts.spark {
Property<string> _change;
public string change => _change.Value;
Property<string> _last;
public string last => _last.Value;
Property<string> _open;
public string open => _open.Value;
Property<ulong> _volume;
public ulong volume => _volume.Value;
+16 -18
View File
@@ -54,34 +54,32 @@
<ComboBox Grid.ColumnSpan="2" Margin="2" ItemsSource="{Binding accounts}" SelectedItem="{Binding account}"/>
<ComboBox ItemsSource="{Binding order_types}" SelectedItem="{Binding selected_order_type}" Margin="2" />
<uag:AlgoDetailsPopupControl ItemsSource="{Binding algo_types}" SelectedItem="{Binding selected_algo_type}" Margin="2" ExpandDirection="Left"/>
<!--<ListBox IsEnabled="False" Margin="0,5">
<ListBoxItem>10</ListBoxItem>
<ListBoxItem>2</ListBoxItem>
<ListBoxItem>25</ListBoxItem>
<ListBoxItem> <TextBlock FontWeight="Bold">2 (mine!)</TextBlock> </ListBoxItem>
<ListBoxItem>11</ListBoxItem>
</ListBox>-->
</StackPanel>
<Button Margin="5,0,5,5" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Command="{Binding show_ticket_command}">Ticket</Button>
<Grid Grid.Column="1" Height="32" VerticalAlignment="Top" TextBlock.FontSize="9">
<Grid Grid.Column="1" Margin="4" Height="24" VerticalAlignment="Top" TextBlock.FontSize="9">
<Grid.Resources>
<Thickness x:Key="text_margin" Right="2" />
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" /> <ColumnDefinition />
<ColumnDefinition Width="Auto" /> <ColumnDefinition />
<ColumnDefinition Width="Auto" /> <!-- padding -->
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Text="{Binding high, StringFormat={}High {0:0.00}}" />
<TextBlock Grid.Row="1" Text="{Binding low, StringFormat={}Low: {0:0.00}}" />
<TextBlock Grid.Row="2" Text="{Binding change, StringFormat={}Change: {0:00}}" />
<TextBlock Grid.Column="1" Text="{Binding last, StringFormat={}Last: {0:0.00}}" />
<TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding volume, StringFormat={}Volume: {0}}" />
<TextBlock Grid.Column="0" Grid.RowSpan="2" Text="{Binding change, StringFormat=0:00}" FontSize="14" Foreground="{mbts:BTSColor success}" />
<TextBlock Grid.Column="1" Grid.Row="0" Text="H:" Margin="{StaticResource text_margin}" />
<TextBlock Grid.Column="1" Grid.Row="1" Text="L:" Margin="{StaticResource text_margin}" />
<TextBlock Grid.Column="2" Grid.Row="0" Text="{Binding high, Mode=OneWay}" Foreground="{mbts:BTSColor success}" FontWeight="Bold" />
<TextBlock Grid.Column="2" Grid.Row="1" Text="{Binding low, Mode=OneWay}" Foreground="{mbts:BTSColor error}" FontWeight="Bold" />
<TextBlock Grid.Column="3" Grid.Row="0" Text="O:" Margin="{StaticResource text_margin}" />
<TextBlock Grid.Column="3" Grid.Row="1" Text="V:" Margin="{StaticResource text_margin}" />
<TextBlock Grid.Column="4" Grid.Row="0" Text="{Binding open, Mode=OneWay}" FontWeight="Bold" />
<TextBlock Grid.Column="4" Grid.Row="1" Text="{Binding volume, Mode=OneWay}" FontWeight="Bold" />
<spark:RecenterCountdown Grid.Column="2" Grid.RowSpan="3"
Width="18" Height="18" Margin="4"
@@ -252,7 +252,7 @@ void SpreaderOrder::on_time(TimeStamp const&)
void SpreaderOrder::on_child_update(OrderKey orderkey,
api::orderman::OrderStatus status,
Quantity filled_quantity,
Price avg_price,
Price average_price,
std::string const *error_msg)
{
using namespace bts::spreader;
@@ -260,7 +260,7 @@ void SpreaderOrder::on_child_update(OrderKey orderkey,
LOG(OrderMan,Diag,
"on_child_update SpreaderOrder."
"k: {} status: {} filled_qty: {} avg_price: {} reject_msg: {}",
orderkey.value(), status, filled_quantity.value(), avg_price.value(), error_msg ? empty:*error_msg);
orderkey.value(), status, filled_quantity.value(), average_price.value(), error_msg ? empty:*error_msg);
if (_state == State::START)
bts_assert(false);
else if (_state == State::WAITING_FOR_FIRST_CONNECT)
@@ -275,7 +275,7 @@ void SpreaderOrder::on_child_update(OrderKey orderkey,
if (q_leg_data_ptr != NULL)
{
SpreaderBookkeepingData::LegData& q_leg_data = *(q_leg_data_ptr);
SpreaderOrderUpdateMessage update_message(orderkey, status, filled_quantity, avg_price, q_leg_data.filled_quantity, q_leg_data.avergage_filled_price);
SpreaderOrderUpdateMessage update_message(orderkey, status, filled_quantity, average_price, q_leg_data.filled_quantity, q_leg_data.avergage_filled_price);
_handle_quoter_order_update(q_leg_data, update_message);
}
else
@@ -284,7 +284,7 @@ void SpreaderOrder::on_child_update(OrderKey orderkey,
SpreaderBookkeepingData::HedgerData* hedger_data = _bookkeeping_data->find_hedger_from_orderkey(orderkey);
if (hedger_data != NULL)
{
SpreaderOrderUpdateMessage update_message(orderkey, status, filled_quantity, avg_price, hedger_data->filled_quantity, hedger_data->avergage_filled_price);
SpreaderOrderUpdateMessage update_message(orderkey, status, filled_quantity, average_price, hedger_data->filled_quantity, hedger_data->avergage_filled_price);
hedger_data->update_fill(filled_quantity);
hedger_data->hedger.update_order_state(update_message);
}
@@ -298,7 +298,7 @@ void SpreaderOrder::on_child_update(OrderKey orderkey,
if (q_leg_data_ptr != NULL)
{
SpreaderBookkeepingData::LegData& q_leg_data = *(q_leg_data_ptr);
SpreaderOrderUpdateMessage update_message(orderkey, status, filled_quantity, avg_price, q_leg_data.filled_quantity, q_leg_data.avergage_filled_price);
SpreaderOrderUpdateMessage update_message(orderkey, status, filled_quantity, average_price, q_leg_data.filled_quantity, q_leg_data.avergage_filled_price);
q_leg_data_ptr->quoter->update_order_status(update_message);
}
else
@@ -306,7 +306,7 @@ void SpreaderOrder::on_child_update(OrderKey orderkey,
SpreaderBookkeepingData::HedgerData* hedger_data = _bookkeeping_data->find_hedger_from_orderkey(orderkey);
if (hedger_data != NULL)
{
SpreaderOrderUpdateMessage update_message(orderkey, status, filled_quantity, avg_price, hedger_data->filled_quantity, hedger_data->avergage_filled_price);
SpreaderOrderUpdateMessage update_message(orderkey, status, filled_quantity, average_price, hedger_data->filled_quantity, hedger_data->avergage_filled_price);
hedger_data->update_fill(filled_quantity);
hedger_data->hedger.update_order_state(update_message);
}
@@ -410,7 +410,7 @@ void SpreaderOrder::_handle_quoter_order_update(SpreaderBookkeepingData::LegData
if (update_message.update_fill_price_quantity(this_fill_quantity, this_fill_price))
{
leg_data.filled_quantity = update_message.filled_quantity;
leg_data.avergage_filled_price = update_message.avg_price;
leg_data.avergage_filled_price = update_message.average_price;
for (size_t idx = 0; idx < _bookkeeping_data->count(); idx++)
{
if (idx != leg_data.leg_property_data.leg_index)
@@ -71,7 +71,7 @@ public:
void on_child_update(OrderKey child_k,
api::orderman::OrderStatus ,
Quantity filled_quantity,
Price avg_price,
Price average_price,
std::string const *reject);
// called when an external error occurs (which could be a risk limit
// breach or a system issue)
@@ -160,7 +160,7 @@ namespace spreader
void SimpleSpreader::on_child_order_update(orderman::OrderKey orderkey,
api::orderman::OrderStatus status,
Quantity filled_quantity,
Price avg_price,
Price average_price,
std::string const *error_msg)
{
if (_state == State::START)
@@ -177,7 +177,7 @@ namespace spreader
if (q_leg_data_ptr != NULL)
{
SpreaderBookkeepingData::LegData& q_leg_data = *(q_leg_data_ptr);
SpreaderOrderUpdateMessage update_message(orderkey, status, filled_quantity, avg_price, q_leg_data.filled_quantity, q_leg_data.avergage_filled_price);
SpreaderOrderUpdateMessage update_message(orderkey, status, filled_quantity, average_price, q_leg_data.filled_quantity, q_leg_data.avergage_filled_price);
_handle_quoter_order_update(q_leg_data, update_message);
}
else
@@ -186,7 +186,7 @@ namespace spreader
SpreaderBookkeepingData::HedgerData* hedger_data = _bookkeeping_data->find_hedger_from_orderkey(orderkey);
if (hedger_data != NULL)
{
SpreaderOrderUpdateMessage update_message(orderkey, status, filled_quantity, avg_price, hedger_data->filled_quantity, hedger_data->avergage_filled_price);
SpreaderOrderUpdateMessage update_message(orderkey, status, filled_quantity, average_price, hedger_data->filled_quantity, hedger_data->avergage_filled_price);
hedger_data->update_fill(filled_quantity);
hedger_data->hedger.update_order_state(update_message);
}
@@ -200,7 +200,7 @@ namespace spreader
if (q_leg_data_ptr != NULL)
{
SpreaderBookkeepingData::LegData& q_leg_data = *(q_leg_data_ptr);
SpreaderOrderUpdateMessage update_message(orderkey, status, filled_quantity, avg_price, q_leg_data.filled_quantity, q_leg_data.avergage_filled_price);
SpreaderOrderUpdateMessage update_message(orderkey, status, filled_quantity, average_price, q_leg_data.filled_quantity, q_leg_data.avergage_filled_price);
q_leg_data_ptr->quoter->update_order_status(update_message);
}
else
@@ -208,7 +208,7 @@ namespace spreader
SpreaderBookkeepingData::HedgerData* hedger_data = _bookkeeping_data->find_hedger_from_orderkey(orderkey);
if (hedger_data != NULL)
{
SpreaderOrderUpdateMessage update_message(orderkey, status, filled_quantity, avg_price, hedger_data->filled_quantity, hedger_data->avergage_filled_price);
SpreaderOrderUpdateMessage update_message(orderkey, status, filled_quantity, average_price, hedger_data->filled_quantity, hedger_data->avergage_filled_price);
hedger_data->update_fill(filled_quantity);
hedger_data->hedger.update_order_state(update_message);
}
@@ -342,7 +342,7 @@ namespace spreader
if (update_message.update_fill_price_quantity (this_fill_quantity, this_fill_price))
{
leg_data.filled_quantity = update_message.filled_quantity;
leg_data.avergage_filled_price = update_message.avg_price;
leg_data.avergage_filled_price = update_message.average_price;
for (size_t idx = 0; idx < _bookkeeping_data->count(); idx++)
{
if (idx != leg_data.leg_property_data.leg_index)
+1 -1
View File
@@ -39,7 +39,7 @@ namespace spreader
void on_child_order_update(orderman::OrderKey orderkey,
api::orderman::OrderStatus status,
Quantity filled_quantity,
Price avg_price,
Price average_price,
std::string const *error_msg_arg) override;
void on_time(const TimeStamp&) override;
void on_user_update(const SpreaderUpdate&) override;
@@ -19,11 +19,11 @@ public:
// original order_state passed from the engine infrastructure
// (do not cache it)
const orderman::OrderKey key;
const api::orderman::OrderStatus status;
const Quantity filled_quantity;
const Price avg_price;
const Quantity previous_filled_quantity;
const Price previous_avg_price;
api::orderman::OrderStatus status;
Quantity filled_quantity;
Price average_price;
Quantity last_update_filled_quantity;
Price last_update_average_price;
//std::string const *error_msg;
SpreaderOrderUpdateMessage(orderman::OrderKey orderkey_arg,
api::orderman::OrderStatus status_arg,
@@ -36,9 +36,9 @@ public:
key(orderkey_arg),
status(status_arg),
filled_quantity(filled_quantity_arg),
avg_price(avg_price_arg),
previous_filled_quantity(previous_filled_quantity_arg),
previous_avg_price(previous_avg_price_arg)
average_price(avg_price_arg),
last_update_filled_quantity(previous_filled_quantity_arg),
last_update_average_price(previous_avg_price_arg)
//error_msg(error_msg_arg)
{ }
bool terminal_status() const { return SpreaderUtils::order_in_terminal_state(status); }
@@ -47,16 +47,30 @@ public:
bool has_fills() const
{
return filled_quantity.value() != previous_filled_quantity.value();
return filled_quantity.value() != last_update_filled_quantity.value();
}
void update(api::orderman::OrderStatus status_arg,
Quantity filled_quantity_arg,
Price average_price_arg,
std::string const *)
{
status = status_arg;
bts_assert(filled_quantity_arg.value() >= filled_quantity.value());
last_update_filled_quantity = Quantity(filled_quantity_arg.value() - filled_quantity.value());
if (last_update_filled_quantity.value() > 0)
last_update_average_price = Price((average_price_arg.value() * filled_quantity_arg.value() - average_price.value() * filled_quantity.value()) / last_update_filled_quantity.value());
filled_quantity = filled_quantity_arg;
average_price = average_price_arg;
}
bool update_fill_price_quantity(Quantity& this_fill_quantity, Price& this_fill_price) const
{
if (filled_quantity.value() != previous_filled_quantity.value())
if (filled_quantity.value() != last_update_filled_quantity.value())
{
bts_assert(filled_quantity.value() > previous_filled_quantity.value());
this_fill_quantity = Quantity(filled_quantity.value() - previous_filled_quantity.value());
double this_price = (avg_price.value()*filled_quantity.value() - previous_avg_price.value()*previous_filled_quantity.value()) / this_fill_quantity.value();
bts_assert(filled_quantity.value() > last_update_filled_quantity.value());
this_fill_quantity = Quantity(filled_quantity.value() - last_update_filled_quantity.value());
double this_price = (average_price.value()*filled_quantity.value() - last_update_average_price.value()*last_update_filled_quantity.value()) / this_fill_quantity.value();
this_fill_price = Price(this_price);
return true;
}