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 adb929f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 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,12 @@ def get_current_price(symbol, user_id)
price.to_f
end

def update_tx(tx, current_price)
tx.current_price = current_price
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)
def update_tx(tx)
tx.current_price = get_current_price(tx.original_symbol, tx.user_id)
if tx.cost.to_f.zero?
tx.cost = get_spot_cost(tx.user_id, tx.original_symbol, tx.event_time.to_date) || tx.price
end
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 adb929f

Please sign in to comment.