andreskull / rFTX

R API for FTX
Other
5 stars 12 forks source link

end_time not working with ftx_my_spot_borrow_history #5

Open Thie1e opened 3 years ago

Thie1e commented 3 years ago

Hi,

first of all, thanks a lot for this package! I think this is going to be very useful.

I tried out some functions, mainly for getting my lending history, which worked, but I can not set an end_time there. The end_time parameter works in ftx_spot_lending_history, for example, but not in ftx_my_spot_borrow_history.

library(rFTX)

ftx_my_spot_borrow_history(key = "mykey", 
                  secret = "mysecret",
                  end_time = 1628721192)
#> Warning in sprintf("Not logged in", query = list(end_time = 1628721192)): one
#> argument not used by format 'Not logged in'
#> 2021-11-02 17:40:24 ERROR::Not logged in
#> $success
#> [1] FALSE
#> 
#> $failure_reason
#> [1] "Not logged in"
#> 
#> $data
#> NULL

ftx_spot_lending_history(key = "mykey", 
                  secret = "mysecret",
                  end_time = 1628721192)
#> $success
#> [1] TRUE
#> 
#> $failure_reason
#> [1] NA
#> 
#> $data
#>      coin                      time         size      rate
#> 1     BNT 2021-08-11T22:00:00+00:00 1.278430e+05 1.027e-05
#> 2     ACB 2021-08-11T22:00:00+00:00 0.000000e+00 1.000e-06
#> 3    BNTX 2021-08-11T22:00:00+00:00 5.025395e-01 1.000e-06
#> 4    ABNB 2021-08-11T22:00:00+00:00 0.000000e+00 1.000e-06
#> 5    TRYB 2021-08-11T22:00:00+00:00 4.738702e+06 2.283e-05
#> 6    COIN 2021-08-11T22:00:00+00:00 9.866499e+02 1.000e-06
#> 7     RSR 2021-08-11T22:00:00+00:00 6.451503e+05 1.000e-06
#> 8     SNX 2021-08-11T22:00:00+00:00 8.234276e+04 6.850e-06
#> 9     ETH 2021-08-11T22:00:00+00:00 7.721051e+04 5.710e-06
#> 10    UNI 2021-08-11T22:00:00+00:00 1.491130e+04 1.000e-06
#> 11    USD 2021-08-11T22:00:00+00:00 1.265550e+09 9.130e-06
#> 12    LTC 2021-08-11T22:00:00+00:00 8.170691e+02 1.000e-06
#> 13    OMG 2021-08-11T22:00:00+00:00 2.042760e+04 1.000e-06
#> 14  MATIC 2021-08-11T22:00:00+00:00 4.226524e+06 1.000e-06
#> 15   BILI 2021-08-11T22:00:00+00:00 1.740910e-03 1.000e-06
#> 16   BYND 2021-08-11T22:00:00+00:00 2.608141e-01 1.000e-06
#> 17    NOK 2021-08-11T22:00:00+00:00 2.184187e+01 1.000e-06
#> 18    YFI 2021-08-11T22:00:00+00:00 1.585818e+02 1.712e-05
#> 19   HOOD 2021-08-11T22:00:00+00:00 5.219764e+03 4.566e-05
#> 20    MKR 2021-08-11T22:00:00+00:00 9.841659e+01 1.000e-06

[...]

Created on 2021-11-02 by the reprex package (v2.0.1)

andreskull commented 3 years ago

verbose() connection printouts below show that the start_time and end_time encoding into url is identical in successful (ftx_trades) and unsuccessful (ftx_my_spot_borrow_history) case. ftx_my_spot_borrow_historywith start_timeand end_timefails while without them succeeds. It seems that the issue is in FTX side that does not implement/api/spot_margin/borrow_history with start_timeand end_time correctly.

GET request with start_timeand end_timeto /api/markets/[market]/tradesendpoint evrything fine:

> ftx_trades(key, secret, "SOL/USD", start_time = now()-1000, end_time = now())
-> GET /api/markets/SOL/USD/trades?start_time=1635886011&end_time=1635887011 HTTP/1.1
-> Host: ftx.com
-> User-Agent: libcurl/7.64.1 r-curl/4.3.2 httr/1.4.2
-> Accept-Encoding: deflate, gzip
-> Accept: application/json, text/xml, application/xml, */*
-> FTX-KEY: 9YTEX4BePPk7yhd2jTZPEuFjYa_ROiVAKVvIElhE
-> FTX-SIGN: b0f1b9fc3be30e8e3217ba8c7a9b517cbd1db1dc8d716ec9c45bde7737fe411b
-> FTX-TS: 1635887010000
-> 
<- HTTP/1.1 200 OK
<- Date: Tue, 02 Nov 2021 21:03:29 GMT
<- Content-Type: application/json
<- Transfer-Encoding: chunked
<- Connection: keep-alive
<- Vary: Accept-Encoding
<- Vary: Accept-Encoding
<- Cache-Control: public, max-age=0
<- ETag: W/"0ca97b7b932f36ee309107637f406703"
<- Vary: Origin
<- Content-Encoding: gzip
<- X-Cache-Status: MISS
<- CF-Cache-Status: MISS
<- Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
<- Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
<- X-Content-Type-Options: nosniff
<- Server: cloudflare
<- CF-RAY: 6a804f4e7ee0b633-TLL
<- alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400, h3-28=":443"; ma=86400, h3-27=":443"; ma=86400

GET request without start_timeand end_timeto /api/spot_margin/borrow_history endpoint evrything fine:

> ftx_my_spot_borrow_history(key, secret) 
-> GET /api/spot_margin/borrow_history HTTP/1.1
-> Host: ftx.com
-> User-Agent: libcurl/7.64.1 r-curl/4.3.2 httr/1.4.2
-> Accept-Encoding: deflate, gzip
-> Accept: application/json, text/xml, application/xml, */*
-> FTX-KEY: 9YTEX4BePPk7yhd2jTZPEuFjYa_ROiVAKVvIElhE
-> FTX-SIGN: a6c676eae16289cccdf6bcdbd7873f7dcbdd229b19f106c4c7d56a5fc4742baf
-> FTX-TS: 1635887748000
-> 
<- HTTP/1.1 200 OK
<- Date: Tue, 02 Nov 2021 21:15:47 GMT
<- Content-Type: application/json
<- Transfer-Encoding: chunked
<- Connection: keep-alive
<- Vary: Accept-Encoding
<- Vary: Accept-Encoding
<- Cache-Control: private, max-age=0, no-cache
<- account-id: 20707144
<- ETag: W/"0d0cd173ded83cacc333a804eb9917c8"
<- Vary: Origin
<- Content-Encoding: gzip
<- X-Cache-Status: MISS
<- CF-Cache-Status: MISS
<- Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
<- Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
<- X-Content-Type-Options: nosniff
<- Server: cloudflare
<- CF-RAY: 6a8061532929b633-TLL
<- alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400, h3-28=":443"; ma=86400, h3-27=":443"; ma=86400

GET request with start_timeand end_timeto /api/spot_margin/borrow_history endpoint fails: 401 UNAUTHORIZED:

> ftx_my_spot_borrow_history(key, secret, start_time = now() - days(200)) 
-> GET /api/spot_margin/borrow_history?start_time=1618603265&end_time=1635886865 HTTP/1.1
-> Host: ftx.com
-> User-Agent: libcurl/7.64.1 r-curl/4.3.2 httr/1.4.2
-> Accept-Encoding: deflate, gzip
-> Accept: application/json, text/xml, application/xml, */*
-> FTX-KEY: 9YTEX4BePPk7yhd2jTZPEuFjYa_ROiVAKVvIElhE
-> FTX-SIGN: 148e87ef48cc591e5273e814ce47476d6099b500498dcc4129bcfbfd8057d37a
-> FTX-TS: 1635886865000
-> 
<- HTTP/1.1 401 UNAUTHORIZED
<- Date: Tue, 02 Nov 2021 21:01:04 GMT
<- Content-Type: application/json
<- Content-Length: 42
<- Connection: keep-alive
<- Cache-Control: private, max-age=0, no-cache
<- account-id: None
<- Vary: Origin, Accept-Encoding
<- CF-Cache-Status: MISS
<- Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
<- Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
<- X-Content-Type-Options: nosniff
<- Server: cloudflare
<- CF-RAY: 6a804bc25866b633-TLL
<- alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400, h3-28=":443"; ma=86400, h3-27=":443"; ma=86400
Thie1e commented 3 years ago

Thanks, looks like it. I don't know much about working with APIs and the appropriate requests, but I just unsuccessfully fiddled around with this GET request for nearly an hour and also could not get it to work.

It's probably not the most important functionality anyway.