Skip to content

Commit

Permalink
初始化文档
Browse files Browse the repository at this point in the history
  • Loading branch information
lestercx committed Jul 7, 2023
0 parents commit a1899c6
Show file tree
Hide file tree
Showing 19 changed files with 922 additions and 0 deletions.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Free Forex Market Data
Free Forex Quote API 免费的外汇贵金属行情API

简单好用的免费开源外汇贵金属行情API

## 功能特性:

- 免费开源

- 获取外汇实时行情

- 获取外汇实时多档盘口

- 获取外汇K线数据

- 获取贵金属实时行情

- 获取贵金属实时多档盘口

- 获取贵金属K线数据




## 接口介绍
- [接入指南](./接入指南.md)
- [错误码说明](./错误码说明.md)
- [code列表](./code列表.md)

### http接口
- [行情地址说明](./http接口/行情地址说明.md)
- [接口限制](./http接口/接口限制.md)
- [通用标准头](./http接口/通用标准头.md)
- [获取最新成交报价查询](./http接口/最新成交报价查询.md)
- [最新盘口报价查询](./http接口/最新盘口报价查询.md)
- [K线查询](./http接口/K线查询.md)

### websocket接口
- [行情地址说明](./websocket接口/行情地址说明.md)
- [接口限制](./websocket接口/接口限制.md)
- [通用标准头](./websocket接口/通用标准头.md)
- [心跳](./websocket接口/心跳.md)
- [成交报价订阅](./websocket接口/成交报价订阅.md)
- [盘口报价订阅](./websocket接口/盘口报价订阅.md)
- [取消报价订阅](./websocket接口/取消报价订阅.md)

## Python使用示例,超简单上手

- [http请求示例](./example/http_request.py)
- [websocket请求示例](./example/websocket_request.py)




## 联系我们

- Telegram: https://t.me/ts_support_erik

## 其他作品

22 changes: 22 additions & 0 deletions code列表.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 目前支持如下code

## 目前支持如下外汇和贵金属代码,需要新增产品可直接联系<br/>
姓名:erik wang<br/>
邮箱:[email protected]<br/>
Telegram: https://t.me/ts_support_erik<br/>

| 类别 | name | code |
| --- | --- | --- |
| 外汇 | GBP/JPY | GBPJPY |
| 外汇 | CAD/JPY | CADJPY |
| 外汇 | GBP/CAD | GBPCAD |
| 外汇 | CAD/CHF | CADCHF |
| 外汇 | USD/JPY | USDJPY |
| 外汇 | EUR/CAD | EURCAD |
| 外汇 | CHF/JPY | CHFJPY |
| 外汇 | EUR/CHF | EURCHF |
| 外汇 | EUR/JPY | EURJPY |
| 外汇 | GBP/CHF | GBPCHF |
| 外汇 | USD/CHF | USDCHF |
| 能源 | UKOIL | UKOIL |
| 贵金属 | GOLD | GOLD |
21 changes: 21 additions & 0 deletions example/http_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import requests # pip3 install requests
import json

# 将如下字段信息进行url的encode,复制到url的查询字符串的query里
"""
{"trace":"3baaa938-f92c-4a74-a228-fd49d5e2f8bc-1678419657806","data":{"code":"USDJPY","kline_type":1,"kline_timestamp_end":0,"query_kline_num":2,"adjust_type":0}}
"""

# Base URL being accessed
test_url = 'https://quote.aatest.online/quote-b-api/kline?token=3662a972-1a5d-4bb1-88b4-66ca0c402a03-1688712831841&query=%7B%22trace%22%3A%223baaa938-f92c-4a74-a228-fd49d5e2f8bc-1678419657806%22%2C%22data%22%3A%7B%22code%22%3A%22USDJPY%22%2C%22kline_type%22%3A1%2C%22kline_timestamp_end%22%3A0%2C%22query_kline_num%22%3A2%2C%22adjust_type%22%3A0%7D%7D'

# Extra headers
test_headers = {
'Content-Type' : 'application/json'
}

resp = requests.get(url=test_url, headers=test_headers)

# Decoded text returned by the request
text = resp.text
print(text)
93 changes: 93 additions & 0 deletions example/websocket_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import json
import websocket # pip install websocket-client

class Feed(object):

def __init__(self):
self.url = 'wss://quote.aatest.online/quote-b-ws-api?token=3662a972-1a5d-4bb1-88b4-66ca0c402a03-1688712831841' # 这里输入websocket的url
self.ws = None

def on_open(self, ws):
"""
Callback object which is called at opening websocket.
1 argument:
@ ws: the WebSocketApp object
"""
print('A new WebSocketApp is opened!')

# 开始订阅(举个例子)
sub_param = {
"cmd_id": 22002,
"seq_id": 123,
"trace":"3baaa938-f92c-4a74-a228-fd49d5e2f8bc-1678419657806",
"data":{
"symbol_list":[
{
"code": "USDJPY",
"depth_level": 5,
},
{
"code": "GBPUSD",
"depth_level": 5,
}
]
}
}
sub_str = json.dumps(sub_param)
ws.send(sub_str)
print("depth quote are subscribed!")

def on_data(self, ws, string, type, continue_flag):
"""
4 argument.
The 1st argument is this class object.
The 2nd argument is utf-8 string which we get from the server.
The 3rd argument is data type. ABNF.OPCODE_TEXT or ABNF.OPCODE_BINARY will be came.
The 4th argument is continue flag. If 0, the data continue
"""

