-
Notifications
You must be signed in to change notification settings - Fork 1
/
seller.js
67 lines (55 loc) · 2.09 KB
/
seller.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
58
59
60
61
62
63
64
65
66
67
const gdaxWrapper = require('./modules/gdaxWrapper');
const config = require('./config.json');
const noise = require('./modules/noise');
const authClient = new gdaxWrapper.getAuthClient(
config.gdax.key,
config.gdax.secret,
config.gdax.passphrase,
"https://api.gdax.com"
);
const productID = process.env.PRODUCT_ID || config.defaults.productId;
const publicClient = gdaxWrapper.getPublicClient(productID);
const interval = config.defaults.peakFinderInterval;
let totalSharesMem, initialStandingMem = false;
const tradingFee = parseFloat(config.gdax.tradingFee);
const lastPurchaseAmount = parseFloat(process.env.LAST_PURCHASE_AMT);
const lastPurchasePrice = parseFloat(process.env.LAST_PURCHASE_PRICE);
const minProfitAllowed = parseFloat(process.env.MIN_PROFIT_PEAK);
const tradingFeeLoss = lastPurchaseAmount * tradingFee;
const initialStanding = (lastPurchaseAmount - tradingFeeLoss);
const totalShares = initialStanding / lastPurchasePrice;
console.log(`Your initial standing is: ${initialStanding}`);
console.log(`Your total shares are: ${totalShares}`);
function shouldDoSale(lastPrice) {
let currentStanding = (lastPrice * totalShares);
let currentStandingWithFee = currentStanding - (currentStanding * tradingFee);
console.log(`Last Price: ${lastPrice} - Total Shares: ${totalShares}`);
console.log(`Your current standing is ${currentStanding}`);
console.log(` minus the trading fee: ${currentStandingWithFee}`);
let profitToBeMade = currentStandingWithFee - lastPurchaseAmount;
console.log(`Profit to be made if sold: ${profitToBeMade}`);
console.log(`----------------------------------------------------------`);
return (profitToBeMade >= minProfitAllowed);
}
function updateStats() {
publicClient.getProductTicker( (err, response, body) => {
if(err) {
console.error(err);
}
else if(body) {
noise.sayTicker(body);
if(shouldDoSale(parseFloat(body.ask))) {
noise.soundAlarm();
}
}
});
}
if(process.env.TLP) {
shouldDoSale(parseFloat(process.env.TLP));
}
else {
updateStats();
setInterval( () => {
updateStats();
}, interval);
}