-
Notifications
You must be signed in to change notification settings - Fork 14
/
rest-promises.js
122 lines (93 loc) · 3.92 KB
/
rest-promises.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
var _ = require('underscore')
var restType = require('./rest')
function promiseRest(clientId, key, secret) {
this.rest = new restType(clientId, key, secret)
}
promiseRest.prototype._promiseWrap = function(func) {
return new Promise((resolve, reject) => {
var callback = (err, data) => {
if (err) reject(err)
else resolve(data)
}
var newArgs = Array.prototype.slice.call(arguments, 1);
newArgs.push(callback)
func.apply(this.rest, newArgs)
})
}
promiseRest.prototype.currency_limits = function () {
return this._promiseWrap(this.rest.currency_limits)
}
promiseRest.prototype.ticker = function (symbol) {
return this._promiseWrap(this.rest.ticker, symbol)
}
promiseRest.prototype.all_tickers = function (symbol) {
return this._promiseWrap(this.rest.all_tickers, symbol)
}
promiseRest.prototype.last_price = function (symbol) {
return this._promiseWrap(this.rest.last_price, symbol)
}
promiseRest.prototype.last_prices = function (symbol) {
return this._promiseWrap(this.rest.last_prices, symbol)
}
promiseRest.prototype.historical_1m = function (symbol, date) {
return this._promiseWrap(this.rest.historical_1m, symbol, date)
}
promiseRest.prototype.orderbook = function (symbol, limit) {
return this._promiseWrap(this.rest.orderbook, symbol, limit)
}
promiseRest.prototype.trade_history = function (symbol, tid) {
return this._promiseWrap(this.rest.trade_history, symbol, tid)
}
// Authenticated API requests
promiseRest.prototype.account_balance = function () {
return this._promiseWrap(this.rest.account_balance)
}
promiseRest.prototype.open_orders = function (symbol) {
return this._promiseWrap(this.rest.open_orders, symbol)
}
promiseRest.prototype.active_orders_status = function (list) {
return this._promiseWrap(this.rest.active_orders_status, list)
}
promiseRest.prototype.archived_orders = function (symbol, limit, dateTo, dateFrom, lastTxDateTo, lastTxDateFrom, status) {
return this._promiseWrap(this.rest.archived_orders, symbol, limit, dateTo, dateFrom, lastTxDateTo, lastTxDateFrom, status)
}
promiseRest.prototype.cancel_order = function (orderId) {
return this._promiseWrap(this.rest.cancel_order, orderId)
}
promiseRest.prototype.cancel_pair_orders = function (symbol) {
return this._promiseWrap(this.rest.cancel_pair_orders, symbol)
}
promiseRest.prototype.place_order = function (symbol, type, amount, price, orderType) {
return this._promiseWrap(this.rest.place_order, symbol, type, amount, price, orderType)
}
promiseRest.prototype.get_order_details = function (orderId) {
return this._promiseWrap(this.rest.get_order_details, orderId)
}
promiseRest.prototype.get_order_transactions = function (orderId) {
return this._promiseWrap(this.rest.get_order_transactions, orderId)
}
promiseRest.prototype.get_crypto_address = function (currency) {
return this._promiseWrap(this.rest.get_crypto_address, currency)
}
promiseRest.prototype.get_my_fee = function () {
return this._promiseWrap(this.rest.get_my_fee)
}
promiseRest.prototype.replace_order = function (symbol, orderId, type, amount, price) {
return this._promiseWrap(this.rest.replace_order, symbol, orderId, type, amount, price)
}
promiseRest.prototype.open_position = function (symbol, msymbol, amount, leverage, ptype, anySlippage, eoprice, stopLossPrice) {
return this._promiseWrap(this.rest.open_position, symbol, msymbol, amount, leverage, ptype, anySlippage, eoprice, stopLossPrice)
}
promiseRest.prototype.open_positions = function (symbol) {
return this._promiseWrap(this.rest.open_positions, symbol)
}
promiseRest.prototype.close_position = function (symbol, orderId) {
return this._promiseWrap(this.rest.close_position, symbol, orderId)
}
promiseRest.prototype.archived_positions = function (symbol) {
return this._promiseWrap(this.rest.archived_positions, symbol)
}
promiseRest.prototype.get_marginal_fee = function (symbol) {
return this._promiseWrap(this.rest.get_marginal_fee, symbol)
}
module.exports = promiseRest