Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.22 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 https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
  9. const node_notifier_1 = __importDefault(require("node-notifier"));
  10. const binance_1 = __importDefault(require("./signal/binance"));
  11. const olymp_1 = __importDefault(require("./signal/olymp"));
  12. const pairs_1 = __importDefault(require("./signal/pairs"));
  13. const ws_1 = __importDefault(require("./ws"));
  14.  
  15. var predohranitel = 0;
  16. var t = new Date();
  17. var timethen = t.getMinutes();
  18. var kolvo = -1;
  19.  
  20. function detectPair(pair) {
  21. let pairOlymp = pair;
  22. let pairBinance = pairs_1.default.Olymp.Binance[pairOlymp];
  23. if (!pairBinance) {
  24. pairBinance = pair;
  25. pairOlymp = pairs_1.default.Binance.Olymp[pairBinance];
  26. }
  27. return { binance: pairBinance, olymp: pairOlymp };
  28. }
  29. /*
  30. request.post({
  31. url: 'https://api.olymptrade.com/v4/user/values',
  32. headers: {
  33. Pragma: `no-cache`,
  34. Origin: `https://olymptrade.com`,
  35. Host: `olymptrade.com`,
  36. Cookie: `session=`
  37. }
  38. }, function (error, response, body){
  39. console.log(body);
  40. });
  41. */
  42. var sred;
  43. var schet_pair1 = 0;
  44. var shit_pair1 = 0;
  45. var sred_pair1 = 1;
  46. var schet_pair2 = 0;
  47. var shit_pair2 = 0;
  48. var sred_pair2 = 1;
  49.  
  50. var pair1_y;
  51. var pair2_y;
  52.  
  53. class OlympBot {
  54. constructor(config) {
  55. this.config = config;
  56. global.conf = config;
  57. this.binance = new binance_1.default();
  58. this.dealEnded = true;
  59. this.update = (pair) => {
  60. const { binance, olymp } = detectPair(pair);
  61. const priceBinance = this.binance.prices[binance];
  62. const priceOlymp = this.olymp.prices[olymp];
  63. const percent = this.olymp.percents[olymp];
  64.  
  65. if (!priceBinance || !priceOlymp)
  66. return;
  67. const diff = priceBinance - priceOlymp;
  68. const config = this.config.pairs[olymp];
  69. global.configg = config;
  70. var delta = Math.abs(diff);
  71. var direction = 0;
  72.  
  73.  
  74. const pair1 = (global.conf.pair1.charAt(0));
  75. const pair2 = (global.conf.pair2.charAt(0));
  76.  
  77. if (pair1 == (pair.charAt(0))) {
  78. schet_pair1 = schet_pair1 + 1;
  79. shit_pair1 = shit_pair1 + delta;
  80. sred_pair1 = shit_pair1 / schet_pair1;
  81. sred = sred_pair1;
  82.  
  83. }
  84. if (pair2 == (pair.charAt(0))) {
  85. schet_pair2 = schet_pair2 + 1;
  86. shit_pair2 = shit_pair2 + delta;
  87. sred_pair2 = shit_pair2 / schet_pair2;
  88. sred = sred_pair2;
  89. }
  90.  
  91. if (delta >= (sred + config.delta.min)){
  92. var direction = "down";
  93. }
  94. if (delta <= (sred - config.delta.min)){
  95. var direction = "up";
  96. }
  97. if (direction == 0)
  98. return;
  99. if ('max' in config.delta && delta > config.delta.max)
  100. return;
  101.  
  102. //console.log(global.conf.proxy);
  103.  
  104. //Предохранитель от волатильности
  105. //Уже фaктически не нужен
  106. let t2 = new Date();
  107. var timenew = t2.getMinutes();
  108. if (timenew >= (timethen + 2)){
  109. timethen = timenew;
  110. predohranitel = predohranitel - 15;
  111. }
  112. if (predohranitel < 30)
  113. predohranitel = predohranitel + 1;
  114. if (predohranitel >= 30){
  115. return;
  116. }
  117.  
  118. if (this.dealEnded) {
  119. console.log('Normal_delta', {
  120. config,
  121. delta,
  122. percent,
  123. perB: 'percent' in config && percent < config.percent
  124. });
  125. }
  126. if ('percent' in config && percent < config.percent)
  127. return;
  128. if (this.dealEnded) {
  129. console.log('New_signal', {
  130. pair: olymp,
  131. delta,
  132. diff,
  133. direction,
  134. percent
  135. });
  136. }
  137. this.deal(olymp, config.amount, direction, config.duration * 60, 'digital', config.group);
  138.  
  139. };
  140. this.wsOlymp = new ws_1.default(config.session, config.proxy);
  141. this.olymp = new olymp_1.default(this.wsOlymp);
  142. this.init();
  143. node_notifier_1.default.notify({
  144. title: 'Olymp Bot',
  145. message: 'Bot is running'
  146. });
  147. console.log('Bot is running');
  148. }
  149. deal(pair, amount, dir, duration, cat, group = 'real') {
  150. kolvo = kolvo + 1;
  151. if (kolvo >= global.configg.kolvo)
  152. return false;
  153.  
  154. node_notifier_1.default.notify({
  155. title: 'Olymp Bot',
  156. message: `New deal has started\r\n${pair}|${amount}|${dir}|${duration}`
  157. });
  158. console.log('New_deal', {
  159. pair,
  160. amount,
  161. dir,
  162. duration,
  163. cat,
  164. group
  165. });
  166. setTimeout(() => (kolvo = -1), duration * 1000);
  167.  
  168. //this.dealEnded = false;
  169. /*
  170. request.post('https://api.olymptrade.com/v4/user/values', function (error, response, html){
  171. console.log(html);
  172. });
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194. /*
  195. headers: {
  196. Pragma: `no-cache`,
  197. Origin: `https://olymptrade.com`,
  198. Host: `api.olymptrade.com`,
  199. Cookie: `session=${global.conf.session}`
  200. }
  201. body: {
  202. "list":["balance"]
  203. }
  204. };
  205. if (proxy) {
  206. options.agent = new https_proxy_agent_1.default(proxy);
  207. options.rejectUnauthorized = false;
  208. }
  209. request(options)
  210. .then(function (response) {
  211. // Запрос был успешным, используйте объект ответа как хотите
  212. })
  213. .catch(function (err) {
  214. // Произошло что-то плохое, обработка ошибки
  215. })
  216. */
  217. return this.wsOlymp.startDeal(pair, amount, dir, duration, cat, group);
  218. }
  219. async subscribe(pair) {
  220. const { binance, olymp } = detectPair(pair);
  221. if (await this.olymp.subscribe(olymp)) {
  222. if (await this.binance.subscribe(binance))
  223. return true;
  224. else
  225. await this.olymp.unsubscribe(olymp);
  226. }
  227. return false;
  228. }
  229. init() {
  230. this.binance.on('signal', this.update);
  231. this.olymp.on('signal', this.update);
  232. for (const pair of Object.keys(this.config.pairs)) {
  233. this.subscribe(pair);
  234. }
  235. }
  236. }
  237. exports.default = OlympBot;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement