Skip to content

Commit

Permalink
Merge pull request #13 from yubing744/owen/view-position-stop-loss
Browse files Browse the repository at this point in the history
Owen/view position stop loss
  • Loading branch information
yubing744 authored Apr 21, 2024
2 parents fb155fe + 92cee81 commit 42b7784
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: clean build test run docker-* tag release

NAME=trading-gpt
VERSION=0.14.10
VERSION=0.15.1

clean:
rm -rf build/*
Expand Down
2 changes: 1 addition & 1 deletion libs/bbgo
34 changes: 17 additions & 17 deletions pkg/env/exchange/exchange_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,6 @@ func (ent *ExchangeEntity) Actions() []*ttypes.ActionDesc {
},
},
},
{
Name: "close_position",
Description: "close position",
Samples: []ttypes.Sample{
{
Input: []string{
"BOLL data changed: UpBand:[2.92 2.92 2.92 2.92 2.92 2.92 2.92 2.92 2.92 2.91 2.91 2.90 2.90 2.89 2.89 2.89 2.89 2.89 2.89 2.90 2.92], SMA:[2.87 2.87 2.87 2.87 2.87 2.87 2.87 2.87 2.87 2.87 2.86 2.86 2.86 2.85 2.85 2.85 2.85 2.85 2.85 2.85 2.86], DownBand:[2.81 2.81 2.82 2.82 2.82 2.82 2.83 2.83 2.82 2.82 2.82 2.81 2.81 2.82 2.82 2.82 2.82 2.82 2.82 2.81 2.80]",
"RSI data changed: [2.66 2.65 2.65 2.64 2.64 2.63 2.63 2.63 2.63 2.63 2.63 2.64 2.65 2.66 2.67 2.67 2.68 2.68 2.68 2.68 2.69]",
"The current position is long, average cost: 2.736, and accumulated profit: 15.324",
"Analyze data, generate trading cmd",
},
Output: []string{
"Execute cmd: /close_position",
},
},
},
},
{
Name: "update_position",
Description: "update position",
Expand All @@ -162,6 +145,23 @@ func (ent *ExchangeEntity) Actions() []*ttypes.ActionDesc {
},
},
},
{
Name: "close_position",
Description: "close position",
Samples: []ttypes.Sample{
{
Input: []string{
"BOLL data changed: UpBand:[2.92 2.92 2.92 2.92 2.92 2.92 2.92 2.92 2.92 2.91 2.91 2.90 2.90 2.89 2.89 2.89 2.89 2.89 2.89 2.90 2.92], SMA:[2.87 2.87 2.87 2.87 2.87 2.87 2.87 2.87 2.87 2.87 2.86 2.86 2.86 2.85 2.85 2.85 2.85 2.85 2.85 2.85 2.86], DownBand:[2.81 2.81 2.82 2.82 2.82 2.82 2.83 2.83 2.82 2.82 2.82 2.81 2.81 2.82 2.82 2.82 2.82 2.82 2.82 2.81 2.80]",
"RSI data changed: [2.66 2.65 2.65 2.64 2.64 2.63 2.63 2.63 2.63 2.63 2.63 2.64 2.65 2.66 2.67 2.67 2.68 2.68 2.68 2.68 2.69]",
"The current position is long, average cost: 2.736, and accumulated profit: 15.324",
"Analyze data, generate trading cmd",
},
Output: []string{
"Execute cmd: /close_position",
},
},
},
},
{
Name: "no_action",
Description: "No action to be taken",
Expand Down
12 changes: 10 additions & 2 deletions pkg/jarvis.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,14 +545,22 @@ func (s *Strategy) handlePositionChanged(_ctx context.Context, session ttypes.IS
side = "long"
}

msg = fmt.Sprintf("The current position is %s with %dx leverage, average cost: %.3f, and accumulated profit: %.3f%s", side, s.Leverage.Int(), position.AverageCost.Float64(), position.AccumulatedProfit.Float64(), "%")
msg = fmt.Sprintf("The current position is %s with %dx leverage, average cost: %.3f, and accumulated profit: %.3f%s.", side, s.Leverage.Int(), position.AverageCost.Float64(), position.AccumulatedProfit.Float64(), "%")

if position.TpTriggerPx != nil {
msg += fmt.Sprintf("\nThe current position's take-profit trigger price is %s.", position.Market.FormatPrice(*position.TpTriggerPx))
}

if position.SlTriggerPx != nil {
msg += fmt.Sprintf("\nThe current position's stop-loss trigger price is %s.", position.Market.FormatPrice(*position.SlTriggerPx))
}

profits := position.GetProfitValues()
if len(profits) > s.MaxWindowSize {
profits = profits[len(profits)-s.MaxWindowSize:]
}

msg = msg + fmt.Sprintf("\nThe profits of the recent %d periods: [%s], and the holding period: %d",
msg = msg + fmt.Sprintf("\nThe profits of the recent %d periods: [%s], and the holding period: %d.",
s.MaxWindowSize,
utils.JoinFloatSlicePercentage([]float64(profits), " "),
position.GetHoldingPeriod())
Expand Down

0 comments on commit 42b7784

Please sign in to comment.