Advertisement
Guest User

Untitled

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