hirokisan / bybit

Bybit client library for Go

Home Page:https://pkg.go.dev/github.com/hirokisan/bybit/v2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

USDT Derivatives balance empty

Nitradamus opened this issue · comments

Hello,

Thanks for this module! I was trying to get the balance for my USDT derivatives wallet on bybit, but it seems I always get an empty response. Can you point me in the right direction?

package main

import (
	"fmt"

	"github.com/hirokisan/bybit"
)

func main() {

	client := bybit.NewClient().WithAuth("xxxxx", "xxxxxxx")
	res, err := client.Wallet().Balance(bybit.CoinUSDT)
	if err != nil {
		fmt.Println(err)
	}
	if client.HasAuth() {
		fmt.Println(res.Result)
	}
}

thanks in advance!

@Nitradamus

Thanks for your comment.

Your API key may have expired, please check it on the admin page.

Otherwise, I think you can find other reason inside CommonResponse like below

fmt.Println(res.CommonResponse)

bybit/service.go

Lines 4 to 13 in b119d59

type CommonResponse struct {
RetCode int `json:"ret_code"`
RetMsg string `json:"ret_msg"`
ExtCode string `json:"ext_code"`
ExtInfo string `json:"ext_info"`
TimeNow string `json:"time_now"`
RateLimitStatus int `json:"rate_limit_status"`
RateLimitResetMs int `json:"rate_limit_reset_ms"`
RateLimit int `json:"rate_limit"`
}

Ah, it seems my key expired just that day. Thanks a lot :)

I am trying to get my wallet balance and unrealised PNL from the result, but it seems I can't query it directly from the res.Result. Is there any way I can access these? like res.Equity, res.UnrealisedPnl

Thanks again :)

You can access these like below

res.Result.Balance[bybit.CoinUSDT].Equity
res.Result.Balance[bybit.CoinUSDT].UnrealisedPnl

Thanks alot for the instructions, all is working fine now. Thanks again for this module!