Trading

The Go SDK provides a TradeClient that wraps all order management and account endpoints. Every method returns ([]byte, error) — the raw JSON response body.

Quick Start

package main

import (
	"fmt"
	"log"

	"github.com/tigerfintech/openapi-sdks/go/client"
	"github.com/tigerfintech/openapi-sdks/go/config"
	"github.com/tigerfintech/openapi-sdks/go/model"
	"github.com/tigerfintech/openapi-sdks/go/trade"
)

func main() {
	cfg, err := config.NewClientConfig(
		config.WithPropertiesFile("tiger_openapi_config.properties"),
	)
	if err != nil {
		log.Fatal(err)
	}

	httpClient := client.NewHttpClient(cfg)
	tc := trade.NewTradeClient(httpClient, cfg.Account)

	// Build a limit order using the helper constructor
	order := model.LimitOrder(cfg.Account, "AAPL", "STK", "BUY", 100, 150.0)

	// Preview before submitting
	preview, err := tc.PreviewOrder(order)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Preview:", string(preview))

	// Place the order
	result, err := tc.PlaceOrder(order)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Order placed:", string(result))
}

Order Model

The model.Order struct represents an order. Use the convenience constructors below or build the struct manually.

Order Fields

FieldTypeDescription
AccountstringAccount identifier
SymbolstringContract symbol, e.g. "AAPL"
SecTypestringSecurity type: STK, OPT, FUT, WAR, IOPT
ActionstringOrder side: BUY or SELL
OrderTypestringMKT, LMT, STP, STP_LMT, TRAIL
TotalQuantityint64Number of shares/contracts
LimitPricefloat64Limit price (required for LMT / STP_LMT)
AuxPricefloat64Stop price (required for STP / STP_LMT)
TimeInForcestringDAY, GTC, GTD
OutsideRthboolAllow execution outside regular trading hours
ExpirystringOption expiry date (YYYYMMDD)
Strikefloat64Option strike price
RightstringOption type: PUT or CALL

Order Constructors

// Limit order
order := model.LimitOrder(account, symbol, secType, action string, qty int64, price float64)

// Market order
order := model.MarketOrder(account, symbol, secType, action string, qty int64)

Example — building orders manually:

import "github.com/tigerfintech/openapi-sdks/go/model"

// Stock limit buy
stockOrder := model.LimitOrder(cfg.Account, "AAPL", "STK", "BUY", 100, 150.0)

// Stock market sell
mktOrder := model.MarketOrder(cfg.Account, "TSLA", "STK", "SELL", 50)

// Option limit buy (call)
optOrder := model.Order{
    Account:       cfg.Account,
    Symbol:        "AAPL",
    SecType:       "OPT",
    Action:        "BUY",
    OrderType:     "LMT",
    TotalQuantity: 1,
    LimitPrice:    5.50,
    TimeInForce:   "DAY",
    Expiry:        "20250117",
    Strike:        150.0,
    Right:         "CALL",
}

Contract Query

GetContract

func (tc *TradeClient) GetContract(symbol, secType string) ([]byte, error)

Returns detailed contract information for a single symbol.

ParameterTypeRequiredDescription
symbolstringYesContract symbol, e.g. "AAPL"
secTypestringYesSecurity type: STK, OPT, FUT, WAR, IOPT
contract, err := tc.Contract("AAPL", "STK")

GetContracts

func (tc *TradeClient) GetContracts(symbols []string, secType string) ([]byte, error)

Returns contract information for multiple symbols in a single request.

ParameterTypeRequiredDescription
symbols[]stringYesList of symbols
secTypestringYesSecurity type for all symbols
contracts, err := tc.Contracts([]string{"AAPL", "TSLA", "MSFT"}, "STK")

GetQuoteContract

func (tc *TradeClient) GetQuoteContract(symbol, secType string) ([]byte, error)

Returns derivative contract details (options or warrants) for the given underlying symbol.

ParameterTypeRequiredDescription
symbolstringYesUnderlying symbol
secTypestringYesDerivative type: OPT, WAR, IOPT
quoteContract, err := tc.QuoteContract("AAPL", "OPT")

