bitfinex_candles: Provides a way to access charting candle info

Description Usage Arguments Value Examples

View source: R/rest_public_endpoints.R

Description

Candles endpoint of Bitfinex API V2. URL Structure: URL structure: https://api.bitfinex.com/v2/candles/trade::TimeFrame::Symbol/Section

Usage

1
2
3
4
bitfinex_candles(symbol = c("tBTCUSD"), time_frame = c("1m", "5m", "15m",
  "30m", "1h", "3h", "6h", "12h", "1D", "7D", "14D", "1M"),
  section = c("last", "hist"), limit = 100, start = NULL, end = NULL,
  period = NULL, aggr = NULL, sort = -1)

Arguments

symbol

The symbol you want information about (e.g. 'tBTCUSD' for pair Bitcoin/US Dollar or 'fUSD' for funding info).

time_frame

Available values: '1m', '5m', '15m', '30m', '1h', '3h', '6h', '12h', '1D', '7D', '14D', '1M'.

section

Available values: "last", "hist".

limit

Number of candles requested.

start

Filter start in milliseconds (ms).

end

Filter end in milliseconds (ms).

period

(for funding only)

sort

if = -1 it sorts results returned with new > old. if = 1 it sorts in the opposite order. Default is -1.

Value

a tibble

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
## Not run: 
# 15 minutos
candles <- tidyr::crossing(symbol = c("tBTCUSD", "tBCHUSD",
                                      "tBTGUSD", "tIOTUSD",
                                      "tXMRUSD", "tLTCUSD",
                                      "tETHUSD", "tDSHUSD",
                                      "tETCUSD", "tZECUSD",
                                      "tXRPUSD", "tEOSUSD",
                                      "tSANUSD", "tOMGUSD"),
                           start = as.numeric(1504234800000 + seq(0, 1200000, by = 15000) * 60 * 1000)) %>%
  filter(start <= as.numeric(now()) * 1000)

#
safely_bitfinex_candles <- purrr::safely(bitfinex_candles)
candles %<>%
  mutate(bitfinex_candles = map2(symbol, start, ~ {
    print(.x)

    nome_do_rds <- sprintf("data/%s_15m_%s.rds", .x, .y)
    if(file.exists(nome_do_rds)) {print("j<c3><a1> existe");return(read_rds(nome_do_rds))}

    Sys.sleep(.1)
    deu_certo <- FALSE
    repeat{
      data <- safely_bitfinex_candles(symbol = .x,
                                      time_frame = '15m',
                                      section = 'hist',
                                      limit = 1000,
                                      start = .y,
                                      period = NULL,
                                      aggr = NULL,
                                      sort = 1
      )

      deu_certo <- is.null(data$error)
      if(deu_certo){ break }
      print("deu errado. tentando novamente em 60 segundos.")
      Sys.sleep(30)
    }


    data <- data$result %>%
      mutate(symbol = .x)
    write_rds(data, path = nome_do_rds)
    return(data)
  }))

## End(Not run)

Athospd/bitfinex documentation built on May 7, 2019, 3:19 p.m.