dca

package
v0.24.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2026 License: Apache-2.0, MIT Imports: 11 Imported by: 0

Documentation

Overview

Package dca provides a client for the Longbridge DCA (dollar-cost averaging) OpenAPI. It supports creating, updating, pausing, resuming, and stopping DCA plans, as well as querying execution history, statistics, and support eligibility.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CalcDateOptions

type CalcDateOptions struct {
	DayOfWeek  string
	DayOfMonth *uint32
}

CalcDateOptions holds optional schedule parameters for calc-date.

type CreateOptions

type CreateOptions struct {
	// DayOfWeek is required for Weekly/Fortnightly plans (e.g. "Monday").
	DayOfWeek string
	// DayOfMonth is required for Monthly plans (e.g. 15).
	DayOfMonth *uint32
	// AllowMargin enables margin financing for this plan.
	AllowMargin bool
}

CreateOptions holds optional parameters for creating a DCA plan.

type DCAContext

type DCAContext struct {
	// contains filtered or unexported fields
}

DCAContext is a client for the Longbridge DCA OpenAPI.

Example:

conf, err := config.NewFromEnv()
dctx, err := dca.NewFromCfg(conf)
list, err := dctx.List(ctx, nil, nil)

func NewFromCfg

func NewFromCfg(cfg *config.Config) (*DCAContext, error)

NewFromCfg creates a DCAContext from a *config.Config.

func NewFromEnv

func NewFromEnv() (*DCAContext, error)

NewFromEnv returns a DCAContext configured from environment variables.

func (*DCAContext) CalcDate

func (d *DCAContext) CalcDate(ctx context.Context, symbol string, frequency DCAFrequency, opts *CalcDateOptions) (*DcaCalcDateResult, error)

CalcDate calculates the next projected trade date for the given schedule parameters.

Path: POST /v1/dailycoins/calc-trd-date

func (*DCAContext) CheckSupport

func (d *DCAContext) CheckSupport(ctx context.Context, symbols []string) ([]*DcaSupportInfo, error)

CheckSupport checks which of the provided symbols support DCA plans.

Path: POST /v1/dailycoins/batch-check-support

func (*DCAContext) Create

func (d *DCAContext) Create(ctx context.Context, symbol string, amount string, frequency DCAFrequency, opts *CreateOptions) (*DcaCreateResult, error)

Create creates a new DCA plan and returns the result containing the new plan ID.

Path: POST /v1/dailycoins/create

func (*DCAContext) History

func (d *DCAContext) History(ctx context.Context, planID string, page int, limit int) (*DcaHistoryResponse, error)

History returns the execution history for a DCA plan.

Path: GET /v1/dailycoins/query-records

func (*DCAContext) List

func (d *DCAContext) List(ctx context.Context, status *DCAStatus, symbol *string) (*DcaList, error)

List returns the caller's DCA plans, optionally filtered by status and/or symbol.

Path: GET /v1/dailycoins/query

func (*DCAContext) Pause

func (d *DCAContext) Pause(ctx context.Context, planID string) error

Pause suspends an active DCA plan.

Path: POST /v1/dailycoins/toggle

func (*DCAContext) Resume

func (d *DCAContext) Resume(ctx context.Context, planID string) error

Resume activates a suspended DCA plan.

Path: POST /v1/dailycoins/toggle

func (*DCAContext) SetReminder

func (d *DCAContext) SetReminder(ctx context.Context, hours string) error

SetReminder updates the advance reminder hours for DCA execution notifications. hours must be one of "1", "6", or "12".

Path: POST /v1/dailycoins/update-alter-hours

func (*DCAContext) Stats

func (d *DCAContext) Stats(ctx context.Context, symbol *string) (*DcaStats, error)

Stats returns aggregated DCA statistics, optionally filtered to a single symbol.

Path: GET /v1/dailycoins/statistic

func (*DCAContext) Stop

func (d *DCAContext) Stop(ctx context.Context, planID string) error

Stop permanently finishes a DCA plan.

Path: POST /v1/dailycoins/toggle

func (*DCAContext) Update

func (d *DCAContext) Update(ctx context.Context, planID string, opts *UpdateOptions) (*DcaCreateResult, error)

Update modifies an existing DCA plan.

Path: POST /v1/dailycoins/update

type DCAFrequency

type DCAFrequency int

DCAFrequency specifies how often a DCA plan executes.

const (
	// DCAFrequencyDaily executes the plan every trading day.
	DCAFrequencyDaily DCAFrequency = iota
	// DCAFrequencyWeekly executes the plan once per week.
	DCAFrequencyWeekly
	// DCAFrequencyFortnightly executes the plan once every two weeks.
	DCAFrequencyFortnightly
	// DCAFrequencyMonthly executes the plan once per month (default).
	DCAFrequencyMonthly
)

func (DCAFrequency) String

func (f DCAFrequency) String() string

String returns the API wire string for a DCAFrequency.

type DCAStatus

type DCAStatus int

DCAStatus represents the lifecycle state of a DCA plan.

