Skip to content

Commit

Permalink
Merge branch 'adshao:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ntminh611 authored Aug 29, 2024
2 parents 0c79288 + 5548d1a commit 725deeb
Show file tree
Hide file tree
Showing 81 changed files with 14,959 additions and 686 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ on:
workflow_dispatch:

jobs:
TyposCheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: crate-ci/[email protected]
with:
config: ./typos.toml

UnitTest:
runs-on: ubuntu-latest
steps:
Expand Down
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ Name | Description | Status
[web-socket-streams.md](https://github.com/binance/binance-spot-api-docs/blob/master/web-socket-streams.md) | Details on available streams and payloads | <input type="checkbox" checked> Implemented
[user-data-stream.md](https://github.com/binance/binance-spot-api-docs/blob/master/user-data-stream.md) | Details on the dedicated account stream | <input type="checkbox" checked> Implemented
[margin-api.md](https://binance-docs.github.io/apidocs/spot/en) | Details on the Margin API (/sapi) | <input type="checkbox" checked> Implemented
[futures-api.md](https://binance-docs.github.io/apidocs/futures/en/#general-info) | Details on the Futures API (/fapi) | <input type="checkbox" checked> Partially Implemented
[delivery-api.md](https://binance-docs.github.io/apidocs/delivery/en/#general-info) | Details on the Coin-M Futures API (/dapi) | <input type="checkbox" checked> Partially Implemented
[futures-api.md](https://binance-docs.github.io/apidocs/futures/en/#general-info) | Details on the Futures API (/fapi) | <input type="checkbox" checked> Implemented
[delivery-api.md](https://binance-docs.github.io/apidocs/delivery/en/#general-info) | Details on the Coin-M Futures API (/dapi) | <input type="checkbox" checked> Implemented
[options-api.md](https://binance-docs.github.io/apidocs/voptions/en/#general-info) | Details on the Options API(/eapi) | <input type="checkbox" checked> Implemented


If you find an unimplemented interface, please submit an issue. It's great if you can open a PR to fix it.

### Installation

Expand All @@ -40,7 +44,12 @@ go get github.com/adshao/go-binance/v1

```golang
import (
// for spot and other interfaces contained in https://binance-docs.github.io/apidocs/spot/en/#change-log
"github.com/adshao/go-binance/v2"

"github.com/adshao/go-binance/v2/futures" // optional package
"github.com/adshao/go-binance/v2/delivery" // optional package
"github.com/adshao/go-binance/v2/options" // optional package
)
```

Expand Down Expand Up @@ -70,6 +79,16 @@ Simply call API in chain style. Call Do() in the end to send HTTP request.

Following are some simple examples, please refer to [godoc](https://godoc.org/github.com/adshao/go-binance) for full references.

If you have any questions, please refer to the specific version of the code for specific reference definitions or usage methods

##### Proxy Client

```
proxyUrl := "http://127.0.0.1:7890" // Please replace it with your exact proxy URL.
client := binance.NewProxiedClient(apiKey, apiSecret, proxyUrl)
```


#### Create Order

```golang
Expand Down Expand Up @@ -219,6 +238,12 @@ You don't need Client in websocket API. Just call binance.WsXxxServe(args, handl

> For delivery API you can use `delivery.WsXxxServe(args, handler, errHandler)`.
If you want to use a proxy, you can set `HTTPS_PROXY` or `HTTP_PROXY` in the environment variable, or you can call `SetWsProxyUrl` in the target packages within your code. Then you can call other websocket functions. For example:
```golang
binance.SetWsProxyUrl("http://127.0.0.1:7890")
binance.WsDepthServe("LTCBTC", wsDepthHandler, errHandler)
```

#### Depth

```golang
Expand Down
27 changes: 27 additions & 0 deletions typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[files]
ignore-files = true
ignore-hidden = false
extend-exclude = [
".git/",
"v2/go.mod",
"v2/go.sum",
"v2/go.work.sum",
]


[default]
extend-ignore-re=[
"ios_54d9b18d8e7a4caf9d149573e16480ba",
"Pn",
"SIZ9",
"alo",
"ot",
"[Cc]ummulative",
"OTU",
"[Tt]ransfered",
]
check-filename = true




15 changes: 14 additions & 1 deletion v2/account_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ import (

// GetAccountService get account info
type GetAccountService struct {
c *Client
c *Client
omitZeroBalances *bool
}

// OmitZeroBalances sets the omitZeroBalances parameter on the request.
// When set to true, the API will return the non-zero balances of an account.
func (s *GetAccountService) OmitZeroBalances(v bool) *GetAccountService {
s.omitZeroBalances = &v
return s
}

// Do send request
Expand All @@ -17,6 +25,10 @@ func (s *GetAccountService) Do(ctx context.Context, opts ...RequestOption) (res
endpoint: "/api/v3/account",
secType: secTypeSigned,
}
if s.omitZeroBalances != nil {
r.setParam("omitZeroBalances", *s.omitZeroBalances)
}

data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
Expand All @@ -43,6 +55,7 @@ type Account struct {
AccountType string `json:"accountType"`
Balances []Balance `json:"balances"`
Permissions []string `json:"permissions"`
UID int64 `json:"uid"`
}

// Balance define user balance of your account
Expand Down
14 changes: 11 additions & 3 deletions v2/account_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,22 @@ func (s *accountServiceTestSuite) TestGetAccount() {
],
"permissions": [
"SPOT"
]
],
"uid": 354937868
}`)
s.mockDo(data, nil)
defer s.assertDo()

omitZeroBalances := true

s.assertReq(func(r *request) {
e := newSignedRequest()
e := newSignedRequest().setParams(params{
"omitZeroBalances": omitZeroBalances,
})
s.assertRequestEqual(e, r)
})

res, err := s.client.NewGetAccountService().Do(newContext())
res, err := s.client.NewGetAccountService().OmitZeroBalances(omitZeroBalances).Do(newContext())
s.r().NoError(err)
e := &Account{
MakerCommission: 15,
Expand Down Expand Up @@ -85,6 +91,7 @@ func (s *accountServiceTestSuite) TestGetAccount() {
},
},
Permissions: []string{"SPOT"},
UID: 354937868,
}
s.assertAccountEqual(e, res)
}
Expand All @@ -108,6 +115,7 @@ func (s *accountServiceTestSuite) assertAccountEqual(e, a *Account) {
r.Equal(e.Balances[i].Free, a.Balances[i].Free, "Free")
r.Equal(e.Balances[i].Locked, a.Balances[i].Locked, "Locked")
}
r.Equal(e.UID, a.UID, "UID")
}

func (s *accountServiceTestSuite) TestGetAccountSnapshot() {
Expand Down
4 changes: 4 additions & 0 deletions v2/asset_detail_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ type Network struct {
WithdrawMax string `json:"withdrawMax"`
WithdrawMin string `json:"withdrawMin"`
SameAddress bool `json:"sameAddress"` // 是否需要memo
EstimatedArrivalTime int `json:"estimatedArrivalTime"`
Busy bool `json:"busy"`
ContractAddressUrl string `json:"contractAddressUrl"`
ContractAddress string `json:"contractAddress"`
}

// GetUserAssetService Get user assets
Expand Down
16 changes: 14 additions & 2 deletions v2/asset_detail_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ func (s *assetDetailServiceTestSuite) TestGetAllCoinsInfo() {
"withdrawIntegerMultiple": "0.00000001",
"withdrawMax": "9999999999.99999999",
"withdrawMin": "0.00000440",
"sameAddress": true
"sameAddress": true,
"estimatedArrivalTime": 25,
"busy": false,
"contractAddressUrl": "https://bscscan.com/token/",
"contractAddress": "0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c"
},
{
"addressRegex": "^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$|^(bc1)[0-9A-Za-z]{39,59}$",
Expand All @@ -96,7 +100,11 @@ func (s *assetDetailServiceTestSuite) TestGetAllCoinsInfo() {
"withdrawIntegerMultiple": "0.00000001",
"withdrawMax": "750",
"withdrawMin": "0.00100000",
"sameAddress": false
"sameAddress": false,
"estimatedArrivalTime": 25,
"busy": false,
"contractAddressUrl": "",
"contractAddress": ""
}
],
"storage": "0.00000000",
Expand All @@ -118,6 +126,10 @@ func (s *assetDetailServiceTestSuite) TestGetAllCoinsInfo() {
s.r().NoError(err)
s.r().Equal(res[0].DepositAllEnable, true, "depositAllEnable")
s.r().Equal(res[0].NetworkList[0].WithdrawEnable, false, "withdrawEnable")
s.r().Equal(res[0].NetworkList[0].EstimatedArrivalTime, 25, "estimatedArrivalTime")
s.r().Equal(res[0].NetworkList[0].Busy, false, "busy")
s.r().Equal(res[0].NetworkList[0].ContractAddressUrl, "https://bscscan.com/token/", "contractAddressUrl")
s.r().Equal(res[0].NetworkList[0].ContractAddress, "0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c", "contractAddress")
s.r().Equal(res[0].NetworkList[1].MinConfirm, 1, "minConfirm")
}

Expand Down
Loading

0 comments on commit 725deeb

Please sign in to comment.