VictorFrWu / bybit.go.api

Bybit Official Open API SDK
MIT License
8 stars 23 forks source link

The documentation shows the fields I need to submit. But "API" responds that the fields are invalid. #28

Closed malware8 closed 6 months ago

malware8 commented 7 months ago

The documentation shows the fields I need to submit. But "API" responds that the fields are invalid.

Link to documentation

`func (c Client) GetTransferableCoin(ctx context.Context, auth Authorization, request GetTransferableCoinRequest) (GetTransferableCoinResponse, error) { client := sdk.NewBybitHttpClient(auth.ApiKey, auth.SecKey, sdk.WithBaseURL(sdk.TESTNET)) params := map[string]interface{}{"fromAccountType": request.FromAccountType, "toAccountType": request.ToAccountType}

client.Debug = true

logrus.Info("Request Params: ", params)

response, err := client.NewAssetService(params).GetTransferableCoin(ctx, sdk.WithRecvWindow(c.cfg.WithRecvWindow))
if err != nil {
    logrus.Error("Bybit SDK - get transferable coin failed with error: ", err.Error())
    if strings.TrimSpace(response.RetMsg) != "" {
        return nil, NewBybitError(response.RetMsg)
    }
    return nil, err
}

logrus.Info("test result", response)
return &GetTransferableCoinResponse{}, nil

}`

log output: bybit.api.go2024/02/09 16:58:58 response body: {"retCode":131203,"retMsg":"request parameter err: fromAccountType invalid",

malware8 commented 6 months ago

func (c Client) GetTransferableCoin(ctx context.Context, auth Authorization, request GetTransferableCoinRequest) (GetTransferableCoinResponse, error) { client := sdk.NewBybitHttpClient(auth.ApiKey, auth.SecKey, sdk.WithBaseURL(sdk.TESTNET))

result := &GetTransferableCoinResponse{}

params := map[string]interface{}{
    "fromAccountType": request.FromAccountType,
    "toAccountType":   request.ToAccountType,
}

response, err := client.NewAssetService(params).GetTransferableCoin(ctx, sdk.WithRecvWindow(c.cfg.WithRecvWindow))
if err != nil {
    logrus.Error("Bybit SDK - get transferable coin failed with error: ", err.Error())
    if strings.TrimSpace(response.RetMsg) != "" {
        return nil, NewBybitError(response.RetMsg)
    }
    return nil, err
}

err = result.FromInterface(response.Result)
if err != nil {
    return nil, err
}
return result, nil

}

image

image

but in the programming language "Python" it works fine

image

malware8 commented 6 months ago

image

VictorFrWu commented 6 months ago

fix it and publish on v1.0.2