An open API service indexing awesome lists of open source software.

https://github.com/teramonagi/bitflyer

R wrapper for bitFlyer's REST API
https://github.com/teramonagi/bitflyer

bitflyer bitflyer-api r

Last synced: 7 months ago
JSON representation

R wrapper for bitFlyer's REST API

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
```

# bitflyer

[![R-CMD-check](https://github.com/teramonagi/bitflyer/workflows/R-CMD-check/badge.svg)](https://github.com/teramonagi/bitflyer/actions)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)

R wrapper for [bitFlyer's API](https://lightning.bitflyer.com/docs/api?lang=en)

## Installation

```{r gh-installation, eval = FALSE}
# Not yet on CRAN
# install.packages("bitflyer")

# Install the development version from GitHub:
# install.packages("devtools")
devtools::install_github("teramonagi/bitflyer")
```

## Preparation of API keys
bitFlyer Private APIs require authentication using an API Key and API Secret.

They can be obtained by generating them on the [developer's page](https://lightning.bitflyer.com/developer).

You must set these keys in `.Renviron`

```bash
❯ cat ~/.Renviron
BITFLYER_LIGHTNING_API_KEY=
BITFLYER_LIGHTNING_API_SECRET=
```
or as global variables in R

```{r, eval=FALSE}
> BITFLYER_LIGHTNING_API_KEY <- "your-api-key"
> BITFLYER_LIGHTNING_API_SECRET <- "your-api-secret"
```

## Example

### HTTP API
#### [HTTP Public API](https://lightning.bitflyer.com/docs/api?lang=en#http-public-api)

```{r public_api}
library("bitflyer")
# Get the list of market
fromJSON(markets())

# Get order book
x <- board(product_code = "BTC_JPY")
x <- fromJSON(x)
str(x)

# Ticker
ticker(product_code = "BTC_JPY")

# Execution History
head(fromJSON(executions()))

# Get orderbook status
fromJSON(get_board_state())

# Get the current status of the exchange.
get_health()
```

#### [HTTP Private API](https://lightning.bitflyer.com/docs/api?lang=en#http-private-api)

The results of this chunk are hidden because you really understand of my portfolio/positions ...

```{r private_api, eval=FALSE}
# Get a list of which HTTP Private APIs can be used with the specified API key
fromJSON(get_permissions())

# Get Margin Status
fromJSON(get_collateral())

#Send a New Order
x <- send_child_order(
product_code = "BTC_JPY",
child_order_type = "LIMIT",
side = "BUY",
price = 300*10^4,
size = 0.001
)
x
child_order_acceptance_id <- fromJSON(x)$child_order_acceptance_id

# List Orders
fromJSON(get_child_orders(product_code = "BTC_JPY", child_order_acceptance_id=child_order_acceptance_id))
# You can also get all active orders
# fromJSON(get_child_orders(product_code = "BTC_JPY", child_order_state="ACTIVE"))

# Cancel the order
cancel_child_order(product_code = "BTC_JPY", child_order_acceptance_id = child_order_acceptance_id)
# You can also cancel all child orders
# cancel_all_child_orders(product_code = "BTC_JPY")

# No active orders (Check)
fromJSON(get_child_orders(product_code = "BTC_JPY", child_order_state="ACTIVE"))

# Get balance
fromJSON(get_balance())

# Get Parent Order Details
get_parent_orders(product_code = "BTC_JPY")

# List Executions
fromJSON(get_executions(product_code = "BTC_JPY"))

# List Balance History
fromJSON(get_balance_history())

# Get Open Interest Summary
get_positions()

# Get Margin Change History
fromJSON(get_collateral_history())

# Get Trading Commission
get_trading_commission(product_code = "BTC_JPY")
```

The following APIs are not implemented yet.

- [Deposits and Withdrawals](https://lightning.bitflyer.com/docs?lang=en#get-crypto-assets-deposit-addresses) APIs
- [Submit New Parent Order (Special order)](https://lightning.bitflyer.com/docs?lang=en#submit-new-parent-order-special-order) API
- Endpoint: `/v1/me/sendparentorder`

### Realtime API
... Not implemented yet(under development) ...