Skip to content

Commit d1e2535

Browse files
committed
Merge branch 'dev'
2 parents 5430118 + ed525ea commit d1e2535

File tree

37 files changed

+478
-271
lines changed

37 files changed

+478
-271
lines changed

API.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package goex
33
// api interface
44

55
type API interface {
6-
LimitBuy(amount, price string, currency CurrencyPair) (*Order, error)
7-
LimitSell(amount, price string, currency CurrencyPair) (*Order, error)
6+
LimitBuy(amount, price string, currency CurrencyPair, opt ...LimitOrderOptionalParameter) (*Order, error)
7+
LimitSell(amount, price string, currency CurrencyPair, opt ...LimitOrderOptionalParameter) (*Order, error)
88
MarketBuy(amount, price string, currency CurrencyPair) (*Order, error)
99
MarketSell(amount, price string, currency CurrencyPair) (*Order, error)
1010
CancelOrder(orderId string, currency CurrencyPair) (bool, error)
@@ -15,7 +15,7 @@ type API interface {
1515

1616
GetTicker(currency CurrencyPair) (*Ticker, error)
1717
GetDepth(size int, currency CurrencyPair) (*Depth, error)
18-
GetKlineRecords(currency CurrencyPair, period , size, since int) ([]Kline, error)
18+
GetKlineRecords(currency CurrencyPair, period, size, since int) ([]Kline, error)
1919
//非个人,整个交易所的交易记录
2020
GetTrades(currencyPair CurrencyPair, since int64) ([]Trade, error)
2121

Const.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,24 @@ const (
168168
TIPS //余币宝
169169
SWAP //永续合约
170170
)
171+
172+
type LimitOrderOptionalParameter int
173+
174+
func (opt LimitOrderOptionalParameter) String() string {
175+
switch opt {
176+
case PostOnly:
177+
return "post_only"
178+
case Fok:
179+
return "fok"
180+
case Ioc:
181+
return "ioc"
182+
default:
183+
return "error-order-optional-parameter"
184+
}
185+
}
186+
187+
const (
188+
PostOnly LimitOrderOptionalParameter = iota + 1
189+
Ioc
190+
Fok
191+
)

FutureRestAPI.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ type FutureRestAPI interface {
4949
* @param openType 1:开多 2:开空 3:平多 4:平空
5050
* @param matchPrice 是否为对手价 0:不是 1:是 ,当取值为1时,price无效
5151
*/
52-
PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice, leverRate int) (string, error)
52+
PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, leverRate float64) (string, error)
5353

54-
LimitFuturesOrder(currencyPair CurrencyPair, contractType, price, amount string, openType int) (*FutureOrder, error)
54+
LimitFuturesOrder(currencyPair CurrencyPair, contractType, price, amount string, openType int, opt ...LimitOrderOptionalParameter) (*FutureOrder, error)
55+
56+
//对手价下单
57+
MarketFuturesOrder(currencyPair CurrencyPair, contractType, amount string, openType int) (*FutureOrder, error)
5558

5659
/**
5760
* 取消订单
@@ -108,10 +111,10 @@ type FutureRestAPI interface {
108111
/**
109112
* 获取K线数据
110113
*/
111-
GetKlineRecords(contract_type string, currency CurrencyPair, period, size, since int) ([]FutureKline, error)
114+
GetKlineRecords(contractType string, currency CurrencyPair, period, size, since int) ([]FutureKline, error)
112115

113116
/**
114117
* 获取Trade数据
115118
*/
116-
GetTrades(contract_type string, currencyPair CurrencyPair, since int64) ([]Trade, error)
119+
GetTrades(contractType string, currencyPair CurrencyPair, since int64) ([]Trade, error)
117120
}

Models.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ type APIConfig struct {
119119
ApiPassphrase string //for okex.com v3 api
120120
ClientId string //for bitstamp.net , huobi.pro
121121

122-
Lever int //杠杆倍数 , for future
122+
Lever float64 //杠杆倍数 , for future
123123
}
124124

125125
type Kline struct {
@@ -163,10 +163,14 @@ type FutureOrder struct {
163163
Currency CurrencyPair
164164
OrderType int //ORDINARY=0 POST_ONLY=1 FOK= 2 IOC= 3
165165
OType int //1:开多 2:开空 3:平多 4: 平空
166-
LeverRate int //倍数
166+
LeverRate float64 //倍数
167167
Fee float64 //手续费
168168
ContractName string
169169
FinishedTime int64 // finished timestamp
170+
171+
//策略委托单
172+
TriggerPrice float64
173+
AlgoType int //1:限价 2:市场价;触发价格类型,默认是限价;为市场价时,委托价格不必填;
170174
}
171175

172176
type FuturePosition struct {
@@ -176,7 +180,7 @@ type FuturePosition struct {
176180
BuyPriceCost float64
177181
BuyProfitReal float64
178182
CreateDate int64
179-
LeverRate int
183+
LeverRate float64
180184
SellAmount float64
181185
SellAvailable float64
182186
SellPriceAvg float64
@@ -186,6 +190,8 @@ type FuturePosition struct {
186190
ContractType string
187191
ContractId int64
188192
ForceLiquPrice float64 //预估爆仓价
193+
ShortPnlRatio float64 //空仓收益率
194+
LongPnlRatio float64 //多仓收益率
189195
}
190196

191197
type HistoricalFunding struct {
@@ -222,7 +228,6 @@ type RepaymentParameter struct {
222228
BorrowId string
223229
}
224230

225-
226231
type TransferParameter struct {
227232
Currency string `json:"currency"`
228233
From int `json:"from"`
@@ -242,7 +247,6 @@ type WithdrawParameter struct {
242247
Fee string `json:"fee"`
243248
}
244249

245-
246250
type DepositWithdrawHistory struct {
247251
WithdrawalId string `json:"withdrawal_id,omitempty"`
248252
Currency string `json:"currency"`

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div align="center">
22
<img width="409" heigth="205" src="https://upload-images.jianshu.io/upload_images/6760989-dec7dc747846880e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="goex">
3-
<img src="https://travis-ci.org/nntaoli-project/goex.svg?branch=dev"/>
3+
<img width="198" height="205" src="https://upload-images.jianshu.io/upload_images/6760989-81f29f7a5dbd9bb6.jpg" >
44
</div>
55

66
### goex目标
@@ -9,6 +9,10 @@ goex项目是为了统一并标准化各个数字资产交易平台的接口而
99

1010
[English](https://github.com/nntaoli-project/goex/blob/dev/README_en.md)
1111

12+
### wiki文档
13+
14+
[文档](https://github.com/nntaoli-project/goex/wiki)
15+
1216
### goex已支持交易所 `23+`
1317

1418
| 交易所 | 行情接口 | 交易接口 | 版本号 |

allcoin/allcoin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,11 @@ func (ac *Allcoin) GetAccount() (*Account, error) {
271271
return &acc, nil
272272
}
273273

274-
func (ac *Allcoin) LimitBuy(amount, price string, currencyPair CurrencyPair) (*Order, error) {
274+
func (ac *Allcoin) LimitBuy(amount, price string, currencyPair CurrencyPair, opt ...LimitOrderOptionalParameter) (*Order, error) {
275275
return ac.placeOrder(amount, price, currencyPair, "LIMIT", "buy")
276276
}
277277

278-
func (ac *Allcoin) LimitSell(amount, price string, currencyPair CurrencyPair) (*Order, error) {
278+
func (ac *Allcoin) LimitSell(amount, price string, currencyPair CurrencyPair, opt ...LimitOrderOptionalParameter) (*Order, error) {
279279
return ac.placeOrder(amount, price, currencyPair, "LIMIT", "sale")
280280
}
281281

atop/atop.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,12 @@ func (at *Atop) GetAccount() (*Account, error) {
306306
}
307307

308308
//hao
309-
func (at *Atop) LimitBuy(amount, price string, currencyPair CurrencyPair) (*Order, error) {
309+
func (at *Atop) LimitBuy(amount, price string, currencyPair CurrencyPair, opt ...LimitOrderOptionalParameter) (*Order, error) {
310310
return at.plateOrder(amount, price, currencyPair, "limit", "buy")
311311
}
312312

313313
//hao
314-
func (at *Atop) LimitSell(amount, price string, currencyPair CurrencyPair) (*Order, error) {
314+
func (at *Atop) LimitSell(amount, price string, currencyPair CurrencyPair, opt ...LimitOrderOptionalParameter) (*Order, error) {
315315
return at.plateOrder(amount, price, currencyPair, "limit", "sale")
316316
}
317317

bigone/Bigone.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ func (bo *Bigone) placeOrder(amount, price string, pair goex.CurrencyPair, order
167167
OrderTime: int(time.Now().Unix())}, nil
168168
}
169169

170-
func (bo *Bigone) LimitBuy(amount, price string, currency goex.CurrencyPair) (*goex.Order, error) {
170+
func (bo *Bigone) LimitBuy(amount, price string, currency goex.CurrencyPair, opt ...goex.LimitOrderOptionalParameter) (*goex.Order, error) {
171171
return bo.placeOrder(amount, price, currency, "LIMIT", "BID")
172172
}
173173

174-
func (bo *Bigone) LimitSell(amount, price string, currency goex.CurrencyPair) (*goex.Order, error) {
174+
func (bo *Bigone) LimitSell(amount, price string, currency goex.CurrencyPair, opt ...goex.LimitOrderOptionalParameter) (*goex.Order, error) {
175175
return bo.placeOrder(amount, price, currency, "LIMIT", "ASK")
176176
}
177177

binance/Binance.go

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,11 @@ func (bn *Binance) GetAccount() (*Account, error) {
398398
return &acc, nil
399399
}
400400

401-
func (bn *Binance) LimitBuy(amount, price string, currencyPair CurrencyPair) (*Order, error) {
401+
func (bn *Binance) LimitBuy(amount, price string, currencyPair CurrencyPair, opt ...LimitOrderOptionalParameter) (*Order, error) {
402402
return bn.placeOrder(amount, price, currencyPair, "LIMIT", "BUY")
403403
}
404404

405-
func (bn *Binance) LimitSell(amount, price string, currencyPair CurrencyPair) (*Order, error) {
405+
func (bn *Binance) LimitSell(amount, price string, currencyPair CurrencyPair, opt ...LimitOrderOptionalParameter) (*Order, error) {
406406
return bn.placeOrder(amount, price, currencyPair, "LIMIT", "SELL")
407407
}
408408

@@ -537,40 +537,6 @@ func (bn *Binance) GetUnfinishOrders(currencyPair CurrencyPair) ([]Order, error)
537537
return orders, nil
538538
}
539539

540-
func (bn *Binance) GetAllUnfinishOrders() ([]Order, error) {
541-
params := url.Values{}
542-
543-
bn.buildParamsSigned(&params)
544-
path := bn.apiV3 + UNFINISHED_ORDERS_INFO + params.Encode()
545-
546-
respmap, err := HttpGet3(bn.httpClient, path, map[string]string{"X-MBX-APIKEY": bn.accessKey})
547-
if err != nil {
548-
return nil, err
549-
}
550-
551-
orders := make([]Order, 0)
552-
for _, v := range respmap {
553-
ord := v.(map[string]interface{})
554-
side := ord["side"].(string)
555-
orderSide := SELL
556-
if side == "BUY" {
557-
orderSide = BUY
558-
}
559-
560-
ordId := ToInt(ord["orderId"])
561-
orders = append(orders, Order{
562-
OrderID: ToInt(ord["orderId"]),
563-
OrderID2: strconv.Itoa(ordId),
564-
Currency: bn.toCurrencyPair(ord["symbol"].(string)),
565-
Price: ToFloat64(ord["price"]),
566-
Amount: ToFloat64(ord["origQty"]),
567-
Side: TradeSide(orderSide),
568-
Status: ORDER_UNFINISH,
569-
OrderTime: ToInt(ord["time"])})
570-
}
571-
return orders, nil
572-
}
573-
574540
func (bn *Binance) GetKlineRecords(currency CurrencyPair, period, size, since int) ([]Kline, error) {
575541
params := url.Values{}
576542
params.Set("symbol", currency.ToSymbol(""))
@@ -662,14 +628,31 @@ func (bn *Binance) GetOrderHistorys(currency CurrencyPair, currentPage, pageSize
662628
orderSide = BUY
663629
}
664630
ordId := ToInt(ord["orderId"])
631+
status := ord["status"].(string)
632+
var tradeStatus TradeStatus
633+
switch status {
634+
case "NEW":
635+
tradeStatus = ORDER_UNFINISH
636+
case "FILLED":
637+
tradeStatus = ORDER_FINISH
638+
case "PARTIALLY_FILLED":
639+
tradeStatus = ORDER_PART_FINISH
640+
case "CANCELED":
641+
tradeStatus = ORDER_CANCEL
642+
case "PENDING_CANCEL":
643+
tradeStatus = ORDER_CANCEL_ING
644+
case "REJECTED":
645+
tradeStatus = ORDER_REJECT
646+
}
647+
665648
orders = append(orders, Order{
666649
OrderID: ToInt(ord["orderId"]),
667650
OrderID2: strconv.Itoa(ordId),
668651
Currency: currency,
669652
Price: ToFloat64(ord["price"]),
670653
Amount: ToFloat64(ord["origQty"]),
671654
Side: TradeSide(orderSide),
672-
Status: ORDER_UNFINISH,
655+
Status: tradeStatus,
673656
OrderTime: ToInt(ord["time"])})
674657
}
675658
return orders, nil

binance/BinanceSwap.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ type BinanceSwap struct {
1919
Binance
2020
}
2121

22-
func (bs *BinanceSwap) LimitFuturesOrder(currencyPair CurrencyPair, contractType, price, amount string, openType int) (*FutureOrder, error) {
23-
return bs.PlaceFutureOrder2(currencyPair, contractType, price, amount, openType, 0, 10)
24-
}
25-
2622
func NewBinanceSwap(config *APIConfig) *BinanceSwap {
2723
if config.Endpoint == "" {
2824
config.Endpoint = baseUrl
@@ -293,7 +289,7 @@ func (bs *BinanceSwap) Transfer(currency Currency, transferType int, amount floa
293289
return ToInt64(respmap["tranId"]), nil
294290
}
295291

296-
func (bs *BinanceSwap) PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice, leverRate int) (string, error) {
292+
func (bs *BinanceSwap) PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, leverRate float64) (string, error) {
297293
fOrder, err := bs.PlaceFutureOrder2(currencyPair, contractType, price, amount, openType, matchPrice, leverRate)
298294
return fOrder.OrderID2, err
299295
}
@@ -308,7 +304,7 @@ func (bs *BinanceSwap) PlaceFutureOrder(currencyPair CurrencyPair, contractType,
308304
* @param openType 1:开多 2:开空 3:平多 4:平空
309305
* @param matchPrice 是否为对手价 0:不是 1:是 ,当取值为1时,price无效
310306
*/
311-
func (bs *BinanceSwap) PlaceFutureOrder2(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice, leverRate int) (*FutureOrder, error) {
307+
func (bs *BinanceSwap) PlaceFutureOrder2(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, leverRate float64) (*FutureOrder, error) {
312308
fOrder := &FutureOrder{
313309
Currency: currencyPair,
314310
ClientOid: GenerateOrderClientId(32),
@@ -362,6 +358,14 @@ func (bs *BinanceSwap) PlaceFutureOrder2(currencyPair CurrencyPair, contractType
362358
return fOrder, nil
363359
}
364360

361+
func (bs *BinanceSwap) LimitFuturesOrder(currencyPair CurrencyPair, contractType, price, amount string, openType int, opt ...LimitOrderOptionalParameter) (*FutureOrder, error) {
362+
return bs.PlaceFutureOrder2(currencyPair, contractType, price, amount, openType, 0, 10)
363+
}
364+
365+
func (bs *BinanceSwap) MarketFuturesOrder(currencyPair CurrencyPair, contractType, amount string, openType int) (*FutureOrder, error) {
366+
return bs.PlaceFutureOrder2(currencyPair, contractType, "0", amount, openType, 1, 10)
367+
}
368+
365369
/**
366370
* 取消订单
367371
* @param symbol btc_usd:比特币 ltc_usd :莱特币
@@ -486,7 +490,7 @@ func (bs *BinanceSwap) GetFuturePosition(currencyPair CurrencyPair, contractType
486490
continue
487491
}
488492
p := FuturePosition{
489-
LeverRate: ToInt(cont["leverage"]),
493+
LeverRate: ToFloat64(cont["leverage"]),
490494
Symbol: currencyPair,
491495
ForceLiquPrice: ToFloat64(cont["liquidationPrice"]),
492496
}

0 commit comments

Comments
 (0)