tiennm99 ee236d1fe0 refactor: rewrite SDK to align with OpenAPI spec
- Split monolithic models.go (738 lines) into 6 domain files
- Fix schema drift: BasicInfo, PersonalInfo, TotalCashDerivativeResponse,
  derivative order types, money transfer types aligned to spec
- Add missing REST endpoints: bsa-ext, bsa-month (supply/demand)
- Add WebSocket support for 5 streaming endpoints (nhooyr.io/websocket)
- Add 45 httptest-based tests (74.9% coverage)
- Rewrite README with full API coverage table

BREAKING CHANGE: struct fields and types changed to match OpenAPI spec.
BasicInfo reduced to 5 fields, TokenResponse uses 'token' field,
PlaceOrderRequest uses int types, derivative order types renamed.
2026-04-05 12:00:18 +07:00

tcbs-api

Go SDK for TCBS OpenAPI trading platform.

Install

go get github.com/tiennm99/tcbs-api

Quick Start

package main

import (
    "context"
    "fmt"
    "log"

    tcbs "github.com/tiennm99/tcbs-api"
)

func main() {
    client := tcbs.NewClient()
    ctx := context.Background()

    // Authenticate
    token, err := client.GetToken(ctx, "your-api-key", "your-otp")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("Authenticated:", token.Token)

    // Get stock prices
    prices, err := client.GetStockPrices(ctx, []string{"FPT", "VNM"})
    if err != nil {
        log.Fatal(err)
    }
    for _, p := range prices {
        fmt.Printf("%s: %.0f\n", p.Ticker, p.MatchPrice)
    }
}

Configuration

// Production (default)
client := tcbs.NewClient()

// SIT environment
client := tcbs.NewClient(tcbs.WithBaseURL(tcbs.SITBaseURL))

// Custom HTTP client
client := tcbs.NewClient(tcbs.WithHTTPClient(&http.Client{Timeout: 60 * time.Second}))

// Pre-set token
client := tcbs.NewClient(tcbs.WithToken("your-jwt-token"))

API Coverage

Authentication

Method Description
GetToken Exchange API Key + OTP for JWT token

Account

Method Description
GetSubAccountInfo Get sub-account profile information

Stock Orders

Method Description
PlaceOrder Place a stock order
UpdateOrder Modify an existing order
CancelOrder Cancel existing orders

Stock Queries

Method Description
GetOrders Get order book
GetOrderByID Get specific order by ID
GetMatchingDetails Get order matching details
GetPurchasingPower Get purchasing power
GetPurchasingPowerBySymbol Get purchasing power for symbol
GetPurchasingPowerBySymbolPrice Get purchasing power for symbol at price
GetMarginQuota Get margin quota
GetMarginAccountInfo Get margin account risk info
GetSupplementaryLoanPackages Get loan package details
GetLoans Get loan list
GetStockAssets Get stock holdings
GetCashBalance Get cash balance
GetCashStatements Get cash statement history
GetMarginInfo Get debt inquiry info

Market Data

Method Description
GetStockPrices Get stock ticker pricing
GetForeignRoom Get foreign investor room info
GetPutThroughInfo Get put-through match info
GetIntradayHistory Get intraday price history
GetSupplyDemand Get 15-min supply/demand data
GetSupplyDemandExt Get extended supply/demand data
GetSupplyDemandMonth Get monthly supply/demand data

Money Management

Method Description
TransferMoney Transfer between sub-accounts
DepositMargin Deposit margin for derivatives
WithdrawMargin Withdraw margin for derivatives

Derivatives

Method Description
GetDerivativeCashStatus Get derivative cash/margin overview
GetDerivativeClosedPositions Get closed positions
GetDerivativeOpenPositions Get open positions
GetDerivativeNormalOrders List normal orders
GetDerivativeConditionOrders List conditional orders
PlaceDerivativeNormalOrder Place normal order
PlaceDerivativeConditionOrder Place conditional order
ChangeDerivativeNormalOrder Modify normal order
ChangeDerivativeConditionOrder Modify conditional order
CancelDerivativeNormalOrder Cancel normal order
CancelDerivativeConditionOrder Cancel conditional order
GetDerivativeMarketInfo Get derivative contract pricing

WebSocket Streams

Method Description
ConnectStockMatch Stock match information stream
ConnectDerivativeMatch Derivative match information stream
ConnectCenter General WebSocket center
ConnectStockPrice Normal stock price stream
ConnectDerivativePrice Derivative price stream

WebSocket Usage

ctx := context.Background()
ws, err := client.ConnectStockPrice(ctx, func(msgType websocket.MessageType, data []byte) {
    fmt.Println("Received:", string(data))
})
if err != nil {
    log.Fatal(err)
}
defer ws.Close()

// Send subscription message
ws.SendJSON(ctx, map[string]string{"action": "subscribe", "ticker": "FPT"})

License

See LICENSE for details.

S
Description
Languages
Go 100%