計算定投日期
Longbridge US 賬戶不支援
此方法需要 AP 數據中心賬戶(香港/新加坡)。美股數據中心賬戶將收到區域限制錯誤。AP 賬戶可操作任意標的,包括美股。
根據給定的定投計劃參數,計算下一次預計交易日期。
SDK Links
Python |
Rust |
Go |
Node.js |
Java |
C++ |
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| symbol | string | 是 | 標的代碼 |
| frequency | string | 是 | 定投頻率:daily、weekly、fortnightly、monthly |
| day_of_week | string | 否 | 每週計劃的執行星期:mon–fri |
| day_of_month | integer | 否 | 每月/每兩週計劃的執行日期:1–28 |
Request Example
from longbridge.openapi import DCAContext, Config, OAuthBuilder, DCAFrequency
oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url))
config = Config.from_oauth(oauth)
ctx = DCAContext(config)
resp = ctx.calc_date("AAPL.US", DCAFrequency.Monthly, day_of_month=15)
print(resp)import asyncio
from longbridge.openapi import AsyncDCAContext, Config, OAuthBuilder, DCAFrequency
async def main() -> None:
oauth = await OAuthBuilder("your-client-id").build_async(lambda url: print("Visit:", url))
config = Config.from_oauth(oauth)
ctx = AsyncDCAContext.create(config)
resp = await ctx.calc_date("AAPL.US", DCAFrequency.Monthly, day_of_month=15)
print(resp)
if __name__ == "__main__":
asyncio.run(main())const { Config, DCAContext, OAuth, DCAFrequency } = require('longbridge')
async function main() {
const oauth = await OAuth.build('your-client-id', (_, url) => {
console.log('Open this URL to authorize: ' + url)
})
const config = Config.fromOAuth(oauth)
const ctx = DCAContext.new(config)
const resp = await ctx.calcDate('AAPL.US', DCAFrequency.Monthly, undefined, 15)
console.log(resp)
}
main().catch(console.error)import com.longbridge.*;
import com.longbridge.dca.*;
class Main {
public static void main(String[] args) throws Exception {
try (OAuth oauth = new OAuthBuilder("your-client-id").build(url -> System.out.println("Open to authorize: " + url)).get();
Config config = Config.fromOAuth(oauth);
DCAContext ctx = DCAContext.create(config)) {
var opts = new CalcDateOptions("AAPL.US", DCAFrequency.MONTHLY).dayOfMonth(15);
var resp = ctx.calcDate(opts).get();
System.out.println(resp);
}
}
}use std::sync::Arc;
use longbridge::{oauth::OAuthBuilder, dca::DCAContext, dca::DCAFrequency, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let oauth = OAuthBuilder::new("your-client-id").build(|url| println!("Open: {url}")).await?;
let config = Arc::new(Config::from_oauth(oauth));
let ctx = DCAContext::new(config);
let resp = ctx.calc_date("AAPL.US", DCAFrequency::Monthly, None, Some(15)).await?;
println!("{:?}", resp);
Ok(())
}package main
import (
"context"
"fmt"
"log"
"github.com/longbridge/openapi-go/config"
"github.com/longbridge/openapi-go/oauth"
"github.com/longbridge/openapi-go/dca"
)
func main() {
o := oauth.New("your-client-id").
OnOpenURL(func(url string) { fmt.Println("Open this URL to authorize:", url) })
if err := o.Build(context.Background()); err != nil {
log.Fatal(err)
}
conf, err := config.New(config.WithOAuthClient(o))
if err != nil {
log.Fatal(err)
}
c, err := dca.NewFromCfg(conf)
if err != nil {
log.Fatal(err)
}
defer c.Close()
dayOfMonth := 15
opts := &dca.CalcDateOptions{
Symbol: "AAPL.US",
Frequency: dca.FrequencyMonthly,
DayOfMonth: &dayOfMonth,
}
resp, err := c.CalcDate(context.Background(), opts)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", resp)
}Response
Response Example
{
"code": 0,
"message": "success",
"data": {
"trade_date": "2024-02-15"
}
}
Response Status
| Status | Description | Schema |
|---|---|---|
| 200 | 成功 | DcaCalcDateResult |
| 400 | 請求錯誤 | None |
Schemas
DcaCalcDateResult
| Name | Type | Required | Description |
|---|---|---|---|
| trade_date | string | true | 下一次預計交易日期(YYYY-MM-DD) |