Skip to content

Commit

Permalink
Updates on events
Browse files Browse the repository at this point in the history
  • Loading branch information
IFFranciscoME committed Nov 29, 2024
1 parent f34d7f9 commit 5df4369
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 202 deletions.
63 changes: 21 additions & 42 deletions atelier/examples/example_market_events.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use atelier::data::market::Orderbook;
use atelier::events::templates;
use atelier::events::templates::enum_create;
use rand::seq::SliceRandom;
use rand::thread_rng;
use atelier::data::market::Orderbook;
use atelier::events::message;
use atelier::events::message::{MarketEventType, MarketEvent};

fn main() {
// -- Base OrderBook -- //
Expand All @@ -14,19 +13,12 @@ fn main() {
let n_levels = 20;
let n_orders = 10;

let mut i_ob = Orderbook::synthetize(bid_price, ask_price, tick_size, n_levels, n_orders);
let _i_ob = Orderbook::synthetize(bid_price, ask_price, tick_size, n_levels, n_orders);

// -------------------------------------------------------------- new limit order -- //
// -------------------------------------------------------------- --------------- -- //

// Use the macro to create the enum
enum_create!(
EventType,
CancelLimitOrder,
NewMarketOrder,
ModifyLimitOrder,
NewLimitOrder
);

// Now you can use the enum
// let _variants = EventType::variants();
Expand All @@ -50,32 +42,32 @@ fn main() {
// ------------------------------------------------ Event generation simulation -- //
// ------------------------------------------------ --------------------------- -- //

let mut vec_variants: Vec<EventType> = vec![];
let mut vec_variants: Vec<MarketEventType> = vec![];

for _ in 1..4 {
vec_variants.push(EventType::random_variants(1)[0].clone());
vec_variants.push(MarketEventType::random_variants(1)[0].clone());
}

// let iter_variants = &vec_variants;
println!("\ngenerated variants were: {:?}\n", &vec_variants);

let mut single_queue: Vec<templates::MarketEvent> = vec![];
let mut single_queue: Vec<MarketEvent> = vec![];

for i_variant in vec_variants {
match i_variant {
EventType::NewMarketOrder => {
MarketEventType::NewMarketOrder => {
single_queue.push(templates::random_new_mo_template().unwrap());
}

EventType::CancelLimitOrder => {
MarketEventType::CancelLimitOrder => {
single_queue.push(templates::random_cancel_lo_template().unwrap());
}

EventType::NewLimitOrder => {
MarketEventType::NewLimitOrder => {
single_queue.push(templates::random_new_lo_template().unwrap());
}

EventType::ModifyLimitOrder => {
MarketEventType::ModifyLimitOrder => {
single_queue.push(templates::random_modify_lo_template().unwrap());
}
}
Expand All @@ -95,37 +87,24 @@ fn main() {

let i_event = single_queue.pop().unwrap();

match i_event.event_data.event_type {
templates::MarketEventType::NewLimitOrder => {
let event_order = i_event.event_content.event_object;

println!("\nOrder to be inserted: {:?}\n", event_order);
match i_event.event_info.event_type {

let r_order =
i_ob.insert_order(event_order.side, event_order.price, event_order.amount);
message::MarketEventType::CancelLimitOrder => {

println!("\nr_order: {:?}", r_order);
}

templates::MarketEventType::ModifyLimitOrder => {
let event_order = i_event.event_content.event_object;
let i_event_content = i_event.event_content;
// println!("\nOrder to be inserted: {:?}\n", &i_event_order);

println!("\n the Order to be modified is: {:?}", event_order);
if let message::EventContent::OrderCancellation(i_order_id) = i_event_content {
println!("Order created: {:?}", &i_order_id);
}

}

templates::MarketEventType::CancelLimitOrder => {
let event_order = i_event.event_content.event_object;
_=> {


println!("\n the Order to be cancelled is: {:?}", event_order);
}

templates::MarketEventType::NewMarketOrder => {
let event_order = &i_event.event_data.event_type;
println!(
"\nThe {:?} MarketEventType is not yet mapped to an exeuction\n",
event_order
);
}
}
}
}
6 changes: 3 additions & 3 deletions atelier/src/events/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ macro_rules! enum_create {

impl $enum_name {

fn variants() -> Vec<Self> {
pub fn variants() -> Vec<Self> {
vec![$(Self::$variant),+]
}

fn random_variants(n_choice:usize) -> Vec<Self> {
pub fn random_variants(n_choice:usize) -> Vec<Self> {
let mut rng = thread_rng();
Self::variants()
.choose_multiple(&mut rng, n_choice)
Expand Down Expand Up @@ -76,7 +76,7 @@ impl EventInfo {
// ---------------------------------------------------- --------------------------- -- //

// Different market events can have different structures for the event_object.
#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub enum EventContent {
OrderCreation(market::Order),
OrderCancellation(u32),
Expand Down
Loading

0 comments on commit 5df4369

Please sign in to comment.