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::single_order_types

Single Order Types Module

use 0x1::option;
use 0x1::string;
use 0x1::timestamp;
use 0x5::order_book_types;
use 0x5::order_match_types;

Enum SingleOrderRequest

enum SingleOrderRequest<M: copy, drop, store> has copy, drop, store
Variants
V1
Fields
account: address
order_id: order_book_types::OrderId
client_order_id: option::Option<string::String>
price: u64
orig_size: u64
remaining_size: u64
is_bid: bool
trigger_condition: option::Option<order_book_types::TriggerCondition>
time_in_force: order_book_types::TimeInForce
creation_time_micros: u64
metadata: M

Enum SingleOrder

enum SingleOrder<M: copy, drop, store> has copy, drop, store
Variants
V1
Fields
order_request: single_order_types::SingleOrderRequest<M>
unique_priority_idx: order_book_types::IncreasingIdx

Enum OrderWithState

enum OrderWithState<M: copy, drop, store> has copy, drop, store
Variants
V1
Fields
order: single_order_types::SingleOrder<M>
is_active: bool

Constants

const EINVALID_ORDER_SIZE_DECREASE: u64 = 1;

Function new_order_request_from_match_details

public fun new_order_request_from_match_details<M: copy, drop, store>(order_match_details: order_match_types::OrderMatchDetails<M>): single_order_types::SingleOrderRequest<M>
Implementation
public fun new_order_request_from_match_details<M: store + copy + drop>(
    order_match_details: OrderMatchDetails<M>
): SingleOrderRequest<M> {
    let (
        order_id,
        account,
        client_order_id,
        _unique_priority_idx,
        price,
        orig_size,
        remaining_size,
        is_bid,
        time_in_force,
        creation_time_micros,
        metadata
    ) = order_match_details.destroy_single_order_match_details();
    SingleOrderRequest::V1 {
        account,
        order_id,
        client_order_id,
        price,
        orig_size,
        remaining_size,
        is_bid,
        trigger_condition: option::none(),
        time_in_force,
        creation_time_micros,
        metadata
    }
}

Function new_single_order

public fun new_single_order<M: copy, drop, store>(order_request: single_order_types::SingleOrderRequest<M>, unique_priority_idx: order_book_types::IncreasingIdx): single_order_types::SingleOrder<M>
Implementation
public fun new_single_order<M: store + copy + drop>(
    order_request: SingleOrderRequest<M>, unique_priority_idx: IncreasingIdx
): SingleOrder<M> {
    SingleOrder::V1 { order_request, unique_priority_idx }
}

Function new_order_with_state

public fun new_order_with_state<M: copy, drop, store>(order: single_order_types::SingleOrder<M>, is_active: bool): single_order_types::OrderWithState<M>
Implementation
public fun new_order_with_state<M: store + copy + drop>(
    order: SingleOrder<M>, is_active: bool
): OrderWithState<M> {
    OrderWithState::V1 { order, is_active }
}

Function get_order_id

public fun get_order_id<M: copy, drop, store>(self: &single_order_types::SingleOrderRequest<M>): order_book_types::OrderId
Implementation
public fun get_order_id<M: store + copy + drop>(
    self: &SingleOrderRequest<M>
): OrderId {
    self.order_id
}

Function get_account

public fun get_account<M: copy, drop, store>(self: &single_order_types::SingleOrderRequest<M>): address
Implementation
public fun get_account<M: store + copy + drop>(
    self: &SingleOrderRequest<M>
): address {
    self.account
}

Function get_trigger_condition

public fun get_trigger_condition<M: copy, drop, store>(self: &single_order_types::SingleOrderRequest<M>): option::Option<order_book_types::TriggerCondition>
Implementation
public fun get_trigger_condition<M: store + copy + drop>(
    self: &SingleOrderRequest<M>
): Option<TriggerCondition> {
    self.trigger_condition
}

Function get_remaining_size

public fun get_remaining_size<M: copy, drop, store>(self: &single_order_types::SingleOrderRequest<M>): u64
Implementation
public fun get_remaining_size<M: store + copy + drop>(
    self: &SingleOrderRequest<M>
): u64 {
    self.remaining_size
}

Function get_client_order_id

public fun get_client_order_id<M: copy, drop, store>(self: &single_order_types::SingleOrderRequest<M>): option::Option<string::String>
Implementation
public fun get_client_order_id<M: store + copy + drop>(
    self: &SingleOrderRequest<M>
): Option<String> {
    self.client_order_id
}

