-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
class NotifyNewSymbolJob < ApplicationJob | ||
queue_as :daily_job | ||
|
||
def perform | ||
msgs = FetchNewSymbolService.execute | ||
msgs.each{|msg| format_notice_blocks(msg)} | ||
|
||
check_symbol_from_api | ||
end | ||
|
||
def check_symbol_from_api | ||
symbols = BinanceFuturesService.new.get_ticker_price.map{|x| x['symbol']} rescue [] | ||
return if symbols.empty? | ||
|
||
redis_key = 'binance_futures_symbols' | ||
prev_symbols = JSON.parse($redis.get(redis_key)) rescue [] | ||
diff_symbols = symbols - prev_symbols | ||
$redis.set(redis_key, symbols) | ||
SlackService.send_notification(nil, format_blocks(diff_symbols)) if diff_symbols.any? | ||
end | ||
|
||
def format_notice_blocks(msg) | ||
[ | ||
{ | ||
"type": "section", | ||
"text": { | ||
"type": "mrkdwn", | ||
"text": msg | ||
} | ||
} | ||
] | ||
end | ||
|
||
def format_api_blocks(symbols) | ||
[ | ||
{ | ||
"type": "section", | ||
"text": { | ||
"type": "mrkdwn", | ||
"text": "*币安合约API新增币种: #{symbols.join(", ")}, 共#{symbols.length}个*" | ||
} | ||
} | ||
] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'openssl' | ||
require 'rest-client' | ||
|
||
class FetchNewSymbolService | ||
BASE_URL = ENV['BINANCE_ANNOUNCEMENT_URL'] | ||
|
||
class << self | ||
def execute | ||
redis_key = 'binance_announcement_fetch_time' | ||
last_fetch_time = $redis.get(redis_key).to_i | ||
page = Nokogiri::HTML(URI.open(BASE_URL)) | ||
data = JSON.parse(page.css("script").children[10]) | ||
catalog = data['appState']['loader']['dataByRouteId']['2a3f']['catalogs'].select{|c| c['catalogName'] == '数字货币及交易对上新'}.first rescue nil | ||
return if catalog.nil? | ||
|
||
$redis.set(redis_key, Time.current.to_i * 1000) | ||
catalog['articles'].select{|a| a['releaseDate'] >= last_fetch_time && a['title'].match(/将上线.*永续合约/)}.map{|a| a['title']} | ||
end | ||
end | ||
end |