更新定投
暂停或恢复已有的定投。
SDK Links
Python | longport.openapi.DCAContext.update |
Rust | longport::dca::DCAContext#update |
Go | DCAContext.Update |
Node.js | DCAContext#update |
Parameters
SDK 方法参数。
| Name | Type | Required | Description |
|---|---|---|---|
| id | string | 是 | 计划 ID(路径参数) |
| action | string | 是 | 执行操作:pause(暂停)或 resume(恢复) |
Request Example
python
from longport.openapi import DCAContext, Config, OAuthBuilder
oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url))
config = Config.from_oauth(oauth)
ctx = DCAContext(config)
resp = ctx.update_dca("1225781523156889600", action="pause")
print(resp)python
import asyncio
from longport.openapi import AsyncDCAContext, Config, OAuthBuilder
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.update_dca("1225781523156889600", action="pause")
print(resp)
if __name__ == "__main__":
asyncio.run(main())javascript
const { Config, DCAContext, OAuth } = require('longport')
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.update_dca()
console.log(resp)
}
main().catch(console.error)java
import com.longport.*;
import com.longport.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 resp = ctx.getUpdateDca().get();
System.out.println(resp);
}
}
}rust
use std::sync::Arc;
use longport::{oauth::OAuthBuilder, dca::DCAContext, 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.update_dca().await?;
println!("{:?}", resp);
Ok(())
}cpp
#include <iostream>
#include <longport.hpp>
using namespace longport;
using namespace longport::dca;
int main() {
OAuthBuilder("your-client-id").build(
[](const std::string& url) { std::cout << "Open: " << url << std::endl; },
[](auto res) {
if (!res) return;
Config config = Config::from_oauth(*res);
DCAContext ctx = DCAContext::create(config);
ctx.update_dca([](auto resp) {
if (resp) std::cout << "OK" << std::endl;
});
});
std::cin.get();
}go
package main
import (
"context"
"fmt"
"log"
"github.com/longportapp/openapi-go/config"
"github.com/longportapp/openapi-go/oauth"
"github.com/longportapp/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()
resp, err := c.UpdateDca(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", resp)
}Response
Response Example
json
{
"code": 0,
"message": "success",
"data": {}
}Response Status
| Status | Description | Schema |
|---|---|---|
| 200 | 成功 | UpdateDcaResponse |
| 400 | 请求错误 | None |
Schemas
UpdateDcaResponse
无响应体字段。