Skip to content

Commit

Permalink
Add OrderBookDepth10 type for Python
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Jan 1, 2024
1 parent e0df740 commit c18dd85
Show file tree
Hide file tree
Showing 13 changed files with 576 additions and 60 deletions.
1 change: 1 addition & 0 deletions nautilus_core/model/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ exclude = [
"OrderId" = "uint64_t"
"OrderBookDelta" = "OrderBookDelta_t"
"OrderBookDeltas" = "OrderBookDeltas_t"
"OrderBookDepth10" = "OrderBookDepth10_t"
"OrderInitialized" = "OrderInitialized_t"
"OrderDenied" = "OrderDenied_t"
"OrderEmulated" = "OrderEmulated_t"
Expand Down
1 change: 1 addition & 0 deletions nautilus_core/model/cbindgen_cython.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ exclude = [
"OrderId" = "uint64_t"
"OrderBookDelta" = "OrderBookDelta_t"
"OrderBookDeltas" = "OrderBookDeltas_t"
"OrderBookDepth10" = "OrderBookDepth10_t"
"OrderInitialized" = "OrderInitialized_t"
"OrderDenied" = "OrderDenied_t"
"OrderEmulated" = "OrderEmulated_t"
Expand Down
6 changes: 3 additions & 3 deletions nautilus_core/model/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub enum AggregationSource {
)]
pub enum AggressorSide {
/// There was no specific aggressor for the trade.
NoAggressor = 0, // Will be replaced by `Option`
NoAggressor = 0,
/// The BUY order was the aggressor for the trade.
#[pyo3(name = "BUYER")]
Buyer = 1,
Expand Down Expand Up @@ -726,8 +726,8 @@ pub enum OptionKind {
pyclass(module = "nautilus_trader.core.nautilus_pyo3.model.enums")
)]
pub enum OrderSide {
/// No order side is specified (only valid in the context of a filter for actions involving orders).
NoOrderSide = 0, // Will be replaced by `Option`
/// No order side is specified.
NoOrderSide = 0,
/// The order is a BUY.
#[pyo3(name = "BUY")]
Buy = 1,
Expand Down
30 changes: 15 additions & 15 deletions nautilus_trader/core/includes/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ typedef enum OptionKind {
*/
typedef enum OrderSide {
/**
* No order side is specified (only valid in the context of a filter for actions involving orders).
* No order side is specified.
*/
NO_ORDER_SIDE = 0,
/**
Expand Down Expand Up @@ -784,7 +784,7 @@ typedef struct OrderBookDelta_t {
* Note: This type is not compatible with `OrderBookDelta` or `OrderBookDeltas` due to
* its specialized structure and limited depth use case.
*/
typedef struct OrderBookDepth10 {
typedef struct OrderBookDepth10_t {
/**
* The instrument ID for the book.
*/
Expand Down Expand Up @@ -813,7 +813,7 @@ typedef struct OrderBookDepth10 {
* The UNIX timestamp (nanoseconds) when the data object was initialized.
*/
uint64_t ts_init;
} OrderBookDepth10;
} OrderBookDepth10_t;

/**
* Represents a single quote tick in a financial market.
Expand Down Expand Up @@ -989,7 +989,7 @@ typedef struct Data_t {
struct OrderBookDelta_t delta;
};
struct {
struct OrderBookDepth10 depth10;
struct OrderBookDepth10_t depth10;
};
struct {
struct QuoteTick_t quote;
Expand Down Expand Up @@ -1392,18 +1392,18 @@ uint64_t orderbook_delta_hash(const struct OrderBookDelta_t *delta);
* - Assumes `bids` and `asks` are valid pointers to arrays of `BookOrder` of length 10.
* - Assumes Rust now takes ownership of the memory for `bids` and `asks`.
*/
struct OrderBookDepth10 orderbook_depth10_new(struct InstrumentId_t instrument_id,
const struct BookOrder_t *bids_ptr,
const struct BookOrder_t *asks_ptr,
uint8_t flags,
uint64_t sequence,
uint64_t ts_event,
uint64_t ts_init);
struct OrderBookDepth10_t orderbook_depth10_new(struct InstrumentId_t instrument_id,
const struct BookOrder_t *bids_ptr,
const struct BookOrder_t *asks_ptr,
uint8_t flags,
uint64_t sequence,
uint64_t ts_event,
uint64_t ts_init);

uint8_t orderbook_depth10_eq(const struct OrderBookDepth10 *lhs,
const struct OrderBookDepth10 *rhs);
uint8_t orderbook_depth10_eq(const struct OrderBookDepth10_t *lhs,
const struct OrderBookDepth10_t *rhs);

uint64_t orderbook_depth10_hash(const struct OrderBookDepth10 *delta);
uint64_t orderbook_depth10_hash(const struct OrderBookDepth10_t *delta);

struct BookOrder_t book_order_from_raw(enum OrderSide order_side,
int64_t price_raw,
Expand Down Expand Up @@ -2085,7 +2085,7 @@ void orderbook_clear_asks(struct OrderBook_API *book, uint64_t ts_event, uint64_

void orderbook_apply_delta(struct OrderBook_API *book, struct OrderBookDelta_t delta);

void orderbook_apply_depth(struct OrderBook_API *book, struct OrderBookDepth10 depth);
void orderbook_apply_depth(struct OrderBook_API *book, struct OrderBookDepth10_t depth);

CVec orderbook_bids(struct OrderBook_API *book);

Expand Down
26 changes: 13 additions & 13 deletions nautilus_trader/core/rust/model.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ cdef extern from "../includes/model.h":

# The order side for a specific order, or action related to orders.
cpdef enum OrderSide:
# No order side is specified (only valid in the context of a filter for actions involving orders).
# No order side is specified.
NO_ORDER_SIDE # = 0,
# The order is a BUY.
BUY # = 1,
Expand Down Expand Up @@ -428,7 +428,7 @@ cdef extern from "../includes/model.h":
#
# Note: This type is not compatible with `OrderBookDelta` or `OrderBookDeltas` due to
# its specialized structure and limited depth use case.
cdef struct OrderBookDepth10:
cdef struct OrderBookDepth10_t:
# The instrument ID for the book.
InstrumentId_t instrument_id;
# The bid orders for the depth update.
Expand Down Expand Up @@ -537,7 +537,7 @@ cdef extern from "../includes/model.h":
cdef struct Data_t:
Data_t_Tag tag;
OrderBookDelta_t delta;
OrderBookDepth10 depth10;
OrderBookDepth10_t depth10;
QuoteTick_t quote;
TradeTick_t trade;
Bar_t bar;
Expand Down Expand Up @@ -836,17 +836,17 @@ cdef extern from "../includes/model.h":
#
# - Assumes `bids` and `asks` are valid pointers to arrays of `BookOrder` of length 10.
# - Assumes Rust now takes ownership of the memory for `bids` and `asks`.
OrderBookDepth10 orderbook_depth10_new(InstrumentId_t instrument_id,
const BookOrder_t *bids_ptr,
const BookOrder_t *asks_ptr,
uint8_t flags,
uint64_t sequence,
uint64_t ts_event,
uint64_t ts_init);
OrderBookDepth10_t orderbook_depth10_new(InstrumentId_t instrument_id,
const BookOrder_t *bids_ptr,
const BookOrder_t *asks_ptr,
uint8_t flags,
uint64_t sequence,
uint64_t ts_event,
uint64_t ts_init);

uint8_t orderbook_depth10_eq(const OrderBookDepth10 *lhs, const OrderBookDepth10 *rhs);
uint8_t orderbook_depth10_eq(const OrderBookDepth10_t *lhs, const OrderBookDepth10_t *rhs);

uint64_t orderbook_depth10_hash(const OrderBookDepth10 *delta);
uint64_t orderbook_depth10_hash(const OrderBookDepth10_t *delta);

BookOrder_t book_order_from_raw(OrderSide order_side,
int64_t price_raw,
Expand Down Expand Up @@ -1425,7 +1425,7 @@ cdef extern from "../includes/model.h":

void orderbook_apply_delta(OrderBook_API *book, OrderBookDelta_t delta);

void orderbook_apply_depth(OrderBook_API *book, OrderBookDepth10 depth);
void orderbook_apply_depth(OrderBook_API *book, OrderBookDepth10_t depth);

CVec orderbook_bids(OrderBook_API *book);

Expand Down
22 changes: 22 additions & 0 deletions nautilus_trader/model/data.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ from nautilus_trader.core.rust.model cimport HaltReason
from nautilus_trader.core.rust.model cimport InstrumentCloseType
from nautilus_trader.core.rust.model cimport MarketStatus
from nautilus_trader.core.rust.model cimport OrderBookDelta_t
from nautilus_trader.core.rust.model cimport OrderBookDepth10_t
from nautilus_trader.core.rust.model cimport OrderSide
from nautilus_trader.core.rust.model cimport PriceType
from nautilus_trader.core.rust.model cimport QuoteTick_t
Expand Down Expand Up @@ -247,6 +248,27 @@ cdef class OrderBookDeltas(Data):
cdef dict to_dict_c(OrderBookDeltas obj)


cdef class OrderBookDepth10(Data):
cdef OrderBookDepth10_t _mem
cdef list[BookOrder] _bids
cdef list[BookOrder] _asks

@staticmethod
cdef OrderBookDepth10 from_mem_c(OrderBookDepth10_t mem)

@staticmethod
cdef OrderBookDepth10 from_dict_c(dict values)

@staticmethod
cdef dict to_dict_c(OrderBookDepth10 obj)

@staticmethod
cdef list capsule_to_list_c(capsule)

@staticmethod
cdef object list_to_capsule_c(list items)


cdef class VenueStatus(Data):
cdef readonly Venue venue
"""The venue.\n\n:returns: `Venue`"""
Expand Down
Loading

0 comments on commit c18dd85

Please sign in to comment.