Skip to content

Commit

Permalink
add last endtime to funding fee histories job
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-xiong committed Oct 26, 2023
1 parent 4f5842a commit 46be876
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/jobs/get_funding_fee_histories_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ def perform(sync_ranking: false)
$redis.set('top_3_symbol_funding_rates', result.to_json)
else
date = Date.yesterday
BinanceFuturesService.new.get_funding_fee_histories(date.strftime('%Q'))
start_at = $redis.get("#{date}__last_endtime") || date.strftime('%Q')
BinanceFuturesService.new.get_funding_fee_histories(start_at)
OkxFuturesService.new.get_funding_fee_histories

UserPosition.available.where(user_id: nil).each do |up|
generate_history(up, date)
end

UserSyncedPosition.available.pluck(:user_id).uniq.each do |user_id|
BinanceFuturesService.new(user_id: user_id).get_funding_fee_histories(date.strftime('%Q'))
start_at = $redis.get("#{date}_#{user_id}_last_endtime") || date.strftime('%Q')
BinanceFuturesService.new(user_id: user_id).get_funding_fee_histories(start_at)
OkxFuturesService.new(user_id: user_id).get_funding_fee_histories
end

Expand All @@ -50,6 +52,7 @@ def get_fee(symbol, source, date, user_id)
fee_list = JSON.parse($redis.get("binance_funding_fee_histories_user_#{user_id}")) rescue nil
return 0 if fee_list.nil?
daily_fees = fee_list.select{|r| Time.at(r['time']/1000).to_date == date && r['symbol'] == symbol}
$redis.set("#{date}_#{user_id}_last_endtime", daily_fees.last['time']) if daily_fees.count == fee_list.count
daily_fees.sum{|f| f['income'].to_f}
elsif source == 'okx'
fee_list = JSON.parse($redis.get("okx_funding_fee_histories_user_#{user_id}")) rescue nil
Expand Down

0 comments on commit 46be876

Please sign in to comment.