dev 2
This commit is contained in:
@@ -2,7 +2,8 @@ package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Tick struct {
|
||||
@@ -12,21 +13,21 @@ type Tick struct {
|
||||
}
|
||||
|
||||
type HistoryDataRequest struct {
|
||||
Len int `json:"len"`
|
||||
Period string `json:"period,omitempty"`
|
||||
Field string `json:"field,omitempty"`
|
||||
DividendType int `json:"dividend_type"`
|
||||
SkipPaused string `json:"skip_paused,omitempty"`
|
||||
Len int
|
||||
Period string
|
||||
Field string
|
||||
DividendType int
|
||||
SkipPaused *bool
|
||||
}
|
||||
|
||||
type MarketDataRequest struct {
|
||||
Fields string `json:"fields,omitempty"`
|
||||
StockCode string `json:"stock_code,omitempty"`
|
||||
StartTime string `json:"start_time,omitempty"`
|
||||
EndTime string `json:"end_time,omitempty"`
|
||||
Period string `json:"period,omitempty"`
|
||||
DividendType string `json:"dividend_type,omitempty"`
|
||||
Count int `json:"count"`
|
||||
Fields []string
|
||||
Stocks []string
|
||||
StartTime string
|
||||
EndTime string
|
||||
Period string
|
||||
DividendType string
|
||||
Count int
|
||||
}
|
||||
|
||||
type SubscribeResult struct {
|
||||
@@ -35,64 +36,30 @@ type SubscribeResult struct {
|
||||
}
|
||||
|
||||
func (c *Client) StockName(ctx context.Context, stockcode string) (any, error) {
|
||||
var out struct {
|
||||
Name any `json:"name"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/stock_name", map[string]any{"stockcode": stockcode}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Name, nil
|
||||
return c.postField(ctx, "/api/data/stock_name", map[string]any{"stockcode": stockcode}, "name")
|
||||
}
|
||||
|
||||
func (c *Client) OpenDate(ctx context.Context, stockcode string) (any, error) {
|
||||
var out struct {
|
||||
OpenDate any `json:"open_date"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/open_date", map[string]any{"stockcode": stockcode}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.OpenDate, nil
|
||||
return c.postField(ctx, "/api/data/open_date", map[string]any{"stockcode": stockcode}, "open_date")
|
||||
}
|
||||
|
||||
func (c *Client) LastVolume(ctx context.Context, stockcode string) (any, error) {
|
||||
var out struct {
|
||||
LastVolume any `json:"last_volume"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/last_volume", map[string]any{"stockcode": stockcode}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.LastVolume, nil
|
||||
return c.postField(ctx, "/api/data/last_volume", map[string]any{"stockcode": stockcode}, "last_volume")
|
||||
}
|
||||
|
||||
func (c *Client) BarTimetag(ctx context.Context, index int) (any, error) {
|
||||
var out struct {
|
||||
Timetag any `json:"timetag"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/bar_timetag", map[string]any{"index": index}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Timetag, nil
|
||||
return c.postField(ctx, "/api/data/bar_timetag", map[string]any{"index": index}, "timetag")
|
||||
}
|
||||
|
||||
func (c *Client) TickTimetag(ctx context.Context) (any, error) {
|
||||
var out struct {
|
||||
Timetag any `json:"timetag"`
|
||||
}
|
||||
if err := c.get(ctx, "/api/data/tick_timetag", &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Timetag, nil
|
||||
return c.getField(ctx, "/api/data/tick_timetag", "timetag")
|
||||
}
|
||||
|
||||
func (c *Client) Sector(ctx context.Context, sector string, realtime string) ([]any, error) {
|
||||
body := map[string]any{"sector": sector}
|
||||
if realtime != "" {
|
||||
body["realtime"] = realtime
|
||||
}
|
||||
func (c *Client) Sector(ctx context.Context, sector string, realtime int) ([]any, error) {
|
||||
var out struct {
|
||||
Stocks []any `json:"stocks"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/sector", body, &out); err != nil {
|
||||
if err := c.post(ctx, "/api/data/sector", map[string]any{"sector": sector, "realtime": realtime}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Stocks, nil
|
||||
@@ -119,99 +86,58 @@ func (c *Client) StockListInSector(ctx context.Context, sectorname string) ([]an
|
||||
}
|
||||
|
||||
func (c *Client) WeightInIndex(ctx context.Context, indexcode, stockcode string) (any, error) {
|
||||
var out struct {
|
||||
Weight any `json:"weight"`
|
||||
}
|
||||
body := map[string]any{"indexcode": indexcode, "stockcode": stockcode}
|
||||
if err := c.post(ctx, "/api/data/weight_in_index", body, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Weight, nil
|
||||
return c.postField(ctx, "/api/data/weight_in_index", map[string]any{"indexcode": indexcode, "stockcode": stockcode}, "weight")
|
||||
}
|
||||
|
||||
func (c *Client) ContractMultiplier(ctx context.Context, contractcode string) (any, error) {
|
||||
var out struct {
|
||||
Multiplier any `json:"multiplier"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/contract_multiplier", map[string]any{"contractcode": contractcode}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Multiplier, nil
|
||||
return c.postField(ctx, "/api/data/contract_multiplier", map[string]any{"contractcode": contractcode}, "multiplier")
|
||||
}
|
||||
|
||||
func (c *Client) RiskFreeRate(ctx context.Context, index int) (any, error) {
|
||||
var out struct {
|
||||
RiskFreeRate any `json:"risk_free_rate"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/risk_free_rate", map[string]any{"index": index}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.RiskFreeRate, nil
|
||||
return c.postField(ctx, "/api/data/risk_free_rate", map[string]any{"index": index}, "risk_free_rate")
|
||||
}
|
||||
|
||||
func (c *Client) DateLocation(ctx context.Context, strdate string) (any, error) {
|
||||
var out struct {
|
||||
Location any `json:"location"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/date_location", map[string]any{"strdate": strdate}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Location, nil
|
||||
return c.postField(ctx, "/api/data/date_location", map[string]any{"strdate": strdate}, "location")
|
||||
}
|
||||
|
||||
func (c *Client) HistoryData(ctx context.Context, req HistoryDataRequest) (any, error) {
|
||||
if req.Len == 0 {
|
||||
req.Len = 10
|
||||
}
|
||||
if req.SkipPaused == "" {
|
||||
req.SkipPaused = "true"
|
||||
skip := "true"
|
||||
if req.SkipPaused != nil {
|
||||
skip = strconv.FormatBool(*req.SkipPaused)
|
||||
}
|
||||
var out map[string]any
|
||||
if err := c.post(ctx, "/api/data/history_data", req, &out); err != nil {
|
||||
return nil, err
|
||||
return c.postField(ctx, "/api/data/history_data", map[string]any{
|
||||
"len": req.Len, "period": req.Period, "field": req.Field,
|
||||
"dividend_type": req.DividendType, "skip_paused": skip,
|
||||
}, "data")
|
||||
}
|
||||
|
||||
func (c *Client) marketDataBody(req MarketDataRequest) map[string]any {
|
||||
return map[string]any{
|
||||
"fields": csvJoin(req.Fields),
|
||||
"stock_code": csvJoin(req.Stocks),
|
||||
"start_time": req.StartTime,
|
||||
"end_time": req.EndTime,
|
||||
"period": req.Period,
|
||||
"dividend_type": req.DividendType,
|
||||
"count": req.Count,
|
||||
}
|
||||
if msg, ok := out["error"].(string); ok && msg != "" {
|
||||
return nil, &BusinessError{Message: msg}
|
||||
}
|
||||
return out["data"], nil
|
||||
}
|
||||
|
||||
func (c *Client) MarketData(ctx context.Context, req MarketDataRequest) (any, error) {
|
||||
var out struct {
|
||||
Data any `json:"data"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/market_data", req, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Data, nil
|
||||
return c.postField(ctx, "/api/data/market_data", c.marketDataBody(req), "data")
|
||||
}
|
||||
|
||||
func (c *Client) MarketDataEx(ctx context.Context, req MarketDataRequest) (any, error) {
|
||||
body := map[string]any{
|
||||
"fields": req.Fields,
|
||||
"stock_code": req.StockCode,
|
||||
"period": req.Period,
|
||||
"start_time": req.StartTime,
|
||||
"end_time": req.EndTime,
|
||||
"count": req.Count,
|
||||
"dividend_type": req.DividendType,
|
||||
}
|
||||
var out struct {
|
||||
Data any `json:"data"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/market_data_ex", body, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Data, nil
|
||||
return c.postField(ctx, "/api/data/market_data_ex", c.marketDataBody(req), "data")
|
||||
}
|
||||
|
||||
func (c *Client) FullTick(ctx context.Context, stocks []string) (map[string]Tick, error) {
|
||||
joined := ArrayJoin(stocks)
|
||||
if joined == "" {
|
||||
return nil, fmt.Errorf("full_tick: stocks empty")
|
||||
}
|
||||
raw := map[string]any{}
|
||||
if err := c.post(ctx, "/api/data/full_tick", map[string]any{"stocks": joined}, &raw); err != nil {
|
||||
if err := c.post(ctx, "/api/data/full_tick", map[string]any{"stocks": stocks}, &raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make(map[string]Tick, len(raw))
|
||||
@@ -228,23 +154,11 @@ func (c *Client) FullTick(ctx context.Context, stocks []string) (map[string]Tick
|
||||
}
|
||||
|
||||
func (c *Client) DividFactors(ctx context.Context, stockcode string) (any, error) {
|
||||
var out struct {
|
||||
Factors any `json:"factors"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/divid_factors", map[string]any{"stockcode": stockcode}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Factors, nil
|
||||
return c.postField(ctx, "/api/data/divid_factors", map[string]any{"stockcode": stockcode}, "factors")
|
||||
}
|
||||
|
||||
func (c *Client) MainContract(ctx context.Context, codemarket string) (any, error) {
|
||||
var out struct {
|
||||
MainContract any `json:"main_contract"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/main_contract", map[string]any{"codemarket": codemarket}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.MainContract, nil
|
||||
return c.postField(ctx, "/api/data/main_contract", map[string]any{"codemarket": codemarket}, "main_contract")
|
||||
}
|
||||
|
||||
func (c *Client) TimetagToDatetime(ctx context.Context, timetag int64, format string) (any, error) {
|
||||
@@ -252,23 +166,11 @@ func (c *Client) TimetagToDatetime(ctx context.Context, timetag int64, format st
|
||||
if format != "" {
|
||||
body["format"] = format
|
||||
}
|
||||
var out struct {
|
||||
Datetime any `json:"datetime"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/timetag_to_datetime", body, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Datetime, nil
|
||||
return c.postField(ctx, "/api/data/timetag_to_datetime", body, "datetime")
|
||||
}
|
||||
|
||||
func (c *Client) TotalShare(ctx context.Context, stockcode string) (any, error) {
|
||||
var out struct {
|
||||
TotalShare any `json:"total_share"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/total_share", map[string]any{"stockcode": stockcode}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.TotalShare, nil
|
||||
return c.postField(ctx, "/api/data/total_share", map[string]any{"stockcode": stockcode}, "total_share")
|
||||
}
|
||||
|
||||
func (c *Client) TradingDates(ctx context.Context, stockcode, startDate, endDate, period string, count int) ([]any, error) {
|
||||
@@ -286,242 +188,145 @@ func (c *Client) TradingDates(ctx context.Context, stockcode, startDate, endDate
|
||||
}
|
||||
|
||||
func (c *Client) Svol(ctx context.Context, stockcode string) (any, error) {
|
||||
var out struct {
|
||||
Svol any `json:"svol"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/svol", map[string]any{"stockcode": stockcode}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Svol, nil
|
||||
return c.postField(ctx, "/api/data/svol", map[string]any{"stockcode": stockcode}, "svol")
|
||||
}
|
||||
|
||||
func (c *Client) Bvol(ctx context.Context, stockcode string) (any, error) {
|
||||
var out struct {
|
||||
Bvol any `json:"bvol"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/bvol", map[string]any{"stockcode": stockcode}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Bvol, nil
|
||||
return c.postField(ctx, "/api/data/bvol", map[string]any{"stockcode": stockcode}, "bvol")
|
||||
}
|
||||
|
||||
func (c *Client) dataPayload(ctx context.Context, path string, body map[string]any) (any, error) {
|
||||
var out map[string]any
|
||||
if err := c.post(ctx, path, body, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if msg, ok := out["error"].(string); ok && msg != "" {
|
||||
return nil, &BusinessError{Message: msg}
|
||||
}
|
||||
if v, ok := out["data"]; ok {
|
||||
return v, nil
|
||||
}
|
||||
return out, nil
|
||||
func (c *Client) Longhubang(ctx context.Context, stockList []string, startTime, endTime string) (any, error) {
|
||||
return c.postField(ctx, "/api/data/longhubang", map[string]any{
|
||||
"stock_list": csvJoin(stockList), "startTime": startTime, "endTime": endTime,
|
||||
}, "data")
|
||||
}
|
||||
|
||||
func (c *Client) Longhubang(ctx context.Context, stockList, startTime, endTime string) (any, error) {
|
||||
return c.dataPayload(ctx, "/api/data/longhubang", map[string]any{
|
||||
"stock_list": stockList, "startTime": startTime, "endTime": endTime,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Client) Top10ShareHolder(ctx context.Context, stockList, dataName, startTime, endTime string) (any, error) {
|
||||
return c.dataPayload(ctx, "/api/data/top10_share_holder", map[string]any{
|
||||
"stock_list": stockList, "data_name": dataName, "start_time": startTime, "end_time": endTime,
|
||||
})
|
||||
func (c *Client) Top10ShareHolder(ctx context.Context, stockList []string, dataName, startTime, endTime string) (any, error) {
|
||||
return c.postField(ctx, "/api/data/top10_share_holder", map[string]any{
|
||||
"stock_list": csvJoin(stockList), "data_name": dataName, "start_time": startTime, "end_time": endTime,
|
||||
}, "data")
|
||||
}
|
||||
|
||||
func (c *Client) OptionDetail(ctx context.Context, optioncode string) (any, error) {
|
||||
var out struct {
|
||||
Detail any `json:"detail"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/option_detail", map[string]any{"optioncode": optioncode}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Detail, nil
|
||||
return c.postField(ctx, "/api/data/option_detail", map[string]any{"optioncode": optioncode}, "detail")
|
||||
}
|
||||
|
||||
func (c *Client) TurnoverRate(ctx context.Context, stockList, startTime, endTime string) (any, error) {
|
||||
return c.dataPayload(ctx, "/api/data/turnover_rate", map[string]any{
|
||||
"stock_list": stockList, "startTime": startTime, "endTime": endTime,
|
||||
})
|
||||
func (c *Client) TurnoverRate(ctx context.Context, stockList []string, startTime, endTime string) (any, error) {
|
||||
return c.postField(ctx, "/api/data/turnover_rate", map[string]any{
|
||||
"stock_list": csvJoin(stockList), "startTime": startTime, "endTime": endTime,
|
||||
}, "data")
|
||||
}
|
||||
|
||||
func (c *Client) ETFInfo(ctx context.Context, stockcode string) (any, error) {
|
||||
var out struct {
|
||||
Info any `json:"info"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/etf_info", map[string]any{"stockcode": stockcode}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Info, nil
|
||||
return c.postField(ctx, "/api/data/etf_info", map[string]any{"stockcode": stockcode}, "info")
|
||||
}
|
||||
|
||||
func (c *Client) ETFIOPV(ctx context.Context, stockcode string) (any, error) {
|
||||
var out struct {
|
||||
IOPV any `json:"iopv"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/etf_iopv", map[string]any{"stockcode": stockcode}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.IOPV, nil
|
||||
return c.postField(ctx, "/api/data/etf_iopv", map[string]any{"stockcode": stockcode}, "iopv")
|
||||
}
|
||||
|
||||
func (c *Client) InstrumentDetail(ctx context.Context, stockcode string) (any, error) {
|
||||
var out struct {
|
||||
Detail any `json:"detail"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/instrumentdetail", map[string]any{"stockcode": stockcode}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Detail, nil
|
||||
return c.postField(ctx, "/api/data/instrumentdetail", map[string]any{"stockcode": stockcode}, "detail")
|
||||
}
|
||||
|
||||
func (c *Client) ContractExpireDate(ctx context.Context, codemarket string) (any, error) {
|
||||
var out struct {
|
||||
ExpireDate any `json:"expire_date"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/contract_expire_date", map[string]any{"codemarket": codemarket}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.ExpireDate, nil
|
||||
return c.postField(ctx, "/api/data/contract_expire_date", map[string]any{"codemarket": codemarket}, "expire_date")
|
||||
}
|
||||
|
||||
func (c *Client) OptionUndlData(ctx context.Context, undlCodeRef string) (any, error) {
|
||||
var out struct {
|
||||
Data any `json:"data"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/option_undl_data", map[string]any{"undl_code_ref": undlCodeRef}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Data, nil
|
||||
return c.postField(ctx, "/api/data/option_undl_data", map[string]any{"undl_code_ref": undlCodeRef}, "data")
|
||||
}
|
||||
|
||||
type FinancialDataRequest struct {
|
||||
Tabname string `json:"tabname,omitempty"`
|
||||
Colname string `json:"colname,omitempty"`
|
||||
Market string `json:"market,omitempty"`
|
||||
Code string `json:"code,omitempty"`
|
||||
ReportType string `json:"report_type,omitempty"`
|
||||
Barpos int `json:"barpos"`
|
||||
FieldList string `json:"fieldList,omitempty"`
|
||||
StockList string `json:"stockList,omitempty"`
|
||||
StartDate string `json:"startDate,omitempty"`
|
||||
EndDate string `json:"endDate,omitempty"`
|
||||
Tabname string
|
||||
Colname string
|
||||
Market string
|
||||
Code string
|
||||
ReportType string
|
||||
Barpos int
|
||||
FieldList []string
|
||||
StockList []string
|
||||
StartDate string
|
||||
EndDate string
|
||||
}
|
||||
|
||||
func (c *Client) FinancialData(ctx context.Context, req FinancialDataRequest) (any, error) {
|
||||
var out map[string]any
|
||||
if err := c.post(ctx, "/api/data/financial_data", req, &out); err != nil {
|
||||
return nil, err
|
||||
body := map[string]any{
|
||||
"tabname": req.Tabname, "colname": req.Colname, "market": req.Market, "code": req.Code,
|
||||
"report_type": req.ReportType, "barpos": req.Barpos,
|
||||
"fieldList": csvJoin(req.FieldList), "stockList": csvJoin(req.StockList),
|
||||
"startDate": req.StartDate, "endDate": req.EndDate,
|
||||
}
|
||||
if msg, ok := out["error"].(string); ok && msg != "" {
|
||||
return nil, &BusinessError{Message: msg}
|
||||
}
|
||||
return out["data"], nil
|
||||
return c.postField(ctx, "/api/data/financial_data", body, "data")
|
||||
}
|
||||
|
||||
type FactorDataRequest struct {
|
||||
FieldList string `json:"fieldList,omitempty"`
|
||||
StockList string `json:"stockList,omitempty"`
|
||||
StockCode string `json:"stockCode,omitempty"`
|
||||
StartDate string `json:"startDate,omitempty"`
|
||||
EndDate string `json:"endDate,omitempty"`
|
||||
FieldList []string
|
||||
StockList []string
|
||||
StockCode string
|
||||
StartDate string
|
||||
EndDate string
|
||||
}
|
||||
|
||||
func (c *Client) FactorData(ctx context.Context, req FactorDataRequest) (any, error) {
|
||||
var out map[string]any
|
||||
if err := c.post(ctx, "/api/data/factor_data", req, &out); err != nil {
|
||||
return nil, err
|
||||
body := map[string]any{
|
||||
"fieldList": csvJoin(req.FieldList), "stockList": csvJoin(req.StockList),
|
||||
"stockCode": req.StockCode, "startDate": req.StartDate, "endDate": req.EndDate,
|
||||
}
|
||||
if msg, ok := out["error"].(string); ok && msg != "" {
|
||||
return nil, &BusinessError{Message: msg}
|
||||
}
|
||||
return out["data"], nil
|
||||
return c.postField(ctx, "/api/data/factor_data", body, "data")
|
||||
}
|
||||
|
||||
func (c *Client) HisSTData(ctx context.Context, stockCode string) (any, error) {
|
||||
var out struct {
|
||||
Data any `json:"data"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/his_st_data", map[string]any{"stockCode": stockCode}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Data, nil
|
||||
return c.postField(ctx, "/api/data/his_st_data", map[string]any{"stockCode": stockCode}, "data")
|
||||
}
|
||||
|
||||
func (c *Client) HisIndexData(ctx context.Context, index string) (any, error) {
|
||||
var out struct {
|
||||
Data any `json:"data"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/his_index_data", map[string]any{"index": index}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Data, nil
|
||||
return c.postField(ctx, "/api/data/his_index_data", map[string]any{"index": index}, "data")
|
||||
}
|
||||
|
||||
func (c *Client) AllSubscription(ctx context.Context) (any, error) {
|
||||
var out struct {
|
||||
Subscriptions any `json:"subscriptions"`
|
||||
}
|
||||
if err := c.get(ctx, "/api/data/all_subscription", &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Subscriptions, nil
|
||||
return c.getField(ctx, "/api/data/all_subscription", "subscriptions")
|
||||
}
|
||||
|
||||
func (c *Client) OptionList(ctx context.Context, undlCode, dedate, opttype, isavailable string) (any, error) {
|
||||
body := map[string]any{"undl_code": undlCode, "dedate": dedate, "opttype": opttype}
|
||||
if isavailable != "" {
|
||||
body["isavailable"] = isavailable
|
||||
func (c *Client) OptionList(ctx context.Context, undlCode, dedate, opttype string, isavailable bool) (any, error) {
|
||||
body := map[string]any{
|
||||
"undl_code": undlCode, "dedate": dedate, "opttype": opttype,
|
||||
"isavailable": strconv.FormatBool(isavailable),
|
||||
}
|
||||
var out struct {
|
||||
OptionList any `json:"option_list"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/option_list", body, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.OptionList, nil
|
||||
return c.postField(ctx, "/api/data/option_list", body, "option_list")
|
||||
}
|
||||
|
||||
func (c *Client) HisContractList(ctx context.Context, market string) (any, error) {
|
||||
var out struct {
|
||||
Contracts any `json:"contracts"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/his_contract_list", map[string]any{"market": market}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Contracts, nil
|
||||
return c.postField(ctx, "/api/data/his_contract_list", map[string]any{"market": market}, "contracts")
|
||||
}
|
||||
|
||||
func (c *Client) OptionIV(ctx context.Context, optioncode string) (any, error) {
|
||||
var out struct {
|
||||
IV any `json:"iv"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/option_iv", map[string]any{"optioncode": optioncode}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.IV, nil
|
||||
return c.postField(ctx, "/api/data/option_iv", map[string]any{"optioncode": optioncode}, "iv")
|
||||
}
|
||||
|
||||
type BSMPriceRequest struct {
|
||||
OptionType string `json:"optionType"`
|
||||
ObjectPrices string `json:"objectPrices"`
|
||||
StrikePrice float64 `json:"strikePrice"`
|
||||
RiskFree float64 `json:"riskFree"`
|
||||
Sigma float64 `json:"sigma"`
|
||||
Days int `json:"days"`
|
||||
Dividend float64 `json:"dividend"`
|
||||
OptionType string
|
||||
ObjectPrices any // float64 或 []float64
|
||||
StrikePrice float64
|
||||
RiskFree float64
|
||||
Sigma float64
|
||||
Days int
|
||||
Dividend float64
|
||||
}
|
||||
|
||||
func (c *Client) BSMPrice(ctx context.Context, req BSMPriceRequest) (any, error) {
|
||||
var out struct {
|
||||
Price any `json:"price"`
|
||||
prices := req.ObjectPrices
|
||||
if vals, ok := req.ObjectPrices.([]float64); ok {
|
||||
parts := make([]string, len(vals))
|
||||
for i, v := range vals {
|
||||
parts[i] = strconv.FormatFloat(v, 'f', -1, 64)
|
||||
}
|
||||
prices = strings.Join(parts, ",")
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/bsm_price", req, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Price, nil
|
||||
return c.postField(ctx, "/api/data/bsm_price", map[string]any{
|
||||
"optionType": req.OptionType, "objectPrices": prices, "strikePrice": req.StrikePrice,
|
||||
"riskFree": req.RiskFree, "sigma": req.Sigma, "days": req.Days, "dividend": req.Dividend,
|
||||
}, "price")
|
||||
}
|
||||
|
||||
type BSMIVRequest struct {
|
||||
@@ -535,13 +340,7 @@ type BSMIVRequest struct {
|
||||
}
|
||||
|
||||
func (c *Client) BSMIV(ctx context.Context, req BSMIVRequest) (any, error) {
|
||||
var out struct {
|
||||
IV any `json:"iv"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/bsm_iv", req, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.IV, nil
|
||||
return c.postField(ctx, "/api/data/bsm_iv", req, "iv")
|
||||
}
|
||||
|
||||
type LocalDataRequest struct {
|
||||
@@ -554,18 +353,12 @@ type LocalDataRequest struct {
|
||||
}
|
||||
|
||||
func (c *Client) LocalData(ctx context.Context, req LocalDataRequest) (any, error) {
|
||||
var out struct {
|
||||
Data any `json:"data"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/data/local_data", req, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Data, nil
|
||||
return c.postField(ctx, "/api/data/local_data", req, "data")
|
||||
}
|
||||
|
||||
func (c *Client) SubscribeQuote(ctx context.Context, stockCode, period, dividendType string) (*SubscribeResult, error) {
|
||||
body := map[string]any{"stock_code": stockCode, "period": period, "dividend_type": dividendType}
|
||||
var out SubscribeResult
|
||||
body := map[string]any{"stock_code": stockCode, "period": period, "dividend_type": dividendType}
|
||||
if err := c.post(ctx, "/api/data/subscribe_quote", body, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user