Better export to CSV.
This commit is contained in:
1 parent
7489d70c95
commit
ec3d642cee
3 files changed
+54
-54
No files matched your search
@@ -21,18 +21,18 @@ int export_tables(std::string const &file, std::string const &out_dir) {
|
||||
event_items(out_dir + "/event_items.csv"),
|
||||
securities(out_dir + "/securities.csv") {
|
||||
|
||||
events << "event_id, transact_time,first_packet_sn,last_packet_sn,"
|
||||
"first_packet_send_time,last_packet_send_time"
|
||||
events << "eid, t_time,first_sn,last_sn,"
|
||||
"first_st,last_st"
|
||||
<< std::endl;
|
||||
|
||||
event_items
|
||||
<< "event_id, transact_time,security_id,trading_status,type,"
|
||||
"change,order_key,side,"
|
||||
"priority,price,quantity,trade_entry_id,aggressor"
|
||||
<< "eid, t_time,sid,status,type,"
|
||||
"change,ok,side,"
|
||||
"pri,price,qty,tid,agg"
|
||||
<< std::endl;
|
||||
|
||||
securities
|
||||
<< "security_id,symbol,security_group,asset,last_update_time"
|
||||
<< "sid,symbol,group,asset,last_t"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ int export_tables(std::string const &file, std::string const &out_dir) {
|
||||
|
||||
<< s->trading_status() << "," // trading status
|
||||
|
||||
<< "deduced_order," // type
|
||||
<< "order_change," // type
|
||||
|
||||
<< "init," // change
|
||||
|
||||
@@ -167,7 +167,7 @@ int export_tables(std::string const &file, std::string const &out_dir) {
|
||||
|
||||
<< s->trading_status() << "," // trading status
|
||||
|
||||
<< "order," // type
|
||||
<< "deduced_order," // type
|
||||
|
||||
<< change_name(deduced_order->change) << ","
|
||||
|
||||
|
||||
@@ -331,7 +331,7 @@ void InstrumentSnapshot::remove_fill(MDP3TradeEntryID tid, MDP3OrderKey oid) {
|
||||
void InstrumentSnapshot::clear_fills() { me->fills.clear(); }
|
||||
|
||||
MaybeOrderChange InstrumentSnapshot::deduced_order_change() const {
|
||||
if (fills().empty())
|
||||
if (fills().empty() || trading_status() != ::mdp3::SecurityTradingStatus::ReadyToTrade )
|
||||
return {};
|
||||
|
||||
Fills aggressor_fills;
|
||||
@@ -359,7 +359,7 @@ MaybeOrderChange InstrumentSnapshot::deduced_order_change() const {
|
||||
Price(result.order.price.price()),
|
||||
Price(f.price.price())))
|
||||
result.order.price = f.price;
|
||||
result.order.quantity.value() += result.order.quantity.value();
|
||||
result.order.quantity.value() += f.quantity.value();
|
||||
}
|
||||
|
||||
// Lets find out if this is a new or existing order. If it was an
|
||||
|
||||
@@ -25,38 +25,38 @@
|
||||
-- (select transacttime, count(*) msg_count from msg group by transacttime) t
|
||||
-- group by
|
||||
-- len
|
||||
drop table event_items;
|
||||
CREATE TABLE event_items(
|
||||
event_id numeric,
|
||||
"transact_time" numeric,
|
||||
"security_id" numeric,
|
||||
"trading_status" TEXT,
|
||||
"type" TEXT,
|
||||
"change" TEXT,
|
||||
"order_key" numeric,
|
||||
"side" TEXT,
|
||||
"priority" numeric,
|
||||
"price" numeric,
|
||||
"quantity" numeric,
|
||||
"trade_entry_id" numeric,
|
||||
"aggressor" TEXT
|
||||
);
|
||||
drop table events;
|
||||
CREATE TABLE events(
|
||||
event_id numeric,
|
||||
"transact_time" numeric,
|
||||
"first_packet_sn" numeric,
|
||||
"last_packet_sn" numeric,
|
||||
"first_packet_send_time" numeric,
|
||||
"last_packet_send_time" numeric
|
||||
eid numeric,
|
||||
"t_time" numeric,
|
||||
"first_sn" numeric,
|
||||
"last_sn" numeric,
|
||||
"first_st" numeric,
|
||||
"last_st" numeric
|
||||
);
|
||||
drop table event_items;
|
||||
CREATE TABLE event_items(
|
||||
eid numeric,
|
||||
"t_time" numeric,
|
||||
"sid" numeric,
|
||||
"status" TEXT,
|
||||
"type" TEXT,
|
||||
"change" TEXT,
|
||||
"ok" numeric,
|
||||
"side" TEXT,
|
||||
"pri" numeric,
|
||||
"price" numeric,
|
||||
"qty" numeric,
|
||||
"tid" numeric,
|
||||
"agg" TEXT
|
||||
);
|
||||
drop table securities;
|
||||
CREATE TABLE securities(
|
||||
"security_id" numeric,
|
||||
"sid" numeric,
|
||||
"symbol" TEXT,
|
||||
"security_group" TEXT,
|
||||
"group" TEXT,
|
||||
"asset" TEXT,
|
||||
"last_update_time" numeric
|
||||
"last_t" numeric
|
||||
);
|
||||
.mode csv
|
||||
.import event_items.csv event_items
|
||||
@@ -71,47 +71,47 @@ select
|
||||
*,
|
||||
(case when type='order' then 1 else 0 end) is_order,
|
||||
(case when type='fill' then 1 else 0 end) is_fill,
|
||||
(case when aggressor='1' then 1 else 0 end) is_aggressor
|
||||
(case when agg='1' then 1 else 0 end) is_agg
|
||||
from
|
||||
event_items
|
||||
where
|
||||
trading_status='ReadyToTrade'
|
||||
status='ReadyToTrade'
|
||||
order by
|
||||
event_id;
|
||||
eid;
|
||||
|
||||
|
||||
drop view orders_fills;
|
||||
create view orders_fills as
|
||||
select
|
||||
transact_time,
|
||||
event_id,
|
||||
t_time,
|
||||
eid,
|
||||
sum(is_order) order_count,
|
||||
sum(is_fill) fill_count,
|
||||
sum(is_aggressor) aggressor_count
|
||||
sum(is_agg) agg_count
|
||||
from
|
||||
event_items_aux
|
||||
where
|
||||
trading_status='ReadyToTrade'
|
||||
status='ReadyToTrade'
|
||||
group by
|
||||
transact_time,event_id ;
|
||||
t_time,eid ;
|
||||
|
||||
drop view simple_fills;
|
||||
create view simple_fills as
|
||||
select * from event_items where event_id in (select event_id from orders_Fills where fill_count=2) ;
|
||||
select * from event_items where eid in (select eid from orders_Fills where fill_count=2) ;
|
||||
|
||||
drop view aggressor_fills;
|
||||
create view aggressor_fills as
|
||||
select * from event_items where aggressor='yes' ;
|
||||
drop view agg_fills;
|
||||
create view agg_fills as
|
||||
select * from event_items where agg='yes' ;
|
||||
|
||||
drop view aggressor_orders;
|
||||
create view aggressor_orders as
|
||||
drop view agg_orders;
|
||||
create view agg_orders as
|
||||
select
|
||||
event_items.event_id,
|
||||
event_items.order_key aggressor_ok
|
||||
event_items.eid,
|
||||
event_items.ok agg_ok
|
||||
|
||||
from
|
||||
event_items, aggressor_fills
|
||||
event_items, agg_fills
|
||||
where
|
||||
event_items.type='order' and
|
||||
event_items.event_id=aggressor_fills.event_id and
|
||||
event_items.order_key=aggressor_fills.order_key;
|
||||
event_items.eid=agg_fills.eid and
|
||||
event_items.ok=agg_fills.ok;
|
||||
Reference in new issue
Block a user