Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.79 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.  
  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. if (direction == 'up'){
  76. var some_shit = delta_2 - delta;
  77. delta = config.delta.min;
  78. }
  79. else
  80. var some_shit = config.delta.min;
  81.  
  82. if (delta < config.delta.min | some_shit < config.delta.min)
  83. return;
  84. if ('max' in config.delta && delta > config.delta.max)
  85. return;
  86.  
  87. //Предохранитель от волатильности
  88. let t2 = new Date();
  89. var timenew = t2.getMinutes();
  90. if (timenew >= (timethen + 3)){
  91. console.log('+');
  92. timethen = timenew;
  93. predohranitel = predohranitel - 5;
  94. }
  95.  
  96. predohranitel = predohranitel + 1;
  97. if (predohranitel >= 10)
  98. return;
  99.  
  100. if (this.dealEnded) {
  101. console.log('Normal_delta', {
  102. config,
  103. delta,
  104. percent,
  105. perB: 'Percent' in config && percent < config.percent
  106. });
  107. }
  108. if ('Percent' in config && percent < config.percent)
  109. return;
  110. if (this.dealEnded) {
  111. console.log('New_signal', {
  112. pair: olymp,
  113. delta,
  114. diff,
  115. direction,
  116. percent
  117. });
  118. }
  119. this.deal(olymp, config.amount, direction, config.duration * 60, 'digital', config.group);
  120. };
  121. this.wsOlymp = new ws_1.default(config.session, config.proxy);
  122. this.olymp = new olymp_1.default(this.wsOlymp);
  123. this.init();
  124. node_notifier_1.default.notify({
  125. title: 'Olymp Bot',
  126. message: 'Bot is running'
  127. });
  128. console.log('Bot is running');
  129. }
  130. deal(pair, amount, dir, duration, cat, group = 'real') {
  131. if (!this.dealEnded)
  132. return false;
  133. node_notifier_1.default.notify({
  134. title: 'Olymp Bot',
  135. message: `New deal has started\r\n${pair}|${amount}|${dir}|${duration}`
  136. });
  137. console.log('New_deal', {
  138. pair,
  139. amount,
  140. dir,
  141. duration,
  142. cat,
  143. group
  144. });
  145. this.dealEnded = false;
  146. setTimeout(() => (this.dealEnded = true), duration * 1000);
  147. return this.wsOlymp.startDeal(pair, amount, dir, duration, cat, group);
  148. }
  149. async subscribe(pair) {
  150. const { binance, olymp } = detectPair(pair);
  151. if (await this.olymp.subscribe(olymp)) {
  152. if (await this.binance.subscribe(binance))
  153. return true;
  154. else
  155. await this.olymp.unsubscribe(olymp);
  156. }
  157. return false;
  158. }
  159. init() {
  160. this.binance.on('signal', this.update);
  161. this.olymp.on('signal', this.update);
  162. for (const pair of Object.keys(this.config.pairs)) {
  163. this.subscribe(pair);
  164. }
  165. }
  166. }
  167. exports.default = OlympBot;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement