Order Operations

PlaceOrder

Purpose

Submits an order to the configured trading account.

Signature

func (c *TradeClient) PlaceOrder(order model.OrderRequest) (*model.PlaceOrderResult, error)

Requires a trading account accessible through the configuration. Institutional accounts can authenticate with SecretKey.

Parameters

model.OrderRequest

SDK fieldTypeRequiredSerializationSDK default and constraints
ActionstringNoOmitted if emptyAllowed values: BUY, SELL
OrderTypestringNoOmitted if emptyAllowed values: MKT, LMT, STP, STP_LMT, TRAIL, AM, AL, TWAP, VWAP, OCA, ICEBERG
TimeInForcestringNoOmitted if emptyAllowed values: DAY, GTC, OPG
SecTypestringNoOmitted if emptyAllowed values: ALL, STK, OPT, WAR, IOPT, FUT, FOP, CASH, MLEG, FUND
MarketstringNoOmitted if emptyAllowed values: ALL, US, HK, CN, SG
CurrencystringNoOmitted if emptyAllowed values: ALL, USD, HKD, CNH, SGD
RightstringNoOmitted if emptyAllowed values: PUT, CALL (option side); br, nr when used as quote adjustment
MinDisplaySizeint64NoOmitted if emptyNone; 冰山单缺省等于 DisplaySize
CheckIntervalsint64NoOmitted if emptyNone; 冰山单默认 30 秒
PriceTypestringNoOmitted if emptyAllowed values: LIMIT_PRICE, ASK_PRICE, BID_PRICE, LATEST_PRICE; 冰山单默认 LIMIT_PRICE

Returns

(*model.PlaceOrderResult, error). Key fields from model.PlaceOrderResult:

FieldTypeDescription
IDint64Order ID
OrderIDint64Order number
SubIDs[]int64Sub-order ID list
Orders[]OrderOrder list

Invocation example

result, err := tc.PlaceOrder(model.OrderRequest{
	Account: "U123456",
	ID: 1,
	Action: "BUY",
	OrderType: "LMT",
	TotalQuantity: 1,
})
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%#v\n", result)
{
  "id": 123456789,
  "orderId": 123456789,
  "symbol": "AAPL",
  "action": "BUY",
  "orderType": "LMT",
  "limitPrice": 310.00,
  "totalQuantity": 100,
  "filledQuantity": 0,
  "status": "Initial",
  "account": "12345678"
}

PreviewOrder

Purpose

Validates an order and estimates commission and margin without placing it.

Signature

func (c *TradeClient) PreviewOrder(order model.OrderRequest) (*model.PreviewResult, error)

Requires a trading account accessible through the configuration. Institutional accounts can authenticate with SecretKey.

Parameters

model.OrderRequest

SDK fieldTypeRequiredSerializationSDK default and constraints
ActionstringNoOmitted if emptyAllowed values: BUY, SELL
OrderTypestringNoOmitted if emptyAllowed values: MKT, LMT, STP, STP_LMT, TRAIL, AM, AL, TWAP, VWAP, OCA, ICEBERG
TimeInForcestringNoOmitted if emptyAllowed values: DAY, GTC, OPG
SecTypestringNoOmitted if emptyAllowed values: ALL, STK, OPT, WAR, IOPT, FUT, FOP, CASH, MLEG, FUND
MarketstringNoOmitted if emptyAllowed values: ALL, US, HK, CN, SG
CurrencystringNoOmitted if emptyAllowed values: ALL, USD, HKD, CNH, SGD
RightstringNoOmitted if emptyAllowed values: PUT, CALL (option side); br, nr when used as quote adjustment
MinDisplaySizeint64NoOmitted if emptyNone; 冰山单缺省等于 DisplaySize
CheckIntervalsint64NoOmitted if emptyNone; 冰山单默认 30 秒
PriceTypestringNoOmitted if emptyAllowed values: LIMIT_PRICE, ASK_PRICE, BID_PRICE, LATEST_PRICE; 冰山单默认 LIMIT_PRICE

Returns

(*model.PreviewResult, error). Key fields from model.PreviewResult:

FieldTypeDescription
AccountstringAccount ID
IsPassboolWhether risk check passed
Commissionfloat64Estimated commission
CommissionCurrencystringCommission currency
MarginCurrencystringMargin currency
InitMarginfloat64Initial margin (after order)
InitMarginBeforefloat64Initial margin (before order)
MaintMarginfloat64Maintenance margin (after order)
MaintMarginBeforefloat64Maintenance margin (before order)
EquityWithLoanfloat64Equity with loan (after order)
EquityWithLoanBeforefloat64Equity with loan (before order)
AvailableEEfloat64Available excess equity
ExcessLiquidityfloat64Excess liquidity
OvernightLiquidationfloat64Overnight liquidation value

Invocation example

result, err := tc.PreviewOrder(model.OrderRequest{
	Account: "U123456",
	ID: 1,
	Action: "BUY",
	OrderType: "LMT",
	TotalQuantity: 1,
})
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%#v\n", result)
{
  "commission": 0.99,
  "margin": 31000.00,
  "buyingPower": 94000.00,
  "estimatedPrice": 310.00,
  "message": "",
  "warning": ""
}

ModifyOrder

Purpose

Changes an existing order identified by its global ID.

Signature

func (c *TradeClient) ModifyOrder(id int64, order model.OrderRequest) (*model.OrderIDResult, error)

Requires a trading account accessible through the configuration. Institutional accounts can authenticate with SecretKey.

Parameters

model.OrderRequest

SDK fieldTypeRequiredSerializationSDK default and constraints
ActionstringNoOmitted if emptyAllowed values: BUY, SELL
OrderTypestringNoOmitted if emptyAllowed values: MKT, LMT, STP, STP_LMT, TRAIL, AM, AL, TWAP, VWAP, OCA, ICEBERG
TimeInForcestringNoOmitted if emptyAllowed values: DAY, GTC, OPG
SecTypestringNoOmitted if emptyAllowed values: ALL, STK, OPT, WAR, IOPT, FUT, FOP, CASH, MLEG, FUND
MarketstringNoOmitted if emptyAllowed values: ALL, US, HK, CN, SG
CurrencystringNoOmitted if emptyAllowed values: ALL, USD, HKD, CNH, SGD
RightstringNoOmitted if emptyAllowed values: PUT, CALL (option side); br, nr when used as quote adjustment
MinDisplaySizeint64NoOmitted if emptyNone; 冰山单缺省等于 DisplaySize
CheckIntervalsint64NoOmitted if emptyNone; 冰山单默认 30 秒
PriceTypestringNoOmitted if emptyAllowed values: LIMIT_PRICE, ASK_PRICE, BID_PRICE, LATEST_PRICE; 冰山单默认 LIMIT_PRICE

Returns

(*model.OrderIDResult, error). Key fields from model.OrderIDResult:

FieldTypeDescription
IDint64Order ID

Invocation example

result, err := tc.ModifyOrder(123456789, model.OrderRequest{
	Account: "U123456",
	ID: 1,
	Action: "BUY",
	OrderType: "LMT",
	TotalQuantity: 1,
})
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%#v\n", result)
{
  "id": 123456789,
  "orderId": 123456789,
  "symbol": "AAPL",
  "action": "BUY",
  "orderType": "LMT",
  "limitPrice": 308.00,
  "totalQuantity": 100,
  "filledQuantity": 0,
  "status": "Initial",
  "account": "12345678"
}

CancelOrder

Purpose

Cancels an existing order identified by its global ID.

Signature

func (c *TradeClient) CancelOrder(id int64) (*model.OrderIDResult, error)

Requires a trading account accessible through the configuration. Institutional accounts can authenticate with SecretKey.

Parameters

ParameterTypeRequiredSDK defaultConstraints
idint64YesNoneGlobal order ID

Returns

(*model.OrderIDResult, error). Key fields from model.OrderIDResult:

FieldTypeDescription
IDint64Order ID

Invocation example

result, err := tc.CancelOrder(123456789)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%#v\n", result)
{
  "id": 123456789,
  "orderId": 123456789,
  "symbol": "AAPL",
  "action": "BUY",
  "orderType": "LMT",
  "limitPrice": 310.00,
  "totalQuantity": 100,
  "filledQuantity": 0,
  "status": "Cancelled",
  "account": "12345678"
}

EstimateTradableQuantity

Purpose

Estimates cash-buy, margin-buy, short-sell, and position-sell quantities. The client fills an empty account field from the client default.

Signature

func (c *TradeClient) EstimateTradableQuantity(req model.EstimateTradableQuantityRequest) (*model.EstimateTradableQuantity, error)

Requires a trading account accessible through the configuration. Institutional accounts can authenticate with SecretKey.

Parameters

model.EstimateTradableQuantityRequest

SDK fieldTypeRequiredSerializationSDK default and constraints
RightstringNoOmitted if emptyAllowed values: PUT, CALL (option side); br, nr when used as quote adjustment
SecTypestringNoOmitted if emptyAllowed values: ALL, STK, OPT, WAR, IOPT, FUT, FOP, CASH, MLEG, FUND
SegTypestringNoOmitted if emptyAllowed values: ALL, SEC, FUT, FUND
ActionstringNoOmitted if emptyAllowed values: BUY, SELL
OrderTypestringNoOmitted if emptyAllowed values: MKT, LMT, STP, STP_LMT, TRAIL, AM, AL, TWAP, VWAP, OCA, ICEBERG
LangstringNoOmitted if emptyAllowed values: zh_CN, zh_TW, en_US

Returns

(*model.EstimateTradableQuantity, error). Key fields from model.EstimateTradableQuantity:

FieldTypeDescription
TradableQuantityfloat64Tradable quantity
MaxCashBuyQuantityfloat64Max cash buy quantity
MaxMarginBuyQuantityfloat64Max margin buy quantity
MaxShortSellQuantityfloat64Max short sell quantity
MaxPositionSellQuantityfloat64Max position sell quantity
CashBuyingPowerfloat64Cash buying power
CurrencystringCurrency

Invocation example

result, err := tc.EstimateTradableQuantity(model.EstimateTradableQuantityRequest{
	Account: "U123456",
	Symbol: "AAPL",
	Expiry: "20260619",
	Strike: "200",
	Right: "CALL",
})
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%#v\n", result)
{
  "tradableQuantity": 320,
  "financingAmount": 99200.00,
  "positionAmount": 0.0
}


Did this page help you?