如何使用 Binance API 检索所有市场对的列表,例如 ETH/BTC?

How to retrieve a list of all market pairs like ETH/BTC using Binance API?

我正在从事一个与加密货币交易相关的项目,我需要 select 币安交易所的市场对,并且根据对的选择,我必须显示各种结果,例如当前价格、24 小时价格变化, 24 小时交易量和该市场对的最近 10 次交易历史。我浏览了 Binance Rest API Docs: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md ,但找不到可以帮助我检索市场对列表的端点。 有没有我不知道的文件?

谢谢。

您正在寻找 /exchangeInfo public 端点。

https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md 查看更多信息:

交换信息

GET /api/v1/exchangeInfo

当前交易所交易规则和交易品种信息

所有硬币对的结果 symbols 数组:

...
"symbols": [{
"symbol": "ETHBTC",
"status": "TRADING",
"baseAsset": "ETH",
"baseAssetPrecision": 8,
"quoteAsset": "BTC",
"quotePrecision": 8,
"orderTypes": [
  // These are defined in the `ENUM definitions` section under `Order types (orderTypes)`.
  // All orderTypes are optional.
],
"icebergAllowed": false,
"filters": [
  // There are defined in the `Filters` section.
  // All filters are optional.
]
}]
...

我认为为新开发者创建代币列表转储并放置在这里会更容易

["BTC","LTC","ETH","NEO","BNB","QTUM","EOS","SNT","BNT","GAS","BCC","USDT","HSR","OAX","DNT","MCO","ICN","ZRX","OMG","WTC","YOYO","LRC","TRX","SNGLS","STRAT","BQX","FUN","KNC","CDT","XVG","IOTA","SNM","LINK","CVC","TNT","REP","MDA","MTL","SALT","NULS","SUB","STX","MTH","ADX","ETC","ENG","ZEC","AST","GNT","DGD","BAT","DASH","POWR","BTG","REQ","XMR","EVX","VIB","ENJ","VEN","ARK","XRP","MOD","STORJ","KMD","RCN","EDO","DATA","DLT","MANA","PPT","RDN","GXS","AMB","ARN","BCPT","CND","GVT","POE","BTS","FUEL","XZC","QSP","LSK","BCD","TNB","ADA","LEND","XLM","CMT","WAVES","WABI","GTO","ICX","OST","ELF","AION","WINGS","BRD","NEBL","NAV","VIBE","LUN","TRIG","APPC","CHAT","RLC","INS","PIVX","IOST","STEEM","NANO","AE","VIA","BLZ","SYS","RPX","NCASH","POA","ONT","ZIL","STORM","XEM","WAN","WPR","QLC","GRS","CLOAK","LOOM","BCN","TUSD","ZEN","SKY","THETA","IOTX","QKC","AGI","NXS","SC","NPXS","KEY","NAS","MFT","DENT","IQ","ARDR","HOT","VET","DOCK","POLY","VTHO","ONG","PHX","HC","GO","PAX","RVN","DCR","USDC","MITH","BCHABC","BCHSV","REN","BTT","USDS","FET","TFUEL","CELR","MATIC","ATOM","PHB","ONE","FTM","BTCB","USDSB","CHZ","COS","ALGO","ERD","DOGE","BGBP","DUSK","ANKR","WIN","TUSDB","COCOS","PERL","TOMO","BUSD","BAND","BEAM","HBAR","XTZ","NGN","DGB","NKN","GBP","EUR","KAVA","RUB","UAH","ARPA","TRY","CTXC","AERGO","BCH","TROY","BRL","VITE","FTT","AUD","OGN","DREP","BULL","BEAR","ETHBULL","ETHBEAR","XRPBULL","XRPBEAR","EOSBULL","EOSBEAR","TCT","WRX","LTO","ZAR","MBL","COTI","BKRW","BNBBULL","BNBBEAR","HIVE","STPT","SOL","IDRT","CTSI","CHR","BTCUP","BTCDOWN","HNT","JST","FIO","BIDR","STMX","MDT","PNT","COMP","IRIS","MKR","SXP","SNX","DAI","ETHUP","ETHDOWN","ADAUP","ADADOWN","LINKUP","LINKDOWN","DOT","RUNE","BNBUP","BNBDOWN","XTZUP","XTZDOWN","AVA","BAL","YFI","SRM","ANT","CRV","SAND","OCEAN","NMR","LUNA","IDEX","RSR","PAXG","WNXM","TRB","EGLD","BZRX","WBTC","KSM","SUSHI","YFII","DIA","BEL","UMA","EOSUP","TRXUP","EOSDOWN","TRXDOWN","XRPUP","XRPDOWN","DOTUP","DOTDOWN","NBS","WING","SWRV","LTCUP","LTCDOWN","CREAM","UNI","OXT","SUN","AVAX","BURGER","BAKE","FLM","SCRT","XVS","CAKE","SPARTA","UNIUP","UNIDOWN","ALPHA","ORN","UTK","NEAR","VIDT","AAVE","FIL","SXPUP","SXPDOWN","INJ","FILDOWN","FILUP","YFIUP","YFIDOWN","CTK","EASY","AUDIO","BCHUP","BCHDOWN","BOT","AXS","AKRO","HARD","KP3R","RENBTC","SLP","STRAX","UNFI","CVP","BCHA","FOR","FRONT","ROSE","HEGIC","AAVEUP","AAVEDOWN","PROM","BETH","SKL","GLM","SUSD","COVER","GHST","SUSHIUP","SUSHIDOWN","XLMUP","XLMDOWN","DF","JUV","PSG","BVND","GRT","CELO","TWT","REEF","OG","ATM","ASR","1INCH","RIF","BTCST","TRU","DEXE","CKB","FIRO","LIT","PROS","VAI","SFP","FXS","DODO","AUCTION","UFT","ACM","PHA","TVK","BADGER","FIS","OM","POND","ALICE","DEGO","BIFI","LINA"]

只需将“报价”变量更改为您想要的报价资产即可。然后在启动脚本后,您将获得一个包含所有基础资产的“allTargets”文件

var request = require('request');
var fs = require('fs')
var quote="USDT"
var options = {
  'method': 'GET',
  'url': 'https://api.binance.com/api/v1/exchangeInfo',
  'headers': {
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  //console.log(JSON.parse(response.body));
  var symbols = JSON.parse(response.body).symbols
  var justUSDTpairs = symbols.map((x)=>{
    if(x.quoteAsset.includes(quote)){
      return x.baseAsset
    }
  }).filter((x)=>{if(x){return x}})
  fs.writeFileSync('allTargets',JSON.stringify(justUSDTpairs))
}); 

对于在谷歌搜索“binance api 交易对”后最终来到这里的 python 用户:

from binance.client import Client

api_key = "xxx"
api_secret = "xxx"

client = Client(api_key, api_secret)
exchange_info = client.get_exchange_info()
for s in exchange_info['symbols']:
    print(s['symbol'])

ETHBTC
LTCBTC
BNBBTC
NEOBTC
QTUMETH
EOSETH
SNTETH
BNTETH
...

使用 pandaspython-binance 在 python 中获取单个 DataFrame 中的所有信息:

from binance.client import Client
import pandas as pd

api_key = ''
api_secret = ''

client = Client(api_key, api_secret)
symbols = client.get_exchange_info()
i = 0
df = pd.DataFrame(columns=symbols[0].keys())
for sym in symbols:
    for key in sym.keys():
        df.at[i, key] = sym[key]
    i = i + 1


df
         symbol  ...     permissions
0        ETHBTC  ...  [SPOT, MARGIN]
1        LTCBTC  ...  [SPOT, MARGIN]
2        BNBBTC  ...  [SPOT, MARGIN]
3        NEOBTC  ...  [SPOT, MARGIN]
4       QTUMETH  ...          [SPOT]
         ...  ...             ...
1710  CHESSBUSD  ...          [SPOT]
1711  CHESSUSDT  ...          [SPOT]
1712     FTMAUD  ...          [SPOT]
1713     FTMBRL  ...          [SPOT]
1714   SCRTBUSD  ...          [SPOT]
[1715 rows x 17 columns]

然后你可以save it to excel如果你需要:

df.to_excel('binance.xlsx')
int symbol_toplam = jsonx[6].Size();

//for(int i = jsonx.Size()-1; i>=0; i--){

for (int y=0;y<=symbol_toplam;y++) {

//for(int t = 0;t<=0;t++) {

// symbols 6 

if ( jsonx[6][y][0].ToStr() != "" ) {

if ( jsonx[6][y][0].ToStr() == symbol_coin ) {

Print("Min Lot:",jsonx[6][y][0].ToStr(),"=",jsonx[6][y][21][1][3].ToStr());
min_lot=jsonx[6][y][21][1][3].ToDbl();
from binance.client import Client
import pandas as pd

client = Client('api_key', 'api_secret')

pairs = pd.DataFrame.from_dict(client.get_all_tickers())['symbol'].to_list()

pairs_sorted = pd.DataFrame.from_dict(client.get_all_tickers()).sort_values(by=['symbol'], ascending=True)['symbol'].to_list()

我想更新上面Emad提供的代码。

from binance.client import Client
import pandas as pd

api_key = 'Your Api Key'
api_secret = 'Your Secret Key'

client = Client(api_key, api_secret)
symbols = client.get_exchange_info()
df = pd.DataFrame(symbols['symbols'])

li = []

for index, data in df.iterrows():
    if data['isMarginTradingAllowed'] == True:
        li.append(data['symbol'])

fdf = pd.DataFrame(li)
fdf.to_excel('Margin Trading Pairs.xlsx', index=False)

我觉得这个publicAPI可以帮到你。

https://api3.binance.com/api/v3/ticker/price