Skip to content

Commit

Permalink
Update combine transactions job
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-xiong committed Nov 18, 2023
1 parent d48aa48 commit 21cabf7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/combine_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def index
sort = params[:sort].presence || "revenue"
sort_type = params[:sort_type].presence || "desc"
@symbol = params[:search]
txs = CombineTransaction.order("#{sort} #{sort_type}")
txs = CombineTransaction.where('qty != ?', 0).order("#{sort} #{sort_type}")
txs = txs.where(source: params[:source]) if params[:source].present?
txs = txs.where(original_symbol: @symbol) if @symbol.present?
@txs = txs.page(params[:page]).per(20)
Expand Down
3 changes: 1 addition & 2 deletions app/jobs/get_okx_spot_trades_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ def combine_trades
end

origin_tx = origin_txs.first
trade_type = total_cost > 0 ? 'buy' : 'sell'
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
fee_symbol: origin_tx.fee_symbol, trade_type: 'buy').first_or_create

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
Expand Down
3 changes: 1 addition & 2 deletions app/jobs/get_spot_trades_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def combine_trades(symbol, current_price)
end

origin_tx = origin_txs.first
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
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: 'buy').first_or_create

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
Expand Down

0 comments on commit 21cabf7

Please sign in to comment.