pub struct CreateOrderRequest {
pub client_order_id: Uuid,
pub side: OrderSide,
pub order_type: OrderType,
pub order_quantity: i64,
pub ticker: String,
pub class_code: String,
pub price: Option<Decimal>,
pub extras: OrderExtras,
}Expand description
Body of an order placement: BcsHttpClient::create_order
and BcsHttpClient::create_order_sync.
Build it with CreateOrderRequest::market or CreateOrderRequest::limit. The quantity is in
pieces, not lots, and the price is per piece. A price you send must be a whole number of price steps
(crate::utils::precision) and inside the exchange band, or the exchange refuses the order.
The fields of OrderExtras are flattened into the body, all of them optional.
§Examples
use brokapi_bcs_protocol::http::models::CreateOrderRequest;
use brokapi_bcs_protocol::models::enums::OrderSide;
use uuid::Uuid;
let req = CreateOrderRequest::limit(Uuid::nil(), "SBER", "TQBR", OrderSide::Buy, 10, dec!(300.5));
assert_eq!(
serde_json::to_value(&req)?,
serde_json::json!({
"clientOrderId": "00000000-0000-0000-0000-000000000000",
"side": "1",
"orderType": "2",
"orderQuantity": 10,
"ticker": "SBER",
"classCode": "TQBR",
"price": 300.5
})
);Fields§
§client_order_id: UuidYour id of the order. Generate a new UUID per order and keep it: it is how you find the order later. The broker docs say it is used to track the order and to prevent duplicates.
side: OrderSideBuy or sell.
order_type: OrderTypeType of the order.
order_quantity: i64Quantity in pieces (not lots), at least 1.
ticker: StringTicker.
class_code: StringClass code (board), for example TQBR.
price: Option<Decimal>Price per piece, above 0, up to 8 decimals. Left out for a market order.
extras: OrderExtrasOptional parameters (time in force, stops, iceberg, spread, offset), flattened into the body.
Implementations§
Source§impl CreateOrderRequest
impl CreateOrderRequest
Sourcepub fn market(
client_order_id: Uuid,
ticker: impl Into<String>,
class_code: impl Into<String>,
side: OrderSide,
quantity: i64,
) -> Self
pub fn market( client_order_id: Uuid, ticker: impl Into<String>, class_code: impl Into<String>, side: OrderSide, quantity: i64, ) -> Self
Builds a market order. The client_order_id is yours: generate a new UUID per order and keep it.
The quantity is in pieces. A market order has no price. The order is not sent by this call, pass
the result to BcsHttpClient::create_order.
§Examples
use brokapi_bcs_protocol::http::models::CreateOrderRequest;
use brokapi_bcs_protocol::models::enums::OrderSide;
use uuid::Uuid;
let req = CreateOrderRequest::market(Uuid::new_v4(), "SBER", "TQBR", OrderSide::Sell, 3);
assert!(req.price.is_none());
assert_eq!(serde_json::to_value(&req)?["orderType"], "1");Sourcepub fn limit(
client_order_id: Uuid,
ticker: impl Into<String>,
class_code: impl Into<String>,
side: OrderSide,
quantity: i64,
price: Decimal,
) -> Self
pub fn limit( client_order_id: Uuid, ticker: impl Into<String>, class_code: impl Into<String>, side: OrderSide, quantity: i64, price: Decimal, ) -> Self
Builds a limit order. The client_order_id is yours: generate a new UUID per order and keep it.
The quantity is in pieces and the price is per piece. The price must be a whole number of price
steps and inside the exchange band, or the order is refused. See crate::utils::precision to
put a price on the step grid. The order is not sent by this call, pass the result to
BcsHttpClient::create_order.
§Examples
use brokapi_bcs_protocol::http::models::CreateOrderRequest;
use brokapi_bcs_protocol::models::enums::OrderSide;
use brokapi_bcs_protocol::utils::precision::precise_down;
use rust_decimal::Decimal;
use uuid::Uuid;
// The price comes from a calculation: put it on the 0.05 step grid first.
let price = precise_down(Decimal::new(10103, 2), Decimal::new(5, 2))?;
let req = CreateOrderRequest::limit(Uuid::new_v4(), "SBER", "TQBR", OrderSide::Buy, 2, price);
assert_eq!(req.price, Some(Decimal::new(10100, 2)));Trait Implementations§
Source§impl Clone for CreateOrderRequest
impl Clone for CreateOrderRequest
Source§fn clone(&self) -> CreateOrderRequest
fn clone(&self) -> CreateOrderRequest
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more