-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ee407e4
Showing
35 changed files
with
1,792 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# 免费开源股票API、港股API、美股API、沪深股票API、A股API实时股票行情数据 | ||
|
||
简单好用易上手的免费开源股票API、港股API、美股API、沪深股票API、A股API、外汇API、商品贵金属API、加密货币API等实时行情数据 | ||
|
||
## 功能特性: | ||
|
||
- 免费开源 | ||
|
||
- 获取港股实时行情API | ||
|
||
- 获取港股实时10档盘口API | ||
|
||
- 获取港股K线数据API | ||
|
||
- 获取美股实时行情API | ||
|
||
- 获取美股实时一档盘口API | ||
|
||
- 获取美股K线数据API | ||
|
||
- 获取沪深A股实时行情API | ||
|
||
- 获取沪深A股实时5档盘口API | ||
|
||
- 获取沪深A股K线数据API | ||
|
||
- 获取加密货币实时行情API | ||
|
||
- 获取加密货币实时多档盘口API | ||
|
||
- 获取加密货币K线数据API | ||
|
||
- 获取外汇实时行情API | ||
|
||
- 获取外汇实时5档盘口API | ||
|
||
- 获取外汇K线数据API | ||
|
||
- 获取贵金属实时行情API | ||
|
||
- 获取贵金属实时5档盘口API | ||
|
||
- 获取贵金属K线数据API | ||
|
||
|
||
|
||
|
||
## 接口介绍 | ||
- [接入指南](./接入指南.md) | ||
- [错误码说明](./错误码说明.md) | ||
- [产品code列表-A股](./产品code列表-A股.md) | ||
- [产品code列表-港股](./产品code列表-港股.md) | ||
- [产品code列表-加密货币(数字币)](./产品code列表-加密货币(数字币).md) | ||
- [产品code列表-美股](./产品code列表-美股.md) | ||
- [产品code列表-商品(贵金属)](./产品code列表-商品(贵金属).md) | ||
- [产品code列表-外汇](./产品code列表-外汇.md) | ||
|
||
### http接口 | ||
- [行情API地址说明](./http接口/API地址说明.md) | ||
- [接口限制](./http接口/接口限制.md) | ||
- [通用标准头](./http接口/通用标准头.md) | ||
- [获取最新成交报价查询](./http接口/最新成交报价查询.md) | ||
- [最新盘口报价查询](./http接口/最新盘口报价查询.md) | ||
- [K线查询](./http接口/K线查询.md) | ||
- [批量K线查询](./http接口/批量K线查询.md) | ||
|
||
### websocket接口 | ||
- [行情API地址说明](./websocket接口/API地址说明.md) | ||
- [接口限制](./websocket接口/接口限制.md) | ||
- [通用标准头](./websocket接口/通用标准头.md) | ||
- [心跳](./websocket接口/心跳.md) | ||
- [成交报价订阅](./websocket接口/成交报价订阅.md) | ||
- [盘口报价订阅](./websocket接口/盘口报价订阅.md) | ||
- [取消报价订阅](./websocket接口/取消报价订阅.md) | ||
|
||
## 免费token获取 | ||
- [token申请](./token申请.md) | ||
|
||
## 使用示例,超简单上手 | ||
### php: | ||
|
||
- [http请求示例](./example/php/php_http_curl.php) | ||
- [websocket请求示例](./example/php/php_websocket_workerman.php) | ||
|
||
### python: | ||
|
||
- [http请求示例](./example/python/http_python_example.py) | ||
- [websocket请求示例](./example/python/websocket_python_example.py) | ||
|
||
### go: | ||
- [http请求示例](./example/go/http_go_example.go) | ||
- [websocket请求示例](./example/go/websocket_go_example.go) | ||
|
||
### java: | ||
- [http请求示例](./example/java/HttpJavaExample.java) | ||
- [websocket请求示例](./example/java/WebSocketJavaExample.java) | ||
|
||
|
||
## 联系我们 | ||
|
||
- Telegram: https://t.me/TS_SUPPORT_Lester | ||
- Email: lester.lin@chixi88.com | ||
|
||
## 其他作品 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module go_example | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/google/uuid v1.6.0 | ||
github.com/gorilla/websocket v1.5.0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= | ||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"strings" | ||
"io/ioutil" | ||
"net/http" | ||
) | ||
|
||
func http_example() { | ||
|
||
/* | ||
将如下JSON进行url的encode,复制到http的查询字符串的query字段里 | ||
{"trace" : "go_http_test1","data" : {"code" : "700.HK","kline_type" : 1,"kline_timestamp_end" : 0,"query_kline_num" : 2,"adjust_type": 0}} | ||
特别注意: | ||
github: https://github.com/alltick/free-quote | ||
token申请:https://alltick.co | ||
把下面url中的testtoken替换为您自己的token | ||
外汇,加密货币(数字币),贵金属的api址: | ||
https://quote.tradeswitcher.com/quote-b-api | ||
股票api地址: | ||
https://quote.tradeswitcher.com/quote-stock-b-api | ||
*/ | ||
url := "https://quote.tradeswitcher.com/quote-stock-b-api/batch-kline?token=testtoken" | ||
log.Println("请求内容:", url) | ||
// 创建一个http.Client对象 | ||
client := &http.Client{} | ||
|
||
body := strings.NewReader(`{"trace": "3380a7a-3e1f-c3a5-5ee3-9e5be0ec8c241692805461","data": {"data_list": [ | ||
{"code": "700.HK","kline_type": 1,"kline_timestamp_end": 0,"query_kline_num": 1000,"adjust_type": 0}, | ||
{"code": "USDJPY","kline_type": 1,"kline_timestamp_end": 0,"query_kline_num": 1000,"adjust_type": 0}, | ||
{"code": "AAPL.US","kline_type": 1,"kline_timestamp_end": 0,"query_kline_num": 1000,"adjust_type": 0}, | ||
{"code": "GOLD","kline_type": 1,"kline_timestamp_end": 0,"query_kline_num": 1000,"adjust_type": 0} | ||
]}}`) // 请求body | ||
|
||
req, err := http.NewRequest("GET", url, body) | ||
if err != nil { | ||
fmt.Println("Error creating request:", err) | ||
return | ||
} | ||
|
||
// 发送请求 | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
fmt.Println("Error sending request:", err) | ||
return | ||
} | ||
defer resp.Body.Close() | ||
|
||
body2, err := ioutil.ReadAll(resp.Body) | ||
|
||
if err != nil { | ||
|
||
log.Println("读取响应失败:", err) | ||
|
||
return | ||
|
||
} | ||
|
||
log.Println("响应内容:", len(body2)) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package main | ||
|
||
func main(){ | ||
//for { | ||
// go http_example() | ||
// time.Sleep(time.Millisecond*10000) | ||
//} | ||
|
||
//time.Sleep(time.Second*1000000) | ||
websocket_example() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/google/uuid" | ||
"github.com/gorilla/websocket" | ||
"log" | ||
"time" | ||
) | ||
|
||
type Symbol struct { | ||
Code string `json:"code"` | ||
DepthLevel int `json:"depth_level"` | ||
} | ||
|
||
type Data struct { | ||
SymbolList []Symbol `json:"symbol_list"` | ||
} | ||
|
||
type Request struct { | ||
CmdID int `json:"cmd_id"` | ||
SeqID int `json:"seq_id"` | ||
Trace string `json:"trace"` | ||
Data Data `json:"data"` | ||
} | ||
|
||
/* | ||
特别注意: | ||
github: https://github.com/alltick/free-quote | ||
token申请:https://alltick.co | ||
把下面url中的testtoken替换为您自己的token | ||
外汇,加密货币(数字币),贵金属的api址: | ||
wss://quote.tradeswitcher.com/quote-b-ws-api | ||
股票api地址: | ||
wss://quote.tradeswitcher.com/quote-stock-b-ws-api | ||
*/ | ||
const( | ||
url ="wss://quote.tradeswitcher.com/quote-b-ws-api?token=testtoken" | ||
) | ||
|
||
func websocket_example() { | ||
|
||
log.Println("Connecting to server at", url) | ||
|
||
c, _, err := websocket.DefaultDialer.Dial(url, nil) | ||
if err != nil { | ||
log.Fatal("dial:", err) | ||
} | ||
defer c.Close() | ||
|
||
//定时10秒发一次心跳 | ||
go func() { | ||
for range time.NewTicker(10*time.Second).C{ | ||
req := Request{ | ||
CmdID: 22000, | ||
SeqID: 123, | ||
Trace: "3380a7a-3e1f-c3a5-5ee3-9e5be0ec8c241692805462", | ||
Data: Data{}, | ||
} | ||
messageBytes, err := json.Marshal(req) | ||
if err != nil { | ||
log.Println("json.Marshal error:", err) | ||
return | ||
} | ||
log.Println("req data:", string(messageBytes)) | ||
|
||
err = c.WriteMessage(websocket.TextMessage, messageBytes) | ||
if err != nil { | ||
log.Println("write:", err) | ||
} | ||
} | ||
}() | ||
|
||
req := Request{ | ||
CmdID: 22002, | ||
SeqID: 123, | ||
Trace: uuid.New().String(), | ||
Data: Data{SymbolList: []Symbol{ | ||
{"GOLD",5}, | ||
{"AAPL.US",5}, | ||
{"700.HK",5}, | ||
{"USDJPY",5}, | ||
}}, | ||
} | ||
messageBytes, err := json.Marshal(req) | ||
if err != nil { | ||
log.Println("json.Marshal error:", err) | ||
return | ||
} | ||
log.Println("req data:", string(messageBytes)) | ||
|
||
err = c.WriteMessage(websocket.TextMessage, messageBytes) | ||
if err != nil { | ||
log.Println("write:", err) | ||
} | ||
|
||
req.CmdID = 22004 | ||
messageBytes, err = json.Marshal(req) | ||
if err != nil { | ||
log.Println("json.Marshal error:", err) | ||
return | ||
} | ||
log.Println("req data:", string(messageBytes)) | ||
|
||
err = c.WriteMessage(websocket.TextMessage, messageBytes) | ||
if err != nil { | ||
log.Println("write:", err) | ||
} | ||
|
||
rece_count := 0 | ||
for{ | ||
_, message, err := c.ReadMessage() | ||
|
||
if err != nil { | ||
log.Println("read:", err) | ||
break | ||
} else { | ||
log.Println("Received message:", string(message)) | ||
} | ||
|
||
rece_count++ | ||
if rece_count % 10000 == 0 { | ||
log.Println("count:", rece_count, " Received message:", string(message)) | ||
} | ||
} | ||
|
||
|
||
} | ||
|
Oops, something went wrong.