Longbridge Developers
立即开始

资金流水

该接口用于获取资金流入/流出方向、资金类别、资金金额、发生时间、关联股票代码和资金流水说明信息。

>_ CLI
longbridge cash-flow

Request

HTTP MethodGET
HTTP URL/v1/asset/cashflow

Parameters

Content-Type: application/json; charset=utf-8

NameTypeRequiredDescription
start_timestringYES开始时间,时间戳,以 秒 为单位,例如:1650037563
end_timestringYES结束时间,时间戳,以 秒 为单位,例如:1650747581
business_typestringNO资金类型

可选值:
1 - 现金
2 - 股票
3 - 基金
symbolstringNO标的代码,例如:AAPL.US
pagestringNO起始页

默认值: 1
数据校验规则:
取值范围: >=1
sizestringNO每页大小

默认值: 50
数据校验规则: 1~10000

Request Example

from datetime import datetime
from longbridge.openapi import TradeContext, Config, OAuthBuilder

oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url))
config = Config.from_oauth(oauth)
ctx = TradeContext(config)
resp = ctx.cash_flow(
    start_at = datetime(2022, 5, 9),
    end_at = datetime(2022, 5, 12),
)
print(resp)
import asyncio
from datetime import datetime
from longbridge.openapi import AsyncTradeContext, 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 = AsyncTradeContext.create(config)
    resp = await ctx.cash_flow(
        start_at = datetime(2022, 5, 9),
        end_at = datetime(2022, 5, 12),
    )
    print(resp)

if __name__ == "__main__":
    asyncio.run(main())
const { Config, TradeContext, OAuth } = 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 = TradeContext.new(config)
  const resp = await ctx.cashFlow({ startAt: new Date(2022, 4, 9), endAt: new Date(2022, 4, 12) })
  console.log(resp)
}
main().catch(console.error)
import com.longbridge.*;
import com.longbridge.trade.*;
import java.time.*;

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);
             TradeContext ctx = TradeContext.create(config)) {
            GetCashFlowOptions opts = new GetCashFlowOptions(
                OffsetDateTime.of(2022, 5, 9, 0, 0, 0, 0, ZoneOffset.UTC),
                OffsetDateTime.of(2022, 5, 12, 0, 0, 0, 0, ZoneOffset.UTC));
            CashFlow[] resp = ctx.getCashFlow(opts).get();
            for (CashFlow c : resp) System.out.println(c);
        }
    }
}
use std::sync::Arc;
use longbridge::{oauth::OAuthBuilder, trade::{TradeContext, GetCashFlowOptions}, Config};
use time::macros::datetime;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let oauth = OAuthBuilder::new("your-client-id").build(|url| println!("Open this URL to authorize: {url}")).await?;
    let config = Arc::new(Config::from_oauth(oauth));
    let (ctx, _) = TradeContext::new(config);
    let opts = GetCashFlowOptions::new(datetime!(2022-05-09 0:00 UTC), datetime!(2022-05-12 0:00 UTC));
    let resp = ctx.cash_flow(opts).await?;
    println!("{:?}", resp);
    Ok(())
}
#include &lt;iostream&gt;
#include <longbridge.hpp>

#ifdef WIN32
#include <windows.h>
#endif

using namespace longbridge;
using namespace longbridge::trade;

static void
run(const OAuth& oauth)
{
    Config config = Config::from_oauth(oauth);
    TradeContext ctx = TradeContext::create(config);

    GetCashFlowOptions opts{}; ctx.account_balance(opts, [](auto res) {
        if (!res) { std::cout << "failed" << std::endl; return; }
        std::cout << "cashflow" << std::endl;
    });
}

int main(int argc, char const* argv[]) {
#ifdef WIN32
    SetConsoleOutputCP(CP_UTF8);
#endif

    const std::string client_id = "your-client-id";
    OAuthBuilder(client_id).build(
    [](const std::string& url) {
        std::cout << "Open this URL to authorize: " << url << std::endl;
    },
    [](auto res) {
        if (!res) {
            std::cout << "authorization failed: " << *res.status().message() << std::endl;
            return;
        }
        run(*res);
    });

    std::cin.get();
    return 0;
}
package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/longbridge/openapi-go/config"
	"github.com/longbridge/openapi-go/oauth"
	"github.com/longbridge/openapi-go/trade"
)

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)
	}
	tctx, err := trade.NewFromCfg(conf)
	if err != nil {
		log.Fatal(err)
	}
	defer tctx.Close()
	start := time.Date(2024, 5, 1, 0, 0, 0, 0, time.UTC).Unix()
	end := time.Date(2024, 6, 1, 0, 0, 0, 0, time.UTC).Unix()
	flows, err := tctx.CashFlow(context.Background(), &trade.GetCashFlow{
		StartAt:      start,
		EndAt:        end,
		BusinessType: trade.BalanceTypeCash,
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", flows)
}

Response

Response Headers

  • Content-Type: application/json

Response Example

{
  "code": 0,
  "data": {
    "list": [
      {
        "transaction_flow_name": "股票买入成交",
        "direction": 1,
        "balance": "-248.60",
        "currency": "USD",
        "business_time": "1621507957",
        "symbol": "AAPL.US",
        "description": "AAPL"
      },
      {
        "transaction_flow_name": "股票买入成交",
        "direction": 1,
        "balance": "-125.16",
        "currency": "USD",
        "business_time": "1621504824",
        "symbol": "AAPL.US",
        "description": "AAPL"
      }
    ]
  }
}

Response Status

StatusDescriptionSchema
200返回成功cashflow_rsp
400内部错误None

Schemas

cashflow_rsp

NameTypeRequiredDescription
listobject[]false流水信息
∟ transaction_flow_namestringtrue流水名称
∟ directionstringtrue流出方向

可选值:
1 - 流出
2 - 流入
∟ business_typestringtrue资金类别

可选值:
1 - 现金
2 - 股票
3 - 基金
∟ balancestringtrue资金金额
∟ currencystringtrue资金币种
∟ business_timestringtrue业务时间
∟ symbolstringfalse关联股票代码信息
∟ descriptionstringfalse资金流水说明