forked from chrisleekr/binance-trading-bot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AppSorting.js
94 lines (87 loc) · 2.26 KB
/
AppSorting.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* eslint-disable react/jsx-no-undef */
/* eslint-disable no-undef */
const sortingAlpha = (symbols, direction) =>
_.orderBy(symbols, s => s.symbol, direction);
const sortingSellProfit = (symbols, direction) =>
_.orderBy(
symbols,
s =>
s.sell.currentProfitPercentage !== null
? s.sell.currentProfitPercentage
: direction === 'asc'
? 999
: -999,
direction
);
const sortingBuyDifference = (symbols, direction) =>
_.orderBy(
symbols,
s =>
s.buy.difference !== null
? s.buy.difference
: direction === 'asc'
? 999
: -999,
direction
);
const sortingDefault = (symbols, direction) =>
_.orderBy(
symbols,
s => {
if (s.buy.openOrders.length > 0) {
const openOrder = s.buy.openOrders[0];
if (openOrder.differenceToCancel) {
return (openOrder.differenceToCancel + 3000) * -10;
}
}
if (s.sell.openOrders.length > 0) {
const openOrder = s.sell.openOrders[0];
if (openOrder.differenceToCancel) {
return (openOrder.differenceToCancel + 2000) * -10;
}
}
if (s.sell.difference) {
return (s.sell.difference + 1000) * -10;
}
return s.buy.difference;
},
direction
);
// eslint-disable-next-line no-unused-vars
const sortingSymbols = (orgSymbols, { selectedSortOption, searchKeyword }) => {
const symbols = orgSymbols.filter(s =>
s.symbol.toLowerCase().includes(searchKeyword.toLowerCase())
);
const sortingMaps = {
default: {
sortingFunc: sortingDefault,
direction: 'asc'
},
'buy-difference-asc': {
sortingFunc: sortingBuyDifference,
direction: 'asc'
},
'buy-difference-desc': {
sortingFunc: sortingBuyDifference,
direction: 'desc'
},
'sell-profit-asc': {
sortingFunc: sortingSellProfit,
direction: 'asc'
},
'sell-profit-desc': {
sortingFunc: sortingSellProfit,
direction: 'desc'
},
'alpha-asc': {
sortingFunc: sortingAlpha,
direction: 'asc'
},
'alpha-desc': {
sortingFunc: sortingAlpha,
direction: 'desc'
}
};
const sortingMap = sortingMaps[selectedSortOption];
return sortingMap.sortingFunc(symbols, sortingMap.direction);
};