Skip to content

Commit

Permalink
[futures] lever field type from int change to float64
Browse files Browse the repository at this point in the history
  • Loading branch information
nntaoli committed Jul 22, 2020
1 parent b5e104e commit ed525ea
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion FutureRestAPI.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type FutureRestAPI interface {
* @param openType 1:开多 2:开空 3:平多 4:平空
* @param matchPrice 是否为对手价 0:不是 1:是 ,当取值为1时,price无效
*/
PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice, leverRate int) (string, error)
PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, leverRate float64) (string, error)

LimitFuturesOrder(currencyPair CurrencyPair, contractType, price, amount string, openType int, opt ...LimitOrderOptionalParameter) (*FutureOrder, error)

Expand Down
8 changes: 3 additions & 5 deletions Models.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type APIConfig struct {
ApiPassphrase string //for okex.com v3 api
ClientId string //for bitstamp.net , huobi.pro

Lever int //杠杆倍数 , for future
Lever float64 //杠杆倍数 , for future
}

type Kline struct {
Expand Down Expand Up @@ -163,7 +163,7 @@ type FutureOrder struct {
Currency CurrencyPair
OrderType int //ORDINARY=0 POST_ONLY=1 FOK= 2 IOC= 3
OType int //1:开多 2:开空 3:平多 4: 平空
LeverRate int //倍数
LeverRate float64 //倍数
Fee float64 //手续费
ContractName string
FinishedTime int64 // finished timestamp
Expand All @@ -180,7 +180,7 @@ type FuturePosition struct {
BuyPriceCost float64
BuyProfitReal float64
CreateDate int64
LeverRate int
LeverRate float64
SellAmount float64
SellAvailable float64
SellPriceAvg float64
Expand Down Expand Up @@ -228,7 +228,6 @@ type RepaymentParameter struct {
BorrowId string
}


type TransferParameter struct {
Currency string `json:"currency"`
From int `json:"from"`
Expand All @@ -248,7 +247,6 @@ type WithdrawParameter struct {
Fee string `json:"fee"`
}


type DepositWithdrawHistory struct {
WithdrawalId string `json:"withdrawal_id,omitempty"`
Currency string `json:"currency"`
Expand Down
6 changes: 3 additions & 3 deletions binance/BinanceSwap.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (bs *BinanceSwap) Transfer(currency Currency, transferType int, amount floa
return ToInt64(respmap["tranId"]), nil
}

func (bs *BinanceSwap) PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice, leverRate int) (string, error) {
func (bs *BinanceSwap) PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, leverRate float64) (string, error) {
fOrder, err := bs.PlaceFutureOrder2(currencyPair, contractType, price, amount, openType, matchPrice, leverRate)
return fOrder.OrderID2, err
}
Expand All @@ -304,7 +304,7 @@ func (bs *BinanceSwap) PlaceFutureOrder(currencyPair CurrencyPair, contractType,
* @param openType 1:开多 2:开空 3:平多 4:平空
* @param matchPrice 是否为对手价 0:不是 1:是 ,当取值为1时,price无效
*/
func (bs *BinanceSwap) PlaceFutureOrder2(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice, leverRate int) (*FutureOrder, error) {
func (bs *BinanceSwap) PlaceFutureOrder2(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, leverRate float64) (*FutureOrder, error) {
fOrder := &FutureOrder{
Currency: currencyPair,
ClientOid: GenerateOrderClientId(32),
Expand Down Expand Up @@ -490,7 +490,7 @@ func (bs *BinanceSwap) GetFuturePosition(currencyPair CurrencyPair, contractType
continue
}
p := FuturePosition{
LeverRate: ToInt(cont["leverage"]),
LeverRate: ToFloat64(cont["leverage"]),
Symbol: currencyPair,
ForceLiquPrice: ToFloat64(cont["liquidationPrice"]),
}
Expand Down
6 changes: 3 additions & 3 deletions coinbene/CoinbeneSwap.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type baseResp struct {
type CoinbeneOrder struct {
OrderId string `json:"orderId"`
Direction string `json:"direction"`
Leverage int `json:"leverage,string"`
Leverage float64 `json:"leverage,string"`
Symbol string `json:"symbol"`
OrderType string `json:"orderType"`
Quantity float64 `json:"quantity,string"`
Expand Down Expand Up @@ -163,7 +163,7 @@ func (swap *CoinbeneSwap) GetFutureUserinfo(currencyPair ...CurrencyPair) (*Futu
return acc, nil
}

func (swap *CoinbeneSwap) PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice, leverRate int) (string, error) {
func (swap *CoinbeneSwap) PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, leverRate float64) (string, error) {
var param struct {
Symbol string `json:"symbol"`
Leverage string `json:"leverage"`
Expand Down Expand Up @@ -229,7 +229,7 @@ func (swap *CoinbeneSwap) GetFuturePosition(currencyPair CurrencyPair, contractT
AvailableQuantity float64 `json:"availableQuantity,string"`
AveragePrice float64 `json:"averagePrice,string"`
CreateTime time.Time `json:"createTime"`
Leverage int `json:"leverage,string"`
Leverage float64 `json:"leverage,string"`
LiquidationPrice float64 `json:"liquidationPrice,string"`
RealisedPnl float64 `json:"realisedPnl,string"`
UnrealisedPnl float64 `json:"unrealisedPnl,string"`
Expand Down
8 changes: 4 additions & 4 deletions huobi/Hbdm.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type OrderInfo struct {
OrderPriceType string `json:"order_price_type"`
Direction string `json:"direction"`
Offset string `json:"offset"`
LeverRate int `json:"lever_rate"`
LeverRate float64 `json:"lever_rate"`
OrderId int64 `json:"order_id"`
ClientOrderId int64 `json:"client_order_id"`
OrderSource string `json:"order_source"`
Expand Down Expand Up @@ -184,7 +184,7 @@ func (dm *Hbdm) GetFuturePosition(currencyPair CurrencyPair, contractType string
ProfitRate float64 `json:"profit_rate"`
Profit float64 `json:"profit"`
PositionMargin float64 `json:"position_margin"`
LeverRate int `json:"lever_rate"`
LeverRate float64 `json:"lever_rate"`
Direction string `json:"direction"`
}

Expand Down Expand Up @@ -234,12 +234,12 @@ func (dm *Hbdm) GetFuturePosition(currencyPair CurrencyPair, contractType string
return positions, nil
}

func (dm *Hbdm) PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice, leverRate int) (string, error) {
func (dm *Hbdm) PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, leverRate float64) (string, error) {
fOrder, err := dm.PlaceFutureOrder2(currencyPair, contractType, price, amount, openType, matchPrice, leverRate)
return fOrder.OrderID2, err
}

func (dm *Hbdm) PlaceFutureOrder2(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice, leverRate int, opt ...LimitOrderOptionalParameter) (*FutureOrder, error) {
func (dm *Hbdm) PlaceFutureOrder2(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, leverRate float64, opt ...LimitOrderOptionalParameter) (*FutureOrder, error) {
var data struct {
OrderId int64 `json:"order_id"`
COrderId int64 `json:"client_order_id"`
Expand Down
4 changes: 2 additions & 2 deletions okex/OKExFuture.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func (ok *OKExFuture) PlaceFutureOrder2(matchPrice int, ord *FutureOrder) (*Futu
return ord, nil
}

func (ok *OKExFuture) PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice, leverRate int) (string, error) {
func (ok *OKExFuture) PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, leverRate float64) (string, error) {
fOrder, err := ok.PlaceFutureOrder2(matchPrice, &FutureOrder{
Price: ToFloat64(price),
Amount: ToFloat64(amount),
Expand Down Expand Up @@ -473,7 +473,7 @@ func (ok *OKExFuture) GetFuturePosition(currencyPair CurrencyPair, contractType
LongPnlRatio float64 `json:"long_pnl_ratio,string"`
LongUnrealisedPnl float64 `json:"long_unrealised_pnl,string"`
RealisedPnl float64 `json:"realised_pnl,string"`
Leverage int `json:"leverage,string"`
Leverage float64 `json:"leverage,string"`
ShortQty float64 `json:"short_qty,string"`
ShortAvailQty float64 `json:"short_avail_qty,string"`
ShortAvgCost float64 `json:"short_avg_cost,string"`
Expand Down
4 changes: 3 additions & 1 deletion okex/OKExSwap.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ type PlaceOrdersInfo struct {
OrderData []*BasePlaceOrderInfo `json:"order_data"`
}

func (ok *OKExSwap) PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice, leverRate int) (string, error) {
func (ok *OKExSwap) PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, leverRate float64) (string, error) {
fOrder, err := ok.PlaceFutureOrder2(currencyPair, contractType, price, amount, openType, matchPrice)
return fOrder.OrderID2, err
}
Expand Down Expand Up @@ -511,6 +511,8 @@ func (ok *OKExSwap) GetFuturePosition(currencyPair CurrencyPair, contractType st
positions[0].SellPriceAvg = sellPosition.AvgCost
positions[0].SellProfitReal = sellPosition.RealizedPnl
positions[0].SellPriceCost = sellPosition.SettlementPrice

positions[0].LeverRate = ToFloat64(sellPosition.Leverage)
}
return positions, nil
}
Expand Down

0 comments on commit ed525ea

Please sign in to comment.