LoginSignup
2
1

More than 3 years have passed since last update.

Node.js版CCXTでbitFlyerのPrivate APIを使う

Posted at

はじめに

ccxt.js経由でbitFlyerの現在のポジション(建玉)を知りたかったのだが、ちょっと調べてもなかった。
詰まったので同様の問題に遭遇した人のためにも解決方法残しておこうと思う。

コード


const ccxt = require('ccxt')
const bitflyer = new ccxt.bitflyer({
    apiKey: env.apiKey, // APIキーを入れる
    secret: env.secret // シークレットをいれる
})
bitflyer.privateGetGetpositions({ product_code: 'FX_BTC_JPY' }).then(data => console.log(data))

ちょっと解説

ccxtでPrivate APIを使うには、メソッドの命名に独自の法則を使っている

private + {メソッドがgetならGet、postならPost} + {private APIの名前}

上の例ではGetメソッドでgetpositionsAPIを使いたいがために、privateGetGetpositionsとなる。
またクエリパラメータが必須なので、それはメソッドの引数としてオブジェクトを渡す。

参考

Python版だが以下の説明がわかりやすかった。
Bitflyerや各取引所の個別APIをCCXTライブラリ経由で直接利用する方法

使いたいbitFlyerのPrivate APIは以下を参照
API Documentation

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1