Created
August 29, 2016 03:33
-
-
Save cesardeazevedo/6f2660a7f2729ccc2f1d5cc5ccdb8105 to your computer and use it in GitHub Desktop.
BlinkTradeJS API
This file contains 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
var moment = require('moment'); | |
var BlinkTradeRest = require('blinktrade').BlinkTradeRest; | |
var BlinkTrade = new BlinkTradeRest({ | |
prod: true, | |
key: 'Ya8EkJ1kJSLyt5ZX60aWlmA7zPEgBqajt7UmvCZEvaA', | |
secret: 'xUS4e9hEl1RGpj4Fmh4KvQYKMWT2yItG9SGlDx4aYfo', | |
currency: 'BRL', | |
}); | |
var since = moment() | |
.subtract(2, 'days') | |
.toDate() | |
.getTime() | |
.toString() | |
.slice(0, 10); | |
BlinkTrade.trades(1000, since).then(function(data) { | |
console.log('Trades', data); | |
}); |
This file contains 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
var BlinkTradeWS = require('blinktrade').BlinkTradeWS; | |
var blinktrade = new BlinkTradeWS(); | |
blinktrade.connect().then(function() { | |
console.log('WebSocket Connceted'); | |
return blinktrade.heartbeat(); | |
}).then(function(heartbeat) { | |
console.log('TestRequest: Latency', heartbeat.Latency); | |
return blinktrade.login('rodrigo', 'abc12345'); | |
}).then(function(login) { | |
console.log('Rodrigo Logged', login); | |
return blinktrade.profile(); | |
}).then(function(profile) { | |
console.log('My Profile', profile); | |
return blinktrade.subscribeTicker(['BLINK:BTCUSD']) | |
.on('BLINK:BTCUSD', function(data) { | |
console.log('Ticker Updated', data); | |
}); | |
}).then(function(ticker) { | |
console.log('Ticker', ticker); | |
return blinktrade.subscribeOrderbook(['BTCUSD']) | |
.on('OB_NEW_ORDER', function(data) { | |
console.log('OB_NEW_ORDER', data); | |
}).on('OB_UPDATE_ORDER', function(data) { | |
console.log('OB_UPDATE_ORDER', data); | |
}).on('OB_DELETE_ORDER', function(data) { | |
console.log('OB_DELETE_ORDER', data); | |
}).on('OB_DELETE_ORDERS_THRU', function(data) { | |
console.log('OB_DELETE_ORDERS_THRU', data); | |
}).on('OB_TRADE_NEW', function(data) { | |
console.log('OB_TRADE_NEW', data); | |
}); | |
}).then(function(marketData) { | |
console.log('OrderBook FULL REFRESH', marketData); | |
return blinktrade.balance() | |
.on('BALANCE', function(data) { | |
console.log('Balance Updated', data); | |
}); | |
}).then(function(balance) { | |
blinktrade.executionReport() | |
.on('EXECUTION_REPORT_NEW', function(data) { | |
console.log('EXECUTION_REPORT_NEW', data); | |
}).on('EXECUTION_REPORT_PARTIAL', function(data) { | |
console.log('EXECUTION_REPORT_PARTIAL', data); | |
}).on('EXECUTION_REPORT_EXECUTION', function(data) { | |
console.log('EXECUTION_REPORT_EXECUTION', data); | |
}).on('EXECUTION_REPORT_CANCELED', function(data) { | |
console.log('EXECUTION_REPORT_CANCELED', data); | |
}).on('EXECUTION_REPORT_REJECTED', function(data) { | |
console.log('EXECUTION_REPORT_REJECTED', data); | |
}); | |
console.log('Sending Order'); | |
return blinktrade.sendOrder({ | |
side: '1', | |
price: parseInt(550 * 1e8, 10), | |
amount: parseInt(0.05 * 1e8, 10), | |
symbol: 'BTCUSD', | |
}); | |
}).then(function(order) { | |
console.log('Cancelling order'); | |
return blinktrade.cancelOrder(order.OrderID, order.ClOrdID); | |
}).then(function(order) { | |
return blinktrade.myOrders(); | |
}).then(function(myOrders) { | |
console.log('My Orders', myOrders); | |
return blinktrade.tradeHistory(); | |
}).then(function(trades) { | |
console.log('Trade History', trades); | |
return blinktrade.logout(); | |
}).then(function(logout) { | |
console.log('Logout'); | |
}).catch(function(err) { | |
console.log('Error', err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment