diff --git a/app/jobs/get_funding_fee_histories_job.rb b/app/jobs/get_funding_fee_histories_job.rb index 06474c8..72c6d1e 100644 --- a/app/jobs/get_funding_fee_histories_job.rb +++ b/app/jobs/get_funding_fee_histories_job.rb @@ -21,7 +21,8 @@ def perform(sync_ranking: false) BinanceFuturesService.new.get_funding_fee_histories(start_at) OkxFuturesService.new.get_funding_fee_histories - UserPosition.available.where(user_id: nil).each do |up| + UserPosition.available.where(user_id: nil).group_by(&:origin_symbol).each do |symbol, data| + up = data.max{|a,b| a.amount <=> b.amount} generate_history(up, date) end @@ -31,7 +32,8 @@ def perform(sync_ranking: false) OkxFuturesService.new(user_id: user_id).get_funding_fee_histories end - UserSyncedPosition.available.each do |up| + UserSyncedPosition.available.group_by(&:origin_symbol).each do |symbol, data| + up = data.max{|a,b| a.amount <=> b.amount} generate_history(up, date) end end @@ -41,7 +43,7 @@ def perform(sync_ranking: false) def generate_history(up, date) funding_fee = get_fee(up.origin_symbol, up.source, date, up.user_id) - SnapshotPosition.joins(:snapshot_info).where(snapshot_info: { user_id: up.user_id }, origin_symbol: up.origin_symbol, event_date: date, source: up.source).each do |snapshot| + snapshots = SnapshotPosition.joins(:snapshot_info).where(snapshot_info: { user_id: up.user_id }, origin_symbol: up.origin_symbol, event_date: date, source: up.source).each do |snapshot| ffh = FundingFeeHistory.where(origin_symbol: snapshot.origin_symbol, event_date: date, source: snapshot.source, user_id: up.user_id, trade_type: up.trade_type).first_or_initialize ffh.update(amount: funding_fee, snapshot_position_id: snapshot&.id) end diff --git a/app/views/shared/_list.html.erb b/app/views/shared/_list.html.erb index 9fbefee..b77f0db 100644 --- a/app/views/shared/_list.html.erb +++ b/app/views/shared/_list.html.erb @@ -10,7 +10,7 @@ <% url = get_list_url(source_type, ch_remote_params(params, h[:sort])) %> <%= link_to "#{h[:name]}", url, remote: true, class: "#{params[:sort] == h[:sort] ? 'text-primary' : ''}" %> <% end %> - <% if h[:sort].in?(["roi", "margin_ratio", "average_durations"]) %> + <% if h[:sort].in?(["roi", "margin_ratio", "average_durations", "funding_fee"]) %> ? <% end %> diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index c2c29b1..c6ac8af 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -18,6 +18,7 @@ zh-CN: total_roi: 总收益 / 总买入成本 margin_ratio: 空单为(当前价 - 最低价)/ 最低价,多单为(最高价 - 当前价)/ 当前价 average_durations: 未平仓投入总持仓时间 / 未平仓投入数量 + funding_fee: 同一个交易对如果同时存在做空和做多的仓位,资金费用只会累积到总投入较大的仓位上面 contract_trading: sell: 多 buy: 空