Skip to content

Commit

Permalink
add trade type to funding fee histories
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-xiong committed Sep 23, 2023
1 parent 3de8696 commit af11160
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
7 changes: 4 additions & 3 deletions app/jobs/get_funding_fee_histories_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ def perform(sync_ranking: false)

def generate_history(up, date)
rate = get_rate(up.origin_symbol, up.source, date)
ffh = FundingFeeHistory.where(origin_symbol: up.origin_symbol, event_date: date, source: up.source, user_id: up.user_id).first_or_initialize
snapshot = SnapshotPosition.joins(:snapshot_info).where(snapshot_info: { user_id: up.user_id }, event_date: ffh.event_date, origin_symbol: ffh.origin_symbol, source: ffh.source).take
ffh.update(rate: rate, amount: rate * up.amount * 3, snapshot_position_id: snapshot&.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|
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(rate: rate, amount: rate * up.amount * 3, snapshot_position_id: snapshot&.id)
end
end

def get_rate(symbol, source, date, get_latest: false)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddTradeTypeToFundingFeeHistories < ActiveRecord::Migration[6.1]
def change
add_column :funding_fee_histories, :trade_type, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit af11160

Please sign in to comment.