daroczig / binancer

An R client to the Public Rest API for Binance.
https://daroczig.github.io/binancer
54 stars 57 forks source link

Error in Retrieving Coin Price in USDT #39

Closed larry77 closed 4 months ago

larry77 commented 4 months ago

Hello,

I do not know if the project is still active, given the number of issues which have not been reacted upon in months, but I would like to signal a bug. Specifically it is for the retrieval of the USDT price of the CRL token.

Please have a look at the reprex below.

library(binancer)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

df <- binance_coins_prices() |>
    as_tibble()

df
#> # A tibble: 1,440 × 2
#>    symbol       usd
#>    <chr>      <dbl>
#>  1 ETH    3371.    
#>  2 LTC      75.7   
#>  3 BNB     417.    
#>  4 NEO      14.0   
#>  5 QTUM      3.72  
#>  6 EOS       0.855 
#>  7 SNT       0.0450
#>  8 BNT       0.885 
#>  9 BCC    4835.    
#> 10 GAS       6.55  
#> # ℹ 1,430 more rows

crv_price <- df |>
    filter(symbol=="CRV")

crv_price
#> # A tibble: 1 × 2
#>   symbol   usd
#>   <chr>  <dbl>
#> 1 CRV     2.87

##this price is simply wrong. As of now (28/02/2024) the price
#of crv in usdt is around 0.6

## Try to understand where this comes from. binance_coins_prices relies on
## binance_ticker_all_prices

df2 <- binance_ticker_all_prices() |>
    as_tibble()

df2
#> # A tibble: 2,493 × 6
#>    symbol      price from   from_usd to    to_usd
#>    <chr>       <dbl> <chr>     <dbl> <chr>  <dbl>
#>  1 ETHBTC  0.0551    ETH   3371.     BTC   61135.
#>  2 LTCBTC  0.00124   LTC     75.7    BTC   61135.
#>  3 BNBBTC  0.00682   BNB    417.     BTC   61135.
#>  4 NEOBTC  0.000229  NEO     14.0    BTC   61135.
#>  5 QTUMETH 0.00111   QTUM     3.72   ETH    3371.
#>  6 EOSETH  0.000254  EOS      0.855  ETH    3371.
#>  7 SNTETH  0.0000134 SNT      0.0450 ETH    3371.
#>  8 BNTETH  0.000263  BNT      0.885  ETH    3371.
#>  9 BCCBTC  0.0791    BCC   4835.     BTC   61135.
#> 10 GASBTC  0.000107  GAS      6.55   BTC   61135.
#> # ℹ 2,483 more rows

crv <- df2 |>
    filter(from=="CRV")

crv ## so the binance_coins_prices picks the to==BNB entry by mistake
#> # A tibble: 4 × 6
#>   symbol      price from  from_usd to    to_usd
#>   <chr>       <dbl> <chr>    <dbl> <chr>  <dbl>
#> 1 CRVBNB  0.00687   CRV      2.87  BNB     417.
#> 2 CRVBTC  0.0000101 CRV      0.618 BTC   61135.
#> 3 CRVUSDT 0.620     CRV      0.620 USDT      1 
#> 4 CRVETH  0.000208  CRV      0.700 ETH    3371.
## Can someone fix this ?

Created on 2024-02-28 with reprex v2.0.2

daroczig commented 4 months ago

Thanks for the report! The repo is unfortunately not very well maintained, but this looks indeed terrible, so I took a look, and came up with a potential fix at #40.

Could you give it a try?

remotes::install_github('daroczig/binancer@fix-usdt-calcs')
binancer::binance_coins_prices()[symbol == 'CRV']
#>    symbol    usd
#> 1:    CRV 0.5926
larry77 commented 4 months ago

Hello!

And thanks for the quick reaction. Now at least the CRV case appears to have been solved. Will reopen this if I spot anything weird with other coins.

library(binancer)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

df <- binance_coins_prices() |>
    as_tibble()

df
#> # A tibble: 559 × 2
#>    symbol           usd
#>    <chr>          <dbl>
#>  1 1000SATS    0.000567
#>  2 1INCH       0.522   
#>  3 1INCHDOWN   0.00615 
#>  4 1INCHUP     0.0657  
#>  5 AAVE      108.      
#>  6 AAVEDOWN    0.00467 
#>  7 AAVEUP      0.601   
#>  8 ACA         0.118   
#>  9 ACE        11.6     
#> 10 ACH         0.0266  
#> # ℹ 549 more rows

crv_price <- df |>
    filter(symbol=="CRV")

crv_price
#> # A tibble: 1 × 2
#>   symbol   usd
#>   <chr>  <dbl>
#> 1 CRV    0.618

sessionInfo()
#> R version 4.3.2 (2023-10-31)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Debian GNU/Linux 12 (bookworm)
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.11.0 
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.11.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
#>  [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
#>  [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       
#> 
#> time zone: Europe/Brussels
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] dplyr_1.1.3    binancer_1.2.0
#> 
#> loaded via a namespace (and not attached):
#>  [1] vctrs_0.6.4       httr_1.4.7        cli_3.6.1         knitr_1.45       
#>  [5] rlang_1.1.2       xfun_0.41         generics_0.1.3    jsonlite_1.8.7   
#>  [9] data.table_1.14.8 glue_1.6.2        htmltools_0.5.7   fansi_1.0.5      
#> [13] rmarkdown_2.25    tibble_3.2.1      evaluate_0.23     snakecase_0.11.1 
#> [17] fastmap_1.1.1     yaml_2.3.7        lifecycle_1.0.4   compiler_4.3.2   
#> [21] fs_1.6.3          pkgconfig_2.0.3   digest_0.6.33     R6_2.5.1         
#> [25] tidyselect_1.2.0  reprex_2.0.2      utf8_1.2.4        curl_5.1.0       
#> [29] pillar_1.9.0      magrittr_2.0.3    logger_0.2.2      tools_4.3.2      
#> [33] withr_2.5.2

Created on 2024-02-29 with reprex v2.0.2

One extra question: what is the future of binancer? I am tempted to include it into some projects of mine, but I simply do not know if it will be further developed (while binance released updates to its api, so much more could be retrieved).

Thanks anyway!

daroczig commented 4 months ago

what is the future of binancer?

That is a good question. I cannot spend enough time on it for sure, so don't expect new features to be added anytime soon on my end. But I keep an eye on serious bugs, and will try to mitigate those ASAP.