Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
nntaoli committed Sep 16, 2022
2 parents 3535522 + 3e58f5e commit ef579dc
Show file tree
Hide file tree
Showing 31 changed files with 1,848 additions and 98 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Go

on:
push:
branches: [ dev ]
pull_request:
branches: [ dev ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18

- name: Build
run: go build -v ./...

# - name: Test
# run: go test -v ./...
1 change: 1 addition & 0 deletions Const.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,5 @@ const (
PostOnly LimitOrderOptionalParameter = iota + 1
Ioc
Fok
Futures_Twoway_Position_Mode //币安双向持仓模式
)
17 changes: 16 additions & 1 deletion Models.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,21 @@ type DepositWithdrawHistory struct {
Timestamp time.Time `json:"timestamp"`
}

type PoloniexCurrency struct {
ID int `json:"id"`
Name string `json:"name"`
HumanType string `json:"humanType"`
CurrencyType string `json:"currencyType"`
TxFee string `json:"txFee"`
MinConf int `json:"minConf"`
DepositAddress string `json:"depositAddress"`
Disabled int `json:"disabled"` //Designates whether (1) or not (0) deposits and withdrawals are disabled.
Frozen int `json:"frozen"` //Designates whether (1) or not (0) trading for this currency is disabled for trading.
Blockchain string `json:"blockchain"`
Delisted int `json:"delisted"`
IsGeofenced int `json:"isGeofenced"`
}

type OptionalParameter map[string]interface{}

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

func (optional OptionalParameter) GetTime(name string) *time.Time {
val := optional["name"]
val := optional[name]
if val != nil {
t, ok := val.(time.Time)
if ok {
Expand Down
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<div align="center">
<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">
<img width="198" height="205" src="https://upload-images.jianshu.io/upload_images/6760989-81f29f7a5dbd9bb6.jpg" >
</div>
![build](https://github.com/WymA/goex/actions/workflows/go.yml/badge.svg?branch=dev)

### goex目标

Expand Down Expand Up @@ -59,12 +56,10 @@ require (

donate
-----------------
BTC:13cBHLk6B7t3Uj7caJbCwv1UaiuiA6Qx8z
BTC: 1GoExWZop4JCJQkjb1UgtVGpjBKmP4DvG8

LTC:LVxM7y1K2dnpuNBU42ei3dKzPySf4VAm1H

ETH:0x98573ddb33cdddce480c3bc1f9279ccd88ca1e93
USDT(TRC20): TGoExC6xvzE4wSA9cYZnwcPaXEjibA5Vtc

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

![微信](wx_pay.JPG) ![支付宝](IMG_1177.jpg)
![微信](wx_pay.JPG) ![支付宝](IMG_1177.jpg)
2 changes: 2 additions & 0 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<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">
</div>

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

### goex

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.
Expand Down
5 changes: 3 additions & 2 deletions bigone/BigoneV3_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package bigone

import (
. "github.com/nntaoli-project/goex"
"net/http"
"testing"

. "github.com/nntaoli-project/goex"

"net"
"net/url"
"time"
Expand Down Expand Up @@ -52,7 +53,7 @@ func TestBigoneV3_GetUnfinishOrders(t *testing.T) {
}
func TestBigoneV3_GetOrderHistorys(t *testing.T) {
return
t.Log(b1.GetOrderHistorys(BTC_USDT, 1, 1))
t.Log(b1.GetOrderHistorys(BTC_USDT, OptionalParameter{"test": 1}))
}
func TestBigoneV3_LimitSell(t *testing.T) {
return
Expand Down
13 changes: 12 additions & 1 deletion binance/Binance.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,30 @@ import (
"encoding/json"
"errors"
"fmt"
. "github.com/nntaoli-project/goex"
"net/http"
"net/url"
"sort"
"strconv"
"strings"
"time"

. "github.com/nntaoli-project/goex"
)

const (
GLOBAL_API_BASE_URL = "https://api.binance.com"
US_API_BASE_URL = "https://api.binance.us"
JE_API_BASE_URL = "https://api.binance.je"

FUTURE_USD_WS_BASE_URL = "wss://fstream.binance.com/ws"
FUTURE_COIN_WS_BASE_URL = "wss://dstream.binance.com/ws"

TESTNET_SPOT_API_BASE_URL = "https://api.binance.com"
TESTNET_SPOT_WS_BASE_URL = "wss://testnet.binance.vision/ws"
TESTNET_SPOT_STREAM_BASE_URL = "wss://testnet.binance.vision/stream"
TESTNET_FUTURE_USD_BASE_URL = "https://testnet.binancefuture.com"
TESTNET_FUTURE_USD_WS_BASE_URL = "wss://fstream.binance.com/ws"
TESTNET_FUTURE_COIN_WS_BASE_URL = "wss://dstream.binance.com/ws"
//API_V1 = API_BASE_URL + "api/v1/"
//API_V3 = API_BASE_URL + "api/v3/"

Expand Down
19 changes: 15 additions & 4 deletions binance/BinanceFutures.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"encoding/json"
"errors"
"fmt"
. "github.com/nntaoli-project/goex"
"github.com/nntaoli-project/goex/internal/logger"
"math"
"net/http"
"net/url"
"sort"
"strings"
"sync"
"time"

. "github.com/nntaoli-project/goex"
"github.com/nntaoli-project/goex/internal/logger"
)

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

func (bs *BinanceFutures) PlaceFutureOrder(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, leverRate float64) (string, error) {
return bs.PlaceFutureOrder2(currencyPair, contractType, price, amount, openType, matchPrice)
}

func (bs *BinanceFutures) PlaceFutureOrder2(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, opt ...LimitOrderOptionalParameter) (string, error) {
apiPath := "order"
symbol, err := bs.adaptToSymbol(currencyPair, contractType)
if err != nil {
Expand All @@ -298,8 +303,14 @@ func (bs *BinanceFutures) PlaceFutureOrder(currencyPair CurrencyPair, contractTy
switch openType {
case OPEN_BUY, CLOSE_SELL:
param.Set("side", "BUY")
if len(opt) > 0 && opt[0] == Futures_Twoway_Position_Mode {
param.Set("positionSide", "LONG")
}
case OPEN_SELL, CLOSE_BUY:
param.Set("side", "SELL")
if len(opt) > 0 && opt[0] == Futures_Twoway_Position_Mode {
param.Set("positionSide", "SHORT")
}
}

bs.base.buildParamsSigned(&param)
Expand Down Expand Up @@ -331,7 +342,7 @@ func (bs *BinanceFutures) PlaceFutureOrder(currencyPair CurrencyPair, contractTy
}

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

func (bs *BinanceFutures) MarketFuturesOrder(currencyPair CurrencyPair, contractType, amount string, openType int) (*FutureOrder, error) {
orderId, err := bs.PlaceFutureOrder(currencyPair, contractType, "", amount, openType, 1, 10)
orderId, err := bs.PlaceFutureOrder2(currencyPair, contractType, "", amount, openType, 1)
return &FutureOrder{
OrderID2: orderId,
Currency: currencyPair,
Expand Down
32 changes: 23 additions & 9 deletions binance/BinanceSwap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"encoding/json"
"errors"
"fmt"
. "github.com/nntaoli-project/goex"
"net/url"
"strconv"
"strings"
"sync"
"time"

. "github.com/nntaoli-project/goex"
)

const (
Expand Down Expand Up @@ -309,21 +310,21 @@ func (bs *BinanceSwap) Transfer(currency Currency, transferType int, amount floa
}

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)
fOrder, err := bs.PlaceFutureOrder2(currencyPair, contractType, price, amount, openType, matchPrice)
return fOrder.OrderID2, err
}

func (bs *BinanceSwap) PlaceFutureOrder2(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, leverRate float64) (*FutureOrder, error) {
func (bs *BinanceSwap) PlaceFutureOrder2(currencyPair CurrencyPair, contractType, price, amount string, openType, matchPrice int, opt ...LimitOrderOptionalParameter) (*FutureOrder, error) {
if contractType == SWAP_CONTRACT {
orderId, err := bs.f.PlaceFutureOrder(currencyPair.AdaptUsdtToUsd(), contractType, price, amount, openType, matchPrice, leverRate)
orderId, err := bs.f.PlaceFutureOrder2(currencyPair.AdaptUsdtToUsd(), contractType, price, amount, openType, matchPrice, opt...)
return &FutureOrder{
OrderID2: orderId,
Price: ToFloat64(price),
Amount: ToFloat64(amount),
Status: ORDER_UNFINISH,
Currency: currencyPair,
OType: openType,
LeverRate: leverRate,
LeverRate: 0,
ContractName: contractType,
}, err
}
Expand All @@ -338,7 +339,7 @@ func (bs *BinanceSwap) PlaceFutureOrder2(currencyPair CurrencyPair, contractType
Price: ToFloat64(price),
Amount: ToFloat64(amount),
OrderType: openType,
LeverRate: leverRate,
LeverRate: 0,
ContractName: contractType,
}

Expand All @@ -352,9 +353,16 @@ func (bs *BinanceSwap) PlaceFutureOrder2(currencyPair CurrencyPair, contractType
switch openType {
case OPEN_BUY, CLOSE_SELL:
params.Set("side", "BUY")
if len(opt) > 0 && opt[0] == Futures_Twoway_Position_Mode {
params.Set("positionSide", "LONG")
}
case OPEN_SELL, CLOSE_BUY:
params.Set("side", "SELL")
if len(opt) > 0 && opt[0] == Futures_Twoway_Position_Mode {
params.Set("positionSide", "SHORT")
}
}

if matchPrice == 0 {
params.Set("type", "LIMIT")
params.Set("price", price)
Expand All @@ -364,6 +372,7 @@ func (bs *BinanceSwap) PlaceFutureOrder2(currencyPair CurrencyPair, contractType
}

bs.buildParamsSigned(&params)

resp, err := HttpPostForm2(bs.httpClient, path, params,
map[string]string{"X-MBX-APIKEY": bs.accessKey})
if err != nil {
Expand All @@ -386,11 +395,11 @@ func (bs *BinanceSwap) PlaceFutureOrder2(currencyPair CurrencyPair, contractType
}

func (bs *BinanceSwap) LimitFuturesOrder(currencyPair CurrencyPair, contractType, price, amount string, openType int, opt ...LimitOrderOptionalParameter) (*FutureOrder, error) {
return bs.PlaceFutureOrder2(currencyPair, contractType, price, amount, openType, 0, 10)
return bs.PlaceFutureOrder2(currencyPair, contractType, price, amount, openType, 0, opt...)
}

func (bs *BinanceSwap) MarketFuturesOrder(currencyPair CurrencyPair, contractType, amount string, openType int) (*FutureOrder, error) {
return bs.PlaceFutureOrder2(currencyPair, contractType, "0", amount, openType, 1, 10)
return bs.PlaceFutureOrder2(currencyPair, contractType, "0", amount, openType, 1)
}

func (bs *BinanceSwap) FutureCancelOrder(currencyPair CurrencyPair, contractType, orderId string) (bool, error) {
Expand All @@ -406,7 +415,12 @@ func (bs *BinanceSwap) FutureCancelOrder(currencyPair CurrencyPair, contractType
path := bs.apiV1 + ORDER_URI
params := url.Values{}
params.Set("symbol", bs.adaptCurrencyPair(currencyPair).ToSymbol(""))
params.Set("orderId", orderId)

if strings.HasPrefix(orderId, "goex") { //goex default clientOrderId Features
params.Set("origClientOrderId", orderId)
} else {
params.Set("orderId", orderId)
}

bs.buildParamsSigned(&params)

Expand Down
6 changes: 3 additions & 3 deletions binance/BinanceSwap_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package binance

import (
goex "github.com/nntaoli-project/goex"
"net"
"net/http"
"net/url"
"testing"
"time"

goex "github.com/nntaoli-project/goex"
)

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

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

Expand Down
Loading

0 comments on commit ef579dc

Please sign in to comment.