diff --git a/app/controllers/page_controller.rb b/app/controllers/page_controller.rb index 0a1c143..c11b4b7 100644 --- a/app/controllers/page_controller.rb +++ b/app/controllers/page_controller.rb @@ -220,6 +220,11 @@ def holding_duration_chart @average_roi_chart_data = GetHoldingDurationsByRoiChartService.execute(average: true) end + def open_orders + @page_index = 36 + @open_orders = OpenPositionOrder.order(amount: :desc).page(params[:page]).per(15) + end + private def get_anchor(data_type) case data_type diff --git a/app/jobs/get_binance_open_orders_job.rb b/app/jobs/get_binance_open_orders_job.rb new file mode 100644 index 0000000..d6dbab5 --- /dev/null +++ b/app/jobs/get_binance_open_orders_job.rb @@ -0,0 +1,26 @@ +class GetBinanceOpenOrdersJob < ApplicationJob + queue_as :daily_job + + def perform + open_orders = BinanceFuturesService.new.get_pending_orders + + OpenPositionOrder.transaction do + open_orders.each do |open_order| + price = open_order['price'].to_f + qty = open_order['origQty'].to_f + amount = price * qty + order = OpenPositionOrder.where(order_id: open_order['orderId'], symbol: open_order['symbol']).first_or_initialize + order.update( + status: open_order['status'], + price: price, + orig_qty: qty, + amount: amount, + order_type: open_order['type'], + trade_type: open_order['side'].downcase, + position_side: open_order['positionSide'].downcase, + stop_price: open_order['stopPrice'] + ) + end + end + end +end \ No newline at end of file diff --git a/app/models/open_position_order.rb b/app/models/open_position_order.rb new file mode 100644 index 0000000..e5dd96d --- /dev/null +++ b/app/models/open_position_order.rb @@ -0,0 +1,2 @@ +class OpenPositionOrder < ApplicationRecord +end diff --git a/app/services/binance_futures_service.rb b/app/services/binance_futures_service.rb index 20b4232..d279fa9 100644 --- a/app/services/binance_futures_service.rb +++ b/app/services/binance_futures_service.rb @@ -56,9 +56,10 @@ def get_my_trades(symbol, from_date) do_request("get", url, payload) end - def get_pending_orders(symbol) + def get_pending_orders(symbol=nil) url = BASE_URL + "/fapi/v1/openOrders?" - payload = {timestamp: get_timestamp, symbol: symbol} + payload = {timestamp: get_timestamp} + payload.merge!({symbol: symbol}) if symbol do_request("get", url, payload) end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e108aec..0541273 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -28,7 +28,7 @@ <%= link_to "首页", public_user_positions_path, class: "nav-link #{@page_index == 1 ? 'active' : ''}" %>