Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
linstohu committed Dec 26, 2023
1 parent 93900b8 commit 26fb1c6
Showing 1 changed file with 37 additions and 23 deletions.
60 changes: 37 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,65 +28,75 @@ It is intended to be used by coders, developers, technically-skilled traders, da
#### Example 1: REST API

```go

package main

import (
"context"
"encoding/json"
"fmt"
"log/slog"

bnUsdmMarket "github.com/linstohu/nexapi/binance/usdmfutures/marketdata"
umtypes "github.com/linstohu/nexapi/binance/usdmfutures/marketdata/types"
umutils "github.com/linstohu/nexapi/binance/usdmfutures/utils"
bnspotmd "github.com/linstohu/nexapi/binance/spot/marketdata"
bnspottypes "github.com/linstohu/nexapi/binance/spot/marketdata/types"
bnspotutils "github.com/linstohu/nexapi/binance/spot/utils"
)

func main() {
cli, err := bnUsdmMarket.NewUSDMFuturesMarketDataClient(&umutils.USDMarginedClientCfg{
Debug: false,
Logger: slog.Default(),
BaseURL: umutils.USDMarginedBaseURL,
cli, err := bnspotmd.NewSpotMarketDataClient(&bnspotutils.SpotClientCfg{
Debug: true,
BaseURL: bnspotutils.BaseURL,
})

if err != nil {
panic(err)
}

trades, err := cli.GetRecentTradeList(context.TODO(), umtypes.GetTradeParams{
orderbook, err := cli.GetOrderbook(context.TODO(), bnspottypes.GetOrderbookParams{
Symbol: "BTCUSDT",
Limit: 10,
Limit: 5,
})
if err != nil {
panic(err)
}

for i, v := range trades {
fmt.Printf("Index-%v, %+v\n", i, v)
limit := orderbook.Http.ApiRes.Header.Get("X-Mbx-Used-Weight-1m")

fmt.Printf("Current used request weight: %v\n", limit)

bytes, err := json.MarshalIndent(orderbook.Body, "", "\t")
if err != nil {
panic(err)
}

fmt.Println(string(bytes))
}

```

#### Example 2: Websocket API
#### Example 2: Websocket

```go

package main

import (
"context"
"fmt"
"log/slog"
"time"

bnUsdmWsMarket "github.com/linstohu/nexapi/binance/usdmfutures/websocketmarket"
bnUsdmWsTypes "github.com/linstohu/nexapi/binance/usdmfutures/websocketmarket/types"
spotws "github.com/linstohu/nexapi/binance/spot/websocketmarket"
"github.com/linstohu/nexapi/binance/spot/websocketmarket/types"
)

func main() {
cli, err := bnUsdmWsMarket.NewMarketStreamClient(context.TODO(), &bnUsdmWsMarket.USDMarginedMarketStreamCfg{
Debug: false,
Logger: slog.Default(),
BaseURL: bnUsdmWsMarket.USDMarginedMarketStreamBaseURL,
cli, err := spotws.NewSpotMarketStreamClient(&spotws.SpotMarketStreamCfg{
Debug: true,
BaseURL: spotws.SpotMarketStreamBaseURL,
AutoReconnect: true,
})
if err != nil {
panic(err)
}

err = cli.Open()
if err != nil {
panic(err)
}
Expand All @@ -97,7 +107,7 @@ func main() {
}

cli.AddListener(topic, func(e any) {
trade, ok := e.(*bnUsdmWsTypes.AggregateTrade)
trade, ok := e.(*types.AggregateTrade)
if !ok {
return
}
Expand All @@ -108,6 +118,10 @@ func main() {

cli.Subscribe([]string{topic})

time.Sleep(20 * time.Second)

cli.Close()

select {}
}

Expand Down

0 comments on commit 26fb1c6

Please sign in to comment.