knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-"
)

bitflyer

R-CMD-check Lifecycle: experimental

R wrapper for bitFlyer's API

Installation

# 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.

You must set these keys in .Renviron

❯ cat ~/.Renviron 
BITFLYER_LIGHTNING_API_KEY=<your-api-key>
BITFLYER_LIGHTNING_API_SECRET=<your-api-secret>

or as global variables in R

> BITFLYER_LIGHTNING_API_KEY <- "your-api-key"
> BITFLYER_LIGHTNING_API_SECRET <- "your-api-secret"

Example

HTTP API

HTTP 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

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

# 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.

Realtime API

... Not implemented yet(under development) ...



teramonagi/bitflyer documentation built on Jan. 12, 2021, 1:02 p.m.