Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

调整目录结构,完成快速开始 #3

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 0 additions & 46 deletions api/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,3 @@ slug: changelog
sidebar_position: 7
---

## 2023-08-17

- 更新获取账户资金接口
- `GET /v1/asset/account` 增加入参 (currency) 字段

## 2023-04-12

- 更新获取股票持仓接口
- `GET /v1/asset/stock` 增加开盘前初始持仓 (init_quantity) 字段


## 2023-04-11

- 新增订单详情查询接口
- `GET /v1/trade/order` 获取订单详情
- 新增预估最大购买数量接口
- `GET /v1/trade/estimate/buy_limit` 获取预估最大购买数量接口
- 美股期权添加市价单和条件单支持

## 2022-07-18

- 更新标的基础信息接口
- 长连接 `Business Command: 10` 响应增加 `board` 字段

## 2022-07-14

- 新增获取保证金比例接口
- `GET /v1/risk/margin-ratio` 获取保证金比例

## 2022-06-30

- 新增获取关注分组接口
- `GET /v1/watchlist/groups` 获取关注分组

## 2022-06-20

- 更新账号资金接口
- `GET /v1/asset/account` 响应增加净资产 (net_assets)、初始保证金 (init_margin)、维持保证金 (maintenance_margin) 字段
- 更新持仓接口
- `GET /v1/asset/stock` 支持用户获取期权持仓

## 2022-06-15

