Skip to content

Commit

Permalink
sync_adshao_go_binance (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Haiss2 authored Oct 13, 2023
1 parent 3495699 commit a45823f
Show file tree
Hide file tree
Showing 33 changed files with 1,720 additions and 77 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Code Review

on:
issue_comment:
types: [created, edited]

jobs:
code-review:
if: |
github.event_name == 'pull_request' ||
(github.event.comment.user.login == 'adshao' &&
startsWith(github.event.comment.body, 'chatgpt'))
runs-on: ubuntu-latest
steps:
- name: OpenAI ChatGPT Code Review
uses: adshao/chatgpt-code-review-action@v0.2.5
with:
PROGRAMMING_LANGUAGE: 'Go'
REVIEW_COMMENT_PREFIX: 'chatgpt:'
FULL_REVIEW_COMMENT: 'chatgpt'
OPENAI_TOKEN: ${{ secrets.OPENAI_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
30 changes: 19 additions & 11 deletions v2/account_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ func (s *GetAccountService) Do(ctx context.Context, opts ...RequestOption) (res

// Account define account info
type Account struct {
MakerCommission int64 `json:"makerCommission"`
TakerCommission int64 `json:"takerCommission"`
BuyerCommission int64 `json:"buyerCommission"`
SellerCommission int64 `json:"sellerCommission"`
CanTrade bool `json:"canTrade"`
CanWithdraw bool `json:"canWithdraw"`
CanDeposit bool `json:"canDeposit"`
UpdateTime uint64 `json:"updateTime"`
AccountType string `json:"accountType"`
Balances []Balance `json:"balances"`
Permissions []string `json:"permissions"`
MakerCommission int64 `json:"makerCommission"`
TakerCommission int64 `json:"takerCommission"`
BuyerCommission int64 `json:"buyerCommission"`
SellerCommission int64 `json:"sellerCommission"`
CommissionRates CommissionRates `json:"commissionRates"`
CanTrade bool `json:"canTrade"`
CanWithdraw bool `json:"canWithdraw"`
CanDeposit bool `json:"canDeposit"`
UpdateTime uint64 `json:"updateTime"`
AccountType string `json:"accountType"`
Balances []Balance `json:"balances"`
Permissions []string `json:"permissions"`
}

// Balance define user balance of your account
Expand All @@ -60,6 +61,13 @@ type GetAccountSnapshotService struct {
limit *int
}

type CommissionRates struct {
Maker string `json:"maker"`
Taker string `json:"taker"`
Buyer string `json:"buyer"`
Seller string `json:"seller"`
}

// Type set account type ("SPOT", "MARGIN", "FUTURES")
func (s *GetAccountSnapshotService) Type(accountType string) *GetAccountSnapshotService {
s.accountType = accountType
Expand Down
26 changes: 21 additions & 5 deletions v2/account_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ func (s *accountServiceTestSuite) TestGetAccount() {
"takerCommission": 15,
"buyerCommission": 0,
"sellerCommission": 0,
"commissionRates": {
"maker": "0.00150000",
"taker": "0.00150000",
"buyer": "0.00000000",
"seller": "0.00000000"
},
"canTrade": true,
"canWithdraw": true,
"canDeposit": true,
Expand Down Expand Up @@ -55,11 +61,17 @@ func (s *accountServiceTestSuite) TestGetAccount() {
TakerCommission: 15,
BuyerCommission: 0,
SellerCommission: 0,
CanTrade: true,
CanWithdraw: true,
CanDeposit: true,
UpdateTime: 123456789,
AccountType: "SPOT",
CommissionRates: CommissionRates{
Maker: "0.00150000",
Taker: "0.00150000",
Buyer: "0.00000000",
Seller: "0.00000000",
},
CanTrade: true,
CanWithdraw: true,
CanDeposit: true,
UpdateTime: 123456789,
AccountType: "SPOT",
Balances: []Balance{
{
Asset: "BTC",
Expand All @@ -83,6 +95,10 @@ func (s *accountServiceTestSuite) assertAccountEqual(e, a *Account) {
r.Equal(e.TakerCommission, a.TakerCommission, "TakerCommission")
r.Equal(e.BuyerCommission, a.BuyerCommission, "BuyerCommission")
r.Equal(e.SellerCommission, a.SellerCommission, "SellerCommission")
r.Equal(e.CommissionRates.Maker, a.CommissionRates.Maker, "CommissionRates.Maker")
r.Equal(e.CommissionRates.Taker, a.CommissionRates.Taker, "CommissionRates.Taker")
r.Equal(e.CommissionRates.Buyer, a.CommissionRates.Buyer, "CommissionRates.Buyer")
r.Equal(e.CommissionRates.Seller, a.CommissionRates.Seller, "CommissionRates.Seller")
r.Equal(e.CanTrade, a.CanTrade, "CanTrade")
r.Equal(e.CanWithdraw, a.CanWithdraw, "CanWithdraw")
r.Equal(e.CanDeposit, a.CanDeposit, "CanDeposit")
Expand Down
35 changes: 29 additions & 6 deletions v2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import (
"os"
"time"

"github.com/bitly/go-simplejson"
jsoniter "github.com/json-iterator/go"

"github.com/adshao/go-binance/v2/common"
"github.com/adshao/go-binance/v2/delivery"
"github.com/adshao/go-binance/v2/futures"
"github.com/bitly/go-simplejson"
jsoniter "github.com/json-iterator/go"
)

// SideType define side type of order
Expand Down Expand Up @@ -151,10 +152,12 @@ const (
SymbolStatusTypeAuctionMatch SymbolStatusType = "AUCTION_MATCH"
SymbolStatusTypeBreak SymbolStatusType = "BREAK"

SymbolFilterTypeLotSize SymbolFilterType = "LOT_SIZE"
SymbolFilterTypePriceFilter SymbolFilterType = "PRICE_FILTER"
SymbolFilterTypePercentPrice SymbolFilterType = "PERCENT_PRICE"
SymbolFilterTypeLotSize SymbolFilterType = "LOT_SIZE"
SymbolFilterTypePriceFilter SymbolFilterType = "PRICE_FILTER"
SymbolFilterTypePercentPrice SymbolFilterType = "PERCENT_PRICE"
// Deprecated: use SymbolFilterTypePercentPrice instead
SymbolFilterTypeMinNotional SymbolFilterType = "MIN_NOTIONAL"
SymbolFilterTypeNotional SymbolFilterType = "NOTIONAL"
SymbolFilterTypeIcebergParts SymbolFilterType = "ICEBERG_PARTS"
SymbolFilterTypeMarketLotSize SymbolFilterType = "MARKET_LOT_SIZE"
SymbolFilterTypeMaxNumAlgoOrders SymbolFilterType = "MAX_NUM_ALGO_ORDERS"
Expand Down Expand Up @@ -987,7 +990,27 @@ func (c *Client) NewGetUserAsset() *GetUserAssetService {
return &GetUserAssetService{c: c}
}

// NewSubTransferHistoryService query transfer histroy (for sub-account)
// NewManagedSubAccountDepositService Deposit Assets Into The Managed Sub-account(For Investor Master Account)
func (c *Client) NewManagedSubAccountDepositService() *ManagedSubAccountDepositService {
return &ManagedSubAccountDepositService{c: c}
}

// NewManagedSubAccountWithdrawalService Withdrawal Assets From The Managed Sub-account(For Investor Master Account)
func (c *Client) NewManagedSubAccountWithdrawalService() *ManagedSubAccountWithdrawalService {
return &ManagedSubAccountWithdrawalService{c: c}
}

// NewManagedSubAccountAssetsService Withdrawal Assets From The Managed Sub-account(For Investor Master Account)
func (c *Client) NewManagedSubAccountAssetsService() *ManagedSubAccountAssetsService {
return &ManagedSubAccountAssetsService{c: c}
}

// NewSubAccountFuturesAccountService Get Detail on Sub-account's Futures Account (For Master Account)
func (c *Client) NewSubAccountFuturesAccountService() *SubAccountFuturesAccountService {
return &SubAccountFuturesAccountService{c: c}
}

// NewSubTransferHistoryService query transfer history (for sub-account)
func (c *Client) NewSubTransferHistoryService() *SubTransferHistoryService {
return &SubTransferHistoryService{c: c}
}
Expand Down
2 changes: 1 addition & 1 deletion v2/delivery/ticker_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ type PriceChangeStats struct {
BaseVolume string `json:"baseVolume"`
OpenTime int64 `json:"openTime"`
CloseTime int64 `json:"closeTime"`
FristID int64 `json:"firstId"`
FirstID int64 `json:"firstId"`
LastID int64 `json:"lastId"`
Count int64 `json:"count"`
}
12 changes: 6 additions & 6 deletions v2/delivery/ticker_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func (s *tickerServiceTestSuite) TestListPriceChangeStats() {
BaseVolume: "138965.76942775",
OpenTime: 1623748920000,
CloseTime: 1623835355736,
FristID: 172749700,
FirstID: 172749700,
LastID: 173464362,
Count: 714658,
}
Expand All @@ -364,7 +364,7 @@ func (s *tickerServiceTestSuite) TestListPriceChangeStats() {
BaseVolume: "648179.55304919",
OpenTime: 1623748920000,
CloseTime: 1623835355187,
FristID: 138575549,
FirstID: 138575549,
LastID: 139103143,
Count: 527595,
}
Expand Down Expand Up @@ -423,7 +423,7 @@ func (s *tickerServiceTestSuite) TestSinglePriceChangeStats() {
BaseVolume: "137750.93213717",
OpenTime: 1623752520000,
CloseTime: 1623838964257,
FristID: 172782522,
FirstID: 172782522,
LastID: 173490102,
Count: 707576,
}
Expand Down Expand Up @@ -498,7 +498,7 @@ func (s *tickerServiceTestSuite) TestPriceChangeStatsWithPair() {
BaseVolume: "8300.32545198",
OpenTime: 1623755580000,
CloseTime: 1623842010140,
FristID: 7516015,
FirstID: 7516015,
LastID: 7591268,
Count: 75254,
}
Expand All @@ -517,7 +517,7 @@ func (s *tickerServiceTestSuite) TestPriceChangeStatsWithPair() {
BaseVolume: "13637.88521626",
OpenTime: 1623755580000,
CloseTime: 1623842010656,
FristID: 32157829,
FirstID: 32157829,
LastID: 32307537,
Count: 149709,
}
Expand All @@ -541,7 +541,7 @@ func (s *tickerServiceTestSuite) assertPriceChangeStatsEqual(e, a *PriceChangeSt
r.Equal(e.BaseVolume, a.BaseVolume, "BaseVolume")
r.Equal(e.OpenTime, a.OpenTime, "OpenTime")
r.Equal(e.CloseTime, a.CloseTime, "CloseTime")
r.Equal(e.FristID, a.FristID, "FristID")
r.Equal(e.FirstID, a.FirstID, "FirstID")
r.Equal(e.LastID, a.LastID, "LastID")
r.Equal(e.Count, a.Count, "Count")
}
37 changes: 37 additions & 0 deletions v2/exchange_info_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,22 @@ type PercentPriceFilter struct {
}

// MinNotionalFilter define min notional filter of symbol
// Deprecated: use NotionalFilter instead
type MinNotionalFilter struct {
MinNotional string `json:"minNotional"`
AveragePriceMins int `json:"avgPriceMins"`
ApplyToMarket bool `json:"applyToMarket"`
}

// NotionalFilter define notional filter of symbol
type NotionalFilter struct {
MinNotional string `json:"minNotional"`
ApplyMinToMarket bool `json:"applyMinToMarket"`
MaxNotional string `json:"maxNotional"`
ApplyMaxToMarket bool `json:"applyMaxToMarket"`
AvgPriceMins int `json:"avgPriceMins"`
}

// IcebergPartsFilter define iceberg part filter of symbol
type IcebergPartsFilter struct {
Limit int `json:"limit"`
Expand Down Expand Up @@ -208,6 +218,7 @@ func (s *Symbol) PercentPriceFilter() *PercentPriceFilter {
}

// MinNotionalFilter return min notional filter of symbol
// Deprecated: use NotionalFilter instead
func (s *Symbol) MinNotionalFilter() *MinNotionalFilter {
for _, filter := range s.Filters {
if filter["filterType"].(string) == string(SymbolFilterTypeMinNotional) {
Expand All @@ -227,6 +238,32 @@ func (s *Symbol) MinNotionalFilter() *MinNotionalFilter {
return nil
}

// NotionalFilter return notional filter of symbol
func (s *Symbol) NotionalFilter() *NotionalFilter {
for _, filter := range s.Filters {
if filter["filterType"].(string) == string(SymbolFilterTypeNotional) {
f := &NotionalFilter{}
if i, ok := filter["minNotional"]; ok {
f.MinNotional = i.(string)
}
if i, ok := filter["applyMinToMarket"]; ok {
f.ApplyMinToMarket = i.(bool)
}
if i, ok := filter["maxNotional"]; ok {
f.MaxNotional = i.(string)
}
if i, ok := filter["applyMaxToMarket"]; ok {
f.ApplyMaxToMarket = i.(bool)
}
if i, ok := filter["avgPriceMins"]; ok {
f.AvgPriceMins = int(i.(float64))
}
return f
}
}
return nil
}

// IcebergPartsFilter return iceberg part filter of symbol
func (s *Symbol) IcebergPartsFilter() *IcebergPartsFilter {
for _, filter := range s.Filters {
Expand Down
26 changes: 15 additions & 11 deletions v2/exchange_info_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *exchangeInfoServiceTestSuite) TestExchangeInfo() {
"ocoAllowed": true,
"isSpotTradingAllowed": true,
"isMarginTradingAllowed": false,
"filters":[{"filterType":"PRICE_FILTER","minPrice":"0.00000100","maxPrice":"100000.00000000","tickSize":"0.00000100"},{"filterType":"LOT_SIZE","minQty":"0.00100000","maxQty":"100000.00000000","stepSize":"0.00100000"},{"filterType":"MIN_NOTIONAL","minNotional":"0.00100000"},{"filterType": "MAX_NUM_ALGO_ORDERS", "maxNumAlgoOrders": 5}],
"filters":[{"filterType":"PRICE_FILTER","minPrice":"0.00000100","maxPrice":"100000.00000000","tickSize":"0.00000100"},{"filterType":"LOT_SIZE","minQty":"0.00100000","maxQty":"100000.00000000","stepSize":"0.00100000"},{"filterType":"NOTIONAL","minNotional":"5.00000000", "applyMinToMarket": true, "maxNotional": "9000000.00000000", "applyMaxToMarket": false, "avgPriceMins": 5},{"filterType": "MAX_NUM_ALGO_ORDERS", "maxNumAlgoOrders": 5}],
"permissions": ["SPOT","MARGIN"]
}
]
Expand Down Expand Up @@ -97,7 +97,7 @@ func (s *exchangeInfoServiceTestSuite) TestExchangeInfo() {
Filters: []map[string]interface{}{
{"filterType": "PRICE_FILTER", "minPrice": "0.00000100", "maxPrice": "100000.00000000", "tickSize": "0.00000100"},
{"filterType": "LOT_SIZE", "minQty": "0.00100000", "maxQty": "100000.00000000", "stepSize": "0.00100000"},
{"filterType": "MIN_NOTIONAL", "minNotional": "0.00100000"},
{"filterType": "NOTIONAL", "minNotional": "5.00000000", "applyMinToMarket": true, "maxNotional": "9000000.00000000", "applyMaxToMarket": false, "avgPriceMins": 5},
{"filterType": "MAX_NUM_ALGO_ORDERS", "maxNumAlgoOrders": 5},
},
Permissions: []string{"SPOT", "MARGIN"},
Expand All @@ -118,12 +118,14 @@ func (s *exchangeInfoServiceTestSuite) TestExchangeInfo() {
TickSize: "0.00000100",
}
s.assertPriceFilterEqual(ePriceFilter, res.Symbols[0].PriceFilter())
eMinNotionalFilter := &MinNotionalFilter{
MinNotional: "0.00100000",
AveragePriceMins: 0,
ApplyToMarket: false,
eMinNotionalFilter := &NotionalFilter{
MinNotional: "5.00000000",
ApplyMinToMarket: true,
MaxNotional: "9000000.00000000",
ApplyMaxToMarket: false,
AvgPriceMins: 5,
}
s.assertMinNotionalFilterEqual(eMinNotionalFilter, res.Symbols[0].MinNotionalFilter())
s.assertMinNotionalFilterEqual(eMinNotionalFilter, res.Symbols[0].NotionalFilter())
eMaxNumAlgoOrdersFilter := &MaxNumAlgoOrdersFilter{
MaxNumAlgoOrders: 5,
}
Expand Down Expand Up @@ -167,7 +169,7 @@ func (s *exchangeInfoServiceTestSuite) assertExchangeInfoEqual(e, a *ExchangeInf
r.Equal(e.Symbols[i].Filters[fi]["minQty"], currentFilter["minQty"], "minQty")
r.Equal(e.Symbols[i].Filters[fi]["maxQty"], currentFilter["maxQty"], "maxQty")
r.Equal(e.Symbols[i].Filters[fi]["stepSize"], currentFilter["stepSize"], "stepSize")
case "MIN_NOTIONAL":
case "NOTIONAL":
r.Equal(e.Symbols[i].Filters[fi]["minNotional"], currentFilter["minNotional"], "minNotional")
}

Expand Down Expand Up @@ -203,11 +205,13 @@ func (s *exchangeInfoServiceTestSuite) assertPercentPriceFilterEqual(e, a *Perce
r.Equal(e.MultiplierDown, a.MultiplierDown, "MultiplierDown")
}

func (s *exchangeInfoServiceTestSuite) assertMinNotionalFilterEqual(e, a *MinNotionalFilter) {
func (s *exchangeInfoServiceTestSuite) assertMinNotionalFilterEqual(e, a *NotionalFilter) {
r := s.r()
r.Equal(e.MinNotional, a.MinNotional, "MinNotional")
r.Equal(e.AveragePriceMins, a.AveragePriceMins, "AveragePriceMins")
r.Equal(e.ApplyToMarket, a.ApplyToMarket, "ApplyToMarket")
r.Equal(e.ApplyMinToMarket, a.ApplyMinToMarket, "ApplyMinToMarket")
r.Equal(e.MaxNotional, a.MaxNotional, "MaxNotional")
r.Equal(e.ApplyMaxToMarket, a.ApplyMaxToMarket, "ApplyMaxToMarket")
r.Equal(e.AvgPriceMins, a.AvgPriceMins, "AvgPriceMins")
}

func (s *exchangeInfoServiceTestSuite) assertIcebergPartsFilterEqual(e, a *IcebergPartsFilter) {
Expand Down
Loading

0 comments on commit a45823f

Please sign in to comment.