From d9e2ecbd04851383cc0da0b83ec424d4de4e833b Mon Sep 17 00:00:00 2001 From: bingo Date: Tue, 5 Mar 2024 18:37:56 +0800 Subject: [PATCH] add --- .gitignore | 132 +++++++++++++++++++++++++++++++++++++++++++ coin_scan_binance.js | 65 +++++++++++++++++++++ package.json | 35 ++++++++++++ 3 files changed, 232 insertions(+) create mode 100644 .gitignore create mode 100644 coin_scan_binance.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ad237c --- /dev/null +++ b/.gitignore @@ -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.* diff --git a/coin_scan_binance.js b/coin_scan_binance.js new file mode 100644 index 0000000..277e1a4 --- /dev/null +++ b/coin_scan_binance.js @@ -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'); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..27fc4fa --- /dev/null +++ b/package.json @@ -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" + } +}