func (b *listenKeyBuilder) PingMarginListenKey(key string) (interface{}, error) {
	var err error
	if key == "" {
		err = errors.New(spotclient.MissParameters)
		return nil, err
	}
	params := "listenKey=" + key
	req, err := b.Builder.Build(http.MethodPut, "/sapi/v1/userDataStream", params, false, false, 0)
	if err != nil {
		logger.Error("Failed to build url: %s", err.Error())
	}
	res, err := binance.HttpRequest(req)
	var parser map[string]interface{}
	err = json.Unmarshal(res, &parser)
	if _, ok := parser["code"]; ok {
		result := model.APIErrorResponse{}
		err = json.Unmarshal(res, &result)
		return result.Message, err
	}
	if bytes.Equal(res, []byte{123, 125}) {
		return true, err
	}
	return nil, err
}
PingMarginListenKey Keepalive a user data stream to prevent a time out. User data streams will close after 60 minutes. It's recommended to send a ping about every 30 minutes.
package spotclient
import (
	"bytes"
	"encoding/json"
	"errors"
	binance "github.com/dirname/binance"
	logger "github.com/dirname/binance/logging"
	"github.com/dirname/binance/model"
	"github.com/dirname/binance/spot/client"
	"net/http"
)
type ListenKeyResponse struct {
	ListenKey string `json:"listenKey"`
}
type listenKeyBuilder struct {
	Builder *binance.PrivateUrlBuilder
}
func NewListenKeyBuilder(host, appKey, appSecret string) *listenKeyBuilder {
	return &listenKeyBuilder{
		Builder: binance.NewPrivateUrlBuilder(host, appKey, appSecret),
	}
}
func (b *listenKeyBuilder) CreateSpotListenKey() (string, error) {
	var err error
	req, err := b.Builder.Build(http.MethodPost, "/api/v3/userDataStream", "", false, false, 0)
	if err != nil {
		logger.Error("Failed to build url: %s", err.Error())
	}
	res, err := binance.HttpRequest(req)
	var parser map[string]interface{}
	err = json.Unmarshal(res, &parser)
	if _, ok := parser["code"]; ok {
		result := model.APIErrorResponse{}
		err = json.Unmarshal(res, &result)
		if err == nil {
			err = errors.New(result.Message)
		}
		return result.Message, err
	}
	result := ListenKeyResponse{}
	err = json.Unmarshal(res, &result)
	return result.ListenKey, err
}
func (b *listenKeyBuilder) PingSpotListenKey(key string) (interface{}, error) {
	var err error
	if key == "" {
		err = errors.New(spotclient.MissParameters)
		return nil, err
	}
	params := "listenKey=" + key
	req, err := b.Builder.Build(http.MethodPut, "/api/v3/userDataStream", params, false, false, 0)
	if err != nil {
		logger.Error("Failed to build url: %s", err.Error())
	}
	res, err := binance.HttpRequest(req)
	var parser map[string]interface{}
	err = json.Unmarshal(res, &parser)
	if _, ok := parser["code"]; ok {
		result := model.APIErrorResponse{}
		err = json.Unmarshal(res, &result)
		return result.Message, err
	}
	if bytes.Equal(res, []byte{123, 125}) {
		return true, err
	}
	return nil, err
}
func (b *listenKeyBuilder) DeleteSpotListenKey(key string) (interface{}, error) {
	var err error
	if key == "" {
		err = errors.New(spotclient.MissParameters)
		return nil, err
	}
	params := "listenKey=" + key
	req, err := b.Builder.Build(http.MethodDelete, "/api/v3/userDataStream", params, false, false, 0)
	if err != nil {
		logger.Error("Failed to build url: %s", err.Error())
	}
	res, err := binance.HttpRequest(req)
	var parser map[string]interface{}
	err = json.Unmarshal(res, &parser)
	if _, ok := parser["code"]; ok {
		result := model.APIErrorResponse{}
		err = json.Unmarshal(res, &result)
		return result.Message, err
	}
	if bytes.Equal(res, []byte{123, 125}) {
		return true, err
	}
	return nil, err
}
func (b *listenKeyBuilder) CreateMarginListenKey() (string, error) {
	var err error
	req, err := b.Builder.Build(http.MethodPost, "/sapi/v1/userDataStream", "", false, false, 0)
	if err != nil {
		logger.Error("Failed to build url: %s", err.Error())
	}
	res, err := binance.HttpRequest(req)
	var parser map[string]interface{}
	err = json.Unmarshal(res, &parser)
	if _, ok := parser["code"]; ok {
		result := model.APIErrorResponse{}
		err = json.Unmarshal(res, &result)
		if err == nil {
			err = errors.New(result.Message)
		}
		return result.Message, err
	}
	result := ListenKeyResponse{}
	err = json.Unmarshal(res, &result)
	return result.ListenKey, err
}