---
slug: trading-stats
title: 成交统计
sidebar_position: 4
language_tabs: false
toc_footers: []
includes: []
search: true
highlight_theme: ''
headingLevel: 2
---

获取指定证券的成交统计数据，展示成交量的价格分布。

<CliCommand>
longbridge trade-stats 700.HK
longbridge trade-stats TSLA.US
</CliCommand>


## SDK

| 语言 | 链接 |
|---|---|
| Python | [longbridge.openapi.market._market_context](https://longbridge.github.io/openapi/python/reference_all/#longbridge.openapi.market._market_context) |
| Rust | [longbridge::<SDKLinks module="market" klass="MarketContext" method="trading_stats" />::market#_market_context](https://longbridge.github.io/openapi/rust/longbridge/<SDKLinks module="market" klass="MarketContext" method="trading_stats" />/struct.market.html#method._market_context) |
| Go | [market.trading_stats](https://pkg.go.dev/github.com/longbridge/openapi-go/<SDKLinks module="market" klass="MarketContext" method="trading_stats" />#market.trading_stats) |
| Node.js | [market#MarketContext](https://longbridge.github.io/openapi/nodejs/classes/market.html#marketcontext) |
| Java | [market.getMarketContext](https://longbridge.github.io/openapi/java/com/longbridge/<SDKLinks module="market" klass="MarketContext" method="trading_stats" />/market.html#getMarketContext) |
| C++ | [longbridge::<SDKLinks module="market" klass="MarketContext" method="trading_stats" />::market::_market_context](https://longbridge.github.io/openapi/cpp/classlongbridge_1_1<SDKLinks module="market" klass="MarketContext" method="trading_stats" />_1_1_market.html) |


## Parameters

> **SDK 方法参数。**

| Name | Type | Required | Description |
| ---- | ---- | -------- | ----------- |
| symbol | string | 是 | 证券代码，例如 `700.HK` |

## Request Example

<Tabs groupId="request-example">
  <TabItem value="python" label="Python">

```python
from longbridge.openapi import MarketContext, Config, OAuthBuilder

oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url))
config = Config.from_oauth(oauth)
ctx = MarketContext(config)

resp = ctx.trading_stats("AAPL.US")
print(resp)
```

  </TabItem>
  <TabItem value="python-async" label="Python (async)">

```python
import asyncio
from longbridge.openapi import AsyncMarketContext, 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 = AsyncMarketContext.create(config)

    resp = await ctx.trading_stats("AAPL.US")
    print(resp)

if __name__ == "__main__":
    asyncio.run(main())
```

  </TabItem>
  <TabItem value="nodejs" label="Node.js">

```javascript
const { Config, MarketContext, 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 = MarketContext.new(config)
  const resp = await ctx.trading_stats('AAPL.US')
  console.log(resp)
}
main().catch(console.error)
```

  </TabItem>
  <TabItem value="java" label="Java">

```java
import com.longbridge.*;
import com.longbridge.market.*;

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);
             MarketContext ctx = MarketContext.create(config)) {
            var resp = ctx.getTradingStats("AAPL.US").get();
            System.out.println(resp);
        }
    }
}
```

  </TabItem>
  <TabItem value="rust" label="Rust">

```rust
use std::sync::Arc;
use longbridge::{oauth::OAuthBuilder, market::MarketContext, 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 = MarketContext::new(config);
    let resp = ctx.trading_stats("AAPL.US").await?;
    println!("{:?}", resp);
    Ok(())
}
```

  </TabItem>
  <TabItem value="cpp" label="C++">

```cpp
#include <iostream>
#include <longbridge.hpp>

using namespace longbridge;
using namespace longbridge::market;

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);
            MarketContext ctx = MarketContext::create(config);
            ctx.trading_stats("AAPL.US", [](auto resp) {
                if (resp) std::cout << "OK" << std::endl;
            });
        });
    std::cin.get();
}
```

  </TabItem>
  <TabItem value="go" label="Go">

```go
package main

import (
	"context"
	"fmt"
	"log"

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

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 := market.NewFromCfg(conf)
	if err != nil {
		log.Fatal(err)
	}
	defer c.Close()
	resp, err := c.TradingStats(context.Background(), "AAPL.US")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", resp)
}
```

  </TabItem>
</Tabs>

## Response


### Response Example

```json
{
  "code": 0,
  "message": "success",
  "data": {
    "statistics": {
      "avgprice": "210.50",
      "buy": "45000000",
      "sell": "38000000",
      "neutral": "12000000",
      "total_amount": "95000000",
      "trades_count": "125000",
      "preclose": "208.20",
      "timestamp": "1778198400",
      "trade_date": [
        "2026-05-13"
      ]
    },
    "trades": [
      {
        "price": "210.00",
        "buy_amount": "5000000",
        "sell_amount": "4000000",
        "neutral_amount": "1000000"
      }
    ]
  }
}
```

### Response Status

| Status | Description | Schema |
| ------ | ----------- | ------ |
| 200    | 成功     | [TradeStatsResponse](#TradeStatsResponse) |
| 400    | 请求错误 | None   |

## Schemas

### TradeStatsResponse

<a id="TradeStatsResponse"></a>

| Name | Type | Required | Description |
| ---- | ---- | -------- | ----------- |
| statistics | object | 是 | 成交统计汇总 |
| statistics.avgprice | string | 否 | 平均成交价 |
| statistics.buy | string | 否 | 总买入成交量 |
| statistics.sell | string | 否 | 总卖出成交量 |
| statistics.neutral | string | 否 | 总中性成交量 |
| statistics.total_amount | string | 否 | 总成交额 |
| statistics.trades_count | string | 否 | 总成交笔数 |
| statistics.preclose | string | 否 | 前收盘价 |
| statistics.timestamp | string | 否 | 统计时间戳 |
| statistics.trade_date | string[] | 否 | 涵盖的交易日期 |
| trades | object[] | 否 | 按价位的成交分布， |
| ∟ price | string | 是 | 价位 |
| ∟ buy_amount | string | 否 | 该价位买入成交额 |
| ∟ sell_amount | string | 否 | 该价位卖出成交额 |
| ∟ neutral_amount | string | 否 | 该价位中性成交额 |
