-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
136 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class OpenPositionOrder < ApplicationRecord | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<div class="m-3 row"> | ||
<div class="col-10 mx-auto"> | ||
<h3>币安合约委托单</h3> | ||
<div class="mt-3"> | ||
<table class="table"> | ||
<thead> | ||
<tr class="table-container-tr"> | ||
<th>币种</th> | ||
<th>类别</th> | ||
<th>委托价</th> | ||
<th>触发价</th> | ||
<th>委托数量</th> | ||
<th>委托金额</th> | ||
<th>订单类型</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% if @open_orders.any? %> | ||
<% @open_orders.each do |order| %> | ||
<tr> | ||
<td><%= order.symbol %></td> | ||
<td class="<%= trade_type_style(order.trade_type) %>"><%= I18n.t("views.trading.#{order.trade_type}") %></td> | ||
<td><%= order.price.round(4) %></td> | ||
<td><%= order.stop_price.round(4) %></td> | ||
<td><%= order.orig_qty.round(4) %></td> | ||
<td><%= order.amount.round(4) %></td> | ||
<td><%= order.order_type %></td> | ||
</tr> | ||
<% end %> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<%= paginate @open_orders %> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class CreateOpenPositionOrders < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :open_position_orders do |t| | ||
t.string :symbol | ||
t.string :order_id | ||
t.string :trade_type | ||
t.string :position_side | ||
t.string :status | ||
t.string :order_type | ||
t.decimal :price | ||
t.decimal :stop_price | ||
t.decimal :orig_qty | ||
t.decimal :amount | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :open_position_orders, :order_id | ||
add_index :open_position_orders, :symbol | ||
add_index :open_position_orders, :trade_type | ||
add_index :open_position_orders, :position_side | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FactoryBot.define do | ||
factory :open_position_order do | ||
symbol { 'BTCUSDT' } | ||
price { 1 } | ||
orig_qty { 1 } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe OpenPositionOrder, type: :model do | ||
let(:open_position_order) { create(:open_position_order) } | ||
|
||
it "have a valid factory" do | ||
expect(open_position_order).to be_valid | ||
end | ||
end |