Methods
(async) downloadData(endpoint, symbol, timeStart, timeEnd, interval, optopt) → {Promise}
- Description:
下載指定時間區間內的 K 線數據(Kline),並可選擇轉為 CSV 格式輸出。
- Source:
Example
import WDwdataBinace from './src/WDwdataBinace.mjs'
function test() {
//wdd
let wdd = WDwdataBinace()
//BTC
let name = 'BTC'
//price
let type = 'price'
//幣安API的klines
let endpoint = 'https://api.binance.com/api/v3/klines'
//BTCUSDT交易對
let symbol = 'BTCUSDT'
//p
let p = wdd.syncData(name, type, endpoint, symbol, { useShowLog: true })
//run
p.run()
}
test()
//get BTC price ts[2020-01-02T11:00:00] -> te[2020-01-02T11:59:59] downloading...
//get BTC price ts[2020-01-02T11:00:00] -> te[2020-01-02T11:59:59] finish
//get BTC price ts[2020-01-02T12:00:00] -> te[2020-01-02T12:59:59] downloading...
//get BTC price ts[2020-01-02T12:00:00] -> te[2020-01-02T12:59:59] finish
//get BTC price ts[2020-01-02T13:00:00] -> te[2020-01-02T13:59:59] downloading...
//continuing...
Parameters:
| Name | Type | Attributes | Default | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
endpoint |
string | API 端點 URL,例如 'https://api.binance.com/api/v3/klines' |
|||||||||||||||||
symbol |
string | 幣種對,例如 'BTCUSDT' |
|||||||||||||||||
timeStart |
string | 開始時間,格式為 'YYYY-MM-DDTHH:mm:ss' |
|||||||||||||||||
timeEnd |
string | 結束時間,格式為 'YYYY-MM-DDTHH:mm:ss' |
|||||||||||||||||
interval |
string | K 線資料間隔時間,例如 '1m', '5m', '1h' 等 |
|||||||||||||||||
opt |
Object |
<optional> |
{}
|
可選參數設定 Properties
|
Returns:
回傳Promise,resolve回傳解析後的 K 線資料陣列,或轉為 CSV 字串(依 useConvertToCsv 而定),reject回傳錯誤訊息
- Type
- Promise
(async) saveData(name, type, endpoint, symbol, interval, optopt) → {Promise}
- Description:
根據指定的時間範圍與設定,自動抓取並儲存指定時長的幣種 K 線資料(Kline)。 若該小時已存在資料檔,且完整,則跳過;否則會下載並儲存成 CSV 檔。
- Source:
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name |
String | 資料名稱分類,例如幣種代號(如 BTC) |
||||||||||||||||||||||||||||||||
type |
String | 資料類型分類,例如 'spot', 'future' 等 |
||||||||||||||||||||||||||||||||
endpoint |
String | 資料 API 端點(例如幣安的 K 線 API) |
||||||||||||||||||||||||||||||||
symbol |
String | 幣種交易對,例如 'BTCUSDT' |
||||||||||||||||||||||||||||||||
interval |
String | K 線間隔(如 '1m', '1h' 等) |
||||||||||||||||||||||||||||||||
opt |
Object |
<optional> |
{}
|
可選設定參數 Properties
|
Returns:
回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
- Type
- Promise
syncData(name, type, endpoint, symbol, optopt) → {Object|function|function}
- Description:
建立一個定時同步資料的任務,定期呼叫 saveData 以抓取與儲存幣種 K 線資料。 可啟動與停止,適合作為長時間後台資料同步機制。
- Source:
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name |
string | 資料名稱分類,例如幣種(如 BTC) |
||||||||||||||||||||||||||||||||||||||||||
type |
string | 資料類型分類,例如 'spot', 'future' 等 |
||||||||||||||||||||||||||||||||||||||||||
endpoint |
string | 資料來源 API 的網址(如 Binance K 線 API) |
||||||||||||||||||||||||||||||||||||||||||
symbol |
string | 幣種交易對(如 'BTCUSDT') |
||||||||||||||||||||||||||||||||||||||||||
opt |
Object |
<optional> |
{}
|
可選設定參數 Properties
|
Returns:
-
返回一個控制物件,包含:
- Type
- Object
-
return.run 啟動同步任務
- Type
- function
-
return.stop 停止同步任務
- Type
- function