abot-info 0.2.4 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/abot-info.gemspec +1 -0
- data/lib/abot/info/database_table.rb +2 -0
- data/lib/abot/info/decorators/coin_decorator.rb +7 -19
- data/lib/abot/info/helpers.rb +49 -7
- data/lib/abot/info/table.rb +6 -5
- data/lib/abot/info/telegram_sender.rb +32 -0
- data/lib/abot/info/version.rb +1 -1
- data/lib/abot/info.rb +21 -2
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c356808904955eec165f429c9a0012bc095865983303853d48ff09239e988e19
|
4
|
+
data.tar.gz: 930de8a6a519242048f9e02603090cdd9560c8040866ec0d23f80b3affa2062e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5fbf25ee4fc34c87213f122de255590ae13e316741b0d049f6bde84dd3cacb52f10e8a002eafb6c4eb269b13f4396e8ea06d6d99acf6f2763d59f29dfbe448d
|
7
|
+
data.tar.gz: f833ee553da12be027dd6e72ebc2544527ec2e64e9080939b2bcbc15628675111e70c1caaf691cbfca2229540bb2778f64c0a0a7f46e3777ca129ebbe7ad35cb
|
data/Gemfile
CHANGED
data/abot-info.gemspec
CHANGED
@@ -14,6 +14,8 @@ module Abot
|
|
14
14
|
API_KEY_TABLE = BASE_CONNECTION.execute('SELECT * FROM api_key').freeze
|
15
15
|
API_KEY = API_KEY_TABLE.first['api'].freeze
|
16
16
|
SECRET_KEY = API_KEY_TABLE.first['secret'].freeze
|
17
|
+
TG_TOKEN = API_KEY_TABLE.first['tg_token'].freeze
|
18
|
+
TG_NAME = API_KEY_TABLE.first['tg_name'].freeze
|
17
19
|
|
18
20
|
class << self
|
19
21
|
def data_coins
|
@@ -7,15 +7,7 @@ module Abot
|
|
7
7
|
def decorated_sell_up
|
8
8
|
return '-' if sell_up == Float::INFINITY
|
9
9
|
|
10
|
-
|
11
|
-
case num_averaging
|
12
|
-
when 1, 2
|
13
|
-
rounded_sell_up > 2 ? Paint[rounded_sell_up, :red] : rounded_sell_up
|
14
|
-
when 3, 4, 5
|
15
|
-
rounded_sell_up > 2 ? rounded_sell_up : Paint[rounded_sell_up, :red]
|
16
|
-
else
|
17
|
-
rounded_sell_up
|
18
|
-
end
|
10
|
+
sell_up.round(2)
|
19
11
|
end
|
20
12
|
|
21
13
|
def decorated_current_profit
|
@@ -44,19 +36,15 @@ module Abot
|
|
44
36
|
end
|
45
37
|
|
46
38
|
def decorated_name
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
''
|
53
|
-
end
|
54
|
-
"#{decorated_name_mobile} (#{account.symbol_info(symbol).try(:[], :priceChangePercent)}%)#{arrow}"
|
39
|
+
"#{name} (#{account.symbol_info(symbol).try(:[], :priceChangePercent)}%)#{pump}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def pump
|
43
|
+
pump_detector == 'True' ? Paint[' (P)', :blue] : ''
|
55
44
|
end
|
56
45
|
|
57
46
|
def decorated_name_mobile
|
58
|
-
|
59
|
-
"#{pump_det}#{name}"
|
47
|
+
"#{name} #{pump}"
|
60
48
|
end
|
61
49
|
|
62
50
|
def decorated_sell_price
|
data/lib/abot/info/helpers.rb
CHANGED
@@ -13,14 +13,17 @@ module Abot
|
|
13
13
|
].freeze
|
14
14
|
|
15
15
|
def self.today_info_str
|
16
|
+
profit_array = DatabaseTable.data_daily_profit
|
17
|
+
return "Сегодня сделок не было \n" if profit_array.blank?
|
18
|
+
|
16
19
|
profit = 'Профит сегодня:'
|
17
20
|
transactions_count = 'Сделок '
|
18
|
-
|
21
|
+
profit_array.each do |c|
|
19
22
|
tick_size = (c['quote'] == 'BTC' ? 7 : 2)
|
20
23
|
profit += "#{Paint[" #{c['sum'].round(tick_size)} #{c['quote']}", :green]};"
|
21
24
|
transactions_count += "#{c['quote']}: #{Paint[c['count'], :green]}; "
|
22
25
|
end
|
23
|
-
"#{profit} #{transactions_count}"
|
26
|
+
"#{profit} #{transactions_count}\n"
|
24
27
|
end
|
25
28
|
|
26
29
|
def self.balance_str(account, current_coins, trade_params)
|
@@ -57,15 +60,54 @@ module Abot
|
|
57
60
|
"#{symbol_name}: " + Paint["#{symbol[:askPrice].to_f} (#{symbol[:priceChangePercent]}%)", percent_color]
|
58
61
|
end
|
59
62
|
|
60
|
-
def self.check_abot
|
61
|
-
|
63
|
+
def self.check_abot(current_coins, telegram)
|
64
|
+
if (Time.now - File.mtime(DatabaseTable::DB_PATH)) > 40
|
65
|
+
if TelegramSender::SENDED_ERROR.blank?
|
66
|
+
TelegramSender::SENDED_ERROR[:warn_send] = true
|
67
|
+
telegram.send_message('WARNING: ПРОВЕРЬТЕ БОТА !!!') if telegram.present?
|
68
|
+
end
|
69
|
+
return Paint['WARNING: ПРОВЕРЬТЕ БОТА !!!', :black, :red] + "\n"
|
70
|
+
elsif TelegramSender::SENDED_ERROR
|
71
|
+
TelegramSender::SENDED_ERROR.clear
|
72
|
+
end
|
73
|
+
|
74
|
+
error_coins = current_coins.map { |c| c.current_price > c.sell_price ? c.name : nil }.compact
|
75
|
+
TelegramSender::SENDED_SELL_ERROR.delete_if { |key, _| !error_coins.include?(key) }
|
76
|
+
|
77
|
+
error_coins.each do |c|
|
78
|
+
if TelegramSender::SENDED_SELL_ERROR[c].to_i < 4
|
79
|
+
TelegramSender::SENDED_SELL_ERROR[c] = TelegramSender::SENDED_SELL_ERROR[c].to_i + 1
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
error_coins.select! { |s| TelegramSender::SENDED_SELL_ERROR[s].to_i > 2 }
|
84
|
+
|
85
|
+
return nil if error_coins.blank?
|
86
|
+
|
87
|
+
if telegram.present? &&
|
88
|
+
error_coins.find { |c| TelegramSender::SENDED_SELL_ERROR[c] == 3 }.present? &&
|
89
|
+
error_coins.find { |c| TelegramSender::SENDED_SELL_ERROR[c] == 4 }.blank?
|
90
|
+
telegram.send_message('WARNING: ПРОВЕРЬТЕ БОТА, ВОЗМОЖНО НУЖЕН РЕБУТ')
|
91
|
+
end
|
92
|
+
Paint['WARNING: ПРОВЕРЬТЕ БОТА, ВОЗМОЖНО НУЖЕН РЕБУТ', :black, :red] + "\n"\
|
62
93
|
end
|
63
94
|
|
64
|
-
def self.check_coins(account, quote_assets)
|
95
|
+
def self.check_coins(account, quote_assets, telegram)
|
65
96
|
coins_without_order = account.coins_without_order(quote_assets)
|
66
|
-
|
67
|
-
|
97
|
+
TelegramSender::SENDED_LOST_COINS.delete_if { |key, _| !coins_without_order.include?(key) }
|
98
|
+
|
99
|
+
coins_without_order.each do |c|
|
100
|
+
if TelegramSender::SENDED_LOST_COINS[c].to_i < 4
|
101
|
+
TelegramSender::SENDED_LOST_COINS[c] = TelegramSender::SENDED_LOST_COINS[c].to_i + 1
|
102
|
+
end
|
68
103
|
end
|
104
|
+
|
105
|
+
coins_without_order.select! { |s| TelegramSender::SENDED_LOST_COINS[s].to_i > 2 }
|
106
|
+
|
107
|
+
return nil if coins_without_order.blank?
|
108
|
+
|
109
|
+
telegram.send_lost_coins(coins_without_order) if telegram.present?
|
110
|
+
Paint["Монеты без ордера: #{coins_without_order.join(', ')}", :black, :red] + "\n"\
|
69
111
|
end
|
70
112
|
end
|
71
113
|
end
|
data/lib/abot/info/table.rb
CHANGED
@@ -6,7 +6,7 @@ module Abot
|
|
6
6
|
class Table < Terminal::Table
|
7
7
|
include Abot::Info::Helpers
|
8
8
|
|
9
|
-
attr_reader :current_coins, :account, :rate_coins, :columns, :trade_params
|
9
|
+
attr_reader :current_coins, :account, :rate_coins, :columns, :trade_params, :telegram
|
10
10
|
|
11
11
|
ALL_HEADINGS = {
|
12
12
|
name: 'Coin',
|
@@ -57,12 +57,13 @@ module Abot
|
|
57
57
|
@rate_coins = options.fetch(:rate_coins, [])
|
58
58
|
@trade_params ||= DatabaseTable.data_settings
|
59
59
|
@current_coins = Coin.current_coins(account, trade_params)
|
60
|
-
|
60
|
+
@telegram = Info::TelegramSender.new if options[:telegram_enable] == 'true'
|
61
61
|
|
62
62
|
options = {
|
63
63
|
headings: columns.map { |h| { value: ALL_HEADINGS[h], alignment: :center } },
|
64
64
|
style: { border_x: '=' }
|
65
65
|
}
|
66
|
+
|
66
67
|
super options
|
67
68
|
end
|
68
69
|
|
@@ -97,9 +98,9 @@ module Abot
|
|
97
98
|
end
|
98
99
|
|
99
100
|
def info_str
|
100
|
-
"#{Helpers.check_coins(account, trade_params["quote_asset"].split(' '))}" \
|
101
|
-
"#{Helpers.check_abot}" \
|
102
|
-
"#{Helpers.today_info_str}
|
101
|
+
"#{Helpers.check_coins(account, trade_params["quote_asset"].split(' '), telegram)}" \
|
102
|
+
"#{Helpers.check_abot(current_coins, telegram)}" \
|
103
|
+
"#{Helpers.today_info_str}" \
|
103
104
|
"#{Helpers.balance_str(account, current_coins, trade_params)}\n" \
|
104
105
|
"#{Helpers.potential_balance_str(account, current_coins, trade_params)}\n" \
|
105
106
|
"#{rate_coins_str}"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Abot
|
4
|
+
module Info
|
5
|
+
class TelegramSender
|
6
|
+
attr_reader :chat_id, :token
|
7
|
+
SENDED_LOST_COINS = {}
|
8
|
+
SENDED_ERROR = {}
|
9
|
+
SENDED_SELL_ERROR = {}
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@chat_id = DatabaseTable::TG_NAME
|
13
|
+
@token = DatabaseTable::TG_TOKEN
|
14
|
+
end
|
15
|
+
|
16
|
+
def send_message(text)
|
17
|
+
Telegram::Bot::Client.run(token) do |bot|
|
18
|
+
message = bot.api.send_message(chat_id: chat_id, text: text)
|
19
|
+
if message['ok'] == true
|
20
|
+
bot.api.pin_chat_message(chat_id: chat_id, message_id: message.dig('result', 'message_id'))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def send_lost_coins(coins_without_order)
|
26
|
+
coins_without_order.each do |coin|
|
27
|
+
send_message("WARNING обнаружена монета без ордера: #{coin}") if SENDED_LOST_COINS[coin].to_i == 3
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/abot/info/version.rb
CHANGED
data/lib/abot/info.rb
CHANGED
@@ -5,12 +5,14 @@ require 'sqlite3'
|
|
5
5
|
require 'terminal-table'
|
6
6
|
require 'paint'
|
7
7
|
require 'binance-ruby'
|
8
|
+
require 'telegram/bot'
|
8
9
|
|
9
10
|
require_relative 'info/option_parser'
|
10
11
|
require_relative 'info/coin'
|
11
12
|
require_relative 'info/binance_account'
|
12
13
|
require_relative 'info/table'
|
13
14
|
require_relative 'info/version'
|
15
|
+
require_relative 'info/telegram_sender'
|
14
16
|
|
15
17
|
module Abot
|
16
18
|
module Info
|
@@ -74,11 +76,19 @@ module Abot
|
|
74
76
|
:symbols, '--symbols=SYMBOL1,SYMBOL2,SYMBOL3',
|
75
77
|
'Пары для отображения курсов',
|
76
78
|
)
|
79
|
+
parser.add_option(
|
80
|
+
:telegram_enable, '--telegram_enable=true',
|
81
|
+
'Отправка в телеграм канал справочной информации',
|
82
|
+
)
|
83
|
+
parser.add_option(
|
84
|
+
:update_time, '--update_time=SECONDS',
|
85
|
+
'Период обновления информации, секунд, мин. 10',
|
86
|
+
)
|
77
87
|
end.final!
|
78
88
|
|
79
89
|
require_relative 'info/database_table'
|
80
90
|
|
81
|
-
start_stats({ rate_coins: rate_coins, columns: columns })
|
91
|
+
start_stats({ rate_coins: rate_coins, columns: columns, telegram_enable: telegram_enable, update_time: update_time })
|
82
92
|
end
|
83
93
|
|
84
94
|
def start_stats(opts)
|
@@ -92,7 +102,7 @@ module Abot
|
|
92
102
|
puts "ERROR: #{e.message}"
|
93
103
|
end
|
94
104
|
|
95
|
-
sleep
|
105
|
+
sleep update_time
|
96
106
|
end
|
97
107
|
end
|
98
108
|
|
@@ -106,6 +116,10 @@ module Abot
|
|
106
116
|
@template ||= Info::OptionParser.instance.options[:template]
|
107
117
|
end
|
108
118
|
|
119
|
+
def telegram_enable
|
120
|
+
@telegram_enable ||= Info::OptionParser.instance.options[:telegram_enable]
|
121
|
+
end
|
122
|
+
|
109
123
|
def columns
|
110
124
|
add = Info::OptionParser.instance.options[:add]&.split(',')&.map { |m| m.to_sym } || []
|
111
125
|
del = Info::OptionParser.instance.options[:del]&.split(',')&.map { |m| m.to_sym } || []
|
@@ -125,6 +139,11 @@ module Abot
|
|
125
139
|
def binance_account
|
126
140
|
BinanceAccount.new(DatabaseTable::API_KEY, DatabaseTable::SECRET_KEY)
|
127
141
|
end
|
142
|
+
|
143
|
+
def update_time
|
144
|
+
sec = Info::OptionParser.instance.options[:update_time].to_i
|
145
|
+
sec > 10 ? sec : 10
|
146
|
+
end
|
128
147
|
end
|
129
148
|
end
|
130
149
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abot-info
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- w_dmitrii
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 1.3.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: telegram-bot-ruby
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.16.0
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.16.0
|
125
139
|
description:
|
126
140
|
email:
|
127
141
|
- wiz.work2021@gmail.com
|
@@ -146,6 +160,7 @@ files:
|
|
146
160
|
- lib/abot/info/helpers.rb
|
147
161
|
- lib/abot/info/option_parser.rb
|
148
162
|
- lib/abot/info/table.rb
|
163
|
+
- lib/abot/info/telegram_sender.rb
|
149
164
|
- lib/abot/info/version.rb
|
150
165
|
- spec/abot/statistics_spec.rb
|
151
166
|
homepage:
|