This repository was archived by the owner on Sep 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcostavering.js
68 lines (56 loc) · 2.37 KB
/
costavering.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
68
"use strict";
let stdio = require('stdio');
let ops = stdio.getopt({
'price': {key: 'p', args: 1, mandatory: true, description: 'Start price to calculate'},
'size': {key: 's',args: 1, mandatory: true, description: 'Size to buy per increment 0.1 ex. for 0.1 LTC'},
'number': {key: 'n', args: 1, description: 'Number of orders'},
'bottombuyprice': {key: 'b', args: 1, description: 'Bottom buy price'},
'increment': {key: 'i', args: 1, mandatory: true, description: 'The increment in cents (5 = 5 cent increment)'},
'sellprice': {key: 't', args: 1, mandatory: true, description: 'Price at which to sell'},
'amount': {key: 'a', args: 1, description: 'Size of crypto you wonna sell (You do not need to fill in number and topprice'},
});
let PRICE = parseFloat(ops.price);
let SIZE = parseFloat(ops.size);
let NUMBER = parseInt(ops.number);
let INCREMENT = ops.increment;
let SELLPRICE = parseFloat(ops.sellprice);
let BOTTOMPRICE = parseFloat(ops.bottombuyprice);
let diffPrice = 0.0;
let incrementInCents = 0;
let AMOUNT = parseFloat(ops.amount);
if (!NUMBER && !AMOUNT && !BOTTOMPRICE){
console.log('Please fill in number of orders or the amount......');
return;
}
if (!NUMBER && BOTTOMPRICE){
diffPrice = parseFloat((PRICE -BOTTOMPRICE) * 100).toFixed(2);
NUMBER = parseInt(diffPrice / INCREMENT) + 1;
}
// Round down so we do not sell
if (!NUMBER && !BOTTOMPRICE){
NUMBER = parseInt(Math.floor(AMOUNT / SIZE));
}
//console.log('DiffPrice: ' + diffPrice);
//console.log('Number orders: ' + NUMBER);
let profit = 0.0;
let breakeven = 0.0;
let buyPrice = 0.0;
let n = 0;
let profitPerOrder = 0.0;
let sizeOrders = 0.0;
for (var i = 0; i < NUMBER;i++) {
n = i + 1;
buyPrice = parseFloat(PRICE - i*(INCREMENT/100)).toFixed(2);
//console.log(n + 'th buyPrice: ' + buyPrice);
profitPerOrder = (SELLPRICE - buyPrice) * SIZE;
profit += profitPerOrder;
//console.log('Profit: ' + parseFloat(profitPerOrder).toFixed(2));
breakeven += parseFloat(buyPrice);
sizeOrders += parseFloat(SIZE);
}
//console.log('Break even total: ' + breakeven);
breakeven = (breakeven / NUMBER);
console.log('Break even sellprice: ' + parseFloat(breakeven).toFixed(3));
console.log('Profit at sellprice ' + SELLPRICE + ' = ' + parseFloat(profit).toFixed(2));
console.log('Number of orders: ' + NUMBER);
console.log('Ordersize: ' + parseFloat(sizeOrders).toFixed(8));