@tadko/bitflyer-client
Version:
A Client for BitFlyer API
349 lines (325 loc) • 11.5 kB
JavaScript
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
;
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(__webpack_require__(1));
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const HttpClient_1 = __webpack_require__(2);
/**
* BitFlyer用のAPIクラスです。
*/
class BitFlyerClient extends HttpClient_1.default {
constructor(key, secret = '') {
super(BitFlyerClient.BASE_URL, key, secret);
this.key = key;
this.secret = secret;
}
/**
* 新規注文を出す
* @param {SendChildOrderRequest} request リクエスト
* @return {Promise<SendChildOrderResponse>} レスポンス
*/
sendChildOrder(request) {
return __awaiter(this, void 0, void 0, function* () {
const path = '/v1/me/sendchildorder';
return yield this.post(path, request);
});
}
/**
* 注文をキャンセルする
* @param {CancelChildOrderRequest} request リクエスト
* @return {Promise<CancelChildOrderResponse>} レスポンス
*/
cancelChildOrder(request) {
return __awaiter(this, void 0, void 0, function* () {
const path = '/v1/me/cancelchildorder';
return yield this.post(path, request);
});
}
/**
* 注文の一覧を取得
* @param {ChildOrdersRequest} request リクエスト
* @return {Promise<ChildOrdersResponse>} レスポンス
*/
getChildOrders(request) {
return __awaiter(this, void 0, void 0, function* () {
const path = '/v1/me/getchildorders';
return yield this.get(path, request);
});
}
/**
* 約定の一覧を取得
* @param {ExecutionsRequest} request リクエスト
* @return {Promise<ExecutionsResponse>} レスポンス
*/
getExecutions(request) {
return __awaiter(this, void 0, void 0, function* () {
const path = '/v1/me/getexecutions';
return yield this.get(path, request);
});
}
/**
* 建玉の一覧を取得
* @param {PositionsRequest} request リクエスト
* @return {Promise<PositionsResponse>} レスポンス
*/
getPositions(request) {
return __awaiter(this, void 0, void 0, function* () {
const path = '/v1/me/getpositions';
return yield this.get(path, request);
});
}
/**
* 資産残高を取得
* @return {Promise<BalanceResponse>} レスポンス
*/
getBalance() {
return __awaiter(this, void 0, void 0, function* () {
const path = '/v1/me/getbalance';
return yield this.get(path);
});
}
/**
* 板情報
* @param {BoardRequest} request リクエスト
* @return {Promise<BoardResponse>} レスポンス
*/
getBoard(request) {
return __awaiter(this, void 0, void 0, function* () {
const path = '/v1/board';
return yield this.get(path, request);
});
}
/**
* Ticker
* @param {TickerRequest} request リクエスト
* @return {Promise<TickerResponse>} レスポンス
*/
getTicker(request) {
return __awaiter(this, void 0, void 0, function* () {
const path = '/v1/ticker';
return yield this.get(path, request);
});
}
/**
* 板の状態
* @param {BoardStateRequest} request リクエスト
* @return {Promise<BoardStateResponse>} レスポンス
*/
getBoardState(request) {
return __awaiter(this, void 0, void 0, function* () {
const path = '/v1/getboardstate';
return yield this.get(path, request);
});
}
}
BitFlyerClient.BASE_URL = 'https://api.bitflyer.jp';
exports.BitFlyerClient = BitFlyerClient;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const rp = __webpack_require__(3);
const Util_1 = __webpack_require__(4);
/**
* APIリクエストを送信するクラスです。
*/
class HttpClient {
constructor(baseUrl, key, secret = '') {
this.baseUrl = baseUrl;
this.key = key;
this.secret = secret;
}
/**
* HTTP GETリクエストを送信します。
* @param {string} path
* @param {T} requestParam
* @return {Promise<R>} リクエスト結果
*/
get(path, requestParam) {
return __awaiter(this, void 0, void 0, function* () {
const method = 'GET';
let pathWithParam = path;
if (requestParam) {
const param = Util_1.queryStringify(requestParam);
if (param) {
pathWithParam += `?${param}`;
}
}
return yield this.call(pathWithParam, method);
});
}
/**
* HTTP POSTリクエストを送信します。
* @param {string} path
* @param {T} requestBody
* @return {Promise<R>} リクエスト結果
*/
post(path, requestBody) {
return __awaiter(this, void 0, void 0, function* () {
const method = 'POST';
const body = JSON.stringify(requestBody);
return yield this.call(path, method, body);
});
}
/**
* HTTPリクエストを送信します。
* @param {string} path
* @param {string} method
* @param {string} body
* @return {Promise<R>} リクエスト結果
*/
call(path, method, body = '') {
return __awaiter(this, void 0, void 0, function* () {
const url = this.baseUrl + path;
const timestamp = Date.now().toString();
const message = timestamp + method + path + body;
const sign = Util_1.hmac(this.secret, message);
const headers = {
'Content-Type': 'application/json',
'ACCESS-KEY': this.key,
'ACCESS-TIMESTAMP': timestamp,
'ACCESS-SIGN': sign
};
const options = {
url: url,
method: method,
headers: headers,
body: body
};
const res = JSON.parse(yield rp(options));
return res;
});
}
}
exports.default = HttpClient;
/***/ }),
/* 3 */
/***/ (function(module, exports) {
module.exports = require("request-promise-native");
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
;
Object.defineProperty(exports, "__esModule", { value: true });
const _ = __webpack_require__(5);
const crypto = __webpack_require__(6);
const querystring = __webpack_require__(7);
function hmac(secret, text, algorithm = 'sha256') {
return crypto
.createHmac(algorithm, secret)
.update(text)
.digest('hex');
}
exports.hmac = hmac;
function queryStringify(o) {
const noUndefined = _.pickBy(o, _.negate(_.isUndefined));
return querystring.stringify(noUndefined);
}
exports.queryStringify = queryStringify;
/***/ }),
/* 5 */
/***/ (function(module, exports) {
module.exports = require("lodash");
/***/ }),
/* 6 */
/***/ (function(module, exports) {
module.exports = require("crypto");
/***/ }),
/* 7 */
/***/ (function(module, exports) {
module.exports = require("querystring");
/***/ })
/******/ ]);
//# sourceMappingURL=index.js.map