diff --git a/app/controllers/page_controller.rb b/app/controllers/page_controller.rb index c11b4b7..294221e 100644 --- a/app/controllers/page_controller.rb +++ b/app/controllers/page_controller.rb @@ -222,7 +222,15 @@ def holding_duration_chart def open_orders @page_index = 36 - @open_orders = OpenPositionOrder.order(amount: :desc).page(params[:page]).per(15) + @symbol = params[:search] + @trade_type = params[:trade_type] + @position_side = params[:position_side] + open_orders = OpenPositionOrder.order(order_time: :desc) + @symbols = open_orders.pluck(:symbol).uniq + open_orders = open_orders.where(symbol: @symbol) if @symbol.present? + open_orders = open_orders.where(trade_type: @trade_type) if @trade_type.present? + open_orders = open_orders.where(position_side: @position_side) if @position_side.present? + @open_orders = open_orders.page(params[:page]).per(15) end private diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c9ed553..5af1091 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -490,6 +490,10 @@ def trade_type_style(trade_type) trade_type.to_s.downcase == 'sell' ? "text-danger" : "text-success" end + def position_side_style(position_side) + position_side.to_s.downcase == 'long' ? "text-danger" : "text-success" + end + def display_symbol(h, s=nil) str = "#{h.from_symbol} / #{h.fee_symbol}" return str if s.present? diff --git a/app/jobs/get_binance_open_orders_job.rb b/app/jobs/get_binance_open_orders_job.rb index d6dbab5..fe65584 100644 --- a/app/jobs/get_binance_open_orders_job.rb +++ b/app/jobs/get_binance_open_orders_job.rb @@ -18,9 +18,13 @@ def perform order_type: open_order['type'], trade_type: open_order['side'].downcase, position_side: open_order['positionSide'].downcase, - stop_price: open_order['stopPrice'] + stop_price: open_order['stopPrice'], + order_time: Time.at(open_order['time']/1000) ) end + + symbols = open_orders.map{|order| order['symbol']} + OpenPositionOrder.where.not(symbol: symbols).delete_all end end end \ No newline at end of file diff --git a/app/views/page/open_orders.html.erb b/app/views/page/open_orders.html.erb index 67c1b8d..0568d36 100644 --- a/app/views/page/open_orders.html.erb +++ b/app/views/page/open_orders.html.erb @@ -1,14 +1,29 @@
订单时间 | 币种 | -类别 | +买卖类别 | +持仓类别 | 委托价 | -触发价 | 委托数量 | 委托金额 | 订单类型 | @@ -18,10 +33,11 @@ <% if @open_orders.any? %> <% @open_orders.each do |order| %>
---|---|---|---|---|---|---|---|---|---|
<%= order.order_time %> | <%= order.symbol %> | <%= I18n.t("views.trading.#{order.trade_type}") %> | +<%= I18n.t("views.trading.#{order.position_side}") %> | <%= order.price.round(4) %> | -<%= order.stop_price.round(4) %> | <%= order.orig_qty.round(4) %> | <%= order.amount.round(4) %> | <%= order.order_type %> | diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index c6ac8af..707f155 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -12,6 +12,8 @@ zh-CN: trading: sell: 卖 buy: 买 + long: 多 + short: 空 revenue: "#买入交易为买入数量 * 当前价格 - 买入成本 / #卖出交易为卖出总价" roi: 收益 / 成本 total_revenue: (买入数量-卖出数量)* 当前价格 + 卖出总价 - 买入成本 diff --git a/db/migrate/20231125091109_add_order_time_to_open_position_orders.rb b/db/migrate/20231125091109_add_order_time_to_open_position_orders.rb new file mode 100644 index 0000000..3b8c0af --- /dev/null +++ b/db/migrate/20231125091109_add_order_time_to_open_position_orders.rb @@ -0,0 +1,6 @@ +class AddOrderTimeToOpenPositionOrders < ActiveRecord::Migration[6.1] + def change + add_column :open_position_orders, :order_time, :datetime + add_index :open_position_orders, :order_time + end +end diff --git a/db/schema.rb b/db/schema.rb index 1357b54..2134522 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_11_24_092319) do +ActiveRecord::Schema.define(version: 2023_11_25_091109) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -215,7 +215,9 @@ t.decimal "amount" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.datetime "order_time" t.index ["order_id"], name: "index_open_position_orders_on_order_id" + t.index ["order_time"], name: "index_open_position_orders_on_order_time" t.index ["position_side"], name: "index_open_position_orders_on_position_side" t.index ["symbol"], name: "index_open_position_orders_on_symbol" t.index ["trade_type"], name: "index_open_position_orders_on_trade_type"