Cancel Order
CancelOrder
Input Parameters
| Parameter | Type | Description |
|---|---|---|
| account | Account | Account |
| orderResult | OrderResult | The order object to cancel |
| unblock | *bool (optional) (default = false) | Whether to use non-blocking |
Result Return
| Parameter | Type | Description |
|---|---|---|
| IsSuccess | bool | Whether successful |
| Data | *OrderResult | Returns order information |
| Message | *string | Returns error message when IsSuccess = false |
Cancellation Information OrderResult Fields
Return type : Object
| Parameter | Type | Description |
|---|---|---|
| FunctionType | *int64 | Function Type: 0 New Order, 10 Execute New Order, 15 Change Price, 20 Change Qty, 30 Cancel Order, 90 Fail |
| Date | *string | Transaction Date |
| SeqNo | *string | Order Sequence Number |
| BranchNo | *string | Branch Code |
| Account | *string | Account |
| OrderNo | *string | Order Number |
| AssetType | *int64 | Asset Type: 0 Securities |
| Market | *string | Market: TAIEX Listed Stocks, TAISDAQ OTC Stocks, TAIEMG Emerging Stocks |
| MarketType | MarketType | Market Type Category: MarketTypeCommon Regular Stock, MarketTypeFixing Fixing, MarketTypeIntradayOdd Intraday Odd Lot, MarketTypeOdd Post-market Odd Lot, MarketTypeEmg Emerging, MarketTypeEmgOdd Emerging Odd Lot |
| StockNo | *string | Stock Symbol |
| BuySell | *BsAction | Buy/Sell Action: BsActionBuy Buy, BsActionSell Sell |
| PriceType | *PriceType | Effective Price Type: PriceTypeLimit Limit, PriceTypeLimitUp Limit Up, PriceTypeLimitDown Limit Down, PriceTypeMarket Market, PriceTypeReference Reference |
| Price | *string | Price |
| Quantity | *int64 | Original Order Quantity |
| TimeInForce | *TimeInForce | Order Condition: TimeInForceRod ROD, TimeInForceFok FOK, TimeInForceIoc IOC |
| OrderType | *OrderType | Order Type: OrderTypeStock Common, OrderTypeMargin Margin, OrderTypeShort Short Sell, OrderTypeDayTrade Day Trade, OrderTypeSbl SBL |
| IsPreOrder | *bool | Is Pre-order |
| Status | *int64 | Order Status: 0 Pre-order, 4 Sending to Backend, 9 Connection Timeout, 10 Order Success, 30 Cancelled Unfilled, 40 Partial Fill/Rest Cancelled, 50 Fully Filled, 90 Fail |
| AfterPriceType | *PriceType | Effective Price Type: PriceTypeLimit Limit, PriceTypeLimitUp Limit Up, PriceTypeLimitDown Limit Down, PriceTypeMarket Market, PriceTypeReference Reference |
| AfterPrice | *string | Effective Order Price |
| Unit | *int64 | Unit |
| AfterQty | *int64 | Effective Order Quantity (including filled part) |
| FilledQty | *int64 | Filled Quantity |
| FilledMoney | *int64 | Filled Amount |
| BeforeQty | *int64 | Effective Qty Before Change |
| BeforePrice | *string | Effective Price Before Change |
| UserDef | *string | User Defined Field |
| LastTime | *string | Last Modified Time |
| Details | *string | Order History (Value exists only when querying OrderResultDetail or OrderHistory) |
| ErrorMessage | *string | Error Message |
Request Example
package main
import (
"fmt"
"fubon"
)
func main() {
// Initialize SDK and login
sdk := fubon.NewSDK()
// ... Login, connection, and other initialization steps ...
// Get Order List
ordResult, err := sdk.Stock.OrderResults(account)
if err != nil {
fmt.Printf("❌ Get Order Results Error: %v\n", err)
return
}
// Select order to cancel
var cancelOrder fubon.OrderResult
if ordResult.Data != nil && len(*ordResult.Data) > 0 {
cancelOrder = (*ordResult.Data)[0]
fmt.Println("Selected order for cancellation")
fmt.Printf("OrderNo: %s, StockNo: %s\n", *cancelOrder.OrderNo, *cancelOrder.StockNo)
// Cancel Order
unblock := false
cancelRes, err := sdk.Stock.CancelOrder(account, cancelOrder, &unblock)
if err != nil {
fmt.Printf("❌ Cancel Order Error: %v (Type: %T)\n", err, err)
return
}
// Check Success
if !cancelRes.IsSuccess {
message := "No message"
if cancelRes.Message != nil {
message = *cancelRes.Message
}
fmt.Printf("Cancel failed. Message: %s\n", message)
return
}
// Output Cancellation Result
if cancelRes.Data != nil {
fmt.Println("✅ Order cancelled successfully!")
fmt.Printf("FunctionType: %d (30=Cancel)\n", *cancelRes.Data.FunctionType)
fmt.Printf("Status: %d (30=Cancelled Unfilled)\n", *cancelRes.Data.Status)
fmt.Printf("OrderNo: %s\n", *cancelRes.Data.OrderNo)
fmt.Printf("AfterQty: %d\n", *cancelRes.Data.AfterQty)
} else {
fmt.Println("Order cancelled but no data returned.")
}
} else {
fmt.Println("⚠️ No orders found for cancellation")
}
}
Response Example
// CancelOrder Return Structure
Result{
IsSuccess: true,
Message: nil,
Data: &OrderResult{
FunctionType: 30, // Function Type (30=Cancel)
Date: "2024/03/08", // Transaction Date
SeqNo: "00000308948", // Order Sequence Number
BranchNo: "6460", // Branch Code
Account: "26", // Account
OrderNo: "x0023", // Order Number
AssetType: 0, // Asset Type
Market: "TAIEX", // Market Type
MarketType: Common, // Market Type Category
StockNo: "1101", // Stock Symbol
BuySell: Sell, // Buy/Sell Action
PriceType: Limit, // Original Price Type
Price: "41.2", // Price
Quantity: 5000, // Original Order Quantity
TimeInForce: Rod, // Order Condition
OrderType: Stock, // Order Type
IsPreOrder: false, // Is Pre-order
Status: 30, // Order Status (30=Cancelled Unfilled)
AfterPriceType: Limit, // Effective Price Type
AfterPrice: "41.2", // Effective Price
Unit: 1000, // Unit
AfterQty: 0, // Effective Order Quantity (0 after cancellation)
FilledQty: 0, // Filled Quantity
FilledMoney: 0, // Filled Amount
BeforeQty: 5000, // Effective Qty Before Change
BeforePrice: "41.2", // Effective Price Before Change
UserDef: "12345678", // User Defined Field
LastTime: "12:53:57.536", // Last Modified Time
Details: nil, // Order History
ErrorMessage: "", // Error Message
},
}
Notes
- Cancellation Conditions: Only unfilled or partially filled orders can be cancelled. Fully filled orders cannot be cancelled.
- FunctionType: hen cancellation is successful,
FunctionTypeis30. - Status: When cancellation is successful,
Statusis30(Cancelled Unfilled) or40(Partial Fill/Rest Cancelled). - AfterQty: After successful cancellation,
AfterQtybecomes0, indicating no effective order quantity. - Order Object: You need to obtain the order list via
OrderResults()first, and then select the order to cancel. - Non-blocking Mode: Use the
&unblockparameter to set whether to use non-blocking mode, default isfalse(blocking mode).