新增標的到股單
向股單中新增一個或多個標的。
SDK Links
Python | longport.openapi.SharelistContext.add_securities |
Rust | longport::sharelist::SharelistContext#add_securities |
Go | SharelistContext.AddSecurities |
Node.js | SharelistContext#addSecurities |
Parameters
SDK 方法參數。
| Name | Type | Required | Description |
|---|---|---|---|
| id | integer | 是 | 股單 ID |
| symbols | string[] | 是 | 待新增的標的代碼 |
Request Example
python
from longport.openapi import SharelistContext, Config, OAuthBuilder
oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url))
config = Config.from_oauth(oauth)
ctx = SharelistContext(config)
ctx.add_securities(123, ["TSLA.US", "AAPL.US"])python
import asyncio
from longport.openapi import AsyncSharelistContext, 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 = AsyncSharelistContext.create(config)
await ctx.add_securities(123, ["TSLA.US", "AAPL.US"])
if __name__ == "__main__":
asyncio.run(main())javascript
const { Config, SharelistContext, 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 = SharelistContext.new(config)
await ctx.addSecurities(123, ['TSLA.US', 'AAPL.US'])
}
main().catch(console.error)java
import com.longport.*;
import com.longport.sharelist.*;
import java.util.Arrays;
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);
SharelistContext ctx = SharelistContext.create(config)) {
ctx.addSecurities(123, Arrays.asList("TSLA.US", "AAPL.US")).get();
}
}
}rust
use std::sync::Arc;
use longport::{oauth::OAuthBuilder, sharelist::SharelistContext, 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 = SharelistContext::new(config);
ctx.add_securities(123, vec!["TSLA.US".into(), "AAPL.US".into()]).await?;
Ok(())
}go
package main
import (
"context"
"fmt"
"log"
"github.com/longportapp/openapi-go/config"
"github.com/longportapp/openapi-go/oauth"
"github.com/longportapp/openapi-go/sharelist"
)
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 := sharelist.NewFromCfg(conf)
if err != nil {
log.Fatal(err)
}
defer c.Close()
if err := c.AddSecurities(context.Background(), 123, []string{"TSLA.US", "AAPL.US"}); err != nil {
log.Fatal(err)
}
}Response
Response Example
json
{
"code": 0,
"message": "success"
}Response Status
| Status | Description | Schema |
|---|---|---|
| 200 | 成功 | None |
| 400 | 請求錯誤 | None |