Skip to content

Commit

Permalink
fix combine txs when qty is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-xiong committed Nov 16, 2023
1 parent adb929f commit d48aa48
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/jobs/get_okx_spot_trades_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def combine_trades
combine_tx = CombineTransaction.where(source: SOURCE, original_symbol: original_symbol, from_symbol: origin_tx.from_symbol, to_symbol: origin_tx.to_symbol,
fee_symbol: origin_tx.fee_symbol, trade_type: trade_type).first_or_create

price = total_cost / total_qty
price = total_qty.zero? ? 0 : total_cost / total_qty
revenue = trade_type == 'buy' ? origin_tx.current_price * total_qty - total_cost : total_cost.abs - origin_tx.current_price * total_qty
roi = revenue / total_cost.abs

Expand Down
2 changes: 1 addition & 1 deletion app/jobs/get_spot_trades_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def combine_trades(symbol, current_price)
trade_type = total_cost > 0 ? 'buy' : 'sell'
combine_tx = CombineTransaction.where(source: SOURCE, original_symbol: symbol, from_symbol: origin_tx.from_symbol, to_symbol: origin_tx.to_symbol, fee_symbol: origin_tx.fee_symbol, trade_type: trade_type).first_or_create

price = total_cost / total_qty
price = total_qty.zero? ? 0 : total_cost / total_qty
revenue = trade_type == 'buy' ? current_price * total_qty - total_cost : total_cost.abs - current_price * total_qty
roi = revenue / total_cost.abs

Expand Down

0 comments on commit d48aa48

Please sign in to comment.