Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Module 0x5::order_book_types

Order book type definitions

use 0x1::option;
use 0x1::string;
use 0x1::transaction_context;

Struct OrderId

struct OrderId has copy, drop, store
Fields
order_id: u128

Struct AccountClientOrderId

struct AccountClientOrderId has copy, drop, store
Fields
account: address
client_order_id: string::String

Struct IncreasingIdx

struct IncreasingIdx has copy, drop, store
Fields
idx: u128

Struct DecreasingIdx

struct DecreasingIdx has copy, drop, store
Fields
idx: u128

Struct OrderType

struct OrderType has copy, drop, store
Fields
type: u16

Enum TimeInForce

Order time in force

enum TimeInForce has copy, drop, store
Variants
GTC
Fields
POST_ONLY
Fields
IOC
Fields

Enum TriggerCondition

enum TriggerCondition has copy, drop, store
Variants
PriceMoveAbove
Fields
0: u64
PriceMoveBelow
Fields
0: u64
TimeBased
Fields
0: u64

Constants

const BULK_ORDER_TYPE: u16 = 1;

const EINVALID_TIME_IN_FORCE: u64 = 5;

const SINGLE_ORDER_TYPE: u16 = 0;

Function single_order_type

public fun single_order_type(): order_book_types::OrderType
Implementation
public fun single_order_type(): OrderType {
    OrderType { type: SINGLE_ORDER_TYPE }
}

Function bulk_order_type

public fun bulk_order_type(): order_book_types::OrderType
Implementation
public fun bulk_order_type(): OrderType {
    OrderType { type: BULK_ORDER_TYPE }
}

Function is_bulk_order_type

public fun is_bulk_order_type(order_type: &order_book_types::OrderType): bool
Implementation
public fun is_bulk_order_type(order_type: &OrderType): bool {
    order_type.type == BULK_ORDER_TYPE
}

Function is_single_order_type

public fun is_single_order_type(order_type: &order_book_types::OrderType): bool
Implementation
public fun is_single_order_type(order_type: &OrderType): bool {
    order_type.type == SINGLE_ORDER_TYPE
}

Function new_order_id_type

public fun new_order_id_type(order_id: u128): order_book_types::OrderId
Implementation
public fun new_order_id_type(order_id: u128): OrderId {
    OrderId { order_id }
}

Function new_account_client_order_id

public fun new_account_client_order_id(account: address, client_order_id: string::String): order_book_types::AccountClientOrderId
Implementation
public fun new_account_client_order_id(
    account: address, client_order_id: String
): AccountClientOrderId {
    AccountClientOrderId { account, client_order_id }
}

Function next_increasing_idx_type

public fun next_increasing_idx_type(): order_book_types::IncreasingIdx
Implementation
public fun next_increasing_idx_type(): IncreasingIdx {
    IncreasingIdx { idx: transaction_context::monotonically_increasing_counter() }
}

Function into_decreasing_idx_type

public fun into_decreasing_idx_type(self: &order_book_types::IncreasingIdx): order_book_types::DecreasingIdx
Implementation
public fun into_decreasing_idx_type(self: &IncreasingIdx): DecreasingIdx {
    DecreasingIdx { idx: MAX_U128 - self.idx }
}

Function get_order_id_value

public fun get_order_id_value(self: &order_book_types::OrderId): u128
Implementation
public fun get_order_id_value(self: &OrderId): u128 {
    self.order_id
}

Function time_in_force_from_index

public fun time_in_force_from_index(index: u8): order_book_types::TimeInForce
Implementation
public fun time_in_force_from_index(index: u8): TimeInForce {
    if (index == 0) {
        TimeInForce::GTC
    } else if (index == 1) {
        TimeInForce::POST_ONLY
    } else if (index == 2) {
        TimeInForce::IOC
    } else {
        abort EINVALID_TIME_IN_FORCE
    }
}

Function good_till_cancelled

public fun good_till_cancelled(): order_book_types::TimeInForce
Implementation
public fun good_till_cancelled(): TimeInForce {
    TimeInForce::GTC
}

Function post_only

public fun post_only(): order_book_types::TimeInForce
Implementation
public fun post_only(): TimeInForce {
    TimeInForce::POST_ONLY
}

Function immediate_or_cancel

public fun immediate_or_cancel(): order_book_types::TimeInForce
Implementation
public fun immediate_or_cancel(): TimeInForce {
    TimeInForce::IOC
}

Function new_time_based_trigger_condition

public fun new_time_based_trigger_condition(time_secs: u64): order_book_types::TriggerCondition
Implementation
public fun new_time_based_trigger_condition(time_secs: u64): TriggerCondition {
    TriggerCondition::TimeBased(time_secs)
}

Function price_move_up_condition

public fun price_move_up_condition(price: u64): order_book_types::TriggerCondition
Implementation
public fun price_move_up_condition(price: u64): TriggerCondition {
    TriggerCondition::PriceMoveAbove(price)
}

Function price_move_down_condition

public fun price_move_down_condition(price: u64): order_book_types::TriggerCondition
Implementation
public fun price_move_down_condition(price: u64): TriggerCondition {
    TriggerCondition::PriceMoveBelow(price)
}

Function get_trigger_condition_indices

public fun get_trigger_condition_indices(self: &order_book_types::TriggerCondition): (option::Option<u64>, option::Option<u64>, option::Option<u64>)
Implementation
public fun get_trigger_condition_indices(
    self: &TriggerCondition
): (option::Option<u64>, option::Option<u64>, option::Option<u64>) {
    match(self) {
        TriggerCondition::PriceMoveAbove(price) => {
            (option::none(), option::some(*price), option::none())
        }
        TriggerCondition::PriceMoveBelow(price) => {
            (option::some(*price), option::none(), option::none())
        }
        TriggerCondition::TimeBased(time) => {
            (option::none(), option::none(), option::some(*time))
        }
    }
}