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 fs = require("fs");
- const newLineChar = require('os').EOL;
- 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 timethenlog = t.getMinutes();
- var kolvo;
- var rubil = 0;
- var pair_kolvo;
- var priceBinanceAgo = 0;
- var sred;
- var finDeltaMin;
- var sred_delta;
- var delta_d;
- var sred_delta_d;
- var diff2;
- var r = 0;
- var signals = 0;
- var pairMassiv;
- var gindir;
- var down = 0;
- var up = 0;
- var real_amount;
- var pairMassivName;
- setTimeout(() => (r = 1), 60000);
- // Вместо ебли с переменными, попробуй регулярное выражение // setInterval(() => alert('tick'), 2000);
- // Pair = [schet, shit, sred, timethenpair, priceBinancePair, timethenpadenie, test_delta, test_shit, средняя дельтa рaзницы со средней дифф, shit для сред дельт, kolvo]
- var pairs = [];
- if ("Bitcoin" in master_config.pairs){
- var BTCUSD = [0,0,1,t.getMinutes(),0,t.getMinutes(),0,0,0,0,0,0];
- pairs.push('BTCUSD');
- }
- if ("ETCUSD" in master_config.pairs){
- var ETCUSD = [0,0,1,t.getMinutes(),0,t.getMinutes(),0,0,0,0,0,0];
- pairs.push('ETCUSD');
- }
- if ("XRPUSD" in master_config.pairs){
- var XRPUSD = [0,0,1,t.getMinutes(),0,t.getMinutes(),0,0,0,0,0,0];
- pairs.push('XRPUSD');
- }
- if ("ETHUSD" in master_config.pairs){
- var ETHUSD = [0,0,1,t.getMinutes(),0,t.getMinutes(),0,0,0,0,0,0];
- pairs.push('ETHUSD');
- }
- function logging(log){
- fs.appendFile("./log.txt",`${newLineChar}${log}`, function(error){
- if(error) throw error;
- });
- return;
- }
- 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 (error, response, body) {
- if (error) {}
- else {
- real_amount = body.data.balance.real.amount;
- console.log('Текущий баланс:', '\x1b[32m', body.data.balance.real.amount, '\x1b[0m');
- }
- });
- }
- function request_last_deal(){
- request({
- 'url':'https://api.olymptrade.com/v3/cabinet/deals-history',
- 'method': "POST",
- 'proxy': `${master_config.proxy}`,
- 'json': {"limit":1,"group":"real","order":"time_close","page":1},
- headers: {
- 'Host': `api.olymptrade.com`,
- 'X-Request-Project': 'bo',
- 'X-Request-Type': 'Api-Request',
- Cookie: `session=${master_config.session}`
- }
- },function callback (error, response, body) {
- if (error) {}
- else {
- console.log('Пара:', '\x1b[32m', body.data[0].pair, '\x1b[0m', 'Статус:', '\x1b[32m', body.data[0].status, '\x1b[0m', 'Изменение баланса:', '\x1b[32m', body.data[0].balance_change, '\x1b[0m');
- }
- });
- }
- 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.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 (real_amount <= master_config.amount.min) {
- process.exit(-1);
- }
- if (!priceBinance || !priceOlymp)
- return;
- const diff = priceOlymp - priceBinance;
- const test_delta = Math.abs(diff);
- const config = this.config.pairs[olymp];
- const pair_kolvo = config.kolvo;
- var direction = 0;
- var t2 = new Date();
- var timenew = t2.getMinutes();
- function updatePairs(pair){
- let pairHere;
- let pairSwitch;
- if (pair.slice(-1) == 'T'){
- pairSwitch = (pair.substring(0, pair.length - 1));
- }
- else {
- pairSwitch = pair;
- }
- if (pair == 'Bitcoin'){
- pairSwitch = 'BTCUSD';
- }
- pairHere = eval(pairSwitch);
- pairMassiv = eval(pairSwitch);
- pairMassivName = pairSwitch;
- pairHere[0] = pairHere[0] + 1;
- pairHere[1] = pairHere[1] + diff;
- pairHere[2] = pairHere[1] / pairHere[0];
- // Delta_testing_zone
- pairHere[6] = pairHere[6] + test_delta;
- sred_delta = pairHere[6] / pairHere[0];
- sred = pairHere[2];
- // Средняя дельтa рaзницы от средней дифф
- diff2 = diff - sred;
- delta_d = Math.abs(diff - sred);
- pairHere[8] = pairHere[8] + delta_d;
- sred_delta_d = pairHere[8] / pairHere[0]
- finDeltaMin = (sred_delta / 100 * config.diff.min);
- kolvo = pairHere[11];
- // Тут функция пaдения
- if (timenew >= (pairHere[5] + config.padenie.time)){
- pairHere[5] = timenew;
- pairHere[4] = priceBinance;
- rubil = 1;
- }
- priceBinanceAgo = pairHere[4];
- }
- updatePairs(pair);
- // Тоже пaдение
- if(rubil == 1){
- if (priceBinance <= (priceBinanceAgo - config.padenie.min)){
- for (var i = 1; i <= config.padenie.kolvo; i++) {
- this.deal(olymp, config.padenie.amount, "up", config.padenie.duration * 60, 'digital', config.group);
- }
- rubil = 0;
- }
- }
- if (r == 0)
- return;
- if (diff > (sred + finDeltaMin))
- direction = "down";
- if (diff < (sred - finDeltaMin))
- direction = "up";
- if (delta_d < (sred_delta_d * config.diff.mnoj))
- return;
- console.log('Стaвкa прошлa', pairMassiv[10], 'Нaпрaвление', direction, 'Пaрa', pair, 'priceOlymp', priceOlymp, 'Время', t2);
- pairMassiv[10] = pairMassiv[10] + 1;
- if (gindir == "down")
- down = down + 1;
- if (gindir == "up")
- up = up + 1;
- if (pairMassivName == 'BTCUSD')
- setTimeout(() => (BTCUSD[10] = 0), 2000);
- if (pairMassivName == 'ETCUSD')
- setTimeout(() => (ETCUSD[10] = 0), 2000);
- if (pairMassivName == 'ETHUSD')
- setTimeout(() => (ETHUSD[10] = 0), 2000);
- if (pairMassivName == 'XRPUSD')
- setTimeout(() => (XRPUSD[10] = 0), 2000);
- setTimeout(() => (up = 0), 30000);
- setTimeout(() => (down = 0), 30000);
- if (pairMassiv[10] < config.diff.signals)
- return;
- if (pairMassiv[11] >= pair_kolvo)
- return;
- pairMassiv[11] = pairMassiv[11] + 1;
- if (pairMassivName == 'BTCUSD')
- setTimeout(() => (BTCUSD[11] = 0), 60000);
- if (pairMassivName == 'ETCUSD')
- setTimeout(() => (ETCUSD[11] = 0), 60000);
- if (pairMassivName == 'ETHUSD')
- setTimeout(() => (ETHUSD[11] = 0), 60000);
- if (pairMassivName == 'XRPUSD')
- setTimeout(() => (XRPUSD[11] = 0), 60000);
- if (true) {
- let y = ({
- pair: olymp,
- diff,
- sred_delta,
- sred,
- priceOlymp,
- percent
- });
- console.log('New_signal', y);
- logging("New signal");
- logging(JSON.stringify(y));
- }
- if ('percent' in config && percent < config.percent){
- console.log('Wrong percent');
- logging('Wrong percent');
- return;
- }
- let am = Math.ceil(real_amount / 100 * config.amount);
- if (am >= 15)
- am = 15
- this.deal(olymp, am, 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}`
- });
- let y = ({
- pair,
- amount,
- dir,
- sred,
- duration,
- cat,
- group
- });
- console.log('NEW DEAL',y);
- logging('NEW DEAL');
- logging(JSON.stringify(y));
- kolvo = kolvo + 1;
- setTimeout(() => (request_real_amount()), 62000);
- setTimeout(() => (request_last_deal()), 62000);
- 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