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 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()
- 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 };
- }
- class OlympBot {
- constructor(config) {
- this.config = 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;
- // Мой дебаг
- //console.log('Pair = ', pair);
- //console.log('Diff = ', diff);
- //console.log('------------------------------');
- // Мой дебаг кончился и начался мой говнокод
- var standart_diff;
- if (pair == 'Bitcoin')
- standart_diff = -15;
- if (pair == 'ETHUSD')
- standart_diff = -0.5;
- if (pair == 'ETCUSD')
- standart_diff = -0.01;
- if (pair == 'XRPUSD')
- standart_diff = -0.00054;
- if (pair == 'LTCUSD')
- standart_diff = -0.135;
- if (pair == 'ZECUSD')
- standart_diff = -0.044;
- if (pair == 'DASHUSD')
- standart_diff = -0.077;
- const delta_2 = Math.abs(standart_diff);
- var delta = Math.abs(diff);
- const direction = diff > standart_diff ? 'up' : 'down'; //Тут был const вместо var
- const config = this.config.pairs[olymp];
- if (direction == 'up'){
- var some_shit = delta_2 - delta;
- delta = config.delta.min;
- }
- else
- var some_shit = config.delta.min;
- if (delta < config.delta.min | some_shit < config.delta.min)
- return;
- if ('max' in config.delta && delta > config.delta.max)
- return;
- //Предохранитель от волатильности
- let t2 = new Date();
- var timenew = t2.getMinutes();
- if (timenew >= (timethen + 3)){
- console.log('+');
- timethen = timenew;
- predohranitel = predohranitel - 5;
- }
- predohranitel = predohranitel + 1;
- if (predohranitel >= 10)
- 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') {
- if (!this.dealEnded)
- 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
- });
- this.dealEnded = false;
- setTimeout(() => (this.dealEnded = true), duration * 1000);
- 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