Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- // tslint:disable: no-console
- const request = require ('request');
- const https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
- const node_notifier_1 = __importDefault(require("node-notifier"));
- const binance_1 = __importDefault(require("./signal/binance"));
- const olymp_1 = __importDefault(require("./signal/olymp"));
- const pairs_1 = __importDefault(require("./signal/pairs"));
- const ws_1 = __importDefault(require("./ws"));
- var predohranitel = 0;
- var t = new Date();
- var timethen = t.getMinutes();
- var kolvo = -1;
- function detectPair(pair) {
- let pairOlymp = pair;
- let pairBinance = pairs_1.default.Olymp.Binance[pairOlymp];
- if (!pairBinance) {
- pairBinance = pair;
- pairOlymp = pairs_1.default.Binance.Olymp[pairBinance];
- }
- return { binance: pairBinance, olymp: pairOlymp };
- }
- /*
- request.post({
- url: 'https://api.olymptrade.com/v4/user/values',
- headers: {
- Pragma: `no-cache`,
- Origin: `https://olymptrade.com`,
- Host: `olymptrade.com`,
- Cookie: `session=`
- }
- }, function (error, response, body){
- console.log(body);
- });
- */
- var sred;
- var schet_pair1 = 0;
- var shit_pair1 = 0;
- var sred_pair1 = 1;
- var schet_pair2 = 0;
- var shit_pair2 = 0;
- var sred_pair2 = 1;
- var pair1_y;
- var pair2_y;
- class OlympBot {
- constructor(config) {
- this.config = config;
- global.conf = config;
- this.binance = new binance_1.default();
- this.dealEnded = true;
- this.update = (pair) => {
- const { binance, olymp } = detectPair(pair);
- const priceBinance = this.binance.prices[binance];
- const priceOlymp = this.olymp.prices[olymp];
- const percent = this.olymp.percents[olymp];
- if (!priceBinance || !priceOlymp)
- return;
- const diff = priceBinance - priceOlymp;
- const config = this.config.pairs[olymp];
- global.configg = config;
- var delta = Math.abs(diff);
- var direction = 0;
- const pair1 = (global.conf.pair1.charAt(0));
- const pair2 = (global.conf.pair2.charAt(0));
- if (pair1 == (pair.charAt(0))) {
- schet_pair1 = schet_pair1 + 1;
- shit_pair1 = shit_pair1 + delta;
- sred_pair1 = shit_pair1 / schet_pair1;
- sred = sred_pair1;
- }
- if (pair2 == (pair.charAt(0))) {
- schet_pair2 = schet_pair2 + 1;
- shit_pair2 = shit_pair2 + delta;
- sred_pair2 = shit_pair2 / schet_pair2;
- sred = sred_pair2;
- }
- if (delta >= (sred + config.delta.min)){
- var direction = "down";
- }
- if (delta <= (sred - config.delta.min)){
- var direction = "up";
- }
- if (direction == 0)
- return;
- if ('max' in config.delta && delta > config.delta.max)
- return;
- //console.log(global.conf.proxy);
- //Предохранитель от волатильности
- //Уже фaктически не нужен
- let t2 = new Date();
- var timenew = t2.getMinutes();
- if (timenew >= (timethen + 2)){
- timethen = timenew;
- predohranitel = predohranitel - 15;
- }
- if (predohranitel < 30)
- predohranitel = predohranitel + 1;
- if (predohranitel >= 30){
- return;
- }
- if (this.dealEnded) {
- console.log('Normal_delta', {
- config,
- delta,
- percent,
- perB: 'percent' in config && percent < config.percent
- });
- }
- if ('percent' in config && percent < config.percent)
- return;
- if (this.dealEnded) {
- console.log('New_signal', {
- pair: olymp,
- delta,
- diff,
- direction,
- percent
- });
- }
- this.deal(olymp, config.amount, direction, config.duration * 60, 'digital', config.group);
- };
- this.wsOlymp = new ws_1.default(config.session, config.proxy);
- this.olymp = new olymp_1.default(this.wsOlymp);
- this.init();
- node_notifier_1.default.notify({
- title: 'Olymp Bot',
- message: 'Bot is running'
- });
- console.log('Bot is running');
- }
- deal(pair, amount, dir, duration, cat, group = 'real') {
- kolvo = kolvo + 1;
- if (kolvo >= global.configg.kolvo)
- return false;
- node_notifier_1.default.notify({
- title: 'Olymp Bot',
- message: `New deal has started\r\n${pair}|${amount}|${dir}|${duration}`
- });
- console.log('New_deal', {
- pair,
- amount,
- dir,
- duration,
- cat,
- group
- });
- setTimeout(() => (kolvo = -1), duration * 1000);
- //this.dealEnded = false;
- /*
- request.post('https://api.olymptrade.com/v4/user/values', function (error, response, html){
- console.log(html);
- });
- /*
- headers: {
- Pragma: `no-cache`,
- Origin: `https://olymptrade.com`,
- Host: `api.olymptrade.com`,
- Cookie: `session=${global.conf.session}`
- }
- body: {
- "list":["balance"]
- }
- };
- if (proxy) {
- options.agent = new https_proxy_agent_1.default(proxy);
- options.rejectUnauthorized = false;
- }
- request(options)
- .then(function (response) {
- // Запрос был успешным, используйте объект ответа как хотите
- })
- .catch(function (err) {
- // Произошло что-то плохое, обработка ошибки
- })
- */
- return this.wsOlymp.startDeal(pair, amount, dir, duration, cat, group);
- }
- async subscribe(pair) {
- const { binance, olymp } = detectPair(pair);
- if (await this.olymp.subscribe(olymp)) {
- if (await this.binance.subscribe(binance))
- return true;
- else
- await this.olymp.unsubscribe(olymp);
- }
- return false;
- }
- init() {
- this.binance.on('signal', this.update);
- this.olymp.on('signal', this.update);
- for (const pair of Object.keys(this.config.pairs)) {
- this.subscribe(pair);
- }
- }
- }
- exports.default = OlympBot;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement