Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.29 KB | None | 0 0
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. // tslint:disable: no-console
  7. const request = require('request');
  8. const fs = require("fs");
  9. const newLineChar = require('os').EOL;
  10. const master_config = require('./config.json');
  11. const https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
  12. const node_notifier_1 = __importDefault(require("node-notifier"));
  13. const binance_1 = __importDefault(require("./signal/binance"));
  14. const olymp_1 = __importDefault(require("./signal/olymp"));
  15. const pairs_1 = __importDefault(require("./signal/pairs"));
  16. const ws_1 = __importDefault(require("./ws"));
  17.  
  18. var t = new Date();
  19. var timethenlog = t.getMinutes();
  20. var kolvo;
  21. var rubil = 0;
  22. var pair_kolvo;
  23. var priceBinanceAgo = 0;
  24. var sred;
  25. var finDeltaMin;
  26. var sred_delta;
  27. var delta_d;
  28. var sred_delta_d;
  29. var diff2;
  30. var r = 0;
  31. var signals = 0;
  32. var pairMassiv;
  33. var gindir;
  34. var down = 0;
  35. var up = 0;
  36. var real_amount;
  37.  
  38. var pairMassivName;
  39.  
  40. setTimeout(() => (r = 1), 60000);
  41.  
  42. // Вместо ебли с переменными, попробуй регулярное выражение // setInterval(() => alert('tick'), 2000);
  43.  
  44. // Pair = [schet, shit, sred, timethenpair, priceBinancePair, timethenpadenie, test_delta, test_shit, средняя дельтa рaзницы со средней дифф, shit для сред дельт, kolvo]
  45. var pairs = [];
  46. if ("Bitcoin" in master_config.pairs){
  47. var BTCUSD = [0,0,1,t.getMinutes(),0,t.getMinutes(),0,0,0,0,0,0];
  48. pairs.push('BTCUSD');
  49. }
  50. if ("ETCUSD" in master_config.pairs){
  51. var ETCUSD = [0,0,1,t.getMinutes(),0,t.getMinutes(),0,0,0,0,0,0];
  52. pairs.push('ETCUSD');
  53. }
  54. if ("XRPUSD" in master_config.pairs){
  55. var XRPUSD = [0,0,1,t.getMinutes(),0,t.getMinutes(),0,0,0,0,0,0];
  56. pairs.push('XRPUSD');
  57. }
  58. if ("ETHUSD" in master_config.pairs){
  59. var ETHUSD = [0,0,1,t.getMinutes(),0,t.getMinutes(),0,0,0,0,0,0];
  60. pairs.push('ETHUSD');
  61. }
  62. function logging(log){
  63. fs.appendFile("./log.txt",`${newLineChar}${log}`, function(error){
  64. if(error) throw error;
  65. });
  66. return;
  67. }
  68. function request_real_amount(){
  69. request({
  70. 'url':'https://api.olymptrade.com/v4/user/values',
  71. 'method': "POST",
  72. 'proxy': `${master_config.proxy}`,
  73. headers: {
  74. 'Host': `api.olymptrade.com`,
  75. 'Content-Type': 'application/json',
  76. 'X-Request-Project': 'bo',
  77. 'X-Request-Type': 'Api-Request',
  78. Cookie: `session=${master_config.session}`
  79. },
  80. json:{
  81. list:["balance"]
  82. }
  83. },function (error, response, body) {
  84. if (error) {}
  85. else {
  86. real_amount = body.data.balance.real.amount;
  87. console.log('Текущий баланс:', '\x1b[32m', body.data.balance.real.amount, '\x1b[0m');
  88. }
  89. });
  90. }
  91. function request_last_deal(){
  92. request({
  93. 'url':'https://api.olymptrade.com/v3/cabinet/deals-history',
  94. 'method': "POST",
  95. 'proxy': `${master_config.proxy}`,
  96. 'json': {"limit":1,"group":"real","order":"time_close","page":1},
  97. headers: {
  98. 'Host': `api.olymptrade.com`,
  99. 'X-Request-Project': 'bo',
  100. 'X-Request-Type': 'Api-Request',
  101. Cookie: `session=${master_config.session}`
  102. }
  103.  
  104. },function callback (error, response, body) {
  105. if (error) {}
  106. else {
  107. console.log('Пара:', '\x1b[32m', body.data[0].pair, '\x1b[0m', 'Статус:', '\x1b[32m', body.data[0].status, '\x1b[0m', 'Изменение баланса:', '\x1b[32m', body.data[0].balance_change, '\x1b[0m');
  108. }
  109. });
  110. }
  111. function detectPair(pair) {
  112. let pairOlymp = pair;
  113. let pairBinance = pairs_1.default.Olymp.Binance[pairOlymp];
  114. if (!pairBinance) {
  115. pairBinance = pair;
  116. pairOlymp = pairs_1.default.Binance.Olymp[pairBinance];
  117. }
  118. return { binance: pairBinance, olymp: pairOlymp };
  119. }
  120. request_real_amount();
  121.  
  122. class OlympBot {
  123. constructor(config) {
  124. this.config = config;
  125. this.binance = new binance_1.default();
  126. this.update = (pair) => {
  127. const { binance, olymp } = detectPair(pair);
  128. const priceBinance = this.binance.prices[binance];
  129. const priceOlymp = this.olymp.prices[olymp];
  130. const percent = this.olymp.percents[olymp];
  131.  
  132. if (real_amount <= master_config.amount.min) {
  133. process.exit(-1);
  134. }
  135. if (!priceBinance || !priceOlymp)
  136. return;
  137. const diff = priceOlymp - priceBinance;
  138. const test_delta = Math.abs(diff);
  139. const config = this.config.pairs[olymp];
  140. const pair_kolvo = config.kolvo;
  141. var direction = 0;
  142. var t2 = new Date();
  143. var timenew = t2.getMinutes();
  144.  
  145. function updatePairs(pair){
  146. let pairHere;
  147. let pairSwitch;
  148. if (pair.slice(-1) == 'T'){
  149. pairSwitch = (pair.substring(0, pair.length - 1));
  150. }
  151. else {
  152. pairSwitch = pair;
  153. }
  154. if (pair == 'Bitcoin'){
  155. pairSwitch = 'BTCUSD';
  156. }
  157. pairHere = eval(pairSwitch);
  158. pairMassiv = eval(pairSwitch);
  159. pairMassivName = pairSwitch;
  160. pairHere[0] = pairHere[0] + 1;
  161. pairHere[1] = pairHere[1] + diff;
  162. pairHere[2] = pairHere[1] / pairHere[0];
  163.  
  164. // Delta_testing_zone
  165. pairHere[6] = pairHere[6] + test_delta;
  166. sred_delta = pairHere[6] / pairHere[0];
  167. sred = pairHere[2];
  168.  
  169. // Средняя дельтa рaзницы от средней дифф
  170. diff2 = diff - sred;
  171. delta_d = Math.abs(diff - sred);
  172. pairHere[8] = pairHere[8] + delta_d;
  173. sred_delta_d = pairHere[8] / pairHere[0]
  174. finDeltaMin = (sred_delta / 100 * config.diff.min);
  175. kolvo = pairHere[11];
  176. // Тут функция пaдения
  177. if (timenew >= (pairHere[5] + config.padenie.time)){
  178. pairHere[5] = timenew;
  179. pairHere[4] = priceBinance;
  180. rubil = 1;
  181. }
  182. priceBinanceAgo = pairHere[4];
  183. }
  184. updatePairs(pair);
  185.  
  186. // Тоже пaдение
  187. if(rubil == 1){
  188. if (priceBinance <= (priceBinanceAgo - config.padenie.min)){
  189. for (var i = 1; i <= config.padenie.kolvo; i++) {
  190. this.deal(olymp, config.padenie.amount, "up", config.padenie.duration * 60, 'digital', config.group);
  191. }
  192. rubil = 0;
  193. }
  194. }
  195. if (r == 0)
  196. return;
  197. if (diff > (sred + finDeltaMin))
  198. direction = "down";
  199. if (diff < (sred - finDeltaMin))
  200. direction = "up";
  201. if (delta_d < (sred_delta_d * config.diff.mnoj))
  202. return;
  203. console.log('Стaвкa прошлa', pairMassiv[10], 'Нaпрaвление', direction, 'Пaрa', pair, 'priceOlymp', priceOlymp, 'Время', t2);
  204. pairMassiv[10] = pairMassiv[10] + 1;
  205. if (gindir == "down")
  206. down = down + 1;
  207. if (gindir == "up")
  208. up = up + 1;
  209.  
  210. if (pairMassivName == 'BTCUSD')
  211. setTimeout(() => (BTCUSD[10] = 0), 2000);
  212.  
  213. if (pairMassivName == 'ETCUSD')
  214. setTimeout(() => (ETCUSD[10] = 0), 2000);
  215.  
  216. if (pairMassivName == 'ETHUSD')
  217. setTimeout(() => (ETHUSD[10] = 0), 2000);
  218.  
  219. if (pairMassivName == 'XRPUSD')
  220. setTimeout(() => (XRPUSD[10] = 0), 2000);
  221.  
  222. setTimeout(() => (up = 0), 30000);
  223. setTimeout(() => (down = 0), 30000);
  224.  
  225. if (pairMassiv[10] < config.diff.signals)
  226. return;
  227. if (pairMassiv[11] >= pair_kolvo)
  228. return;
  229. pairMassiv[11] = pairMassiv[11] + 1;
  230.  
  231. if (pairMassivName == 'BTCUSD')
  232. setTimeout(() => (BTCUSD[11] = 0), 60000);
  233.  
  234. if (pairMassivName == 'ETCUSD')
  235. setTimeout(() => (ETCUSD[11] = 0), 60000);
  236.  
  237. if (pairMassivName == 'ETHUSD')
  238. setTimeout(() => (ETHUSD[11] = 0), 60000);
  239.  
  240. if (pairMassivName == 'XRPUSD')
  241. setTimeout(() => (XRPUSD[11] = 0), 60000);
  242.  
  243. if (true) {
  244. let y = ({
  245. pair: olymp,
  246. diff,
  247. sred_delta,
  248. sred,
  249. priceOlymp,
  250. percent
  251. });
  252. console.log('New_signal', y);
  253. logging("New signal");
  254. logging(JSON.stringify(y));
  255. }
  256. if ('percent' in config && percent < config.percent){
  257. console.log('Wrong percent');
  258. logging('Wrong percent');
  259. return;
  260. }
  261. let am = Math.ceil(real_amount / 100 * config.amount);
  262. if (am >= 15)
  263. am = 15
  264. this.deal(olymp, am, direction, config.duration * 60, 'digital', config.group);
  265.  
  266. };
  267. this.wsOlymp = new ws_1.default(config.session, config.proxy);
  268. this.olymp = new olymp_1.default(this.wsOlymp);
  269. this.init();
  270. node_notifier_1.default.notify({
  271. title: 'Olymp Bot',
  272. message: 'Bot is running'
  273. });
  274. console.log('Bot is running');
  275. }
  276. deal(pair, amount, dir, duration, cat, group = 'real') {
  277. node_notifier_1.default.notify({
  278. title: 'Olymp Bot',
  279. message: `New deal has started\r\n${pair}|${amount}|${dir}|${duration}`
  280. });
  281. let y = ({
  282. pair,
  283. amount,
  284. dir,
  285. sred,
  286. duration,
  287. cat,
  288. group
  289. });
  290. console.log('NEW DEAL',y);
  291. logging('NEW DEAL');
  292. logging(JSON.stringify(y));
  293.  
  294. kolvo = kolvo + 1;
  295. setTimeout(() => (request_real_amount()), 62000);
  296. setTimeout(() => (request_last_deal()), 62000);
  297. return this.wsOlymp.startDeal(pair, amount, dir, duration, cat, group);
  298. }
  299. async subscribe(pair) {
  300. const { binance, olymp } = detectPair(pair);
  301. if (await this.olymp.subscribe(olymp)) {
  302. if (await this.binance.subscribe(binance))
  303. return true;
  304. else
  305. await this.olymp.unsubscribe(olymp);
  306. }
  307. return false;
  308. }
  309. init() {
  310. this.binance.on('signal', this.update);
  311. this.olymp.on('signal', this.update);
  312. for (const pair of Object.keys(this.config.pairs)) {
  313. this.subscribe(pair);
  314. }
  315. }
  316. }
  317. exports.default = OlympBot;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement