dev 4
This commit is contained in:
@@ -31,31 +31,33 @@ type Assets struct {
|
||||
Available float64 `json:"available"`
|
||||
}
|
||||
|
||||
func (c *Client) Positions(ctx context.Context) ([]Position, error) {
|
||||
func (c *Client) Positions(ctx context.Context) ([]string, []Position, error) {
|
||||
return c.decodePositions(ctx, "/api/v2/positions")
|
||||
}
|
||||
|
||||
func (c *Client) Holding(ctx context.Context) ([]Position, error) {
|
||||
func (c *Client) Holding(ctx context.Context) ([]string, []Position, error) {
|
||||
return c.decodePositions(ctx, "/api/holding")
|
||||
}
|
||||
|
||||
func (c *Client) decodePositions(ctx context.Context, path string) ([]Position, error) {
|
||||
func (c *Client) decodePositions(ctx context.Context, path string) ([]string, []Position, error) {
|
||||
raw := map[string]json.RawMessage{}
|
||||
if err := c.post(ctx, path, map[string]any{"account": c.accountType}, &raw); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
codes := make([]string, 0, len(raw))
|
||||
out := make([]Position, 0, len(raw))
|
||||
for code, blob := range raw {
|
||||
var p Position
|
||||
if err := json.Unmarshal(blob, &p); err != nil {
|
||||
return nil, fmt.Errorf("position %s: %w", code, err)
|
||||
return nil, nil, fmt.Errorf("position %s: %w", code, err)
|
||||
}
|
||||
if p.StockCode == "" {
|
||||
p.StockCode = code
|
||||
}
|
||||
codes = append(codes, code)
|
||||
out = append(out, p)
|
||||
}
|
||||
return out, nil
|
||||
return codes, out, nil
|
||||
}
|
||||
|
||||
func (c *Client) Assets(ctx context.Context) (*Assets, error) {
|
||||
|
||||
Reference in New Issue
Block a user