def on_message(self, ws, message):
"""
Callback object which is called when received data.
2 arguments:
@ ws: the WebSocketApp object
@ message: utf-8 data received from the server
"""
# 对收到的message进行解析
result = eval(message)
print(result)

def on_error(self, ws, error):
"""
Callback object which is called when got an error.
2 arguments:
@ ws: the WebSocketApp object
@ error: exception object
"""
print(error)

def on_close(self, ws, close_status_code, close_msg):
"""
Callback object which is called when the connection is closed.
2 arguments:
@ ws: the WebSocketApp object
@ close_status_code
@ close_msg
"""
print('The connection is closed!')

def start(self):
self.ws = websocket.WebSocketApp(
self.url,
on_open=self.on_open,
on_message=self.on_message,
on_data=self.on_data,
on_error=self.on_error,
on_close=self.on_close,
)
self.ws.run_forever()


if __name__ == "__main__":
feed = Feed()
feed.start()
101 changes: 101 additions & 0 deletions http接口/K线查询.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
## GET K线查询

GET /quote-b-api/kline

### 请求参数

| 名称 | 位置 | 类型 | 必选 | 说明 |
| ---------------------- | ----- | ------- | ---- | ------------------------------------------------------------ |
| token | query | string || |
| query | query | string || 查看query请求参数说明 |

> query 请求参数
将如下json进行UrlEncode编码,赋值到url的查询字符串的query里
```json
{
"trace": "3baaa938-f92c-4a74-a228-fd49d5e2f8bc-1678419657806",
"data": {
"code": "USDJPY",
"kline_type": 1,
"kline_timestamp_end": 0,
"query_kline_num": 2,
"adjust_type": 0
}
}
```

### query请求参数

| 名称 | 类型 | 必选 | 说明 |
| ---------------------- | ------- | ---- | ------------------------------------------------------------ |
| trace | string || 追踪码,用来查询日志使用,请保证每次请求时唯一 |
| data | object || |
| » code | string || 请查看code列表,选择你要查询的code |
| » kline_type | integer || k线类型,1分钟K,2为5分钟K,3为15分钟K,4为30分钟K,5为小时K,6为2小时K,7为4小时K,8为日K,9为周K,10为月K |
| » kline_timestamp_end | integer || 从那个时间点往前查,为0表示从当前时间,默认为0 |
| » query_kline_num | integer || 查询多少根K线,最多1000根 |
| » adjust_type | integer || 复权类型,对于股票类的code才有效,例如:0:除权,1:前复权 |

> 返回示例
> OK
```json
{
"ret": 200,
"msg": "ok",
"trace": "3baaa938-f92c-4a74-a228-fd49d5e2f8bc",
"data": {
"code": "USDJPY",
"kline_type": 1,
"kline_list": [
{
"timestamp": "1677829200",
"open_price": "136.421",
"close_price": "136.412",
"high_price": "136.422",
"low_price": "136.407",
"volume": "0",
"turnover": "0"
},
{
"timestamp": "1677829260",
"open_price": "136.412",
"close_price": "136.401",
"high_price": "136.415",
"low_price": "136.397",
"volume": "0",
"turnover": "0"
}
]
}
}
```

### 返回结果

| 状态码 | 状态码含义 | 说明 | 数据模型 |
| ------ | ------------------------------------------------------- | ---- | -------- |
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | Inline |

### 返回数据结构

状态码 **200**

| 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
| --------------- | -------- | ---- | ---- | ------ | ------------------------------------------------------------ |
| » ret | integer | true | | | |
| » msg | string | true | | | |
| » trace | string | true | | | |
| » data | object | true | | | |
| »» code | string | true | | | 代码 |
| »» kline_type | integer | true | | | k线类型,1分钟K,2为5分钟K,3为15分钟K,4为30分钟K,5为小时K,6为2小时K,7为4小时K,8为日K,9为周K,10为月K |
| »» kline_list | [object] | true | | | |
| »»» timestamp | string | true | | | 该K线时间戳 |
| »»» open_price | string | true | | | 该K线开盘价 |
| »»» close_price | string | true | | | 该K线收盘价 |
| »»» high_price | string | true | | | 该K线最高价 |
| »»» low_price | string | true | | | 该K线最低价 |
| »»» volume | string | true | | | 该K线成交数量 |
| »»» turnover | string | true | | | 该K线成交金额 |
20 changes: 20 additions & 0 deletions http接口/接口限制.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# http接口限制

## http接口限制1-IP类限制
相同IP的多次请求,按接口确定具体次数限制,互不影响

- /kline 每10秒只能请求1次
- /depth-tick 每秒只能请求1次
- /trade-tick 每秒只能请求1次
### 举例:
- IP为A,调用/kline接口查询K线,14:03:01请求了1次,并且它也在这一分钟调用了/trade-tick接口查询成交报价1次,后台服务都能正常提供服务
- IP为A,调用/kline接口查询K线,14:03:01请求了2次,前1次后台服务都能正常提供服务,最后1次给出错误回应

## http接口限制2-连接数限制
为避免过多请求对于后台服务造成过大压力,最大连接数限制在100个,视后续服务运行表现再进行调节,超过限制的请求,直接会断开连接

## http接口限制3-K线查询限制
一次只能查询1个code的K线,一次最多只能查询1000根K线,对于查询超过1000根以上的,则按1000根来进行查询

## http接口限制4-报价查询限制
一次查询,最多只能查询5个code,对于查询超过5个以上的,则按5个来查询
Loading

0 comments on commit a1899c6

Please sign in to comment.