pub struct OrderBuilder { /* private fields */ }Expand description
Order builder implementing a fluent API design.
Provides a type-safe and user-friendly way to construct orders.
§Examples
use ccxt_core::types::OrderSide;
use ccxt_core::types::order::OrderBuilder;
use rust_decimal_macros::dec;
// Create a limit buy order
let order = OrderBuilder::new("BTC/USDT".to_string(), OrderSide::Buy, dec!(0.1))
.limit(dec!(50000))
.client_order_id("my-order-123")
.post_only()
.build()
.expect("valid order configuration");
// Create a market sell order
let order = OrderBuilder::new("ETH/USDT".to_string(), OrderSide::Sell, dec!(1.5))
.market()
.build()
.expect("valid order configuration");Implementations§
Source§impl OrderBuilder
impl OrderBuilder
Sourcepub fn new(symbol: String, side: OrderSide, amount: Decimal) -> OrderBuilder
pub fn new(symbol: String, side: OrderSide, amount: Decimal) -> OrderBuilder
Creates a new order builder instance.
§Arguments
symbol- Trading pair symbol (for example, “BTC/USDT”)side- Order side (buy or sell)amount- Order quantity
Sourcepub fn limit(self, price: Decimal) -> OrderBuilder
pub fn limit(self, price: Decimal) -> OrderBuilder
Sets the builder to create a limit order.
Sourcepub fn market(self) -> OrderBuilder
pub fn market(self) -> OrderBuilder
Sets the builder to create a market order.
Sourcepub fn limit_maker(self, price: Decimal) -> OrderBuilder
pub fn limit_maker(self, price: Decimal) -> OrderBuilder
Sets the builder to create a post-only limit order.
Sourcepub fn stop_loss(self, stop_price: Decimal) -> OrderBuilder
pub fn stop_loss(self, stop_price: Decimal) -> OrderBuilder
Sets the builder to create a stop-loss order.
Sourcepub fn stop_loss_limit(
self,
stop_price: Decimal,
price: Decimal,
) -> OrderBuilder
pub fn stop_loss_limit( self, stop_price: Decimal, price: Decimal, ) -> OrderBuilder
Sets the builder to create a stop-loss limit order.
Sourcepub fn take_profit(self, trigger_price: Decimal) -> OrderBuilder
pub fn take_profit(self, trigger_price: Decimal) -> OrderBuilder
Sets the builder to create a take-profit order.
Sourcepub fn take_profit_limit(
self,
trigger_price: Decimal,
price: Decimal,
) -> OrderBuilder
pub fn take_profit_limit( self, trigger_price: Decimal, price: Decimal, ) -> OrderBuilder
Sets the builder to create a take-profit limit order.
Sourcepub fn stop_market(self, stop_price: Decimal) -> OrderBuilder
pub fn stop_market(self, stop_price: Decimal) -> OrderBuilder
Sets the builder to create a stop-market order.
Sourcepub fn stop_limit(self, stop_price: Decimal, price: Decimal) -> OrderBuilder
pub fn stop_limit(self, stop_price: Decimal, price: Decimal) -> OrderBuilder
Sets the builder to create an alternative stop-limit order form.
Sourcepub fn trailing_stop(self, callback_rate: Decimal) -> OrderBuilder
pub fn trailing_stop(self, callback_rate: Decimal) -> OrderBuilder
Sets the builder to create a trailing stop order.
Sourcepub fn client_order_id(self, id: impl Into<String>) -> OrderBuilder
pub fn client_order_id(self, id: impl Into<String>) -> OrderBuilder
Sets the client order identifier.
Sourcepub fn time_in_force(self, tif: TimeInForce) -> OrderBuilder
pub fn time_in_force(self, tif: TimeInForce) -> OrderBuilder
Sets the time-in-force policy.
Sourcepub fn trigger_price(self, price: Decimal) -> OrderBuilder
pub fn trigger_price(self, price: Decimal) -> OrderBuilder
Sets the trigger price.
Sourcepub fn take_profit_price(self, price: Decimal) -> OrderBuilder
pub fn take_profit_price(self, price: Decimal) -> OrderBuilder
Sets the take-profit price.
Sourcepub fn stop_loss_price(self, price: Decimal) -> OrderBuilder
pub fn stop_loss_price(self, price: Decimal) -> OrderBuilder
Sets the stop-loss price.
Sourcepub fn trailing_delta(self, delta: Decimal) -> OrderBuilder
pub fn trailing_delta(self, delta: Decimal) -> OrderBuilder
Sets the trailing delta (in basis points).
Sourcepub fn trailing_percent(self, percent: Decimal) -> OrderBuilder
pub fn trailing_percent(self, percent: Decimal) -> OrderBuilder
Sets the trailing percentage.
Sourcepub fn activation_price(self, price: Decimal) -> OrderBuilder
pub fn activation_price(self, price: Decimal) -> OrderBuilder
Sets the activation price.
Sourcepub fn callback_rate(self, rate: Decimal) -> OrderBuilder
pub fn callback_rate(self, rate: Decimal) -> OrderBuilder
Sets the callback rate (used for futures trailing stops).
Sourcepub fn working_type(self, wtype: impl Into<String>) -> OrderBuilder
pub fn working_type(self, wtype: impl Into<String>) -> OrderBuilder
Sets the working type (CONTRACT_PRICE or MARK_PRICE).
Sourcepub fn post_only(self) -> OrderBuilder
pub fn post_only(self) -> OrderBuilder
Marks the order as post-only.
Sourcepub fn reduce_only(self) -> OrderBuilder
pub fn reduce_only(self) -> OrderBuilder
Marks the order as reduce-only (used for futures).
Sourcepub fn build(self) -> Result<Order, OrderBuilderError>
pub fn build(self) -> Result<Order, OrderBuilderError>
Validates the configuration and builds an Order.
Ensures the order configuration is valid. For example:
- Limit orders require a price
- Stop orders require a stop price
- Quantities must be greater than zero
§Errors
Returns OrderBuilderError if the configuration is invalid.
Trait Implementations§
Source§impl Clone for OrderBuilder
impl Clone for OrderBuilder
Source§fn clone(&self) -> OrderBuilder
fn clone(&self) -> OrderBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more