Skip to content

Commit da7742d

Browse files
author
evzpav
committedJun 24, 2021
Implement trailing stop order for Binance
1 parent f05bab7 commit da7742d

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed
 

‎README.md

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ func (s *BasicStrategy) OnTick() error {
8585
s.Exchange.OpenLong(symbol, OrderTypeLimit, 5000, 10)
8686
s.Exchange.CloseLong(symbol, OrderTypeLimit, 6000, 10)
8787

88+
//Trailing Stop Market Order - sell stop loss order for long position
89+
callbackRate := 5.0 // from 0.1% until 5% allowed
90+
s.Exchange.PlaceOrder(symbol, Sell, OrderTypeTrailingStopMarket, 0.0, 10,
91+
OrderCallbackRateOption(callbackRate), OrderReduceOnlyOption(true))
92+
8893
s.Exchange.PlaceOrder(symbol,
8994
Buy, OrderTypeLimit, 1000.0, 10, OrderPostOnlyOption(true))
9095

‎README_en.md

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ func (s *BasicStrategy) OnTick() error {
8585
s.Exchange.OpenLong(symbol, OrderTypeLimit, 5000, 10)
8686
s.Exchange.CloseLong(symbol, OrderTypeLimit, 6000, 10)
8787

88+
//Trailing Stop Market Order - sell stop loss order for long position
89+
callbackRate := 5.0 // from 0.1% until 5% allowed
90+
s.Exchange.PlaceOrder(symbol, Sell, OrderTypeTrailingStopMarket, 0.0, 10,
91+
OrderCallbackRateOption(callbackRate), OrderReduceOnlyOption(true))
92+
8893
s.Exchange.PlaceOrder(symbol,
8994
Buy, OrderTypeLimit, 1000.0, 10, OrderPostOnlyOption(true))
9095

‎consts.go

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const (
5858
OrderTypeLimit // 限价单
5959
OrderTypeStopMarket // 市价止损单
6060
OrderTypeStopLimit // 限价止损单
61+
OrderTypeTrailingStopMarket
6162
)
6263

6364
func (t OrderType) String() string {
@@ -70,6 +71,8 @@ func (t OrderType) String() string {
7071
return "StopMarket"
7172
case OrderTypeStopLimit:
7273
return "StopLimit"
74+
case OrderTypeTrailingStopMarket:
75+
return "TrailingStopMarket"
7376
default:
7477
return "None"
7578
}

‎exchanges/binancefutures/binancefutures.go

+4
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ func (b *BinanceFutures) PlaceOrder(symbol string, direction Direction, orderTyp
209209
case OrderTypeStopLimit:
210210
_orderType = futures.OrderTypeStop
211211
service = service.StopPrice(fmt.Sprint(params.StopPx))
212+
case OrderTypeTrailingStopMarket:
213+
_orderType = futures.OrderTypeTrailingStopMarket
212214
}
213215

214216
if orderType != OrderTypeMarket {
@@ -443,6 +445,8 @@ func (b *BinanceFutures) convertOrderType(orderType futures.OrderType) OrderType
443445
return OrderTypeStopLimit
444446
case futures.OrderTypeStopMarket:
445447
return OrderTypeStopMarket
448+
case futures.OrderTypeTrailingStopMarket:
449+
return OrderTypeTrailingStopMarket
446450
default:
447451
return OrderTypeLimit
448452
}

‎go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE
5858
github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87/go.mod h1:iGLljf5n9GjT6kc0HBvyI1nOKnGQbNB66VzSNbK5iks=
5959
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
6060
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
61-
github.com/adshao/go-binance/v2 v2.2.1 h1:H5tfXqDu+bx1mZqJP+5gc8ahidgDFvj683M3RStg9C4=
62-
github.com/adshao/go-binance/v2 v2.2.1/go.mod h1:o+84WK3DQxq9vEKV9ncRcQi+J7RFCGhM27osbECZiJQ=
6361
github.com/adshao/go-binance/v2 v2.2.2 h1:vKpvZupkgcUPG/CSl9uW0s5hqxzVZgNI/nEzKG1JiUs=
6462
github.com/adshao/go-binance/v2 v2.2.2/go.mod h1:o+84WK3DQxq9vEKV9ncRcQi+J7RFCGhM27osbECZiJQ=
6563
github.com/airbrake/gobrake v3.6.1+incompatible/go.mod h1:wM4gu3Cn0W0K7GUuVWnlXZU11AGBXMILnrdOU8Kn00o=

0 commit comments

Comments
 (0)
Please sign in to comment.