@@ -4,12 +4,13 @@ import (
44 "encoding/json"
55 "errors"
66 "fmt"
7- . "github.com/nntaoli-project/goex"
87 "net/url"
98 "strconv"
109 "strings"
1110 "sync"
1211 "time"
12+
13+ . "github.com/nntaoli-project/goex"
1314)
1415
1516const (
@@ -309,21 +310,21 @@ func (bs *BinanceSwap) Transfer(currency Currency, transferType int, amount floa
309310}
310311
311312func (bs * BinanceSwap ) PlaceFutureOrder (currencyPair CurrencyPair , contractType , price , amount string , openType , matchPrice int , leverRate float64 ) (string , error ) {
312- fOrder , err := bs .PlaceFutureOrder2 (currencyPair , contractType , price , amount , openType , matchPrice , leverRate )
313+ fOrder , err := bs .PlaceFutureOrder2 (currencyPair , contractType , price , amount , openType , matchPrice )
313314 return fOrder .OrderID2 , err
314315}
315316
316- func (bs * BinanceSwap ) PlaceFutureOrder2 (currencyPair CurrencyPair , contractType , price , amount string , openType , matchPrice int , leverRate float64 ) (* FutureOrder , error ) {
317+ func (bs * BinanceSwap ) PlaceFutureOrder2 (currencyPair CurrencyPair , contractType , price , amount string , openType , matchPrice int , opt ... LimitOrderOptionalParameter ) (* FutureOrder , error ) {
317318 if contractType == SWAP_CONTRACT {
318- orderId , err := bs .f .PlaceFutureOrder (currencyPair .AdaptUsdtToUsd (), contractType , price , amount , openType , matchPrice , leverRate )
319+ orderId , err := bs .f .PlaceFutureOrder2 (currencyPair .AdaptUsdtToUsd (), contractType , price , amount , openType , matchPrice , opt ... )
319320 return & FutureOrder {
320321 OrderID2 : orderId ,
321322 Price : ToFloat64 (price ),
322323 Amount : ToFloat64 (amount ),
323324 Status : ORDER_UNFINISH ,
324325 Currency : currencyPair ,
325326 OType : openType ,
326- LeverRate : leverRate ,
327+ LeverRate : 0 ,
327328 ContractName : contractType ,
328329 }, err
329330 }
@@ -338,7 +339,7 @@ func (bs *BinanceSwap) PlaceFutureOrder2(currencyPair CurrencyPair, contractType
338339 Price : ToFloat64 (price ),
339340 Amount : ToFloat64 (amount ),
340341 OrderType : openType ,
341- LeverRate : leverRate ,
342+ LeverRate : 0 ,
342343 ContractName : contractType ,
343344 }
344345
@@ -352,9 +353,16 @@ func (bs *BinanceSwap) PlaceFutureOrder2(currencyPair CurrencyPair, contractType
352353 switch openType {
353354 case OPEN_BUY , CLOSE_SELL :
354355 params .Set ("side" , "BUY" )
356+ if len (opt ) > 0 && opt [0 ] == Futures_Twoway_Position_Mode {
357+ params .Set ("positionSide" , "LONG" )
358+ }
355359 case OPEN_SELL , CLOSE_BUY :
356360 params .Set ("side" , "SELL" )
361+ if len (opt ) > 0 && opt [0 ] == Futures_Twoway_Position_Mode {
362+ params .Set ("positionSide" , "SHORT" )
363+ }
357364 }
365+
358366 if matchPrice == 0 {
359367 params .Set ("type" , "LIMIT" )
360368 params .Set ("price" , price )
@@ -364,6 +372,7 @@ func (bs *BinanceSwap) PlaceFutureOrder2(currencyPair CurrencyPair, contractType
364372 }
365373
366374 bs .buildParamsSigned (& params )
375+
367376 resp , err := HttpPostForm2 (bs .httpClient , path , params ,
368377 map [string ]string {"X-MBX-APIKEY" : bs .accessKey })
369378 if err != nil {
@@ -386,11 +395,11 @@ func (bs *BinanceSwap) PlaceFutureOrder2(currencyPair CurrencyPair, contractType
386395}
387396
388397func (bs * BinanceSwap ) LimitFuturesOrder (currencyPair CurrencyPair , contractType , price , amount string , openType int , opt ... LimitOrderOptionalParameter ) (* FutureOrder , error ) {
389- return bs .PlaceFutureOrder2 (currencyPair , contractType , price , amount , openType , 0 , 10 )
398+ return bs .PlaceFutureOrder2 (currencyPair , contractType , price , amount , openType , 0 , opt ... )
390399}
391400
392401func (bs * BinanceSwap ) MarketFuturesOrder (currencyPair CurrencyPair , contractType , amount string , openType int ) (* FutureOrder , error ) {
393- return bs .PlaceFutureOrder2 (currencyPair , contractType , "0" , amount , openType , 1 , 10 )
402+ return bs .PlaceFutureOrder2 (currencyPair , contractType , "0" , amount , openType , 1 )
394403}
395404
396405func (bs * BinanceSwap ) FutureCancelOrder (currencyPair CurrencyPair , contractType , orderId string ) (bool , error ) {
@@ -406,7 +415,12 @@ func (bs *BinanceSwap) FutureCancelOrder(currencyPair CurrencyPair, contractType
406415 path := bs .apiV1 + ORDER_URI
407416 params := url.Values {}
408417 params .Set ("symbol" , bs .adaptCurrencyPair (currencyPair ).ToSymbol ("" ))
409- params .Set ("orderId" , orderId )
418+
419+ if strings .HasPrefix (orderId , "goex" ) { //goex default clientOrderId Features
420+ params .Set ("origClientOrderId" , orderId )
421+ } else {
422+ params .Set ("orderId" , orderId )
423+ }
410424
411425 bs .buildParamsSigned (& params )
412426
0 commit comments