Created
October 1, 2017 11:06
-
-
Save manu354/36a4d73c95d78adc9bf47393f3b3ad7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function gdaxOpen(price, volume, coinTicker, type, orderID) { | |
| return new Promise((async(resolve, reject) => { | |
| function callback(err, response, data) { | |
| if (err) throw err; | |
| console.log('gdax response:, ERR:', err, "Ticker:", data.product_id, coinTicker, "Type: .. Price", data.side, type, price, "Response message:", data.message); | |
| // logger.write(`GDAX api call response: ${data}`); | |
| if (data.id) resolve(data.id); | |
| else { | |
| console.log(data); | |
| resolve(false) | |
| } | |
| } | |
| function infoCallback(err, response, data) { | |
| if (err) throw err; | |
| console.log('gdax info api call succ, ERR:', err, "DATA:", "status?", data.status, /* data,*/ "Buy/Sell:", data.side, "Ticker:", data.product_id, "Response message:", data.message); | |
| logger.write(`GDAX api call (for info) response: ${data}`); | |
| if (data) resolve(data); | |
| else resolve(false); | |
| } | |
| try { | |
| price = price.toPrecision(4); | |
| const apiURI = 'https://api.gdax.com'; | |
| const sandboxURI = 'https://api-public.sandbox.gdax.com'; | |
| const params = { | |
| price, // USD | |
| size: volume, // BTC | |
| product_id: coinTicker, | |
| // post_only: true, | |
| }; | |
| // console.log(params); | |
| function trade(gdax) { | |
| if (type === 'long') { | |
| gdax.buy(params, callback); | |
| // console.log('Placing buy order direct from API'); | |
| } else if (type === 'short') { | |
| gdax.sell(params, callback); | |
| // console.log('Placing sell order direct from API'); | |
| } else if (type === 'close') { | |
| gdax.cancelOrder(orderID, callback); | |
| // console.log('Canceling order direct from API'); | |
| } else if (type == 'info') { | |
| gdax.getOrder(orderID, infoCallback); | |
| // console.log('getting order direct from API'); | |
| } | |
| } | |
| const key = '....'; | |
| const b64secret = '...'; | |
| const passphrase = '....'; | |
| const gdax = new Gdax.AuthenticatedClient(key, b64secret, passphrase, apiURI); | |
| trade(gdax); | |
| else { | |
| console.log("Ticker isnt either eur, btc or usd") | |
| } | |
| } catch (e) { | |
| console.log(e); | |
| reject(e); | |
| } | |
| })); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment