Documentation
¶
Index ¶
- Constants
- func EncryptPassword(raw, timestamp string) (encrypted string, err error)
- func NewError(httpStatus int, resp *apiResponse) error
- type ApiError
- type Client
- func (c *Client) Call(ctx context.Context, method, path string, queryParams interface{}, ...) (err error)
- func (c *Client) CheckRegion(path, required string) error
- func (c *Client) Delete(ctx context.Context, path string, queryParams interface{}, resp interface{}, ...) error
- func (c *Client) Get(ctx context.Context, path string, queryParams url.Values, resp interface{}, ...) error
- func (c *Client) GetOTP(ctx context.Context, ropts ...RequestOption) (string, error)
- func (c *Client) GetOTPV2(ctx context.Context, ropts ...RequestOption) (string, error)
- func (c *Client) IsUS() bool
- func (c *Client) Post(ctx context.Context, path string, body interface{}, resp interface{}, ...) error
- func (c *Client) Put(ctx context.Context, path string, body interface{}, resp interface{}, ...) error
- type Option
- func WithAccessToken(accessToken string) Option
- func WithAppKey(appKey string) Option
- func WithAppSecret(appSecret string) Option
- func WithClient(cli *http.Client) Option
- func WithExtraHeaders(headers map[string]string) Option
- func WithLanguage(language openapi.Language) Option
- func WithOAuthClient(o *oauth.OAuth) Option
- func WithTimeout(timeout time.Duration) Option
- func WithURL(url string) Option
- type Options
- type RegionRestrictedError
- type RequestOption
- type RequestOptions
Constants ¶
const DefaultHttpUrl = "https://openapi.longbridge.com"
DefaultHttpUrl
const DefaultTimeout = 15 * time.Second
DefaultTimeout
Variables ¶
This section is empty.
Functions ¶
func EncryptPassword ¶
EncryptPassword use to encrypt password Use aes with cbc mode to encrypt password 1. use md5(timestamp) as secret key for md5 have fixed length 2. use key[:16] is cbc iv 3. md5(raw_password) as plain content 4. padding plain content 5. encrypt
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a http client to access Longbridge REST OpenAPI
func NewFromCfg ¶
NewFromCfg init longbridge http client from *config.Config
func (*Client) Call ¶
func (c *Client) Call(ctx context.Context, method, path string, queryParams interface{}, body interface{}, resp interface{}, ropts ...RequestOption) (err error)
Call will send request with signature to http server
func (*Client) CheckRegion ¶ added in v0.26.0
CheckRegion verifies that the current session's region matches required. Returns *RegionRestrictedError if it does not; nil otherwise. required must be "US" or "AP".
func (*Client) Delete ¶
func (c *Client) Delete(ctx context.Context, path string, queryParams interface{}, resp interface{}, ropts ...RequestOption) error
Delete sends Delete request with queryParams
func (*Client) Get ¶
func (c *Client) Get(ctx context.Context, path string, queryParams url.Values, resp interface{}, ropts ...RequestOption) error
Get sends Get request with queryParams
func (*Client) GetOTP ¶
GetOTP to get one time password Reference: https://open.longbridge.com/en/docs/socket-token-api
func (*Client) IsUS ¶ added in v0.26.0
IsUS reports whether the configured credentials belong to the US data center.
type Option ¶
type Option func(*Options)
Option for http client
func WithAccessToken ¶
WithAccessToken to set access token
func WithExtraHeaders ¶ added in v0.24.1
WithExtraHeaders sets additional HTTP headers to send with every request.
func WithLanguage ¶
WithLanguage to set language
func WithOAuthClient ¶
WithOAuthClient sets the OAuth client for token auto-refresh.
func WithTimeout ¶
WithTimeout to set http client timeout. Worked when Options.Client is not set
type Options ¶
type Options struct {
URL string
AppKey string
AppSecret string
AccessToken string
Timeout time.Duration
Client *http.Client
Language openapi.Language
// OAuthClient when set: token and app key are taken from it (auto-refresh).
OAuthClient *oauth.OAuth
// ExtraHeaders are additional HTTP headers sent with every request.
ExtraHeaders map[string]string
}
Options for http client
type RegionRestrictedError ¶ added in v0.26.0
type RegionRestrictedError struct {
// Path is the API path or WebSocket command that was called.
Path string
// Required is the data center the API requires ("US" or "AP").
Required string
// Current is the data center of the current session ("US" or "AP").
Current string
}
RegionRestrictedError is returned when an API is called from the wrong data center. It mirrors the Rust SDK's HttpClientError::DcRegionRestricted.
func (*RegionRestrictedError) Error ¶ added in v0.26.0
func (e *RegionRestrictedError) Error() string
type RequestOption ¶
type RequestOption func(*RequestOptions)
RequestOption use to set addition info to request
type RequestOptions ¶
type RequestOptions struct {
// Request Header
Header nhttp.Header
// contains filtered or unexported fields
}
RequestOptions use to set additional information for the request