Limit Order Events
Parse limit order events from program logs using Borsh deserialization.
You can listen to limit order events by parsing through the program logs for emitted data. Events are Borsh-serialized and emitted in program logs for every order lifecycle operation.
Event structure
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, BorshDeserialize, BorshSerialize)]
pub struct LimitOrderEvent {
/// Event discriminator, used to identify the event type
/// Create - 1, Take - 2, Cancel - 3, Modify - 4, Withdraw - 5, CloseExpired - 6
pub discriminator: u8,
/// Instruction that triggered the event
pub instruction: u8,
/// The status of the order
pub status: u8,
/// Unique identifier for the order, used to differentiate orders for same
/// (owner, input_mint, output_mint) tuple
pub id: u8,
/// The public key of the order
pub maker: Pubkey,
/// The mint of the input token
pub input_mint: Pubkey,
/// The mint of the output token
pub output_mint: Pubkey,
/// The slot at which the event was emitted
pub slot: u64,
/// The slot at which the order was created
pub creation_slot: u64,
/// The slot at which the order expires
pub expiration_slot: u64,
/// The amount of input tokens to be exchanged
pub amount: u64,
/// The amount of input tokens that have been filled
pub amount_filled: u64,
/// The amount of output tokens that have been exchanged
pub out_amount_filled: u64,
/// The amount of fees paid in the smallest unit of from_token mint
pub fees_paid: u64,
/// Price base in the order, in the smallest unit of output token
pub price_base: u64,
/// Price exponent, price is calculated as price_base * 10^(-price_exponent)
pub price_exponent: u8,
/// Time in order, used to determine how long the order is valid
pub time_in_force: u8,
/// Fee rate in ticks, used to determine the fee charged for the order
pub fee_ticks: u8,
}Instruction discriminators
The discriminator field is always 0. The instruction field identifies which operation triggered the event:
1—PlaceOrder— A new limit order was created.2—TakeOrder— A searcher filled (partially or fully) an order.3—CancelOrder— The maker cancelled the order.4—ModifyOrder— The maker modified the order parameters.5—WithdrawFilled— The maker withdrew filled output tokens from a partially filled order.6—CloseExpired— An expired order was closed and rent reclaimed.
Related pages
Limit Orders Overview — Order structure, time-in-force, order status, fees
Placing Taker Orders — TakeOrder instruction and execution code
Error Codes — Program error codes
Last updated

