Skip to content

Commit

Permalink
fix spot current price
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-xiong committed Nov 16, 2023
1 parent d8c03c6 commit 00a7881
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/jobs/get_okx_spot_trades_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ def perform(user_id: nil)
current_price: current_price,
event_time: event_time
)
update_tx(tx, current_price)
update_tx(tx)
ids.push(tx.id)
end

txs.where.not(id: ids).each do |tx|
update_tx(tx, current_price)
update_tx(tx)
end

combine_trades if user_id.nil?
Expand All @@ -65,10 +65,10 @@ def get_current_price(symbol, user_id)
price.to_f
end

def update_tx(tx, current_price)
tx.current_price = current_price
def update_tx(tx)
tx.current_price = get_current_price(tx.origin_symbol, tx.user_id)
tx.cost = get_spot_cost(tx.user_id, tx.original_symbol, tx.event_time.to_date) || tx.price
tx.revenue = get_revenue(tx.trade_type, tx.amount, tx.cost, tx.qty, current_price)
tx.revenue = get_revenue(tx.trade_type, tx.amount, tx.cost, tx.qty, tx.current_price)
tx.roi = tx.revenue / tx.amount
tx.save
end
Expand Down

0 comments on commit 00a7881

Please sign in to comment.