From da1d0706b5a249569c40a289f293499da0f2208e Mon Sep 17 00:00:00 2001 From: Pan Xiong <xp0729@gmail.com> Date: Sat, 23 Sep 2023 19:59:07 +1000 Subject: [PATCH] Update trading fee --- app/models/adding_positions_history.rb | 2 +- app/models/user_position.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/adding_positions_history.rb b/app/models/adding_positions_history.rb index 5b550f1..a219256 100644 --- a/app/models/adding_positions_history.rb +++ b/app/models/adding_positions_history.rb @@ -46,7 +46,7 @@ def trading_fee fee = $redis.get("aph_#{id}_trading_fee") if fee.nil? if snapshot_position.present? - fee = FundingFeeHistory.where('user_id is null and origin_symbol = ? and event_date <= ?', origin_symbol, event_date - 1.day).sum(&:amount) * (amount / snapshot_position.amount) + fee = FundingFeeHistory.where('user_id is null and origin_symbol = ? and event_date <= ? and trade_type = ?', origin_symbol, event_date - 1.day, trade_type).sum(&:amount) * (amount / snapshot_position.amount) else fee = 0 end diff --git a/app/models/user_position.rb b/app/models/user_position.rb index 336020b..869249d 100644 --- a/app/models/user_position.rb +++ b/app/models/user_position.rb @@ -77,11 +77,11 @@ def ranking end def funding_fee - FundingFeeHistory.where(user_id: user_id, origin_symbol: origin_symbol).sum(&:amount).round(4) + FundingFeeHistory.where(user_id: user_id, origin_symbol: origin_symbol, trade_type: trade_type).sum(&:amount).round(4) end def last_funding_fee - FundingFeeHistory.where(user_id: user_id, origin_symbol: origin_symbol).where('event_date < ?', Date.yesterday).sum(&:amount).round(4) + FundingFeeHistory.where(user_id: user_id, origin_symbol: origin_symbol, trade_type: trade_type).where('event_date < ?', Date.yesterday).sum(&:amount).round(4) end def notes