-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
224 lines (169 loc) · 5.54 KB
/
index.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
const express = require('express')
const app = express()
app.use(express.json())
const Binance = require('binance-api-node').default
const client = new Binance({
apiKey: process.env.KEY,
apiSecret: process.env.SECKEY
})
let maxCoinPrice = -1;
let intervalObj;
app.post('/', function (req, res) {
console.log(req.body)
switch(req.body['action']){
case 'info':
GetCoinInfo()
break;
case 'sell':
SellMarket()
break;
case 'buy':
BuyMarket();
break;
default:
console.log("Error command!!!!!!!!!!!!!!!!!!");
}
res.status(200).json({
msg: "OK"
})
})
////////// XRP DOGE
async function BuyMarket(){
let coinToBuy = "DOGEUSDT" ///////////
let coinPrice = await getCoinPrice(coinToBuy)
let USDTCount = await getWalletCoinCount("USDT")
let coinCount = Math.floor((USDTCount-0.1)/coinPrice) //usdt count USDTCount-0.1
if(USDTCount < 35){
console.log("HEEEEEEEEEEEEEEEEEYYYYYY, BALANCE LESSS --- 35 --- USDT");
return;
}
console.log(`${coinToBuy} price ${coinPrice}`)
console.log(`${coinToBuy} count ${coinCount}`)
console.log(`usdt count ${USDTCount}`)
console.log(
await client.order({
symbol: coinToBuy,
side: 'BUY',
quantity: coinCount,
type: 'MARKET'
})
)
await setOCO(coinToBuy, coinPrice, 0.025);
console.log("!!!!!!!!!!!!!!!!SOVERSHENA POKUPKA!!!!!!!!!!!!!!")
console.log(` ${USDTCount} USDT --> ${coinCount} ${coinToBuy}, Market price: ${coinPrice}`)
customSellSkriptStart(coinToBuy, coinPrice)
}
async function SellMarket(){
let coinToSell = "DOGEUSDT" //////////////////////
try{
console.log(
await client.cancelOpenOrders({
symbol: coinToSell
})
)
} catch(ex){
console.log("ERROR TRY TO CANCEL OPEN ORDER")
} finally {
let coinCount = Math.floor(await getWalletCoinCount('DOGE')) ///////////////////////////
console.log(`RUNNING FINALY CONSTRUCTION ${coinCount}`)
console.log(
await client.order({
symbol: coinToSell,
side: 'SELL',
quantity: coinCount,
type: 'MARKET'
})
)
let USDTCount = await getWalletCoinCount("USDT")
let BNBCount = await getWalletCoinCount("BNB")
console.log("!!!!!!!!!!!!!!!!!SOVERSHENA PRODASHA!!!!!!!!!!!!!!")
console.log(`Curent USDT = ${USDTCount}`)
console.log(`Curent BNB = ${BNBCount}`)
clearInterval(intervalObj);
}
}
async function customSellSkriptStart(coinCode, coinPrice){
setPercent1 = false;
setPercent2 = false;
setPercent3 = false;
setPercent5 = false;
coinPricePercent1 = (coinPrice*1.01).toPrecision(5);
coinPricePercent2 = (coinPrice*1.02).toPrecision(5);
coinPricePercent3 = (coinPrice*1.03).toPrecision(5);
coinPricePercent5 = (coinPrice*1.05).toPrecision(5);
intervalObj = setInterval( async() => {
let currentCoinPrice = await getCoinPrice(coinCode);
if(currentCoinPrice > maxCoinPrice){
maxCoinPrice = currentCoinPrice;
console.log(`NEW MAX PRICE : ${maxCoinPrice}`);
}
if( maxCoinPrice > coinPricePercent5 && !setPercent5){
setPercent5 = true;
await setOCO(coinCode, maxCoinPrice, 0.03);
} else if( maxCoinPrice > coinPricePercent3 && !setPercent3){
setPercent3 = true;
await setOCO(coinCode, maxCoinPrice, 0.02);
} else if( maxCoinPrice > coinPricePercent2 && !setPercent2){
setPercent2 = true;
await setOCO(coinCode, maxCoinPrice, 0.018);
} else if( maxCoinPrice > coinPricePercent1 && !setPercent1){
setPercent1 = true;
await setOCO(coinCode, maxCoinPrice, 0.02);
}
}, 2000);
maxCoinPrice = -1;
}
////////////////////////////functions/////////////////////////
async function setOCO(coinCode, coinPrice, downPercent){
let OSO = await getOCOLimits(coinPrice, downPercent)
console.log(OSO)
WalletInfo = await client.accountInfo();
coinCount = Math.floor(WalletInfo.balances.find(item=>item.asset==="DOGE").free); /////////////////////////////////// DOGE
try{
console.log(
await client.cancelOpenOrders({
symbol: coinCode
})
)
} catch(ex){
console.log("ERROR TRY TO CANCEL OPEN ORDER")
} finally{
console.log("RUNING FINALLY CONSTRUCTION")
console.log("DOGECOUNT +++++++ TO SET OSO ", coinCount)
await client.orderOco({
symbol: coinCode,
side: 'SELL',
quantity: coinCount,
price: OSO.top,
stopPrice: OSO.stop,
stopLimitPrice: OSO.limit
})
console.log(`SET OSO FOR --- ${downPercent} --- percent`);
}
}
async function GetCoinInfo(){
WalletInfo = await client.accountInfo();
console.log(`USDT -> ${WalletInfo.balances.find(item=>item.asset==="USDT").free}`)
console.log(`BNB -> ${WalletInfo.balances.find(item=>item.asset==="BNB").free}`)
}
async function getCoinPrice(coin){
let coinPrice = await client.prices({
symbol: coin
})
return coinPrice[coin]
}
async function getWalletCoinCount(coin){
let WalletInfo = await client.accountInfo()
return WalletInfo.balances.find(item=>item.asset===coin).free
}
function getOCOLimits(coinPrice, downPercent=0.04, upPercent = 0.10){
var topPrice = (parseFloat(coinPrice) + (coinPrice*upPercent)).toPrecision(5)
var stopPrice = (coinPrice - (coinPrice*downPercent)).toPrecision(5)
var limitPrice = (stopPrice*0.996).toPrecision(5)
return {
"top": topPrice,
"stop": stopPrice,
"limit": limitPrice
}
}
app.listen(process.env.PORT)