Order Management

PlaceOrder

func (tc *TradeClient) PlaceOrder(order model.Order) ([]byte, error)

Submits an order to the exchange. Returns the server-assigned order ID on success.

ParameterTypeRequiredDescription
ordermodel.OrderYesOrder details
order := model.LimitOrder(cfg.Account, "AAPL", "STK", "BUY", 100, 150.0)
result, err := tc.PlaceOrder(order)
// result: {"id":123456789,"status":"Submitted"}

PreviewOrder

func (tc *TradeClient) PreviewOrder(order model.Order) ([]byte, error)

Validates an order and returns estimated commission and margin impact without actually placing it.

preview, err := tc.PreviewOrder(order)
// preview: {"commission":1.0,"marginImpact":15000.0,"valid":true}

ModifyOrder

func (tc *TradeClient) ModifyOrder(id int64, order model.Order) ([]byte, error)

Modifies the price or quantity of an existing open order.

ParameterTypeRequiredDescription
idint64YesOrder ID to modify
ordermodel.OrderYesUpdated order parameters
// Change limit price from 150 to 148
order.LimitPrice = 148.0
modResult, err := tc.ModifyOrder(123456789, order)

CancelOrder

func (tc *TradeClient) CancelOrder(id int64) ([]byte, error)

Cancels an open order by ID.

ParameterTypeRequiredDescription
idint64YesOrder ID to cancel
cancelResult, err := tc.CancelOrder(123456789)

Order Query

GetOrders

func (tc *TradeClient) GetOrders() ([]byte, error)

Returns all orders (pending, filled, and cancelled) for the current trading day.

orders, err := tc.Orders()

GetActiveOrders

func (tc *TradeClient) GetActiveOrders() ([]byte, error)

Returns only orders that are currently pending (submitted but not yet filled or cancelled).

activeOrders, err := tc.ActiveOrders()

GetInactiveOrders

func (tc *TradeClient) GetInactiveOrders() ([]byte, error)

Returns orders that have been cancelled or have expired.

inactiveOrders, err := tc.InactiveOrders()

GetFilledOrders

func (tc *TradeClient) GetFilledOrders() ([]byte, error)

Returns orders that have been fully or partially filled.

filledOrders, err := tc.FilledOrders()

Positions and Assets

GetPositions

func (tc *TradeClient) GetPositions() ([]byte, error)

Returns all current open positions (symbol, quantity, average cost, market value, unrealized P&L).

positions, err := tc.Positions()

GetAssets

func (tc *TradeClient) GetAssets() ([]byte, error)

Returns account asset summary (net liquidation value, cash balance, buying power, margin usage).

assets, err := tc.Assets()

GetPrimeAssets

func (tc *TradeClient) GetPrimeAssets() ([]byte, error)

Returns consolidated asset summary for prime (multi-currency) accounts, aggregated across all sub-accounts.

primeAssets, err := tc.PrimeAssets()

GetOrderTransactions

func (tc *TradeClient) GetOrderTransactions(id int64) ([]byte, error)

Returns the individual fill records (executions) associated with a specific order.

ParameterTypeRequiredDescription
idint64YesOrder ID
transactions, err := tc.OrderTransactions(123456789)
// transactions: [{"price":150.0,"quantity":100,"timestamp":1700000000}]

Generic Raw API Call

When the SDK has not yet wrapped a specific API endpoint, use ExecuteRaw on the underlying HttpClient to call it directly:

package main

import (
	"fmt"
	"log"

	"github.com/tigerfintech/openapi-sdks/go/client"
	"github.com/tigerfintech/openapi-sdks/go/config"
)

func main() {
	cfg, err := config.NewClientConfig(
		config.WithPropertiesFile("tiger_openapi_config.properties"),
	)
	if err != nil {
		log.Fatal(err)
	}

	httpClient := client.NewHttpClient(cfg)

	// Pass the API method name and a raw JSON parameter string
	resp, err := httpClient.ExecuteRaw("market_state", `{"market":"US"}`)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Raw response:", resp)
}