mirror of
https://github.com/tiennm99/tcbs-api.git
synced 2026-06-09 22:12:38 +00:00
ee236d1fe0
- 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.
35 lines
889 B
Go
35 lines
889 B
Go
package tcbs
|
|
|
|
import "context"
|
|
|
|
// TokenRequest represents the request body for exchanging API Key + OTP for JWT Token.
|
|
type TokenRequest struct {
|
|
OTP string `json:"otp"`
|
|
APIKey string `json:"apiKey"`
|
|
}
|
|
|
|
// TokenResponse represents a successful token exchange response.
|
|
type TokenResponse struct {
|
|
Token string `json:"token"`
|
|
}
|
|
|
|
// TokenErrorResponse represents a failed token exchange response.
|
|
type TokenErrorResponse struct {
|
|
Code string `json:"code"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
// GetToken exchanges an API Key and OTP for a JWT token.
|
|
func (c *Client) GetToken(ctx context.Context, apiKey, otp string) (*TokenResponse, error) {
|
|
var resp TokenResponse
|
|
err := c.doRequest(ctx, "POST", "/gaia/v1/oauth2/openapi/token", nil, &TokenRequest{
|
|
APIKey: apiKey,
|
|
OTP: otp,
|
|
}, &resp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
c.SetToken(resp.Token)
|
|
return &resp, nil
|
|
}
|