init: CryptoCoin desktop ticker

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-23 21:57:39 +08:00
commit 3b979089d9
69 changed files with 8974 additions and 0 deletions

View File

@@ -0,0 +1,158 @@
# CryptoCoin 币安 API 代理Cloudflare Worker
当本机无法直连 `api.binance.com` 时,可通过此 Worker 转发行情请求。
## 部署
1. 安装 [Node.js](https://nodejs.org/) 与 Cloudflare 账号
2. 在本目录执行:
```bash
npm install
npx wrangler login
npm run deploy
```
3. 记下部署后的地址,例如:
```
https://cryptocoin-binance-proxy.你的用户名.workers.dev
```
4. 在 CryptoCoin 中配置(二选一):
**方式 A托盘菜单**
- 托盘右键 → **行情源** → 带 **✓** 的项为当前模式
- **CF Worker 代理** 需在设置文件中已填写 `proxyBaseUrl`
-**直连** 不会删除已保存的代理地址
**方式 B编辑设置文件**
路径(与 **CryptoCoin.exe** 同级的 `data` 目录):
```
D:\WindowsApp\CryptoCoin\data\settings.json
```
代理模式:
```json
{
"enabled": ["BTCUSDT", "ETHUSDT"],
"proxyBaseUrl": "https://cryptocoin-binance-proxy.你的用户名.workers.dev",
"useProxy": true,
"refreshIntervalMs": 5000
}
```
直连模式:
```json
{
"enabled": ["BTCUSDT", "ETHUSDT"],
"proxyBaseUrl": "https://cryptocoin-binance-proxy.你的用户名.workers.dev",
"useProxy": false,
"refreshIntervalMs": 5000
}
```
`refreshIntervalMs` 可选值毫秒3000、5000、10000、30000、60000、180000、300000、600000也可在托盘 **刷新间隔** 中切换。
改完后重启应用,或在托盘切换一次「直连 / 代理」。
**Release 用户**:修改代码后需执行 `npm run tauri build` 并重新安装,否则仍为旧版行为。
## 接口说明
- `GET /health` — 健康检查
- `GET /api/v3/ticker/24hr?symbols=...` — 转发至币安同名接口
仅允许 `/api/` 路径,其它路径返回 404。
## 本地调试
```bash
npm run dev
```
默认 `http://127.0.0.1:8787`,可浏览器访问 `/health` 验证。

View File

@@ -0,0 +1,12 @@
{
"name": "cryptocoin-binance-proxy",
"private": true,
"version": "1.0.0",
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev"
},
"devDependencies": {
"wrangler": "^4.0.0"
}
}

View File

@@ -0,0 +1,69 @@
/**
* CryptoCoin Binance API 反向代理
* 将 /api/v3/... 转发到 https://api.binance.com/api/v3/...
*/
const BINANCE_ORIGIN = "https://api.binance.com";
const ALLOWED_PREFIX = "/api/";
export default {
async fetch(request) {
if (request.method === "OPTIONS") {
return cors(new Response(null, { status: 204 }));
}
const url = new URL(request.url);
if (url.pathname === "/" || url.pathname === "/health") {
return cors(
new Response(JSON.stringify({ ok: true, service: "cryptocoin-binance-proxy" }), {
headers: { "content-type": "application/json" },
}),
);
}
if (!url.pathname.startsWith(ALLOWED_PREFIX)) {
return cors(new Response("Not Found", { status: 404 }));
}
const target = `${BINANCE_ORIGIN}${url.pathname}${url.search}`;
try {
const upstream = await fetch(target, {
method: request.method,
headers: {
"User-Agent": "CryptoCoin-Widget/1.0",
Accept: "application/json",
},
});
const body = await upstream.arrayBuffer();
const headers = new Headers(upstream.headers);
headers.set("access-control-allow-origin", "*");
return new Response(body, {
status: upstream.status,
statusText: upstream.statusText,
headers,
});
} catch (err) {
return cors(
new Response(JSON.stringify({ error: String(err) }), {
status: 502,
headers: { "content-type": "application/json" },
}),
);
}
},
};
function cors(response) {
const headers = new Headers(response.headers);
headers.set("access-control-allow-origin", "*");
headers.set("access-control-allow-methods", "GET, OPTIONS");
headers.set("access-control-allow-headers", "Content-Type");
return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers,
});
}

View File

@@ -0,0 +1,6 @@
name = "cryptocoin-binance-proxy"
main = "src/index.js"
compatibility_date = "2024-08-01"
# 部署后得到地址类似: https://cryptocoin-binance-proxy.<你的子域>.workers.dev
# 填入应用设置 proxyBaseUrl不要末尾斜杠