forked from moncici007/binance
-
Notifications
You must be signed in to change notification settings - Fork 0
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
bingo
authored and
bingo
committed
Mar 5, 2024
0 parents
commit d9e2ecb
Showing
3 changed files
with
232 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,132 @@ | ||
package-lock.json | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
web_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
.stylelintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
.temp | ||
.cache | ||
|
||
# Docusaurus cache and generated files | ||
.docusaurus | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
|
||
# yarn v2 | ||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* |
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,65 @@ | ||
import axios from 'axios'; | ||
import { axiosConfig } from '@moncici/proxy'; | ||
import { sleep } from '@moncici/sleep'; | ||
import { formatTimestamp } from '@moncici/date-time-processor'; | ||
import { notify } from 'feishu-notifier' | ||
|
||
const retryDuration = 1000; | ||
|
||
export async function getPricesByCoins(symbols) { | ||
const url = `https://api.binance.com/api/v3/ticker/price?symbols=[${symbols}]`; | ||
|
||
try { | ||
const response = await axios.get(url, axiosConfig); | ||
if (response.status == 429) { | ||
sleep(retryDuration); | ||
} | ||
const data = response.data; | ||
console.log(`${formatTimestamp(new Date())} ${symbols} 实时价格:`, response.data); | ||
notify('', data); | ||
return data | ||
} catch(error) { | ||
console.error(`无法获取 ${symbols} USD 价格:`, error.response.data); | ||
notify('', error.response.data); | ||
throw error; // 将错误向上抛出 | ||
} | ||
} | ||
|
||
export async function getPriceByCoin(symbol) { | ||
const url = `https://api.binance.com/api/v3/ticker/price?symbol=${symbol}`; | ||
|
||
try { | ||
const response = await axios.get(url, axiosConfig); | ||
if (response.status == 429) { | ||
sleep(retryDuration); | ||
} | ||
const data = response.data; | ||
console.log(`${symbol} 实时价格:`, response.data); | ||
return data | ||
} catch(error) { | ||
console.error(`无法获取 ${symbol} USD 价格:`, error.response.data); | ||
throw error; // 将错误向上抛出 | ||
} | ||
} | ||
|
||
// https://api.binance.com/api/v3/klines?interval=1m&limit=3&symbol=BTCUSDT | ||
export async function getKlines(symbol) { | ||
const url = `https://api.binance.com/api/v3/klines?interval=5m&limit=3&symbol=${symbol}`; | ||
console.log(url); | ||
|
||
try { | ||
const response = await axios.get(url, axiosConfig); | ||
if (response.status == 429) { | ||
sleep(retryDuration); | ||
} | ||
const data = response.data; | ||
// console.log(`${symbol} 实时价格:`, response.data); | ||
return data | ||
} catch(error) { | ||
console.error(`无法获取 ${symbol} USD 价格:`, error.response.data); | ||
throw error; // 将错误向上抛出 | ||
} | ||
} | ||
|
||
// getPricesByCoins(`"BTCUSDT","ETHUSDT","AVAXUSDT","ARBUSDT","LINKUSDT","MATICUSDT","OPUSDT","SOLUSDT"`); | ||
// getPriceByCoin('ETHUSDT'); |
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,35 @@ | ||
{ | ||
"name": "@moncici/binance", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "coin_scan_binance.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/moncici007/binance" | ||
}, | ||
"website": "https://github.com/moncici007/binance.git", | ||
"keywords": [ | ||
"binance", | ||
"client", | ||
"arbitrim" | ||
], | ||
"author": "moncici007", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/moncici007/binance/issues" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org" | ||
}, | ||
"homepage": "https://github.com/moncici007/binance#readme", | ||
"dependencies": { | ||
"@moncici/date-time-processor": "^1.0.3", | ||
"@moncici/proxy": "^1.0.1", | ||
"@moncici/sleep": "^1.0.0", | ||
"feishu-notifier": "^1.0.2" | ||
} | ||
} |