Skip to main content

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:

info

Unblock mode ususally pairs with order and filled callbacks for order management

info

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。

block

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.

unblock

Using Block

After placing the order, the Order Response received will contain the complete data, including fields such as the order number.

#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)

Using Unblock

After placing the order, the Order Response received will not contain the complete data, such as the order number.

#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

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

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)