MyNixOS website logo
Description

An Unofficial Wrapper for 'okx exchange v5' API.

An unofficial wrapper for 'okx exchange v5' API <https://www.okx.com/docs-v5/en/>, including 'REST' API and 'WebSocket' API.

okxAPI

An unofficial wrapper for Okx exchange v5 API

Installation

You can install the released version of okxAPI from CRAN with:

install.packages("okxAPI")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("fanggong/okxAPI")

Requirements

Please refer to okx my api page regarding V5 API Key creation.

Example

REST API

You can implement all REST API requests in Okx exchange by inheriting the restAPI class. For example, to implement Get currencies, you can define the class and call the method as follows:

myRestAPI <- R6::R6Class(
  inherit = restAPI,
  public = list(
    get_currencies = function(ccy, process = "identity") {
      self$get_result(
        api = "/api/v5/asset/currencies", method = "GET", process = process,
        ccy = ccy
      )
    }
  )
)
tmp <- myRestAPI$new(api_key, secret_key, passphrase)
tmp$get_currencies("BTC")

For commonly used interfaces, they have been implemented in this package. The naming convention is as follows: for "/api/v5/AAA/BBB", a new class named restAPIAAA, which inherits from restAPI, has been defined in this package. The BBB method in this new class is used to call the API.

WebSocket API Public Channel

A websocketAPIpublic class based on websocket package is used here.

Create new websocketAPIpublic object and initiate the connection to the server.

tmp <- websocketAPIpublic$new()
tmp$connect()

Subscribe BTC-USDT-SWAP 5m candlesticks data.

msg <- list(
  op = "subscribe",
  args = list(
    list(channel = "candle5m", instId = "BTC-USDT-SWAP")
  )
)
msg <- jsonlite::toJSON(msg, auto_unbox = TRUE, pretty = TRUE)
tmp$send(msg)

Pass your own callback function

tmp$on_message(function(event) {
  if (event$data == "pong") {
    cat("Bingo!!")
  }
})
tmp$send("ping")

Close the connection.

tmp$close()

WebSocket API Private Channel

A websocketAPIprivate class based on websocket package is used here.

Create new websocketAPIprivate object and initiate the connection to the server.

tmp <- websocketAPIprivate$new(api_key, secret_key, passphrase)
tmp$connect()
Sys.sleep(1)  # Waiting for connection success
tmp$login()

Subscribe account information.

msg <- list(
  op = "subscribe",
  args = list(
    list(channel = "account", ccy = "USDT")
  )
)
msg <- jsonlite::toJSON(msg, auto_unbox = TRUE, pretty = TRUE)
tmp$send(msg)

Pass your own callback function.

tmp$on_message(function(event) {
  if (event$data == "pong") {
    cat("Bingo!!")
  }
})
tmp$send("ping")

Close the connection.

tmp$close()
Metadata

Version

0.1.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows