Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 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 node_notifier_1 = __importDefault(require("node-notifier"));
  8. const binance_1 = __importDefault(require("./signal/binance"));
  9. const olymp_1 = __importDefault(require("./signal/olymp"));
  10. const pairs_1 = __importDefault(require("./signal/pairs"));
  11. const ws_1 = __importDefault(require("./ws"));
  12. var predohranitel = 0;
  13. var t = new Date();
  14. var timethen = t.getMinutes();
  15. var kolvo = 1;
  16.  
  17. function detectPair(pair) {
  18. let pairOlymp = pair;
  19. let pairBinance = pairs_1.default.Olymp.Binance[pairOlymp];
  20. if (!pairBinance) {
  21. pairBinance = pair;
  22. pairOlymp = pairs_1.default.Binance.Olymp[pairBinance];
  23. }
  24. return { binance: pairBinance, olymp: pairOlymp };
  25. }
  26. class OlympBot {
  27. constructor(config) {
  28. this.config = config;
  29. this.binance = new binance_1.default();
  30. this.dealEnded = true;
  31. this.update = (pair) => {
  32. const { binance, olymp } = detectPair(pair);
  33. const priceBinance = this.binance.prices[binance];
  34. const priceOlymp = this.olymp.prices[olymp];
  35. const percent = this.olymp.percents[olymp];
  36.  
  37. if (!priceBinance || !priceOlymp)
  38. return;
  39. const diff = priceBinance - priceOlymp;
  40.  
  41. // Мой дебаг
  42. //console.log('Pair = ', pair);
  43. //console.log('Diff = ', diff);
  44. //console.log('------------------------------');
  45. // Мой дебаг кончился и начался мой говнокод
  46.  
  47. var standart_diff;
  48. if (pair == 'Bitcoin')
  49. standart_diff = -15;
  50.  
  51. if (pair == 'ETHUSD')
  52. standart_diff = -0.5;
  53.  
  54. if (pair == 'ETCUSD')
  55. standart_diff = -0.01;
  56.  
  57. if (pair == 'XRPUSD')
  58. standart_diff = -0.00054;
  59.  
  60. if (pair == 'LTCUSD')
  61. standart_diff = -0.135;
  62.  
  63. if (pair == 'ZECUSD')
  64. standart_diff = -0.044;
  65.  
  66. if (pair == 'DASHUSD')
  67. standart_diff = -0.077;
  68.  
  69.  
  70. const delta_2 = Math.abs(standart_diff);
  71. var delta = Math.abs(diff);
  72. const direction = diff > standart_diff ? 'up' : 'down'; //Тут был const вместо var
  73. const config = this.config.pairs[olymp];
  74.  
  75. global.conf = config;
  76.  
  77. if (direction == 'up'){
  78. var some_shit = delta_2 - delta;
  79. delta = config.delta.min;
  80. }
  81. else
  82. var some_shit = config.delta.min;
  83.  
  84. if (delta < config.delta.min | some_shit < config.delta.min)
  85. return;
  86. if ('max' in config.delta && delta > config.delta.max)
  87. return;
  88.  
  89. //Предохранитель от волатильности
  90. let t2 = new Date();
  91. var timenew = t2.getMinutes();
  92. if (timenew >= (timethen + 3)){
  93. timethen = timenew;
  94. predohranitel = predohranitel - 15;
  95. }
  96.  
  97. if (predohranitel < 30)
  98. predohranitel = predohranitel + 1;
  99. if (predohranitel >= 30)
  100. return;
  101.  
  102. if (this.dealEnded) {
  103. console.log('Normal_delta', {
  104. config,
  105. delta,
  106. percent,
  107. perB: 'Percent' in config && percent < config.percent
  108. });
  109. }
  110. if ('Percent' in config && percent < config.percent)
  111. return;
  112. if (this.dealEnded) {
  113. console.log('New_signal', {
  114. pair: olymp,
  115. delta,
  116. diff,
  117. direction,
  118. percent
  119. });
  120. }
  121. this.deal(olymp, config.amount, direction, config.duration * 60, 'digital', config.group);
  122.  
  123. };
  124. this.wsOlymp = new ws_1.default(config.session, config.proxy);
  125. this.olymp = new olymp_1.default(this.wsOlymp);
  126. this.init();
  127. node_notifier_1.default.notify({
  128. title: 'Olymp Bot',
  129. message: 'Bot is running'
  130. });
  131. console.log('Bot is running');
  132. }
  133. deal(pair, amount, dir, duration, cat, group = 'real') {
  134.  
  135. kolvo = kolvo + 1;
  136. if (global.conf.kolvo >= kolvo)
  137. return false;
  138.  
  139. node_notifier_1.default.notify({
  140. title: 'Olymp Bot',
  141. message: `New deal has started\r\n${pair}|${amount}|${dir}|${duration}`
  142. });
  143. console.log('New_deal', {
  144. pair,
  145. amount,
  146. dir,
  147. duration,
  148. cat,
  149. group
  150. });
  151. //this.dealEnded = false;
  152. setTimeout(() => (kolvo = 1), duration * 100);
  153. return this.wsOlymp.startDeal(pair, amount, dir, duration, cat, group);
  154. }
  155. async subscribe(pair) {
  156. const { binance, olymp } = detectPair(pair);
  157. if (await this.olymp.subscribe(olymp)) {
  158. if (await this.binance.subscribe(binance))
  159. return true;
  160. else
  161. await this.olymp.unsubscribe(olymp);
  162. }
  163. return false;
  164. }
  165. init() {
  166. this.binance.on('signal', this.update);
  167. this.olymp.on('signal', this.update);
  168. for (const pair of Object.keys(this.config.pairs)) {
  169. this.subscribe(pair);
  170. }
  171. }
  172. }
  173. exports.default = OlympBot;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement