Unblock Order
First, let's begin by understanding the concepts of block and unblock. Block and Unblock are two different ways used to describe events, operations, or communication methods. Here are their basic concepts and distinction:
Unblock mode ususally pairs with order and filled callbacks for order management
Block(阻塞)mode can also be used with concurrency programming to send multiple requests simultaneously
Reference Concurrency Code Example
Block(阻塞):
Block operations refer to events or operations that occur in a predetermined sequence, and one operation must be completed before another can begin. Block is typically used in queue processing, where one task must wait for another to finish before it can proceed。
Unblock(非阻塞):
Unblock operations refer to events or operations that do not have to occur in a fixed sequence and can be executed in parallel. One operation does not need to wait for the completion of another. Unblock processing is typically used in multi-tasking environments where unblock operations are needed to improve efficiency and performance.
Using Block
After placing the order, the Order Response received will contain the complete data, including fields such as the order number.
- Python
- Node.js
- C#
#Create Order Object
order = Order(
buy_sell = BSAction.Buy,
symbol = "2881",
price = "66",
quantity = 2000,
market_type = MarketType.Common,
price_type = PriceType.Limit,
time_in_force = TimeInForce.ROD,
order_type = OrderType.Stock,
user_def = "From_Py" # optional field
)
sdk.stock.place_order(accounts.data[0], order) #Place Order
#Or Using
#sdk.stock.place_order(accounts.data[0], order, False)
//Create Order Object
const order = {
buySell: BSAction.Buy,
symbol: "2881",
price: "66",
quantity: 2000,
marketType: MarketType.Common,
priceType: PriceType.Limit,
timeInForce: TimeInForce.ROD,
orderType: OrderType.Stock,
userDef: "from Js"
};
sdk.stock.placeOrder(accounts.data[0], order);
// Or Using
//sdk.stock.placeOrder(accounts.data[0], order, false);
//Create Order Object
var order = new Order(
BsAction.Buy,
"2881",
"66",
2000,
MarketType.Common,
PriceType.Limit,
TimeInForce.Rod,
OrderType.Stock,
null
);
sdk.Stock.PlaceOrder(accounts.data[0] ,order); // Block mode
//Or Using
//sdk.Stock.PlaceOrder(accounts.data[0] ,order, false);
Using Unblock
After placing the order, the Order Response received will not contain the complete data, such as the order number.
- Python
- Node.js
- C#
#Create Order Object
order = Order(
buy_sell = BSAction.Buy,
symbol = "2881",
price = "66",
quantity = 2000,
market_type = MarketType.Common,
price_type = PriceType.Limit,
time_in_force = TimeInForce.ROD,
order_type = OrderType.Stock,
user_def = "From_Py" # optional field
)
sdk.stock.place_order(accounts.data[0], order, True) #Place Order
//Create Order Object
const order = {
buySell: BSAction.Buy,
symbol: "2881",
price: "66",
quantity: 2000,
marketType: MarketType.Common,
priceType: PriceType.Limit,
timeInForce: TimeInForce.ROD,
orderType: OrderType.Stock,
userDef: "from Js"
};
sdk.stock.placeOrder(accounts.data[0], order, true);
//Create Order Object
var order = new Order(
BsAction.Buy,
"2881",
"66",
2000,
MarketType.Common,
PriceType.Limit,
TimeInForce.Rod,
OrderType.Stock,
null
);
sdk.Stock.PlaceOrder(accounts.data[0] ,order, true); // Place Order with unblock mode
The following are functions that support Unblock orders:
- PlaceOrder - Plcae Order
- ModifyPrice - Modify Order Price
- ModifyQuantity - Modify Order Quantity
- CancelOrder - Cancel Order
Concurrency Code Example
- Python
- Node.js
- C#
import concurrent.futures
#Create Order Object
order = Order(
buy_sell = BSAction.Buy,
symbol = "2881",
price = "66",
quantity = 2000,
market_type = MarketType.Common,
price_type = PriceType.Limit,
time_in_force = TimeInForce.ROD,
order_type = OrderType.Stock,
user_def = "From_Py" # optional
)
# Place orders
def my_place_order():
sdk.stock.place_order(accounts.data[0], order) #Place Order
with concurrent.futures.ThreadPoolExecutor() as executor:
# Submit 20 tasks
futures = [executor.submit(my_place_order) for _ in range(20)]
# Wait for all tasks to complete
concurrent.futures.wait(futures)
//Create Order Object
const order = {
buySell: BSAction.Buy,
symbol: "2881",
price: "66",
quantity: 2000,
marketType: MarketType.Common,
priceType: PriceType.Limit,
timeInForce: TimeInForce.ROD,
orderType: OrderType.Stock,
userDef: "from Js"
};
// Place orders
function my_place_order() {
return new Promise((resolve) => {
sdk.stock.placeOrder(accounts.data[0], order);
resolve();
});
}
async function main() {
const tasks = [];
for (let i = 0; i < 20; i++) {
tasks.push(my_place_order());
}
await Promise.all(tasks); // Wait for all tasks to complete
}
main().then(() => {
console.log("All tasks completed")
});
using System;
using System.Threading.Tasks;
// Create Order Object
var order = new Order(
BsAction.Buy,
"2881",
"66",
2000,
MarketType.Common,
PriceType.Limit,
TimeInForce.Rod,
OrderType.Stock,
null
);
// Place orders
Task[] tasks = new Task[20];
for (int i = 0; i < 20; i++)
{
task[i] = Task.Run(() => sdk.Stock.PlaceOrder(accounts.data[0], order));
}
Task.WaitAll(tasks);