-
Notifications
You must be signed in to change notification settings - Fork 0
/
example2.js
58 lines (47 loc) · 2 KB
/
example2.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
'use strict'; // jshint ignore:line
// jshint esversion: 6
/* globals require: true, __dirname: true, process: true, console: true, module: true */
var BitFinexAPI = require('.');
var options = {
events: true,
refresh: 60, // Refresh time in seconds (Default: 60)
currency: 'USD' // Convert price to different currencies. (Default USD)
};
var bitfinex = new BitFinexAPI(options);
bitfinex.getTickers('btc', ticker => {
console.log('\nBitcoin tickers info (currency: %s): \n', options.currency);
console.log(ticker);
});
// Put event for price greater or equal than X
bitfinex.onPriceAbove('BTC', 4000, (symbol, event) => {
console.log('BTC price is greater than 4000 of your defined currency');
event.price = event.price + 100; // Increase the price that the event needs to be fired.
});
bitfinex.onPriceBelow('BTC', 10000, (symbol, event) => {
console.log('BTC price is lesser than 3000 of your defined currency');
event.price = event.price - 100; // Decrease the price that the event needs to be fired.
});
/*
// Put event for percent change. You can define negative and positive percent changes.
bitfinex.onPricePercentChange7d('ETH', 15, (symbol, event) => {
console.log('BTC has a percent change above 15% in the last 7 days');
event.percent = event.percent + 5; // Increase the percentile change that the event needs to be fired.
});
*/
/*
bitfinex.onPricePercentChange24h('ETH', -10, (symbol, event) => {
console.log('BTC has a percent change beyond -10% in the last 24h');
event.percent = event.percent - 5; // Decrease the percentile change that the event needs to be fired.
});
*/
/*
bitfinex.onPricePercentChange1h('LTC', 10, (symbol, event) => {
console.log(symbol);
bitfinex.deleteEvent(event); // Deletes the event
});
*/
// Put event on BTC with no conditions. It will trigger every 60 seconds (*) with information about that symbol (*: Or the defined time in options)
bitfinex.onTickerUpdate('BTC', (symbol, event) => {
console.log(symbol);
bitfinex.deleteEvent(event); // Deletes the event
});