Closed Snickerrr closed 3 years ago
Please, paste your code and verbose request+response (switch to verbose mode as documented):
If you do the above – from there it should be obvious what exactly is happening.
Thanks for the reply.
Here's is the code I just made to show the problem. I started coding JS a month or so ago so I know my code isn't the cleanest. I couldn't get it compacter then this. You shouldn't run it longer then 10 seconds or so or you get rate limited.
const ccxt = require('ccxt');
let binance = new ccxt.binance({
enableRateLimit: false, // Yes I don't use the build in rate limiter
});
const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
async function getSymbols() {
await binance.loadMarkets();
binance.verbose = true;
let symbols = binance.symbols
await sleep(1000);
priceandLog(symbols);
}
async function priceandLog(symbols) {
symbols.forEach(async function(item) {
let market = binance.market (item);
let price = await binance.fetchTicker(item);
console.log(item + " " + market.precision.price + " " + price.ask);
if (price.ask === 0) {
console.log("Hmmmm, why does the above pair have a precision but no price?");
}
})
}
getSymbols();
What it supposed to do is first load the markets, then send the symbols of all the markets on the exchange to a function which for each of the symbols asks the information about the market and the price.
The first few symbols where it fetches the ticker for returns this:
fetch:
binance GET https://api.binance.com/api/v3/ticker/24hr?symbol=ZRXBNB
Request:
{}
undefined
after that it returns markets where it can fetch the tickers from. But sometimes it will return information like this:
handleRestResponse:
binance GET https://api.binance.com/api/v3/ticker/24hr?symbol=AAVEBKRW 200 OK
Response:
{
'Access-Control-Allow-Methods': 'GET, HEAD, OPTIONS',
'Access-Control-Allow-Origin': '*',
'Cache-Control': 'no-cache, no-store, must-revalidate',
Connection: 'keep-alive',
'Content-Encoding': 'gzip',
'Content-Length': '228',
'Content-Security-Policy': "default-src 'self'",
'Content-Type': 'application/json;charset=UTF-8',
Date: 'Sun, 11 Apr 2021 10:24:38 GMT',
Expires: '0',
Pragma: 'no-cache',
Server: 'nginx',
'Strict-Transport-Security': 'max-age=31536000; includeSubdomains',
Via: '1.1 9bd09ac7aca1ea8ca6c788136a9ce480.cloudfront.net (CloudFront)',
'X-Amz-Cf-Id': 'GaepagySfMgLEIeB95yG8atFs5FQTcKLevAEbnwz31ai3085EB_YmQ==',
'X-Amz-Cf-Pop': 'AMS50-C1',
'X-Cache': 'Miss from cloudfront',
'X-Content-Security-Policy': "default-src 'self'",
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'SAMEORIGIN',
'X-Mbx-Used-Weight': '39',
'X-Mbx-Used-Weight-1m': '39',
'X-Mbx-Uuid': '08670440-0b40-474a-a30b-77710d63ef7f',
'X-Webkit-Csp': "default-src 'self'",
'X-Xss-Protection': '1; mode=block'
}
{"symbol":"AAVEBKRW","priceChange":"0.00000000","priceChangePercent":"0.000","weightedAvgPrice":"164167.00000000","prevClosePrice":"164167.00000000","lastPrice":"164167.00000000","lastQty":"0.00700000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"0.00000000","askQty":"0.00000000","openPrice":"164167.00000000","highPrice":"164167.00000000","lowPrice":"164167.00000000","volume":"0.00700000","quoteVolume":"1149.16900000","openTime":1617241339533,"closeTime":1617327739533,"firstId":23191,"lastId":23191,"count":1}
AAVE/BKRW 0 0
Hmmmm, why does the above pair have a precision but no price?
The markets doesn't have any prices or quantities. The closeTime is a date before today. It looks like it just isn't updating. What's wrong in my code?
@Snickerrr nothing is wrong with your code, some idle markets can have zero values, if there's no liquidity there. You might want to ask binance about it, cause the data you posted above is served to you from binance directly (it's literally the response from binance as is).
Documented here: https://github.com/ccxt/ccxt/wiki/Manual#ticker-structure
Here's my output, it's the same:
~/ccxt $ node examples/js/cli binance fetchTicker AAVE/BKRW --verbose
Node.js: v14.15.4
CCXT v1.47.25
binance.fetchTicker (AAVE/BKRW)
fetch:
binance GET https://api.binance.com/api/v3/ticker/24hr?symbol=AAVEBKRW
Request:
{}
undefined
handleRestResponse:
binance GET https://api.binance.com/api/v3/ticker/24hr?symbol=AAVEBKRW 200 OK
Response:
{
'Access-Control-Allow-Methods': 'GET, HEAD, OPTIONS',
'Access-Control-Allow-Origin': '*',
'Cache-Control': 'no-cache, no-store, must-revalidate',
Connection: 'keep-alive',
'Content-Encoding': 'gzip',
'Content-Length': '226',
'Content-Security-Policy': "default-src 'self'",
'Content-Type': 'application/json;charset=UTF-8',
Date: 'Sun, 11 Apr 2021 12:26:33 GMT',
Expires: '0',
Pragma: 'no-cache',
Server: 'nginx',
'Strict-Transport-Security': 'max-age=31536000; includeSubdomains',
Via: '1.1 552d1a24616d6b8d6e3fbbdf18a54b6a.cloudfront.net (CloudFront)',
'X-Amz-Cf-Id': 'G_j0hEYidQyCXY7t_-yek5EkKeaWVZYvAQChe--hApuE2iVc_-HlXw==',
'X-Amz-Cf-Pop': 'AMS50-C1',
'X-Cache': 'Miss from cloudfront',
'X-Content-Security-Policy': "default-src 'self'",
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'SAMEORIGIN',
'X-Mbx-Used-Weight': '92',
'X-Mbx-Used-Weight-1m': '92',
'X-Mbx-Uuid': 'b4e8570c-715c-4846-af64-372c330c5157',
'X-Webkit-Csp': "default-src 'self'",
'X-Xss-Protection': '1; mode=block'
}
{"symbol":"AAVEBKRW","priceChange":"0.00000000","priceChangePercent":"0.000","weightedAvgPrice":"164167.00000000","prevClosePrice":"164167.00000000","lastPrice":"164167.00000000","lastQty":"0.00700000","bidPrice":"0.00000000","bidQty":"0.00000000","askPrice":"0.00000000","askQty":"0.00000000","openPrice":"164167.00000000","highPrice":"164167.00000000","lowPrice":"164167.00000000","volume":"0.00700000","quoteVolume":"1149.16900000","openTime":1614601319507,"closeTime":1614687719507,"firstId":23191,"lastId":23191,"count":1}
{ symbol: "AAVE/BKRW",
timestamp: 1614687719507,
datetime: "2021-03-02T12:21:59.507Z",
high: 164167,
low: 164167,
bid: 0,
bidVolume: 0,
ask: 0,
askVolume: 0,
vwap: 164167,
open: 164167,
close: 164167,
last: 164167,
previousClose: 164167,
change: 0,
percentage: 0,
average: undefined,
baseVolume: 0.007,
quoteVolume: 1149.169,
info: { symbol: "AAVEBKRW",
priceChange: "0.00000000",
priceChangePercent: "0.000",
weightedAvgPrice: "164167.00000000",
prevClosePrice: "164167.00000000",
lastPrice: "164167.00000000",
lastQty: "0.00700000",
bidPrice: "0.00000000",
bidQty: "0.00000000",
askPrice: "0.00000000",
askQty: "0.00000000",
openPrice: "164167.00000000",
highPrice: "164167.00000000",
lowPrice: "164167.00000000",
volume: "0.00700000",
quoteVolume: "1149.16900000",
openTime: "1614601319507",
closeTime: "1614687719507",
firstId: "23191",
lastId: "23191",
count: 1 } }
Ahaaa, ofcourse. Thanks for clarifying! I will add a condition where liquidity must be high.
This may be a stupid question but I have the issue where sometimes binance.symbols returns invalid symbols. It somehow will find the properties of the market with binance.market() , but when I call the fetchTicker() function it will return zero. Ofcourse I await the loadMarkets() function first. When I look in binance I also can't find the pair that returns 0. What I can find is the statement where Binance has deleted the pair from their platform.... Can't be possible that the loadmarkets function returns outdated symbols?