Skip to content

Commit

Permalink
update funding fee for same symbol positions
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-xiong committed Nov 8, 2023
1 parent a0fcb69 commit eb80ec9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions app/jobs/get_funding_fee_histories_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]) %>
<span class="question-mark" data-bs-toggle="tooltip" title='<%= t("views.trading.#{h[:sort]}") %>'>?</span>
<% end %>
</th>
Expand Down
1 change: 1 addition & 0 deletions config/locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ zh-CN:
total_roi: 总收益 / 总买入成本
margin_ratio: 空单为(当前价 - 最低价)/ 最低价,多单为(最高价 - 当前价)/ 当前价
average_durations: 未平仓投入总持仓时间 / 未平仓投入数量
funding_fee: 同一个交易对如果同时存在做空和做多的仓位,资金费用只会累积到总投入较大的仓位上面
contract_trading:
sell:
buy:
Expand Down

0 comments on commit eb80ec9

Please sign in to comment.