From 21cabf778925dba79b63c3aa7a0049d1e0f56d97 Mon Sep 17 00:00:00 2001 From: Pan Xiong Date: Sat, 18 Nov 2023 20:59:06 +1100 Subject: [PATCH] Update combine transactions job --- app/controllers/combine_transactions_controller.rb | 2 +- app/jobs/get_okx_spot_trades_job.rb | 3 +-- app/jobs/get_spot_trades_job.rb | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/controllers/combine_transactions_controller.rb b/app/controllers/combine_transactions_controller.rb index 9f65a89..0450b9f 100644 --- a/app/controllers/combine_transactions_controller.rb +++ b/app/controllers/combine_transactions_controller.rb @@ -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) diff --git a/app/jobs/get_okx_spot_trades_job.rb b/app/jobs/get_okx_spot_trades_job.rb index ab208bb..738d1cd 100644 --- a/app/jobs/get_okx_spot_trades_job.rb +++ b/app/jobs/get_okx_spot_trades_job.rb @@ -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 diff --git a/app/jobs/get_spot_trades_job.rb b/app/jobs/get_spot_trades_job.rb index ca5b2d8..7a903ad 100644 --- a/app/jobs/get_spot_trades_job.rb +++ b/app/jobs/get_spot_trades_job.rb @@ -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