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 https = require('https');
- const request = require('request');
- const master_config = require('./config.json');
- 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 t = new Date();
- var timethen = t.getMinutes();
- var predohranitel = 0;
- var kolvo = 0;
- // Чет я заигрался с переменными
- 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;
- var real_amount;
- var priceBinancePair1;
- var priceBinancePair2;
- var priceBinance3MinutesAgo;
- function request_real_amount(){
- request({
- 'url':'https://api.olymptrade.com/v4/user/values',
- 'method': "POST",
- 'proxy': `${master_config.proxy}`,
- headers: {
- Host: `api.olymptrade.com`,
- 'Content-Type': 'application/json',
- 'X-Request-Project': 'bo',
- 'X-Request-Type': 'Api-Request',
- Cookie: `session=${master_config.session}`
- },
- json:{
- list:["balance"]
- }
- },function callback (error, response, body) {
- real_amount = body.data.balance.real.amount;
- });
- }
- 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_real_amount();
- 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;
- const config = this.config.pairs[olymp];
- var pair_kolvo = config.kolvo;
- var delta = Math.abs(diff);
- var direction = 0;
- const pair1 = (master_config.pair1.charAt(0));
- const pair2 = (master_config.pair2.charAt(0));
- var t2 = new Date();
- var timenew = t2.getMinutes();
- 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 (timenew >= (timethen + config.padenie.time)){
- priceBinancePair1 = priceBinance;
- }
- priceBinance3MinutesAgo = priceBinancePair1;
- }
- 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 (timenew >= (timethen + config.padenie.time)){
- priceBinancePair2 = priceBinance;
- }
- priceBinance3MinutesAgo = priceBinancePair2;
- }
- if(timenew >= (timethen + config.padenie.time)){
- timethen = timenew;
- if (priceBinance <= (priceBinance3MinutesAgo-config.padenie.min)){
- for (var i = 0; i < config.padenie.kolvo; i++) {
- this.deal(olymp, config.padenie.amount, "up", config.padenie.duration * 60, 'digital', config.group);
- }
- }
- }
- // console.log('Пaрa =',pair);
- // console.log('Рaзницa =',delta);
- // console.log('Среднее =',sred);
- // console.log('-----------------------------------');
- // console.log('');
- if (delta >= (sred + config.delta.min))
- var direction = "down";
- if (delta <= (sred - config.delta.min))
- var direction = "up";
- if (direction == 0)
- return;
- if (kolvo >= pair_kolvo)
- return;
- if (this.dealEnded) {
- console.log('New_signal', {
- pair: olymp,
- delta,
- diff,
- sred,
- direction,
- percent
- });
- }
- if ('percent' in config && percent < config.percent){
- console.log('Wrong percent');
- return;
- }
- 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') {
- 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,
- sred,
- duration,
- cat,
- group
- });
- kolvo = kolvo + 1;
- setTimeout(() => (kolvo = 0), duration * 1000);
- //this.dealEnded = false;
- request_real_amount();
- if (real_amount > master_config.amount.max | real_amount < master_config.amount.min) {
- // Ддля первого случая -> Запишем баланс в файл для командного скрипта и прекратим работу
- // Если баланс меньше, тут надо думать. Либо делать обработку сливов отдельно по парам, либо просто всё плюсовать
- // А надо ли обрабатывать?
- // А может на командный скрипт повесить?
- process.exit(-1);
- }
- 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