Function get_price

public fun get_price<M: copy, drop, store>(self: &single_order_types::SingleOrderRequest<M>): u64
Implementation
public fun get_price<M: store + copy + drop>(self: &SingleOrderRequest<M>): u64 {
    self.price
}

Function is_bid

public fun is_bid<M: copy, drop, store>(self: &single_order_types::SingleOrderRequest<M>): bool
Implementation
public fun is_bid<M: store + copy + drop>(self: &SingleOrderRequest<M>): bool {
    self.is_bid
}

Function get_creation_time_micros

public fun get_creation_time_micros<M: copy, drop, store>(self: &single_order_types::SingleOrderRequest<M>): u64
Implementation
public fun get_creation_time_micros<M: store + copy + drop>(
    self: &SingleOrderRequest<M>
): u64 {
    self.creation_time_micros
}

Function get_unique_priority_idx

public fun get_unique_priority_idx<M: copy, drop, store>(self: &single_order_types::SingleOrder<M>): order_book_types::IncreasingIdx
Implementation
public fun get_unique_priority_idx<M: store + copy + drop>(
    self: &SingleOrder<M>
): IncreasingIdx {
    self.unique_priority_idx
}

Function get_order_request

public fun get_order_request<M: copy, drop, store>(self: &single_order_types::SingleOrder<M>): &single_order_types::SingleOrderRequest<M>
Implementation
public fun get_order_request<M: store + copy + drop>(
    self: &SingleOrder<M>
): &SingleOrderRequest<M> {
    &self.order_request
}

Function get_order_request_mut

public fun get_order_request_mut<M: copy, drop, store>(self: &mut single_order_types::SingleOrder<M>): &mut single_order_types::SingleOrderRequest<M>
Implementation
public fun get_order_request_mut<M: store + copy + drop>(
    self: &mut SingleOrder<M>
): &mut SingleOrderRequest<M> {
    &mut self.order_request
}

Function get_order_from_state

public fun get_order_from_state<M: copy, drop, store>(self: &single_order_types::OrderWithState<M>): &single_order_types::SingleOrder<M>
Implementation
public fun get_order_from_state<M: store + copy + drop>(
    self: &OrderWithState<M>
): &SingleOrder<M> {
    &self.order
}

Function get_order_from_state_mut

public fun get_order_from_state_mut<M: copy, drop, store>(self: &mut single_order_types::OrderWithState<M>): &mut single_order_types::SingleOrder<M>
Implementation
public fun get_order_from_state_mut<M: store + copy + drop>(
    self: &mut OrderWithState<M>
): &mut SingleOrder<M> {
    &mut self.order
}

Function get_metadata_from_state

public fun get_metadata_from_state<M: copy, drop, store>(self: &single_order_types::OrderWithState<M>): M
Implementation
public fun get_metadata_from_state<M: store + copy + drop>(
    self: &OrderWithState<M>
): M {
    self.order.order_request.metadata
}

Function set_metadata_in_state

public fun set_metadata_in_state<M: copy, drop, store>(self: &mut single_order_types::OrderWithState<M>, metadata: M)
Implementation
public fun set_metadata_in_state<M: store + copy + drop>(
    self: &mut OrderWithState<M>, metadata: M
) {
    self.order.order_request.metadata = metadata;
}

Function increase_remaining_size_from_state

public fun increase_remaining_size_from_state<M: copy, drop, store>(self: &mut single_order_types::OrderWithState<M>, size: u64)
Implementation
public fun increase_remaining_size_from_state<M: store + copy + drop>(
    self: &mut OrderWithState<M>, size: u64
) {
    self.order.order_request.remaining_size += size;
}

Function decrease_remaining_size_from_state

public fun decrease_remaining_size_from_state<M: copy, drop, store>(self: &mut single_order_types::OrderWithState<M>, size: u64)
Implementation
public fun decrease_remaining_size_from_state<M: store + copy + drop>(
    self: &mut OrderWithState<M>, size: u64
) {
    assert!(
        self.order.order_request.remaining_size > size,
        EINVALID_ORDER_SIZE_DECREASE
    );
    self.order.order_request.remaining_size -= size;
}

Function set_remaining_size_from_state

public fun set_remaining_size_from_state<M: copy, drop, store>(self: &mut single_order_types::OrderWithState<M>, remaining_size: u64)
Implementation
public fun set_remaining_size_from_state<M: store + copy + drop>(
    self: &mut OrderWithState<M>, remaining_size: u64
) {
    self.order.order_request.remaining_size = remaining_size;
}

Function get_remaining_size_from_state

public fun get_remaining_size_from_state<M: copy, drop, store>(self: &single_order_types::OrderWithState<M>): u64
Implementation
public fun get_remaining_size_from_state<M: store + copy + drop>(
    self: &OrderWithState<M>
): u64 {
    self.order.order_request.remaining_size
}

Function get_unique_priority_idx_from_state

public fun get_unique_priority_idx_from_state<M: copy, drop, store>(self: &single_order_types::OrderWithState<M>): order_book_types::IncreasingIdx
Implementation
public fun get_unique_priority_idx_from_state<M: store + copy + drop>(
    self: &OrderWithState<M>
): IncreasingIdx {
    self.order.unique_priority_idx
}

Function is_active_order

public fun is_active_order<M: copy, drop, store>(self: &single_order_types::OrderWithState<M>): bool
Implementation
public fun is_active_order<M: store + copy + drop>(
    self: &OrderWithState<M>
): bool {
    self.is_active
}

Function destroy_order_from_state

public fun destroy_order_from_state<M: copy, drop, store>(self: single_order_types::OrderWithState<M>): (single_order_types::SingleOrder<M>, bool)
Implementation
public fun destroy_order_from_state<M: store + copy + drop>(
    self: OrderWithState<M>
): (SingleOrder<M>, bool) {
    let OrderWithState::V1 { order, is_active } = self;
    (order, is_active)
}

Function destroy_single_order

public fun destroy_single_order<M: copy, drop, store>(self: single_order_types::SingleOrder<M>): (single_order_types::SingleOrderRequest<M>, order_book_types::IncreasingIdx)
Implementation
public fun destroy_single_order<M: store + copy + drop>(
    self: SingleOrder<M>
): (SingleOrderRequest<M>, IncreasingIdx) {
    let SingleOrder::V1 { order_request, unique_priority_idx } = self;
    (order_request, unique_priority_idx)
}

Function destroy_single_order_request

public fun destroy_single_order_request<M: copy, drop, store>(self: single_order_types::SingleOrderRequest<M>): (address, order_book_types::OrderId, option::Option<string::String>, u64, u64, u64, bool, option::Option<order_book_types::TriggerCondition>, order_book_types::TimeInForce, u64, M)
Implementation
public fun destroy_single_order_request<M: store + copy + drop>(
    self: SingleOrderRequest<M>
): (
    address,
    OrderId,
    Option<String>,
    u64,
    u64,
    u64,
    bool,
    Option<TriggerCondition>,
    TimeInForce,
    u64,
    M
) {
    let SingleOrderRequest::V1 {
        account,
        order_id,
        client_order_id,
        price,
        orig_size,
        remaining_size,
        is_bid,
        trigger_condition,
        time_in_force,
        metadata,
        creation_time_micros
    } = self;
    (
        account,
        order_id,
        client_order_id,
        price,
        orig_size,
        remaining_size,
        is_bid,
        trigger_condition,
        time_in_force,
        creation_time_micros,
        metadata
    )
}

Function new_single_order_request

public fun new_single_order_request<M: copy, drop, store>(account: address, order_id: order_book_types::OrderId, client_order_id: option::Option<string::String>, price: u64, orig_size: u64, remaining_size: u64, is_bid: bool, trigger_condition: option::Option<order_book_types::TriggerCondition>, time_in_force: order_book_types::TimeInForce, metadata: M): single_order_types::SingleOrderRequest<M>
Implementation
public fun new_single_order_request<M: store + copy + drop>(
    account: address,
    order_id: OrderId,
    client_order_id: Option<String>,
    price: u64,
    orig_size: u64,
    remaining_size: u64,
    is_bid: bool,
    trigger_condition: Option<TriggerCondition>,
    time_in_force: TimeInForce,
    metadata: M
): SingleOrderRequest<M> {
    SingleOrderRequest::V1 {
        account,
        order_id,
        client_order_id,
        price,
        orig_size,
        remaining_size,
        is_bid,
        trigger_condition,
        time_in_force,
        creation_time_micros: timestamp::now_microseconds(),
        metadata
    }
}