diff --git a/functions/bx-api.js b/functions/bx-api.js index 9166e4e..cfe7bcd 100644 --- a/functions/bx-api.js +++ b/functions/bx-api.js @@ -51,6 +51,25 @@ class BxApi { netProfit: (omgSum*omgPrice) + thbSum, }; } + + createBxOrder(pairing, type, amount, rate) { + const url = `${BX_API_URL}order/`; + const unixTime = Date.now() * 1000; + return axios.post(url, qs.stringify({ + key: this.apiKey, + nonce: unixTime, + signature: this.getSignature(unixTime), + pairing: pairing, + type: type, + amount: amount, + rate: rate + })).then({success: success, order_id: order_id, error: error} => { + if (!success) throw error; + return order_id; + }).catch(e => { + return e; + }); + } getSignature(nonce) { return crypto.createHash('sha256')