- 新增行情资金流接口
- 长连接 `Business Command:24` 获取标的当日资金流向
- 长连接 `Business Command:25` 获取标的当日资金分布
9 changes: 4 additions & 5 deletions api/getting-developed/error-codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ sidebar_position: 10
| HTTP Status | code | message | 说明 |
| ----------- | ------ | ---------------------- | ---------------------------------------- |
| 403 | 403201 | signature invalid | 签名无效 |
| 403 | 403202 | duplicate request | 重复请求,同一个请求没有更换 X-Timestamp |
| 403 | 403203 | apikey illegal | App Key 无效 |
| 403 | 403205 | ip is not allowed | IP 地址无权访问 |
| 401 | 401003 | token expired | Access Token 已过期,请刷新 Access Token |
| 429 | 429001 | ip request ratelimit | IP 访问过于频繁,请稍后再试 |
| 403 | 403305 | ip is not allowed | IP 地址无权访问 |
| 401 | 401003 | token expired | Access Token 已过期 |
| 401 | 401004 | token invalid | token 不正确 |
| 429 | 429002 | api request is limited | 接口访问过于频繁,请稍后再试 |
| 500 | 500000 | internal error | 服务内部错误,请联系客户经理进行处理 |
| 500 | 500000 | internal error | 服务内部错误,请联系客户经理进行处理 |
45 changes: 16 additions & 29 deletions api/getting-developed/how-to-access-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ sidebar_position: 1
| 注意事项 | 参考文档 |
| -------------------------------------------- | ------------------------------------------------- |
| 推荐使用各自语言的 SDK,而不是调用原生的接口 | [SDK 快速开始页面](../docs/getting-started) |
| 阅读 OpenAPI 介绍中开通相应服务 | [OpenAPI 如何开通](../docs/#如何开通) |
| 阅读 OpenAPI 介绍中使用权限及限制 | [OpenAPI 使用权限及限制](../docs/#使用权限及限制) |
| 了解通用错误码,便于查找调用接口出错的原因 | [通用错误码](../docs/error-codes) |

## REST API 文档约定格式
Expand Down Expand Up @@ -57,27 +55,21 @@ GET 请求时默认所有参数为查询参数,非 GET 请求时默认所有

## API 调用流程

### 1. 开通服务
### 1. 获取调用 Access Token

参考 [OpenAPI 介绍](../docs/#如何开通) 开通相应服务。
连接商务获取测试使用的 Access Token

### 2. 获取 App Key 信息及 Access Token

在 [开发者后台](https://open.longportapp.com/account) 中获取 **Access Token**, **App Key** 以及 **App Secret**。

**Access Token** 的有效期是三个月,失效后可以在开发者后台重置。在失效之前,可以通过调用 [刷新 Access Token](./refresh-token-api) API 进行刷新。

### 3. 生成签名
### 2. 生成签名

:::tip

本页介绍的内容大部分,我们的 [OpenAPI SDK](/sdk) 已经完整实现了,你如果是 [SDK](/sdk) 用户,可以直接忽略签名认证部分。
本页介绍的内容大部分,我们的 [SDK](/sdk) 已经完整实现了,你如果是 [SDK](/sdk) 用户,可以直接忽略签名认证部分。

此部分内容是为了给非 SDK 用户提供参考。

:::

先根据相应的 API 文档构造请求后,通过 OpenAPI SDK 直接调用 API,SDK 会帮助生成签名,或者通过以下流程创建签名。
先根据相应的 API 文档构造请求后,通过 SDK 直接调用 API,SDK 会帮助生成签名,或者通过以下流程创建签名。

#### 添加 `X-Api-Key`、`X-Timestamp`、`Authorization`

Expand Down Expand Up @@ -132,40 +124,35 @@ headers['X-Api-Signature'] = sign(method, uri, headers, params, body, secret)

```

### 4. 调用 API
### 3. 调用 API

使用 HTTP 客户端发送签名过后的请求。

## 基本路径

- HTTP API - `https://openapi.longportapp.com`
- WebSocket - `wss://openapi-quote.longportapp.com`

## API Request

调用服务端接口需要是用 HTTPS 协议,JSON 格式,并是用 `UTF-8` 编码。

测试接口示例如下:

```bash
curl -v https://openapi.longportapp.com/v1/test \
curl -i -v https://openapi.longbridge.xyz/v1/test \
-H "X-Api-Signature: {签名}" -H "X-Api-Key: {Appkey}" \
-H "Authorization: {AccessToken}" -H "X-Timestamp: 1539095200.123"
```

获取股票持仓接口是`GET`请求并需要传递参数,示例如下:
获取账户资产信息是 `GET` 请求并需要传递参数,示例如下:

```bash
curl -v https://openapi.longportapp.com/v1/asset/stock?symbol=700.HK&symbol=BABA.US \
curl -i -v https://openapi.longbridge.xyz/v1/whaleapi/asset/detail_info?currency=HKD&account_no=xxx \
-H "X-Api-Signature: {签名}" -H "X-Api-Key: {AppKey}" \
-H "Authorization: {AccessToken}" -H "X-Timestamp: 1539095200.123"
```

委托下单接口是`POST`请求并需要传递`Body`参数,示例如下:

```bash
curl -v -XPOST https://openapi.longportapp.com/v1/trade/order \
-d '{ "side": "Buy", symbol": "700.HK", "order_type": "LO", "submitted_price": "50", "submitted_quantity": "200", "time_in_force": "Day", remark": "Hello from Shell"}' \
curl -i -v -X POST https://openapi.longportapp.com/v1/whaleapi/trade/order \
-d '{ "side": "Buy", symbol": "700.HK", "order_type": "LO", "submitted_price": "50", "submitted_quantity": "200", "time_in_force": "Day", "remark": "Hello from Shell", "account_no": "xxx"}' \
-H "X-Api-Signature: {签名}" -H "X-Api-Key: {AppKey}" \
-H "Authorization: {AccessToken}" -H "X-Timestamp: 1539095200.123"
-H "Content-Type: application/json; charset=utf-8"
Expand Down Expand Up @@ -219,13 +206,13 @@ import hmac

# request 请求信息
# 请求方法
method = "POST"
method = "DELETE"
# 请求路径
uri = "/v1/trade/order/submit"
# 请求参数 如 member_id=1&account_channel=2
uri = "/v1/whalapi/trade/order"
# url query params
params = ""
# 请求 body
body = json.dumps({ "order_id": '683615454870679552' })
body = json.dumps({ "order_id": '683615454870679552', "account_no": 'xxx' })
# 请求头部信息
headers = {}
headers['X-Api-Key'] = '${app_key}'
Expand Down Expand Up @@ -255,7 +242,7 @@ def sign(method, uri, headers, params, body, secret):
headers['X-Api-Signature'] = sign(method, uri, headers, params, body, app_secret)

# 请求接口
response = requests.request(method, "https://openapi.longportapp.com" + uri + '?' + params, headers=headers, data=body)
response = requests.request(method, "https://openapi.longbridge.xyz" + uri + '?' + params, headers=headers, data=body)

print(response.text)

Expand Down
67 changes: 0 additions & 67 deletions api/getting-developed/refresh-token-api.md

This file was deleted.

Loading