Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement trailing stop order for Binance #42

Merged
merged 2 commits into from
Jun 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ func (s *BasicStrategy) OnTick() error {
s.Exchange.OpenLong(symbol, OrderTypeLimit, 5000, 10)
s.Exchange.CloseLong(symbol, OrderTypeLimit, 6000, 10)

//Trailing Stop Market Order - Binance - sell stop loss order for long position
callbackRate := 5.0 // from 0.1% until 5% allowed
s.Exchange.PlaceOrder(symbol, Sell, OrderTypeTrailingStopMarket, 0.0, 10,
OrderCallbackRateOption(callbackRate),
OrderActivationPriceOption(5000.0), // optional - default as the latest price
OrderReduceOnlyOption(true),
)

s.Exchange.PlaceOrder(symbol,
Buy, OrderTypeLimit, 1000.0, 10, OrderPostOnlyOption(true))

Expand Down
8 changes: 8 additions & 0 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ func (s *BasicStrategy) OnTick() error {
s.Exchange.OpenLong(symbol, OrderTypeLimit, 5000, 10)
s.Exchange.CloseLong(symbol, OrderTypeLimit, 6000, 10)

//Trailing Stop Market Order - Binance - sell stop loss order for long position
callbackRate := 5.0 // from 0.1% until 5% allowed
s.Exchange.PlaceOrder(symbol, Sell, OrderTypeTrailingStopMarket, 0.0, 10,
OrderCallbackRateOption(callbackRate),
OrderActivationPriceOption(5000.0), // optional - default as the latest price
OrderReduceOnlyOption(true),
)

s.Exchange.PlaceOrder(symbol,
Buy, OrderTypeLimit, 1000.0, 10, OrderPostOnlyOption(true))

Expand Down
3 changes: 3 additions & 0 deletions consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const (
OrderTypeLimit // 限价单
OrderTypeStopMarket // 市价止损单
OrderTypeStopLimit // 限价止损单
OrderTypeTrailingStopMarket
)

func (t OrderType) String() string {
Expand All @@ -70,6 +71,8 @@ func (t OrderType) String() string {
return "StopMarket"
case OrderTypeStopLimit:
return "StopLimit"
case OrderTypeTrailingStopMarket:
return "TrailingStopMarket"
default:
return "None"
}
Expand Down
4 changes: 4 additions & 0 deletions exchanges/binancefutures/binancefutures.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ func (b *BinanceFutures) PlaceOrder(symbol string, direction Direction, orderTyp
case OrderTypeStopLimit:
_orderType = futures.OrderTypeStop
service = service.StopPrice(fmt.Sprint(params.StopPx))
case OrderTypeTrailingStopMarket:
_orderType = futures.OrderTypeTrailingStopMarket
}

if orderType != OrderTypeMarket {
Expand Down Expand Up @@ -443,6 +445,8 @@ func (b *BinanceFutures) convertOrderType(orderType futures.OrderType) OrderType
return OrderTypeStopLimit
case futures.OrderTypeStopMarket:
return OrderTypeStopMarket
case futures.OrderTypeTrailingStopMarket:
return OrderTypeTrailingStopMarket
default:
return OrderTypeLimit
}
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE
github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87/go.mod h1:iGLljf5n9GjT6kc0HBvyI1nOKnGQbNB66VzSNbK5iks=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/adshao/go-binance/v2 v2.2.1 h1:H5tfXqDu+bx1mZqJP+5gc8ahidgDFvj683M3RStg9C4=
github.com/adshao/go-binance/v2 v2.2.1/go.mod h1:o+84WK3DQxq9vEKV9ncRcQi+J7RFCGhM27osbECZiJQ=
github.com/adshao/go-binance/v2 v2.2.2 h1:vKpvZupkgcUPG/CSl9uW0s5hqxzVZgNI/nEzKG1JiUs=
github.com/adshao/go-binance/v2 v2.2.2/go.mod h1:o+84WK3DQxq9vEKV9ncRcQi+J7RFCGhM27osbECZiJQ=
github.com/airbrake/gobrake v3.6.1+incompatible/go.mod h1:wM4gu3Cn0W0K7GUuVWnlXZU11AGBXMILnrdOU8Kn00o=
Expand Down