Skip to content

Commit

Permalink
Update adding positions histories roi logic brtr/coin_elite#722
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-xiong committed Sep 15, 2023
1 parent c60fc6f commit b2482a7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/models/adding_positions_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def get_revenue
end

def roi
((get_revenue / (amount.abs + get_revenue)) * 100).round(4)
adding_amount = trade_type == 'sell' ? amount.abs + get_revenue : amount.abs
((get_revenue / adding_amount) * 100).round(4)
end

def amount_ratio
Expand Down
4 changes: 2 additions & 2 deletions config/locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ zh-CN:
sell:
buy:
adding_rate: 新增的投入带来的总的盈利或者亏损的金额 / 新增的投入
revenue: 空单:新增金额 - 新增数量*最新价格 - / 多单:新增数量*最新价格 - 新增金额
revenue: 空单:新增金额 - 新增数量*最新价格 / 多单:新增数量*最新价格 - 新增金额
trading_fee: 交易当天的仓位快照总的资金费用乘以该笔交易占当天仓位的比例
roi: 已实现收益 / 平仓金额
roi: 空单:已实现收益 / 平仓金额 / 多单: 已实现收益 / (平仓金额 + 已实现收益)
closing_revenue: 收益 - 资金费用
wallet_history:
deposit: 充值
Expand Down
2 changes: 1 addition & 1 deletion spec/models/adding_positions_history_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

describe '#roi' do
it 'should equal revenue divide amount' do
roi = ((adding_positions_history.get_revenue / (adding_positions_history.amount.abs + adding_positions_history.get_revenue)) * 100).round(4)
roi = ((adding_positions_history.get_revenue / (adding_positions_history.amount.abs)) * 100).round(4)
expect(adding_positions_history.roi).to eq (roi)
end
end
Expand Down

0 comments on commit b2482a7

Please sign in to comment.