const (
	// DCAStatusActive is the default running state.
	DCAStatusActive DCAStatus = iota
	// DCAStatusSuspended means the plan is paused.
	DCAStatusSuspended
	// DCAStatusFinished means the plan has been permanently stopped.
	DCAStatusFinished
)

func (DCAStatus) String

func (s DCAStatus) String() string

String returns the API wire string for a DCAStatus.

type DcaCalcDateResult

type DcaCalcDateResult struct {
	TradeDate time.Time
}

DcaCalcDateResult holds the next projected trade date.

type DcaCreateResult

type DcaCreateResult struct {
	PlanID string
}

DcaCreateResult is returned when creating or updating a plan.

type DcaHistoryRecord

type DcaHistoryRecord struct {
	// CreatedAt is the execution timestamp string.
	CreatedAt string
	// OrderID is the order identifier.
	OrderID string
	// Status is the execution status string.
	Status string
	// Action is the action taken.
	Action string
	// OrderType is the order type used.
	OrderType string
	// ExecutedQty is the number of shares executed (nil if not filled).
	ExecutedQty *decimal.Decimal
	// ExecutedPrice is the execution price (nil if not filled).
	ExecutedPrice *decimal.Decimal
	// ExecutedAmount is the total execution amount (nil if not filled).
	ExecutedAmount *decimal.Decimal
	// RejectedReason explains why the order was rejected, if applicable.
	RejectedReason string
	// Symbol is the security symbol.
	Symbol string
}

DcaHistoryRecord is a single DCA execution event.

type DcaHistoryResponse

type DcaHistoryResponse struct {
	Records []*DcaHistoryRecord
	HasMore bool
}

DcaHistoryResponse is the paginated response for execution history.

type DcaList

type DcaList struct {
	Plans []*DcaPlan
}

DcaList holds a list of DCA plans.

type DcaPlan

type DcaPlan struct {
	// PlanID is the unique identifier of the plan.
	PlanID string
	// Status is the current lifecycle state of the plan.
	Status DCAStatus
	// Symbol is the security symbol in Longbridge format (e.g. "700.HK").
	Symbol string
	// MemberID is the user's member identifier.
	MemberID string
	// Aaid is the account asset ID.
	Aaid string
	// AccountChannel identifies the brokerage channel.
	AccountChannel string
	// DisplayAccount is the masked account display string.
	DisplayAccount string
	// Market is the market identifier.
	Market string
	// PerInvestAmount is the amount invested per execution.
	PerInvestAmount decimal.Decimal
	// Frequency is the recurrence interval.
	Frequency DCAFrequency
	// DayOfWeek is the scheduled day of week for weekly plans (e.g. "Monday").
	DayOfWeek string
	// DayOfMonth is the scheduled day of month for monthly plans (e.g. "15").
	DayOfMonth string
	// AllowMarginFinance indicates whether margin financing is enabled.
	AllowMarginFinance bool
	// AlterHours is the advance reminder hours before execution.
	AlterHours string
	// CreatedAt is the creation timestamp of the plan.
	CreatedAt string
	// UpdatedAt is the last update timestamp.
	UpdatedAt string
	// NextTrdDate is the next projected trade date.
	NextTrdDate string
	// StockName is the display name of the security.
	StockName string
	// CumAmount is the total cumulative invested amount (nil if not available).
	CumAmount *decimal.Decimal
	// IssueNumber is the number of executions completed.
	IssueNumber int64
	// AverageCost is the average cost per share (nil if not available).
	AverageCost *decimal.Decimal
	// CumProfit is the cumulative profit/loss (nil if not available).
	CumProfit *decimal.Decimal
}

DcaPlan is the idiomatic Go representation of a DCA investment plan.

type DcaStats

type DcaStats struct {
	// ActiveCount is the number of active plans.
	ActiveCount string
	// FinishedCount is the number of finished plans.
	FinishedCount string
	// SuspendedCount is the number of suspended plans.
	SuspendedCount string
	// NearestPlans is the list of plans executing soonest.
	NearestPlans []*DcaPlan
	// RestDays is the number of rest days remaining.
	RestDays string
	// TotalAmount is the total invested across all plans (nil if not available).
	TotalAmount *decimal.Decimal
	// TotalProfit is the total profit/loss across all plans (nil if not available).
	TotalProfit *decimal.Decimal
}

DcaStats holds aggregated statistics across DCA plans.

type DcaSupportInfo

type DcaSupportInfo struct {
	// Symbol is the security symbol.
	Symbol string
	// SupportRegularSaving indicates whether DCA is supported.
	SupportRegularSaving bool
}

DcaSupportInfo holds DCA eligibility for a single security.

type UpdateOptions

type UpdateOptions struct {
	Amount      *string
	Frequency   *DCAFrequency
	DayOfWeek   *string
	DayOfMonth  *uint32
	AllowMargin *bool
}

UpdateOptions holds the fields that can be updated on an existing DCA plan. Nil/zero fields are not sent.

Directories

Path Synopsis
Package jsontypes contains the raw JSON wire types for the DCA API.
Package jsontypes contains the raw JSON wire types for the DCA API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL