Skip to content

Commit

Permalink
update new platforms transactions page
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-xiong committed Jan 6, 2024
1 parent 624b572 commit d9f1838
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 12 deletions.
6 changes: 4 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def transactions_table_headers
},
{
name: "币种投入/总投入",
sort: "none"
sort: "cost_ratio"
},
{
name: "预计收益 / 实际收益",
Expand Down Expand Up @@ -538,8 +538,10 @@ def get_list_url(source_type, params)
def get_origin_list_url(source_type, params)
if source_type == :public
origin_transactions_path(params)
else
elsif source_type == :users
users_origin_transactions_path(params)
else
new_platforms_origin_transactions_path(params)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/jobs/generate_origin_transactions_snapshots_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def perform(date: Date.today)

def generate_snapshot(transactions_snapshot_info)
# 查找符合条件的原始交易记录
origin_transactions = OriginTransaction.where(trade_type: 'buy', user_id: nil)
origin_transactions = OriginTransaction.year_to_date.where(trade_type: 'buy', user_id: nil)

# 批量处理原始交易记录
origin_transactions.find_each(batch_size: 100) do |origin_transaction|
Expand Down
4 changes: 2 additions & 2 deletions app/jobs/get_gate_spot_trades_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def get_revenue(trade_type, amount, cost, qty, current_price)

def get_spot_cost(user_id, origin_symbol, date)
cost = SpotBalanceSnapshotRecord.joins(:spot_balance_snapshot_info)
.find_by(spot_balance_snapshot_info: {user_id: user_id, event_date: date}, origin_symbol: origin_symbol, source: SOURCE)&.price.to_f
cost = UserSpotBalance.find_by(user_id: user_id, origin_symbol: origin_symbol, source: SOURCE)&.price.to_f if cost.zero? && date == Date.today
.find_by(spot_balance_snapshot_info: {user_id: user_id, event_date: date}, origin_symbol: origin_symbol, source: SOURCE)&.price
cost = UserSpotBalance.find_by(user_id: user_id, origin_symbol: origin_symbol, source: SOURCE)&.price if cost.nil? && date == Date.today
cost
end
end
4 changes: 2 additions & 2 deletions app/models/origin_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ class OriginTransaction < ApplicationRecord
FILTER_SYMBOL = %w(USDC).freeze

def self.available
OriginTransaction.where.not(source: ['gate', 'bitget']).where('from_symbol NOT IN (?) and ((from_symbol IN (?) AND amount >= 50) OR from_symbol NOT IN (?))', FILTER_SYMBOL, SKIP_SYMBOLS, SKIP_SYMBOLS)
OriginTransaction.where('from_symbol NOT IN (?) and ((from_symbol IN (?) AND amount >= 50) OR from_symbol NOT IN (?))', FILTER_SYMBOL, SKIP_SYMBOLS, SKIP_SYMBOLS)
end

def self.year_to_date
OriginTransaction.where('event_time >= ?', DateTime.parse('2023-01-01'))
OriginTransaction.where.not(source: ['gate', 'bitget']).where('event_time >= ?', DateTime.parse('2023-01-01'))
end

def self.total_summary(user_id=nil)
Expand Down
2 changes: 1 addition & 1 deletion app/models/user_spot_balance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class UserSpotBalance < ApplicationRecord

scope :available, -> { where("qty > 0") }

enum source: [:binance, :okx, :huobi]
enum source: [:binance, :okx, :huobi, :gate]

def current_price
OriginTransaction.find_by(original_symbol: origin_symbol, source: source)&.current_price
Expand Down
39 changes: 39 additions & 0 deletions app/views/origin_transactions/_new_list.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<table class="table">
<thead>
<tr class="table-container-tr">
<% transactions_table_headers.each do |h| %>
<% next if h[:sort].in?(['cost_ratio', 'revenue_ratio']) %>
<th scope="col">
<% if h[:sort] == "none" %>
<%= "#{h[:name]}" %>
<% else %>
<% url = get_origin_list_url(source_type, ch_remote_params(params, h[:sort])) %>
<%= link_to "#{h[:name]}", url, remote: true, class: "#{params[:sort] == h[:sort] ? 'text-primary' : ''}" %>
<% end %>
</th>
<% end %>
<th></th>
</tr>
</thead>
<tbody>
<% @txs.each do |h| %>
<tr>
<td><%= h.event_time.strftime('%Y-%m-%d %H:%M:%S') rescue '' %></td>
<td><%= h.from_symbol %> / <%= h.to_symbol %></td>
<td class="<%= trade_type_style(h.trade_type) %>"><%= h.trade_type == 'buy' ? '买入' : '卖出' %></td>
<td data-bs-toggle="tooltip" title='<%= h.price %>'><%= h.price.round(4) %> <%= h.to_symbol %></td>
<td data-bs-toggle="tooltip" title='<%= h.cost %>'><%= h.cost.round(4) %> <%= h.to_symbol %></td>
<td data-bs-toggle="tooltip" title='<%= h.current_price %>'><%= h.current_price.round(4) %> <%= h.to_symbol %></td>
<td><%= h.qty.round(4) %></td>
<td><%= h.amount.round(4) %> <%= h.to_symbol %></td>
<td class="<%= h.revenue > 0 ? 'pos-num' : 'neg-num' %>"><%= display_spot_tx_revenue(h.revenue, h.to_symbol, h.trade_type) %></td>
<td class="<%= h.roi > 0 ? 'pos-num' : 'neg-num' %>" ><%= display_spot_tx_roi(h.roi, h.trade_type) %></td>
<td><%= h.source %></td>
</tr>
<% end %>
</tbody>
</table>

<div class="paginationBox p-4">
<%= paginate @txs %>
</div>
4 changes: 1 addition & 3 deletions app/views/origin_transactions/new_platforms.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
<div class="input-group mb-3 position-filter">
<%= select_tag(:search, options_for_select(@total_txs.pluck(:original_symbol).uniq, @symbol), { prompt: '请选择币种...', class: 'select2-dropdown form-control' }) %>
<span class='ms-3'></span>
<%= select_tag(:campaign, options_for_select(@total_txs.pluck(:campaign).compact.uniq, @campaign),{ prompt: '请选择campaign...', class: 'select2-dropdown form-control' }) %>
<span class='ms-3'></span>
<%= select_tag(:trade_type, options_for_select([['买入', 'buy'], ['卖出', 'sell']], @trade_type),{ prompt: '请选择交易类别...', class: 'select2-dropdown form-control' }) %>
<span class='ms-3'></span>
<%= select_tag(:source, options_for_select(@total_txs.pluck(:source).compact.uniq, @source),{ prompt: '请选择来源...', class: 'select2-dropdown form-control' }) %>
Expand All @@ -19,7 +17,7 @@
<% end %>
</div>
<div id="trading-histories-container">
<%= render partial: "list", locals: { source_type: :public } %>
<%= render partial: "new_list", locals: { source_type: :new_platform } %>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/origin_transactions/new_platforms.js.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
$("#trading-histories-container").html("<%= j render partial: "list", locals: { source_type: :public } %>");
$("#trading-histories-container").html("<%= j render partial: "new_list", locals: { source_type: :new_platform } %>");
$('[data-bs-toggle="tooltip"]').tooltip();

0 comments on commit d9f1838

Please sign in to comment.