dev 2
This commit is contained in:
@@ -102,69 +102,47 @@ func (c *Client) styleOrder(ctx context.Context, path string, body map[string]an
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func (c *Client) OrderLots(ctx context.Context, stock string, lots int, style string, price float64, accID string) (*StyleOrderResult, error) {
|
||||
return c.styleOrder(ctx, "/api/trade/order_lots", styleBody(stock, style, price, accID, "lots", lots))
|
||||
func (c *Client) OrderLots(ctx context.Context, stock string, lots int, style string, price float64) (*StyleOrderResult, error) {
|
||||
return c.styleOrder(ctx, "/api/trade/order_lots", map[string]any{"stock": stock, "lots": lots, "style": style, "price": price})
|
||||
}
|
||||
|
||||
func (c *Client) OrderValue(ctx context.Context, stock string, value float64, style string, price float64, accID string) (*StyleOrderResult, error) {
|
||||
return c.styleOrder(ctx, "/api/trade/order_value", styleBody(stock, style, price, accID, "value", value))
|
||||
func (c *Client) OrderValue(ctx context.Context, stock string, value float64, style string, price float64) (*StyleOrderResult, error) {
|
||||
return c.styleOrder(ctx, "/api/trade/order_value", map[string]any{"stock": stock, "value": value, "style": style, "price": price})
|
||||
}
|
||||
|
||||
func (c *Client) OrderPercent(ctx context.Context, stock string, percent float64, style string, price float64, accID string) (*StyleOrderResult, error) {
|
||||
return c.styleOrder(ctx, "/api/trade/order_percent", styleBody(stock, style, price, accID, "percent", percent))
|
||||
func (c *Client) OrderPercent(ctx context.Context, stock string, percent float64, style string, price float64) (*StyleOrderResult, error) {
|
||||
return c.styleOrder(ctx, "/api/trade/order_percent", map[string]any{"stock": stock, "percent": percent, "style": style, "price": price})
|
||||
}
|
||||
|
||||
func (c *Client) OrderTargetValue(ctx context.Context, stock string, tarValue float64, style string, price float64, accID string) (*StyleOrderResult, error) {
|
||||
return c.styleOrder(ctx, "/api/trade/order_target_value", styleBody(stock, style, price, accID, "tar_value", tarValue))
|
||||
func (c *Client) OrderTargetValue(ctx context.Context, stock string, tarValue float64, style string, price float64) (*StyleOrderResult, error) {
|
||||
return c.styleOrder(ctx, "/api/trade/order_target_value", map[string]any{"stock": stock, "tar_value": tarValue, "style": style, "price": price})
|
||||
}
|
||||
|
||||
func (c *Client) OrderTargetPercent(ctx context.Context, stock string, tarPercent float64, style string, price float64, accID string) (*StyleOrderResult, error) {
|
||||
return c.styleOrder(ctx, "/api/trade/order_target_percent", styleBody(stock, style, price, accID, "tar_percent", tarPercent))
|
||||
func (c *Client) OrderTargetPercent(ctx context.Context, stock string, tarPercent float64, style string, price float64) (*StyleOrderResult, error) {
|
||||
return c.styleOrder(ctx, "/api/trade/order_target_percent", map[string]any{"stock": stock, "tar_percent": tarPercent, "style": style, "price": price})
|
||||
}
|
||||
|
||||
func (c *Client) OrderShares(ctx context.Context, stock string, shares int, style string, price float64, accID string) (*StyleOrderResult, error) {
|
||||
return c.styleOrder(ctx, "/api/trade/order_shares", styleBody(stock, style, price, accID, "shares", shares))
|
||||
func (c *Client) OrderShares(ctx context.Context, stock string, shares int, style string, price float64) (*StyleOrderResult, error) {
|
||||
return c.styleOrder(ctx, "/api/trade/order_shares", map[string]any{"stock": stock, "shares": shares, "style": style, "price": price})
|
||||
}
|
||||
|
||||
func styleBody(stock, style string, price float64, accID, key string, val any) map[string]any {
|
||||
body := map[string]any{"stock": stock, key: val, "price": price}
|
||||
if style != "" {
|
||||
body["style"] = style
|
||||
}
|
||||
if accID != "" {
|
||||
body["accId"] = accID
|
||||
}
|
||||
return body
|
||||
func (c *Client) FuturesBuyOpen(ctx context.Context, stock string, amount int, style string, price float64) (*StyleOrderResult, error) {
|
||||
return c.styleOrder(ctx, "/api/trade/futures/buy_open", map[string]any{"stock": stock, "amount": amount, "style": style, "price": price})
|
||||
}
|
||||
|
||||
func (c *Client) futures(ctx context.Context, path, stock string, amount int, style string, price float64, accID string) (*StyleOrderResult, error) {
|
||||
body := map[string]any{"stock": stock, "amount": amount, "price": price}
|
||||
if style != "" {
|
||||
body["style"] = style
|
||||
}
|
||||
if accID != "" {
|
||||
body["accId"] = accID
|
||||
}
|
||||
return c.styleOrder(ctx, path, body)
|
||||
func (c *Client) FuturesBuyCloseTdayFirst(ctx context.Context, stock string, amount int, style string, price float64) (*StyleOrderResult, error) {
|
||||
return c.styleOrder(ctx, "/api/trade/futures/buy_close_tdayfirst", map[string]any{"stock": stock, "amount": amount, "style": style, "price": price})
|
||||
}
|
||||
|
||||
func (c *Client) FuturesBuyOpen(ctx context.Context, stock string, amount int, style string, price float64, accID string) (*StyleOrderResult, error) {
|
||||
return c.futures(ctx, "/api/trade/futures/buy_open", stock, amount, style, price, accID)
|
||||
func (c *Client) FuturesBuyCloseYdayFirst(ctx context.Context, stock string, amount int, style string, price float64) (*StyleOrderResult, error) {
|
||||
return c.styleOrder(ctx, "/api/trade/futures/buy_close_ydayfirst", map[string]any{"stock": stock, "amount": amount, "style": style, "price": price})
|
||||
}
|
||||
func (c *Client) FuturesBuyCloseTdayFirst(ctx context.Context, stock string, amount int, style string, price float64, accID string) (*StyleOrderResult, error) {
|
||||
return c.futures(ctx, "/api/trade/futures/buy_close_tdayfirst", stock, amount, style, price, accID)
|
||||
func (c *Client) FuturesSellOpen(ctx context.Context, stock string, amount int, style string, price float64) (*StyleOrderResult, error) {
|
||||
return c.styleOrder(ctx, "/api/trade/futures/sell_open", map[string]any{"stock": stock, "amount": amount, "style": style, "price": price})
|
||||
}
|
||||
func (c *Client) FuturesBuyCloseYdayFirst(ctx context.Context, stock string, amount int, style string, price float64, accID string) (*StyleOrderResult, error) {
|
||||
return c.futures(ctx, "/api/trade/futures/buy_close_ydayfirst", stock, amount, style, price, accID)
|
||||
func (c *Client) FuturesSellCloseTdayFirst(ctx context.Context, stock string, amount int, style string, price float64) (*StyleOrderResult, error) {
|
||||
return c.styleOrder(ctx, "/api/trade/futures/sell_close_tdayfirst", map[string]any{"stock": stock, "amount": amount, "style": style, "price": price})
|
||||
}
|
||||
func (c *Client) FuturesSellOpen(ctx context.Context, stock string, amount int, style string, price float64, accID string) (*StyleOrderResult, error) {
|
||||
return c.futures(ctx, "/api/trade/futures/sell_open", stock, amount, style, price, accID)
|
||||
}
|
||||
func (c *Client) FuturesSellCloseTdayFirst(ctx context.Context, stock string, amount int, style string, price float64, accID string) (*StyleOrderResult, error) {
|
||||
return c.futures(ctx, "/api/trade/futures/sell_close_tdayfirst", stock, amount, style, price, accID)
|
||||
}
|
||||
func (c *Client) FuturesSellCloseYdayFirst(ctx context.Context, stock string, amount int, style string, price float64, accID string) (*StyleOrderResult, error) {
|
||||
return c.futures(ctx, "/api/trade/futures/sell_close_ydayfirst", stock, amount, style, price, accID)
|
||||
func (c *Client) FuturesSellCloseYdayFirst(ctx context.Context, stock string, amount int, style string, price float64) (*StyleOrderResult, error) {
|
||||
return c.styleOrder(ctx, "/api/trade/futures/sell_close_ydayfirst", map[string]any{"stock": stock, "amount": amount, "style": style, "price": price})
|
||||
}
|
||||
|
||||
type TaskResult struct {
|
||||
@@ -172,45 +150,37 @@ type TaskResult struct {
|
||||
TaskID any `json:"taskId"`
|
||||
}
|
||||
|
||||
func (c *Client) task(ctx context.Context, path, taskID, accountType string) (*TaskResult, error) {
|
||||
body := map[string]any{"taskId": taskID}
|
||||
if accountType != "" {
|
||||
body["accountType"] = accountType
|
||||
}
|
||||
func (c *Client) CancelTask(ctx context.Context, taskID string) (*TaskResult, error) {
|
||||
return c.task(ctx, "/api/trade/cancel_task", taskID)
|
||||
}
|
||||
func (c *Client) PauseTask(ctx context.Context, taskID string) (*TaskResult, error) {
|
||||
return c.task(ctx, "/api/trade/pause_task", taskID)
|
||||
}
|
||||
func (c *Client) ResumeTask(ctx context.Context, taskID string) (*TaskResult, error) {
|
||||
return c.task(ctx, "/api/trade/resume_task", taskID)
|
||||
}
|
||||
|
||||
func (c *Client) task(ctx context.Context, path, taskID string) (*TaskResult, error) {
|
||||
var out TaskResult
|
||||
if err := c.post(ctx, path, body, &out); err != nil {
|
||||
if err := c.post(ctx, path, map[string]any{"taskId": taskID, "accountType": c.accountType}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func (c *Client) CancelTask(ctx context.Context, taskID, accountType string) (*TaskResult, error) {
|
||||
return c.task(ctx, "/api/trade/cancel_task", taskID, accountType)
|
||||
}
|
||||
func (c *Client) PauseTask(ctx context.Context, taskID, accountType string) (*TaskResult, error) {
|
||||
return c.task(ctx, "/api/trade/pause_task", taskID, accountType)
|
||||
}
|
||||
func (c *Client) ResumeTask(ctx context.Context, taskID, accountType string) (*TaskResult, error) {
|
||||
return c.task(ctx, "/api/trade/resume_task", taskID, accountType)
|
||||
}
|
||||
|
||||
func (c *Client) DoOrder(ctx context.Context) (map[string]any, error) {
|
||||
var out map[string]any
|
||||
if err := c.post(ctx, "/api/trade/do_order", map[string]any{}, &out); err != nil {
|
||||
if err := c.post(ctx, "/api/trade/do_order", nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *Client) TradeDetailData(ctx context.Context, account, datatype string) ([]map[string]string, error) {
|
||||
body := map[string]any{
|
||||
"account": c.Account(account),
|
||||
"datatype": datatype,
|
||||
}
|
||||
func (c *Client) TradeDetailData(ctx context.Context, datatype string) ([]map[string]string, error) {
|
||||
var out struct {
|
||||
Data []map[string]string `json:"data"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/trade/trade_detail_data", body, &out); err != nil {
|
||||
if err := c.post(ctx, "/api/trade/trade_detail_data", map[string]any{"account": c.accountType, "datatype": datatype}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if out.Data == nil {
|
||||
@@ -219,84 +189,61 @@ func (c *Client) TradeDetailData(ctx context.Context, account, datatype string)
|
||||
return out.Data, nil
|
||||
}
|
||||
|
||||
func (c *Client) ValueByOrderID(ctx context.Context, orderID, accountType, datatype string) (map[string]string, error) {
|
||||
body := map[string]any{"orderId": orderID, "accountType": accountType, "datatype": datatype}
|
||||
func (c *Client) ValueByOrderID(ctx context.Context, orderID, datatype string) (map[string]string, error) {
|
||||
var out struct {
|
||||
OrderID string `json:"orderId"`
|
||||
Data map[string]string `json:"data"`
|
||||
Data map[string]string `json:"data"`
|
||||
}
|
||||
body := map[string]any{"orderId": orderID, "accountType": c.accountType, "datatype": datatype}
|
||||
if err := c.post(ctx, "/api/trade/value_by_order_id", body, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Data, nil
|
||||
}
|
||||
|
||||
func (c *Client) LastOrderID(ctx context.Context, account, datatype string) (any, error) {
|
||||
body := map[string]any{"account": c.Account(account), "datatype": datatype}
|
||||
func (c *Client) LastOrderID(ctx context.Context, datatype string) (any, error) {
|
||||
var out struct {
|
||||
LastOrderID any `json:"last_order_id"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/trade/last_order_id", body, &out); err != nil {
|
||||
if err := c.post(ctx, "/api/trade/last_order_id", map[string]any{"account": c.accountType, "datatype": datatype}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.LastOrderID, nil
|
||||
}
|
||||
|
||||
func (c *Client) CanCancelOrder(ctx context.Context, orderID, accountType string) (any, error) {
|
||||
body := map[string]any{"orderId": orderID, "accountType": accountType}
|
||||
func (c *Client) CanCancelOrder(ctx context.Context, orderID string) (any, error) {
|
||||
var out struct {
|
||||
CanCancel any `json:"can_cancel"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/trade/can_cancel_order", body, &out); err != nil {
|
||||
if err := c.post(ctx, "/api/trade/can_cancel_order", map[string]any{"orderId": orderID, "accountType": c.accountType}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.CanCancel, nil
|
||||
}
|
||||
|
||||
func (c *Client) contractList(ctx context.Context, path, accID string) ([]map[string]string, error) {
|
||||
body := map[string]any{}
|
||||
if accID != "" {
|
||||
body["accId"] = accID
|
||||
}
|
||||
func (c *Client) contractList(ctx context.Context, path string) ([]map[string]string, error) {
|
||||
var out struct {
|
||||
Data []map[string]string `json:"data"`
|
||||
}
|
||||
if err := c.post(ctx, path, body, &out); err != nil {
|
||||
if err := c.post(ctx, path, nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Data, nil
|
||||
}
|
||||
|
||||
func (c *Client) DebtContract(ctx context.Context, accID string) ([]map[string]string, error) {
|
||||
return c.contractList(ctx, "/api/trade/debt_contract", accID)
|
||||
func (c *Client) DebtContract(ctx context.Context) ([]map[string]string, error) {
|
||||
return c.contractList(ctx, "/api/trade/debt_contract")
|
||||
}
|
||||
func (c *Client) AssureContract(ctx context.Context, accID string) ([]map[string]string, error) {
|
||||
return c.contractList(ctx, "/api/trade/assure_contract", accID)
|
||||
func (c *Client) AssureContract(ctx context.Context) ([]map[string]string, error) {
|
||||
return c.contractList(ctx, "/api/trade/assure_contract")
|
||||
}
|
||||
func (c *Client) EnableShortContract(ctx context.Context, accID string) ([]map[string]string, error) {
|
||||
return c.contractList(ctx, "/api/trade/enable_short_contract", accID)
|
||||
func (c *Client) EnableShortContract(ctx context.Context) ([]map[string]string, error) {
|
||||
return c.contractList(ctx, "/api/trade/enable_short_contract")
|
||||
}
|
||||
|
||||
func (c *Client) IPOData(ctx context.Context, typ string) (any, error) {
|
||||
var out struct {
|
||||
Data any `json:"data"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/trade/ipo_data", map[string]any{"type": typ}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Data, nil
|
||||
return c.postField(ctx, "/api/trade/ipo_data", map[string]any{"type": typ}, "data")
|
||||
}
|
||||
|
||||
func (c *Client) NewPurchaseLimit(ctx context.Context, accid string) (any, error) {
|
||||
body := map[string]any{}
|
||||
if accid != "" {
|
||||
body["accid"] = accid
|
||||
}
|
||||
var out struct {
|
||||
Data any `json:"data"`
|
||||
}
|
||||
if err := c.post(ctx, "/api/trade/new_purchase_limit", body, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Data, nil
|
||||
func (c *Client) NewPurchaseLimit(ctx context.Context) (any, error) {
|
||||
return c.postField(ctx, "/api/trade/new_purchase_limit", nil, "data")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user