Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frank/dlob #12

Merged
merged 18 commits into from
Mar 18, 2024
Merged

frank/dlob #12

merged 18 commits into from
Mar 18, 2024

Conversation

soundsonacid
Copy link
Contributor

No description provided.

Copy link
Collaborator

@jordy25519 jordy25519 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Assuming we will rebuild the node list frequently the Box allocations (and deallocations) will become expensive

Suggest using something like https://crates.io/crates/typed-arena or an object pool to reuse allocations

  1. not sure the trait and distinct structs for each node type is helpful?
struct DlobNode {
    order: Order,
    user_account: Account,
    kind: NodeKind,
    next: Option<*mut DlobNode>,
    prev: Option<*mut DlobNode>
}
  1. can't comment on the use of the raw pointers as I haven't used them much

Copy link
Collaborator

@jordy25519 jordy25519 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lots of work done here! haven't grokked everything yet but left some simple feedback

} else if is_one_of_variant(
&order.order_type,
&[
OrderType::Market,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bit flags could help here (probably another PR): https://docs.rs/bitflags/latest/bitflags/#working-with-flags-values

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure will do down the line, just need this merged in for jit maker rn

src/dlob/dlob.rs Outdated Show resolved Hide resolved
src/dlob/market.rs Outdated Show resolved Hide resolved
Comment on lines +44 to +47
if self.order_sigs.contains_key(&order_sig) {
self.order_sigs.remove(&order_sig);
return Some(node);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if self.order_sigs.contains_key(&order_sig) {
self.order_sigs.remove(&order_sig);
return Some(node);
}
return self.order_sigs.remove(&order_sig)
}

same for asks

Copy link
Contributor Author

@soundsonacid soundsonacid Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't really like this because dashmap remove returns Option<K, V> so i'm getting Option<String, Node> out of here when all i actually want is Option Node and I can't transform Option<String, Node> with something annoying

}
}

pub(crate) type Exchange = DashMap<String, DashMap<u16, Market>>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if hashmap makes sense vs. e.g a struct

struct Exchange {
    perp: DashMap<u16, Market>>,
    spot: DashMap<u16, Market>>,
}

}

pub(crate) fn get_order_signature(order_id: u32, user_account: Pubkey) -> String {
format!("{}-{}", order_id, user_account.to_string())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about the string key, something like this with Display/to_string method may be better

#[derive(Eq, Hash, PartialEq)]
struct OrderKey {
    user: Pubkey,
    order_id: u32,
}

pub type OrderKey = (Pubkey, u32); could also work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like the string key, i think for simplicity it makes a lot of sense

@soundsonacid soundsonacid merged commit 15ce9ce into drift-labs:main Mar 18, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants