Created
September 6, 2016 22:29
-
-
Save cesardeazevedo/9e30fe7e5494d3644ef2b9e9ded363e2 to your computer and use it in GitHub Desktop.
BlinkTradeJS Examples
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
var BlinkTradeWS = require('blinktrade').BlinkTradeWS; | |
var blinktrade = new BlinkTradeWS(); | |
blinktrade.connect().then(function() { | |
return blinktrade.login({ username: 'rodrigo', password: 'abc12345' }); | |
}).then(function(logged) { | |
console.log(logged); | |
}).catch(function(err) { | |
console.log(err); | |
}); |
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
var BlinkTradeWS = require('blinktrade').BlinkTradeWS; | |
var blinktrade = new BlinkTradeWS(); | |
blinktrade.connect().then(function() { | |
return blinktrade.login({ username: 'rodrigo', password: 'abc12345' }); | |
}).then(function(logged) { | |
return blinktrade.balance(); | |
}).then(function(balance) { | |
console.log('Balance', balance); | |
}).catch(function(err) { | |
console.log(err); | |
}); |
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
var BlinkTradeWS = require('blinktrade').BlinkTradeWS; | |
var blinktrade = new BlinkTradeWS(); | |
blinktrade.connect().then(function() { | |
return blinktrade.login({ username: 'rodrigo', password: 'abc12345' }); | |
}).then(function(logged) { | |
return blinktrade.requestDeposit(); | |
}).then(function(deposit) { | |
console.log('\nBitcoin Deposit \n', deposit); | |
return blinktrade.requestDeposit({ | |
value: parseInt(200 * 1e8), | |
currency: 'BRL', | |
depositMethodId: 502, | |
}); | |
}).then(function(deposit) { | |
console.log('\nFiat Deposit \n', deposit); | |
}).catch(function(err) { | |
console.log(err); | |
}); |
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
var BlinkTradeWS = require('blinktrade').BlinkTradeWS; | |
var blinktrade = new BlinkTradeWS(); | |
function onBalanceUpdate(newBalance) { | |
console.log('Balance Updated', newBalance); | |
} | |
function onExecutionReportNew(data) { | |
console.log('EXECUTION_REPORT:NEW', data); | |
} | |
function onExecutionReportPartial(data) { | |
console.log('EXECUTION_REPORT:PARTIAL', data); | |
} | |
function onExecutionReportExecution(data) { | |
console.log('EXECUTION_REPORT:EXECUTION', data); | |
} | |
function onExecutionReportCanceled(data) { | |
console.log('EXECUTION_REPORT:CANCELED', data); | |
} | |
function onExecutionReportRejected(data) { | |
console.log('EXECUTION_REPORT:REJECTED', data); | |
} | |
function onOrderBookNewOrder(data) { | |
console.log('OB:NEW_ORDER', data); | |
} | |
function onOrderBookUpdateOrder(data) { | |
console.log('OB:UPDATE_ORDER', data); | |
} | |
function onOrderBookDeleteOrder(data) { | |
console.log('OB:DELETE_ORDER', data); | |
} | |
function onOrderBookDeleteThruOrder(data) { | |
console.log('OB:DELETE_ORDERS_THRU', data); | |
} | |
function onOrderBookTradeNew(data) { | |
console.log('OB:TRADE_NEW', data); | |
} | |
function onAnyTicker(data) { | |
console.log('Any Ticker Updated'); | |
} | |
function onBTCUSD(data) { | |
console.log('BTCUSD', data); | |
} | |
function onBTCBRL(data) { | |
console.log('BTCBRL', data); | |
} | |
blinktrade.connect().then(function() { | |
return blinktrade.login({ username: 'rodrigo', password: 'abc12345' }); | |
}).then(function(logged) { | |
return blinktrade.balance().on('BALANCE', onBalanceUpdate); | |
}).then(function(balance) { | |
console.log('Balance', balance); | |
blinktrade.executionReport() | |
.on('EXECUTION_REPORT:NEW', onExecutionReportNew) | |
.on('EXECUTION_REPORT:PARTIAL', onExecutionReportPartial) | |
.on('EXECUTION_REPORT:EXECUTION', onExecutionReportExecution) | |
.on('EXECUTION_REPORT:CANCELED', onExecutionReportCanceled) | |
.on('EXECUTION_REPORT:REJECTED', onExecutionReportRejected); | |
return blinktrade.subscribeOrderbook(['BTCUSD']) | |
.on('OB:NEW_ORDER', onOrderBookNewOrder) | |
.on('OB:UPDATE_ORDER', onOrderBookUpdateOrder) | |
.on('OB:DELETE_ORDER', onOrderBookDeleteOrder) | |
.on('OB:DELETE_ORDERS_THRU', onOrderBookDeleteThruOrder) | |
.on('OB:TRADE_NEW', onOrderBookTradeNew); | |
}).then(function(orderbook) { | |
return blinktrade.subscribeTicker(['BLINK:BTCUSD', 'BLINK:BTCBRL']) | |
.on('BLINK:*', onAnyTicker) | |
.on('BLINK:BTCUSD', onBTCUSD) | |
.many('BLINK:BTCBRL', 2, onBTCBRL); | |
}).then(function(ticker) { | |
return blinktrade.sendOrder({ | |
side: '1', | |
price: parseInt(550 * 1e8, 10), | |
amount: parseInt(0.05 * 1e8, 10), | |
symbol: 'BTCUSD', | |
}); | |
}).then(function(order) { | |
return blinktrade.cancelOrder({ | |
orderId: order.OrderID, | |
clientId: order.ClOrdID | |
}); | |
}).catch(function(err) { | |
console.log(err); | |
}); |
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
var BlinkTradeWS = require('blinktrade').BlinkTradeWS; | |
var blinktrade = new BlinkTradeWS(); | |
function onNew(data) { | |
console.log('New Order Received', data); | |
} | |
function onPartial(data) { | |
console.log('Order Partially Executed', data); | |
} | |
function onExecution(data) { | |
console.log('Order Executed', data); | |
} | |
function onCanceled(data) { | |
console.log('Order Canceled', data); | |
} | |
function onRejected(data) { | |
console.log('Order Rejected', data); | |
} | |
blinktrade.connect().then(function() { | |
return blinktrade.login({ username: 'rodrigo', password: 'abc12345' }); | |
}).then(function(logged) { | |
blinktrade.executionReport() | |
.on('EXECUTION_REPORT:NEW', onNew) | |
.on('EXECUTION_REPORT:PARTIAL', onPartial) | |
.on('EXECUTION_REPORT:EXECUTION', onExecution) | |
.on('EXECUTION_REPORT:CANCELED', onCanceled) | |
.on('EXECUTION_REPORT:REJECTED', onRejected); | |
return blinktrade.sendOrder({ | |
side: '1', | |
price: parseInt(550 * 1e8, 10), | |
amount: parseInt(0.05 * 1e8, 10), | |
symbol: 'BTCUSD', | |
}); | |
}).then(function(order) { | |
// Cancel order after 5 seconds | |
setTimeout(function() { | |
return blinktrade.cancelOrder({ orderId: order.OrderID, clientId: order.ClOrdID }); | |
}, 5000) | |
}).catch(function(err) { | |
console.log(err); | |
}); |
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
var BlinkTradeWS = require('blinktrade').BlinkTradeWS; | |
var blinktrade = new BlinkTradeWS(); | |
blinktrade.connect().then(function() { | |
return blinktrade.subscribeOrderbook(['BTCUSD']) | |
}).then(function(orderbook) { | |
console.log(orderbook); | |
}).catch(function(err) { | |
console.log(err); | |
}); |
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
/* eslint-disable */ | |
var moment = require('moment'); | |
var BlinkTradeRest = require('blinktrade').BlinkTradeRest; | |
var BlinkTrade = new BlinkTradeRest({ | |
prod: true, | |
currency: 'BRL', | |
}); | |
var since = moment() | |
.subtract(2, 'days') | |
.toDate() | |
.getTime() | |
.toString() | |
.slice(0, 10); | |
BlinkTrade.ticker().then(function(data) { | |
console.log('Ticker', data); | |
}); | |
BlinkTrade.orderbook().then(function(data) { | |
console.log('OrderBook', data.pair, 'Bids:', data.bids.length, 'Asks:', data.asks.length); | |
}); | |
BlinkTrade.trades(1000, since).then(function(data) { | |
console.log('Trades', data.length); | |
}); |
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
var BlinkTradeWS = require('blinktrade').BlinkTradeWS; | |
var blinktrade = new BlinkTradeWS(); | |
blinktrade.connect().then(function() { | |
return blinktrade.login({ username: 'rodrigo', password: 'abc12345' }); | |
}).then(function(logged) { | |
return blinktrade.requestDepositList() | |
}).then(function(deposits) { | |
console.log('Deposits', deposits); | |
}).catch(function(err) { | |
console.log(err); | |
}); | |
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
var BlinkTradeWS = require('blinktrade').BlinkTradeWS; | |
var blinktrade = new BlinkTradeWS(); | |
blinktrade.connect().then(function() { | |
return blinktrade.login({ username: 'rodrigo', password: 'abc12345' }); | |
}).then(function(logged) { | |
return blinktrade.requestWithdrawList() | |
}).then(function(withdraws) { | |
console.log('Withdraws', withdraws.WithdrawListGrp); | |
}).catch(function(err) { | |
console.log(err); | |
}); |
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
var BlinkTradeRest = require('blinktrade').BlinkTradeRest; | |
var blinktrade = new BlinkTradeRest({ | |
prod: false, | |
key: 'Ya8EkJ1kJSLyt5ZX60aWlmA7zPEgBqajt7UmvCZEvaA', | |
secret: 'xUS4e9hEl1RGpj4Fmh4KvQYKMWT2yItG9SGlDx4aYfo', | |
currency: 'BRL', | |
}); | |
blinktrade.sendOrder({ | |
side: '1', | |
price: parseInt(550 * 1e8, 10), | |
amount: parseInt(0.05 * 1e8, 10), | |
symbol: 'BTCUSD', | |
}).then(function(order) { | |
console.log(order); | |
console.log('Cancelling order: #' + order[0].OrderID); | |
return blinktrade.cancelOrder({ orderId: order[0].OrderID, clientId: order[0].ClOrdID }); | |
}).then(function(order) { | |
console.log(order); | |
console.log('Order: #' + order[0].OrderID + ' cancelled'); | |
}).catch(function(err) { | |
console.log(err); | |
}); | |
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
var BlinkTradeWS = require('blinktrade').BlinkTradeWS; | |
var blinktrade = new BlinkTradeWS(); | |
blinktrade.connect().then(function() { | |
return blinktrade.login({ username: 'rodrigo', password: 'abc12345' }); | |
}).then(function() { | |
return blinktrade.sendOrder({ | |
side: '1', | |
price: parseInt(550 * 1e8, 10), | |
amount: parseInt(0.05 * 1e8, 10), | |
symbol: 'BTCUSD', | |
}); | |
}).then(function(order) { | |
console.log(order); | |
console.log('Cancelling order: #' + order.OrderID); | |
return blinktrade.cancelOrder({ orderId: order.OrderID, clientId: order.ClOrdID }); | |
}).then(function(order) { | |
console.log('Order: #' + order.OrderID + ' cancelled'); | |
}).catch(function(err) { | |
console.log(err); | |
}); |
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
var BlinkTradeWS = require('blinktrade').BlinkTradeWS; | |
var blinktrade = new BlinkTradeWS(); | |
blinktrade.connect().then(function() { | |
return blinktrade.subscribeTicker(['BLINK:BTCUSD']) | |
}).then(function(ticker) { | |
console.log(ticker); | |
}).catch(function(err) { | |
console.log(err); | |
}); |
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
var BlinkTradeWS = require('blinktrade').BlinkTradeWS; | |
var blinktrade = new BlinkTradeWS(); | |
blinktrade.connect().then(function() { | |
return blinktrade.tradeHistory(); | |
}).then(function(trades) { | |
console.log(trades); | |
}).catch(function(err) { | |
console.log(err); | |
}); |
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
var BlinkTradeWS = require('blinktrade').BlinkTradeWS; | |
var blinktrade = new BlinkTradeWS(); | |
blinktrade.connect().then(function() { | |
return blinktrade.login({ username: 'rodrigo', password: 'abc12345' }); | |
}).then(function(logged) { | |
return blinktrade.requestWithdraw({ | |
amount: parseInt(200 * 1e8), | |
currency: 'USD', | |
method: 'PayPal', | |
data: { | |
Email: '[email protected]' | |
} | |
}); | |
}).then(function(withdraw) { | |
console.log('\nFIAT Withdraw: \n', withdraw); | |
return blinktrade.requestWithdraw({ | |
amount: parseInt(0.5 * 1e8), | |
currency: 'BTC', | |
method: 'bitcoin', | |
data: { | |
Wallet: '1KdEQfoxxgfgV1GkGb9JBX1F9fiaCqZdgV' | |
} | |
}); | |
}).then(function(withdraw) { | |
console.log('\nBitcoin Withdraw: \n', withdraw); | |
}).catch(function(err) { | |
console.log(err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment