Skip to content

Commit ef579dc

Browse files
committed
Merge branch 'dev'
2 parents 3535522 + 3e58f5e commit ef579dc

31 files changed

+1848
-98
lines changed

.github/workflows/go.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
branches: [ dev ]
6+
pull_request:
7+
branches: [ dev ]
8+
9+
jobs:
10+
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v3
18+
with:
19+
go-version: 1.18
20+
21+
- name: Build
22+
run: go build -v ./...
23+
24+
# - name: Test
25+
# run: go test -v ./...

Const.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,5 @@ const (
193193
PostOnly LimitOrderOptionalParameter = iota + 1
194194
Ioc
195195
Fok
196+
Futures_Twoway_Position_Mode //币安双向持仓模式
196197
)

Models.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,21 @@ type DepositWithdrawHistory struct {
263263
Timestamp time.Time `json:"timestamp"`
264264
}
265265

266+
type PoloniexCurrency struct {
267+
ID int `json:"id"`
268+
Name string `json:"name"`
269+
HumanType string `json:"humanType"`
270+
CurrencyType string `json:"currencyType"`
271+
TxFee string `json:"txFee"`
272+
MinConf int `json:"minConf"`
273+
DepositAddress string `json:"depositAddress"`
274+
Disabled int `json:"disabled"` //Designates whether (1) or not (0) deposits and withdrawals are disabled.
275+
Frozen int `json:"frozen"` //Designates whether (1) or not (0) trading for this currency is disabled for trading.
276+
Blockchain string `json:"blockchain"`
277+
Delisted int `json:"delisted"`
278+
IsGeofenced int `json:"isGeofenced"`
279+
}
280+
266281
type OptionalParameter map[string]interface{}
267282

268283
func (optional OptionalParameter) Optional(name string, value interface{}) OptionalParameter {
@@ -287,7 +302,7 @@ func (optional OptionalParameter) GetFloat64(name string) float64 {
287302
}
288303

289304
func (optional OptionalParameter) GetTime(name string) *time.Time {
290-
val := optional["name"]
305+
val := optional[name]
291306
if val != nil {
292307
t, ok := val.(time.Time)
293308
if ok {

README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
<div align="center">
2-
<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 width="198" height="205" src="https://upload-images.jianshu.io/upload_images/6760989-81f29f7a5dbd9bb6.jpg" >
4-
</div>
1+
![build](https://github.com/WymA/goex/actions/workflows/go.yml/badge.svg?branch=dev)
52

63
### goex目标
74

@@ -59,12 +56,10 @@ require (
5956

6057
donate
6158
-----------------
62-
BTC:13cBHLk6B7t3Uj7caJbCwv1UaiuiA6Qx8z
59+
BTC: 1GoExWZop4JCJQkjb1UgtVGpjBKmP4DvG8
6360

64-
LTC:LVxM7y1K2dnpuNBU42ei3dKzPySf4VAm1H
65-
66-
ETH:0x98573ddb33cdddce480c3bc1f9279ccd88ca1e93
61+
USDT(TRC20): TGoExC6xvzE4wSA9cYZnwcPaXEjibA5Vtc
6762

6863
### 欢迎为作者付一碗面钱
6964

70-
![微信](wx_pay.JPG) ![支付宝](IMG_1177.jpg)
65+
![微信](wx_pay.JPG) ![支付宝](IMG_1177.jpg)

README_en.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
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">
33
</div>
44

5+
![build](https://github.com/WymA/goex/actions/workflows/go.yml/badge.svg?branch=dev)
6+
57
### goex
68

79
goex project is designed to unify and standardize the interfaces of each digital asset trading platform. The same strategy can be switched to any trading platform at any time without changing any code.

bigone/BigoneV3_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package bigone
22

33
import (
4-
. "github.com/nntaoli-project/goex"
54
"net/http"
65
"testing"
76

7+
. "github.com/nntaoli-project/goex"
8+
89
"net"
910
"net/url"
1011
"time"
@@ -52,7 +53,7 @@ func TestBigoneV3_GetUnfinishOrders(t *testing.T) {
5253
}
5354
func TestBigoneV3_GetOrderHistorys(t *testing.T) {
5455
return
55-
t.Log(b1.GetOrderHistorys(BTC_USDT, 1, 1))
56+
t.Log(b1.GetOrderHistorys(BTC_USDT, OptionalParameter{"test": 1}))
5657
}
5758
func TestBigoneV3_LimitSell(t *testing.T) {
5859
return

binance/Binance.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,30 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7-
. "github.com/nntaoli-project/goex"
87
"net/http"
98
"net/url"
109
"sort"
1110
"strconv"
1211
"strings"
1312
"time"
13+
14+
. "github.com/nntaoli-project/goex"
1415
)
1516

1617
const (
1718
GLOBAL_API_BASE_URL = "https://api.binance.com"
1819
US_API_BASE_URL = "https://api.binance.us"
1920
JE_API_BASE_URL = "https://api.binance.je"
21+
22+
FUTURE_USD_WS_BASE_URL = "wss://fstream.binance.com/ws"
23+
FUTURE_COIN_WS_BASE_URL = "wss://dstream.binance.com/ws"
24+
25+
TESTNET_SPOT_API_BASE_URL = "https://api.binance.com"
26+
TESTNET_SPOT_WS_BASE_URL = "wss://testnet.binance.vision/ws"
27+
TESTNET_SPOT_STREAM_BASE_URL = "wss://testnet.binance.vision/stream"
28+
TESTNET_FUTURE_USD_BASE_URL = "https://testnet.binancefuture.com"
29+
TESTNET_FUTURE_USD_WS_BASE_URL = "wss://fstream.binance.com/ws"
30+
TESTNET_FUTURE_COIN_WS_BASE_URL = "wss://dstream.binance.com/ws"
2031
//API_V1 = API_BASE_URL + "api/v1/"
2132
//API_V3 = API_BASE_URL + "api/v3/"
2233

binance/BinanceFutures.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7-
. "github.com/nntaoli-project/goex"
8-
"github.com/nntaoli-project/goex/internal/logger"
97
"math"
108
"net/http"
119
"net/url"
1210
"sort"
1311
"strings"
1412
"sync"
1513
"time"
14+
15+
. "github.com/nntaoli-project/goex"
16+
"github.com/nntaoli-project/goex/internal/logger"
1617
)
1718

1819
type BaseResponse struct {
@@ -275,6 +276,10 @@ func (bs *BinanceFutures) GetFutureUserinfo(currencyPair ...CurrencyPair) (*Futu
275276
}
276277

277278
func (bs *BinanceFutures) PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, leverRate float64) (string, error) {
279+
return bs.PlaceFutureOrder2(currencyPair, contractType, price, amount, openType, matchPrice)
280+
}
281+
282+
func (bs *BinanceFutures) PlaceFutureOrder2(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, opt ...LimitOrderOptionalParameter) (string, error) {
278283
apiPath := "order"
279284
symbol, err := bs.adaptToSymbol(currencyPair, contractType)
280285
if err != nil {
@@ -298,8 +303,14 @@ func (bs *BinanceFutures) PlaceFutureOrder(currencyPair CurrencyPair, contractTy
298303
switch openType {
299304
case OPEN_BUY, CLOSE_SELL:
300305
param.Set("side", "BUY")
306+
if len(opt) > 0 && opt[0] == Futures_Twoway_Position_Mode {
307+
param.Set("positionSide", "LONG")
308+
}
301309
case OPEN_SELL, CLOSE_BUY:
302310
param.Set("side", "SELL")
311+
if len(opt) > 0 && opt[0] == Futures_Twoway_Position_Mode {
312+
param.Set("positionSide", "SHORT")
313+
}
303314
}
304315

305316
bs.base.buildParamsSigned(&param)
@@ -331,7 +342,7 @@ func (bs *BinanceFutures) PlaceFutureOrder(currencyPair CurrencyPair, contractTy
331342
}
332343

333344
func (bs *BinanceFutures) LimitFuturesOrder(currencyPair CurrencyPair, contractType, price, amount string, openType int, opt ...LimitOrderOptionalParameter) (*FutureOrder, error) {
334-
orderId, err := bs.PlaceFutureOrder(currencyPair, contractType, price, amount, openType, 0, 10)
345+
orderId, err := bs.PlaceFutureOrder2(currencyPair, contractType, price, amount, openType, 0, opt...)
335346
return &FutureOrder{
336347
OrderID2: orderId,
337348
Currency: currencyPair,
@@ -343,7 +354,7 @@ func (bs *BinanceFutures) LimitFuturesOrder(currencyPair CurrencyPair, contractT
343354
}
344355

345356
func (bs *BinanceFutures) MarketFuturesOrder(currencyPair CurrencyPair, contractType, amount string, openType int) (*FutureOrder, error) {
346-
orderId, err := bs.PlaceFutureOrder(currencyPair, contractType, "", amount, openType, 1, 10)
357+
orderId, err := bs.PlaceFutureOrder2(currencyPair, contractType, "", amount, openType, 1)
347358
return &FutureOrder{
348359
OrderID2: orderId,
349360
Currency: currencyPair,

binance/BinanceSwap.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1516
const (
@@ -309,21 +310,21 @@ func (bs *BinanceSwap) Transfer(currency Currency, transferType int, amount floa
309310
}
310311

311312
func (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

388397
func (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

392401
func (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

396405
func (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

binance/BinanceSwap_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package binance
22

33
import (
4-
goex "github.com/nntaoli-project/goex"
54
"net"
65
"net/http"
76
"net/url"
87
"testing"
98
"time"
9+
10+
goex "github.com/nntaoli-project/goex"
1011
)
1112

1213
var bs = NewBinanceSwap(&goex.APIConfig{
@@ -15,7 +16,6 @@ var bs = NewBinanceSwap(&goex.APIConfig{
1516
Transport: &http.Transport{
1617
Proxy: func(req *http.Request) (*url.URL, error) {
1718
return url.Parse("socks5://127.0.0.1:1080")
18-
return nil, nil
1919
},
2020
Dial: (&net.Dialer{
2121
Timeout: 10 * time.Second,
@@ -40,7 +40,7 @@ func TestBinanceSwap_GetFutureIndex(t *testing.T) {
4040
}
4141

4242
func TestBinanceSwap_GetKlineRecords(t *testing.T) {
43-
kline, err := bs.GetKlineRecords("", goex.BTC_USDT, goex.KLINE_PERIOD_4H, 1, 0)
43+
kline, err := bs.GetKlineRecords("", goex.BTC_USDT, goex.KLINE_PERIOD_4H, 1, goex.OptionalParameter{"test": 0})
4444
t.Log(err, kline[0].Kline)
4545
}
4646

0 commit comments

Comments
 (0)