Skip to content

Commit

Permalink
Release v0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alplabin committed Aug 23, 2024
1 parent 2c15779 commit b6d6d3d
Show file tree
Hide file tree
Showing 15 changed files with 241 additions and 77 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Change log

## v0.7.0 - 2024-08-23

### Added
- SPOT `FIAT` Endpoints:
- `GET /sapi/v1/fiat/orders` - Get Fiat Deposit/Withdraw History
- `GET /sapi/v1/fiat/payments` - Get Fiat Payments History
- Websocket Stream:
- `<symbol>@miniTicker` - Individual Symbol Mini Ticker Stream

### Updated
- Updated `SymbolInfo` and `SymbolFilter` types

### Fixed
- Fixed issue with `stopCh` not stopping the WebSocket connection
- Fixed the `stop` method for `userDataStream`
- Fixed symbols method for `NewTicker24hrService`

## v0.6.0 - 2024-06-19

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"time"

binance_connector "github.com/binance/binance-connector-go"
)
Expand All @@ -18,10 +19,15 @@ func WsAllMarketMiniTickers() {
errHandler := func(err error) {
fmt.Println(err)
}
doneCh, _, err := websocketStreamClient.WsAllMarketMiniTickersStatServe(wsAllMarketMiniTickersHandler, errHandler)
doneCh, stopCh, err := websocketStreamClient.WsAllMarketMiniTickersStatServe(wsAllMarketMiniTickersHandler, errHandler)
if err != nil {
fmt.Println(err)
return
}
// use stopCh to exit
go func() {
time.Sleep(10 * time.Second)
stopCh <- struct{}{}
}()
<-doneCh
}
8 changes: 7 additions & 1 deletion examples/websocket/AllMarketTickers/AllMarketTickers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"time"

binance_connector "github.com/binance/binance-connector-go"
)
Expand All @@ -18,10 +19,15 @@ func WsAllMarketTickersExample() {
errHandler := func(err error) {
fmt.Println(err)
}
doneCh, _, err := websocketStreamClient.WsAllMarketTickersStatServe(wsAllMarketTickersHandler, errHandler)
doneCh, stopCh, err := websocketStreamClient.WsAllMarketTickersStatServe(wsAllMarketTickersHandler, errHandler)
if err != nil {
fmt.Println(err)
return
}
// use stopCh to exit
go func() {
time.Sleep(10 * time.Second)
stopCh <- struct{}{}
}()
<-doneCh
}
2 changes: 1 addition & 1 deletion examples/websocket/CombinedDepth/CombinedDepth.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func WsCombinedDepthHandlerExample() {
}
// use stopCh to exit
go func() {
time.Sleep(5 * time.Second)
time.Sleep(10 * time.Second)
stopCh <- struct{}{}
}()
// remove this if you do not want to be blocked here
Expand Down
33 changes: 33 additions & 0 deletions examples/websocket/MarketMiniTickers/MarketMiniTickers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"fmt"
"time"

binance_connector "github.com/binance/binance-connector-go"
)

func main() {
WsMarketMiniTickers()
}

func WsMarketMiniTickers() {
websocketStreamClient := binance_connector.NewWebsocketStreamClient(false)
wsMarketMiniTickersHandler := func(event binance_connector.WsMarketMiniTickerStatEvent) {
fmt.Println(binance_connector.PrettyPrint(event))
}
errHandler := func(err error) {
fmt.Println(err)
}
doneCh, stopCh, err := websocketStreamClient.WsMarketMiniTickersStatServe("BNBBTC", wsMarketMiniTickersHandler, errHandler)
if err != nil {
fmt.Println(err)
return
}
// use stopCh to exit
go func() {
time.Sleep(10 * time.Second)
stopCh <- struct{}{}
}()
<-doneCh
}
8 changes: 7 additions & 1 deletion examples/websocket/aggtrades/aggtrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"time"

binance_connector "github.com/binance/binance-connector-go"
)
Expand All @@ -20,10 +21,15 @@ func AggTradesExample() {
errHandler := func(err error) {
fmt.Println(err)
}
doneCh, _, err := websocketStreamClient.WsAggTradeServe("BTCUSDT", wsAggTradeHandler, errHandler)
doneCh, stopCh, err := websocketStreamClient.WsAggTradeServe("BTCUSDT", wsAggTradeHandler, errHandler)
if err != nil {
fmt.Println(err)
return
}
// use stopCh to exit
go func() {
time.Sleep(10 * time.Second)
stopCh <- struct{}{}
}()
<-doneCh
}
8 changes: 7 additions & 1 deletion examples/websocket/bookticker/bookticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"time"

binance_connector "github.com/binance/binance-connector-go"
)
Expand All @@ -18,10 +19,15 @@ func WsBookTickerExample() {
errHandler := func(err error) {
fmt.Println(err)
}
doneCh, _, err := websocketStreamClient.WsBookTickerServe("LTCBTC", wsBookTickerHandler, errHandler)
doneCh, stopCh, err := websocketStreamClient.WsBookTickerServe("LTCBTC", wsBookTickerHandler, errHandler)
if err != nil {
fmt.Println(err)
return
}
// use stopCh to exit
go func() {
time.Sleep(10 * time.Second)
stopCh <- struct{}{}
}()
<-doneCh
}
2 changes: 1 addition & 1 deletion examples/websocket/depth/depth.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func WsDepthHandlerExample() {
}
// use stopCh to exit
go func() {
time.Sleep(5 * time.Second)
time.Sleep(10 * time.Second)
stopCh <- struct{}{}
}()
// remove this if you do not want to be blocked here
Expand Down
8 changes: 7 additions & 1 deletion examples/websocket/kline/kline.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"time"

binance_connector "github.com/binance/binance-connector-go"
)
Expand All @@ -18,10 +19,15 @@ func WsKlineExample() {
errHandler := func(err error) {
fmt.Println(err)
}
doneCh, _, err := websocketStreamClient.WsKlineServe("LTCBTC", "1m", wsKlineHandler, errHandler)
doneCh, stopCh, err := websocketStreamClient.WsKlineServe("LTCBTC", "1m", wsKlineHandler, errHandler)
if err != nil {
fmt.Println(err)
return
}
// use stopCh to exit
go func() {
time.Sleep(10 * time.Second)
stopCh <- struct{}{}
}()
<-doneCh
}
8 changes: 7 additions & 1 deletion examples/websocket/trades/trades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"time"

binance_connector "github.com/binance/binance-connector-go"
)
Expand All @@ -18,10 +19,15 @@ func WsTradeExample() {
errHandler := func(err error) {
fmt.Println(err)
}
doneCh, _, err := websocketStreamClient.WsTradeServe("LTCBTC", wsTradeHandler, errHandler)
doneCh, stopCh, err := websocketStreamClient.WsTradeServe("LTCBTC", wsTradeHandler, errHandler)
if err != nil {
fmt.Println(err)
return
}
// use stopCh to exit
go func() {
time.Sleep(10 * time.Second)
stopCh <- struct{}{}
}()
<-doneCh
}
96 changes: 66 additions & 30 deletions market.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,34 +103,53 @@ type ExchangeFilter struct {

// Symbol define symbol
type SymbolInfo struct {
Symbol string `json:"symbol"`
Status string `json:"status"`
BaseAsset string `json:"baseAsset"`
BaseAssetPrecision int64 `json:"baseAssetPrecision"`
QuoteAsset string `json:"quoteAsset"`
QuotePrecision int64 `json:"quotePrecision"`
OrderTypes []string `json:"orderTypes"`
IcebergAllowed bool `json:"icebergAllowed"`
OcoAllowed bool `json:"ocoAllowed"`
QuoteOrderQtyMarketAllowed bool `json:"quoteOrderQtyMarketAllowed"`
IsSpotTradingAllowed bool `json:"isSpotTradingAllowed"`
IsMarginTradingAllowed bool `json:"isMarginTradingAllowed"`
Filters []*SymbolFilter `json:"filters"`
Permissions []string `json:"permissions"`
Symbol string `json:"symbol"`
Status string `json:"status"`
BaseAsset string `json:"baseAsset"`
BaseAssetPrecision int64 `json:"baseAssetPrecision"`
QuoteAsset string `json:"quoteAsset"`
QuotePrecision int64 `json:"quotePrecision"`
QuoteAssetPrecision int64 `json:"quoteAssetPrecision"`
OrderTypes []string `json:"orderTypes"`
IcebergAllowed bool `json:"icebergAllowed"`
OcoAllowed bool `json:"ocoAllowed"`
QuoteOrderQtyMarketAllowed bool `json:"quoteOrderQtyMarketAllowed"`
AllowTrailingStop bool `json:"allowTrailingStop"`
CancelReplaceAllowed bool `json:"cancelReplaceAllowed"`
IsSpotTradingAllowed bool `json:"isSpotTradingAllowed"`
IsMarginTradingAllowed bool `json:"isMarginTradingAllowed"`
Filters []*SymbolFilter `json:"filters"`
Permissions []string `json:"permissions"`
PermissionSets [][]string `json:"permissionSets"`
DefaultSelfTradePreventionMode string `json:"defaultSelfTradePreventionMode"`
AllowedSelfTradePreventionModes []string `json:"allowedSelfTradePreventionModes"`
}

// SymbolFilter define symbol filter
type SymbolFilter struct {
FilterType string `json:"filterType"`
MinPrice string `json:"minPrice"`
MaxPrice string `json:"maxPrice"`
TickSize string `json:"tickSize"`
MinQty string `json:"minQty"`
MaxQty string `json:"maxQty"`
StepSize string `json:"stepSize"`
MinNotional string `json:"minNotional"`
Limit uint `json:"limit"`
MaxNumAlgoOrders int64 `json:"maxNumAlgoOrders"`
ApplyMinToMarket bool `json:"applyMinToMarket"`
ApplyMaxToMarket bool `json:"applyMaxToMarket"`
AskMultiplierDown string `json:"askMultiplierDown"`
AskMultiplierUp string `json:"askMultiplierUp"`
AvgPriceMins int64 `json:"avgPriceMins"`
BidMultiplierDown string `json:"bidMultiplierDown"`
BidMultiplierUp string `json:"bidMultiplierUp"`
FilterType string `json:"filterType"`
Limit uint `json:"limit"`
MaxNotional string `json:"maxNotional"`
MaxNumAlgoOrders int64 `json:"maxNumAlgoOrders"`
MaxNumOrders int64 `json:"maxNumOrders"`
MaxPrice string `json:"maxPrice"`
MaxQty string `json:"maxQty"`
MaxTrailingAboveDelta int64 `json:"maxTrailingAboveDelta"`
MaxTrailingBelowDelta int64 `json:"maxTrailingBelowDelta"`
MinNotional string `json:"minNotional"`
MinPrice string `json:"minPrice"`
MinQty string `json:"minQty"`
MinTrailingAboveDelta int64 `json:"minTrailingAboveDelta"`
MinTrailingBelowDelta int64 `json:"minTrailingBelowDelta"`
StepSize string `json:"stepSize"`
TickSize string `json:"tickSize"`
}

// Binance Order Book endpoint (GET /api/v3/depth)
Expand Down Expand Up @@ -659,7 +678,7 @@ func (s *Ticker24hr) Symbols(symbols []string) *Ticker24hr {
}

// Send the request
func (s *Ticker24hr) Do(ctx context.Context, opts ...RequestOption) (res *Ticker24hrResponse, err error) {
func (s *Ticker24hr) Do(ctx context.Context, opts ...RequestOption) (res []*Ticker24hrResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/api/v3/ticker/24hr",
Expand All @@ -669,16 +688,33 @@ func (s *Ticker24hr) Do(ctx context.Context, opts ...RequestOption) (res *Ticker
r.setParam("symbol", *s.symbol)
}
if s.symbols != nil {
r.setParam("symbols", *s.symbols)
s, _ := json.Marshal(s.symbols)
r.setParam("symbols", string(s))
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
return []*Ticker24hrResponse{}, err
}
res = new(Ticker24hrResponse)
err = json.Unmarshal(data, res)
var raw json.RawMessage
err = json.Unmarshal(data, &raw)
if err != nil {
return nil, err
return []*Ticker24hrResponse{}, err
}

if raw[0] == '[' {
res = make([]*Ticker24hrResponse, 0)
err = json.Unmarshal(data, &res)
if err != nil {
return []*Ticker24hrResponse{}, err
}
} else {
// The response is a single object, not an array, make sure to add it to the slice
singleRes := new(Ticker24hrResponse)
err = json.Unmarshal(data, &singleRes)
if err != nil {
return []*Ticker24hrResponse{}, err
}
res = append(res, singleRes)
}
return res, nil
}
Expand Down
Loading

0 comments on commit b6d6d3d

Please sign in to comment.