support binance futures trading data

This commit is contained in:
narumi 2023-05-05 14:27:26 +08:00
parent f686a6de83
commit 174fd7b8e7
12 changed files with 1357 additions and 0 deletions

View File

@ -0,0 +1,33 @@
package binanceapi
import (
"time"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/requestgen"
)
type FuturesGlobalLongShortAccountRatio struct {
Symbol string `json:"symbol"`
LongShortRatio fixedpoint.Value `json:"longShortRatio"`
LongAccount fixedpoint.Value `json:"longAccount"`
ShortAccount fixedpoint.Value `json:"shortAccount"`
Timestamp types.MillisecondTimestamp `json:"timestamp"`
}
//go:generate requestgen -method GET -url "/futures/data/globalLongShortAccountRatio" -type FuturesGlobalLongShortAccountRatioRequest -responseType []FuturesGlobalLongShortAccountRatio
type FuturesGlobalLongShortAccountRatioRequest struct {
client requestgen.AuthenticatedAPIClient
symbol string `param:"symbol"`
period types.Interval `param:"period"`
limit *uint64 `param:"limit"`
startTime *time.Time `param:"startTime,milliseconds"`
endTime *time.Time `param:"endTime,milliseconds"`
}
func (c *FuturesRestClient) NewFuturesGlobalLongShortAccountRatioRequest() *FuturesGlobalLongShortAccountRatioRequest {
return &FuturesGlobalLongShortAccountRatioRequest{client: c}
}

View File

@ -0,0 +1,24 @@
package binanceapi
import (
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/requestgen"
)
type FuturesOpenInterest struct {
OpenInterest fixedpoint.Value `json:"openInterest"`
Symbol string `json:"symbol"`
Time types.MillisecondTimestamp `json:"time"`
}
//go:generate requestgen -method GET -url "/fapi/v1/openInterest" -type FuturesGetOpenInterestRequest -responseType FuturesOpenInterest
type FuturesGetOpenInterestRequest struct {
client requestgen.AuthenticatedAPIClient
symbol string `param:"symbol"`
}
func (c *FuturesRestClient) NewFuturesGetOpenInterestRequest() *FuturesGetOpenInterestRequest {
return &FuturesGetOpenInterestRequest{client: c}
}

View File

@ -0,0 +1,148 @@
// Code generated by "requestgen -method GET -url /fapi/v1/openInterest -type FuturesGetOpenInterestRequest -responseType FuturesOpenInterest"; DO NOT EDIT.
package binanceapi
import (
"context"
"encoding/json"
"fmt"
"net/url"
"reflect"
"regexp"
)
func (f *FuturesGetOpenInterestRequest) Symbol(symbol string) *FuturesGetOpenInterestRequest {
f.symbol = symbol
return f
}
// GetQueryParameters builds and checks the query parameters and returns url.Values
func (f *FuturesGetOpenInterestRequest) GetQueryParameters() (url.Values, error) {
var params = map[string]interface{}{}
query := url.Values{}
for _k, _v := range params {
query.Add(_k, fmt.Sprintf("%v", _v))
}
return query, nil
}
// GetParameters builds and checks the parameters and return the result in a map object
func (f *FuturesGetOpenInterestRequest) GetParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
// check symbol field -> json key symbol
symbol := f.symbol
// assign parameter of symbol
params["symbol"] = symbol
return params, nil
}
// GetParametersQuery converts the parameters from GetParameters into the url.Values format
func (f *FuturesGetOpenInterestRequest) GetParametersQuery() (url.Values, error) {
query := url.Values{}
params, err := f.GetParameters()
if err != nil {
return query, err
}
for _k, _v := range params {
if f.isVarSlice(_v) {
f.iterateSlice(_v, func(it interface{}) {
query.Add(_k+"[]", fmt.Sprintf("%v", it))
})
} else {
query.Add(_k, fmt.Sprintf("%v", _v))
}
}
return query, nil
}
// GetParametersJSON converts the parameters from GetParameters into the JSON format
func (f *FuturesGetOpenInterestRequest) GetParametersJSON() ([]byte, error) {
params, err := f.GetParameters()
if err != nil {
return nil, err
}
return json.Marshal(params)
}
// GetSlugParameters builds and checks the slug parameters and return the result in a map object
func (f *FuturesGetOpenInterestRequest) GetSlugParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
return params, nil
}
func (f *FuturesGetOpenInterestRequest) applySlugsToUrl(url string, slugs map[string]string) string {
for _k, _v := range slugs {
needleRE := regexp.MustCompile(":" + _k + "\\b")
url = needleRE.ReplaceAllString(url, _v)
}
return url
}
func (f *FuturesGetOpenInterestRequest) iterateSlice(slice interface{}, _f func(it interface{})) {
sliceValue := reflect.ValueOf(slice)
for _i := 0; _i < sliceValue.Len(); _i++ {
it := sliceValue.Index(_i).Interface()
_f(it)
}
}
func (f *FuturesGetOpenInterestRequest) isVarSlice(_v interface{}) bool {
rt := reflect.TypeOf(_v)
switch rt.Kind() {
case reflect.Slice:
return true
}
return false
}
func (f *FuturesGetOpenInterestRequest) GetSlugsMap() (map[string]string, error) {
slugs := map[string]string{}
params, err := f.GetSlugParameters()
if err != nil {
return slugs, nil
}
for _k, _v := range params {
slugs[_k] = fmt.Sprintf("%v", _v)
}
return slugs, nil
}
func (f *FuturesGetOpenInterestRequest) Do(ctx context.Context) (*FuturesOpenInterest, error) {
// empty params for GET operation
var params interface{}
query, err := f.GetParametersQuery()
if err != nil {
return nil, err
}
apiURL := "/fapi/v1/openInterest"
req, err := f.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params)
if err != nil {
return nil, err
}
response, err := f.client.SendRequest(req)
if err != nil {
return nil, err
}
var apiResponse FuturesOpenInterest
if err := response.DecodeJSON(&apiResponse); err != nil {
return nil, err
}
return &apiResponse, nil
}

View File

@ -0,0 +1,32 @@
package binanceapi
import (
"time"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/requestgen"
)
type FuturesOpenInterestStatistics struct {
Symbol string `json:"symbol"`
SumOpenInterest fixedpoint.Value `json:"sumOpenInterest"`
SumOpenInterestValue fixedpoint.Value `json:"sumOpenInterestValue"`
Timestamp types.MillisecondTimestamp `json:"timestamp"`
}
//go:generate requestgen -method GET -url "/futures/data/openInterestHist" -type FuturesGetOpenInterestStatisticsRequest -responseType []FuturesOpenInterestStatistics
type FuturesGetOpenInterestStatisticsRequest struct {
client requestgen.AuthenticatedAPIClient
symbol string `param:"symbol,required"`
period types.Interval `param:"period,required"`
limit *uint64 `param:"limit"`
startTime *time.Time `param:"startTime,milliseconds"`
endTime *time.Time `param:"endTime,milliseconds"`
}
func (c *FuturesRestClient) NewFuturesGetOpenInterestStatisticsRequest() *FuturesGetOpenInterestStatisticsRequest {
return &FuturesGetOpenInterestStatisticsRequest{client: c}
}

View File

@ -0,0 +1,214 @@
// Code generated by "requestgen -method GET -url /futures/data/openInterestHist -type FuturesGetOpenInterestStatisticsRequest -responseType []FuturesOpenInterestStatistics"; DO NOT EDIT.
package binanceapi
import (
"context"
"encoding/json"
"fmt"
"github.com/c9s/bbgo/pkg/types"
"net/url"
"reflect"
"regexp"
"strconv"
"time"
)
func (f *FuturesGetOpenInterestStatisticsRequest) Symbol(symbol string) *FuturesGetOpenInterestStatisticsRequest {
f.symbol = symbol
return f
}
func (f *FuturesGetOpenInterestStatisticsRequest) Period(period types.Interval) *FuturesGetOpenInterestStatisticsRequest {
f.period = period
return f
}
func (f *FuturesGetOpenInterestStatisticsRequest) Limit(limit uint64) *FuturesGetOpenInterestStatisticsRequest {
f.limit = &limit
return f
}
func (f *FuturesGetOpenInterestStatisticsRequest) StartTime(startTime time.Time) *FuturesGetOpenInterestStatisticsRequest {
f.startTime = &startTime
return f
}
func (f *FuturesGetOpenInterestStatisticsRequest) EndTime(endTime time.Time) *FuturesGetOpenInterestStatisticsRequest {
f.endTime = &endTime
return f
}
// GetQueryParameters builds and checks the query parameters and returns url.Values
func (f *FuturesGetOpenInterestStatisticsRequest) GetQueryParameters() (url.Values, error) {
var params = map[string]interface{}{}
query := url.Values{}
for _k, _v := range params {
query.Add(_k, fmt.Sprintf("%v", _v))
}
return query, nil
}
// GetParameters builds and checks the parameters and return the result in a map object
func (f *FuturesGetOpenInterestStatisticsRequest) GetParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
// check symbol field -> json key symbol
symbol := f.symbol
// TEMPLATE check-required
if len(symbol) == 0 {
return nil, fmt.Errorf("symbol is required, empty string given")
}
// END TEMPLATE check-required
// assign parameter of symbol
params["symbol"] = symbol
// check period field -> json key period
period := f.period
// TEMPLATE check-required
if len(period) == 0 {
return nil, fmt.Errorf("period is required, empty string given")
}
// END TEMPLATE check-required
// assign parameter of period
params["period"] = period
// check limit field -> json key limit
if f.limit != nil {
limit := *f.limit
// assign parameter of limit
params["limit"] = limit
} else {
}
// check startTime field -> json key startTime
if f.startTime != nil {
startTime := *f.startTime
// assign parameter of startTime
// convert time.Time to milliseconds time stamp
params["startTime"] = strconv.FormatInt(startTime.UnixNano()/int64(time.Millisecond), 10)
} else {
}
// check endTime field -> json key endTime
if f.endTime != nil {
endTime := *f.endTime
// assign parameter of endTime
// convert time.Time to milliseconds time stamp
params["endTime"] = strconv.FormatInt(endTime.UnixNano()/int64(time.Millisecond), 10)
} else {
}
return params, nil
}
// GetParametersQuery converts the parameters from GetParameters into the url.Values format
func (f *FuturesGetOpenInterestStatisticsRequest) GetParametersQuery() (url.Values, error) {
query := url.Values{}
params, err := f.GetParameters()
if err != nil {
return query, err
}
for _k, _v := range params {
if f.isVarSlice(_v) {
f.iterateSlice(_v, func(it interface{}) {
query.Add(_k+"[]", fmt.Sprintf("%v", it))
})
} else {
query.Add(_k, fmt.Sprintf("%v", _v))
}
}
return query, nil
}
// GetParametersJSON converts the parameters from GetParameters into the JSON format
func (f *FuturesGetOpenInterestStatisticsRequest) GetParametersJSON() ([]byte, error) {
params, err := f.GetParameters()
if err != nil {
return nil, err
}
return json.Marshal(params)
}
// GetSlugParameters builds and checks the slug parameters and return the result in a map object
func (f *FuturesGetOpenInterestStatisticsRequest) GetSlugParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
return params, nil
}
func (f *FuturesGetOpenInterestStatisticsRequest) applySlugsToUrl(url string, slugs map[string]string) string {
for _k, _v := range slugs {
needleRE := regexp.MustCompile(":" + _k + "\\b")
url = needleRE.ReplaceAllString(url, _v)
}
return url
}
func (f *FuturesGetOpenInterestStatisticsRequest) iterateSlice(slice interface{}, _f func(it interface{})) {
sliceValue := reflect.ValueOf(slice)
for _i := 0; _i < sliceValue.Len(); _i++ {
it := sliceValue.Index(_i).Interface()
_f(it)
}
}
func (f *FuturesGetOpenInterestStatisticsRequest) isVarSlice(_v interface{}) bool {
rt := reflect.TypeOf(_v)
switch rt.Kind() {
case reflect.Slice:
return true
}
return false
}
func (f *FuturesGetOpenInterestStatisticsRequest) GetSlugsMap() (map[string]string, error) {
slugs := map[string]string{}
params, err := f.GetSlugParameters()
if err != nil {
return slugs, nil
}
for _k, _v := range params {
slugs[_k] = fmt.Sprintf("%v", _v)
}
return slugs, nil
}
func (f *FuturesGetOpenInterestStatisticsRequest) Do(ctx context.Context) ([]FuturesOpenInterestStatistics, error) {
// empty params for GET operation
var params interface{}
query, err := f.GetParametersQuery()
if err != nil {
return nil, err
}
apiURL := "/futures/data/openInterestHist"
req, err := f.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params)
if err != nil {
return nil, err
}
response, err := f.client.SendRequest(req)
if err != nil {
return nil, err
}
var apiResponse []FuturesOpenInterestStatistics
if err := response.DecodeJSON(&apiResponse); err != nil {
return nil, err
}
return apiResponse, nil
}

View File

@ -0,0 +1,32 @@
package binanceapi
import (
"time"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/requestgen"
)
type FuturesTakerBuySellVolume struct {
BuySellRatio fixedpoint.Value `json:"buySellRatio"`
BuyVol fixedpoint.Value `json:"buyVol"`
SellVol fixedpoint.Value `json:"sellVol"`
Timestamp types.MillisecondTimestamp `json:"timestamp"`
}
//go:generate requestgen -method GET -url "/futures/data/takerlongshortRatio" -type FuturesTakerBuySellVolumeRequest -responseType []FuturesTakerBuySellVolume
type FuturesTakerBuySellVolumeRequest struct {
client requestgen.AuthenticatedAPIClient
symbol string `param:"symbol"`
period types.Interval `param:"period"`
limit *uint64 `param:"limit"`
startTime *time.Time `param:"startTime,milliseconds"`
endTime *time.Time `param:"endTime,milliseconds"`
}
func (c *FuturesRestClient) NewFuturesTakerBuySellVolumeRequest() *FuturesTakerBuySellVolumeRequest {
return &FuturesTakerBuySellVolumeRequest{client: c}
}

View File

@ -0,0 +1,33 @@
package binanceapi
import (
"time"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/requestgen"
)
type FuturesTopTraderLongShortAccountRatio struct {
Symbol string `json:"symbol"`
LongShortRatio fixedpoint.Value `json:"longShortRatio"`
LongAccount fixedpoint.Value `json:"longAccount"`
ShortAccount fixedpoint.Value `json:"shortAccount"`
Timestamp types.MillisecondTimestamp `json:"timestamp"`
}
//go:generate requestgen -method GET -url "/futures/data/topLongShortAccountRatio" -type FuturesTopTraderLongShortAccountRatioRequest -responseType []FuturesTopTraderLongShortAccountRatio
type FuturesTopTraderLongShortAccountRatioRequest struct {
client requestgen.AuthenticatedAPIClient
symbol string `param:"symbol"`
period types.Interval `param:"period"`
limit *uint64 `param:"limit"`
startTime *time.Time `param:"startTime,milliseconds"`
endTime *time.Time `param:"endTime,milliseconds"`
}
func (c *FuturesRestClient) NewFuturesTopTraderLongShortAccountRatioRequest() *FuturesTopTraderLongShortAccountRatioRequest {
return &FuturesTopTraderLongShortAccountRatioRequest{client: c}
}

View File

@ -0,0 +1,33 @@
package binanceapi
import (
"time"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/requestgen"
)
type FuturesTopTraderLongShortPositionRatio struct {
Symbol string `json:"symbol"`
LongShortRatio fixedpoint.Value `json:"longShortRatio"`
LongAccount fixedpoint.Value `json:"longAccount"`
ShortAccount fixedpoint.Value `json:"shortAccount"`
Timestamp types.MillisecondTimestamp `json:"timestamp"`
}
//go:generate requestgen -method GET -url "/futures/data/topLongShortPositionRatio" -type FuturesTopTraderLongShortPositionRatioRequest -responseType []FuturesTopTraderLongShortPositionRatio
type FuturesTopTraderLongShortPositionRatioRequest struct {
client requestgen.AuthenticatedAPIClient
symbol string `param:"symbol"`
period types.Interval `param:"period"`
limit *uint64 `param:"limit"`
startTime *time.Time `param:"startTime,milliseconds"`
endTime *time.Time `param:"endTime,milliseconds"`
}
func (c *FuturesRestClient) NewFuturesTopTraderLongShortPositionRatioRequest() *FuturesTopTraderLongShortPositionRatioRequest {
return &FuturesTopTraderLongShortPositionRatioRequest{client: c}
}

View File

@ -0,0 +1,202 @@
// Code generated by "requestgen -method GET -url /futures/data/globalLongShortAccountRatio -type FuturesGlobalLongShortAccountRatioRequest -responseType []FuturesGlobalLongShortAccountRatio"; DO NOT EDIT.
package binanceapi
import (
"context"
"encoding/json"
"fmt"
"github.com/c9s/bbgo/pkg/types"
"net/url"
"reflect"
"regexp"
"strconv"
"time"
)
func (f *FuturesGlobalLongShortAccountRatioRequest) Symbol(symbol string) *FuturesGlobalLongShortAccountRatioRequest {
f.symbol = symbol
return f
}
func (f *FuturesGlobalLongShortAccountRatioRequest) Period(period types.Interval) *FuturesGlobalLongShortAccountRatioRequest {
f.period = period
return f
}
func (f *FuturesGlobalLongShortAccountRatioRequest) Limit(limit uint64) *FuturesGlobalLongShortAccountRatioRequest {
f.limit = &limit
return f
}
func (f *FuturesGlobalLongShortAccountRatioRequest) StartTime(startTime time.Time) *FuturesGlobalLongShortAccountRatioRequest {
f.startTime = &startTime
return f
}
func (f *FuturesGlobalLongShortAccountRatioRequest) EndTime(endTime time.Time) *FuturesGlobalLongShortAccountRatioRequest {
f.endTime = &endTime
return f
}
// GetQueryParameters builds and checks the query parameters and returns url.Values
func (f *FuturesGlobalLongShortAccountRatioRequest) GetQueryParameters() (url.Values, error) {
var params = map[string]interface{}{}
query := url.Values{}
for _k, _v := range params {
query.Add(_k, fmt.Sprintf("%v", _v))
}
return query, nil
}
// GetParameters builds and checks the parameters and return the result in a map object
func (f *FuturesGlobalLongShortAccountRatioRequest) GetParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
// check symbol field -> json key symbol
symbol := f.symbol
// assign parameter of symbol
params["symbol"] = symbol
// check period field -> json key period
period := f.period
// assign parameter of period
params["period"] = period
// check limit field -> json key limit
if f.limit != nil {
limit := *f.limit
// assign parameter of limit
params["limit"] = limit
} else {
}
// check startTime field -> json key startTime
if f.startTime != nil {
startTime := *f.startTime
// assign parameter of startTime
// convert time.Time to milliseconds time stamp
params["startTime"] = strconv.FormatInt(startTime.UnixNano()/int64(time.Millisecond), 10)
} else {
}
// check endTime field -> json key endTime
if f.endTime != nil {
endTime := *f.endTime
// assign parameter of endTime
// convert time.Time to milliseconds time stamp
params["endTime"] = strconv.FormatInt(endTime.UnixNano()/int64(time.Millisecond), 10)
} else {
}
return params, nil
}
// GetParametersQuery converts the parameters from GetParameters into the url.Values format
func (f *FuturesGlobalLongShortAccountRatioRequest) GetParametersQuery() (url.Values, error) {
query := url.Values{}
params, err := f.GetParameters()
if err != nil {
return query, err
}
for _k, _v := range params {
if f.isVarSlice(_v) {
f.iterateSlice(_v, func(it interface{}) {
query.Add(_k+"[]", fmt.Sprintf("%v", it))
})
} else {
query.Add(_k, fmt.Sprintf("%v", _v))
}
}
return query, nil
}
// GetParametersJSON converts the parameters from GetParameters into the JSON format
func (f *FuturesGlobalLongShortAccountRatioRequest) GetParametersJSON() ([]byte, error) {
params, err := f.GetParameters()
if err != nil {
return nil, err
}
return json.Marshal(params)
}
// GetSlugParameters builds and checks the slug parameters and return the result in a map object
func (f *FuturesGlobalLongShortAccountRatioRequest) GetSlugParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
return params, nil
}
func (f *FuturesGlobalLongShortAccountRatioRequest) applySlugsToUrl(url string, slugs map[string]string) string {
for _k, _v := range slugs {
needleRE := regexp.MustCompile(":" + _k + "\\b")
url = needleRE.ReplaceAllString(url, _v)
}
return url
}
func (f *FuturesGlobalLongShortAccountRatioRequest) iterateSlice(slice interface{}, _f func(it interface{})) {
sliceValue := reflect.ValueOf(slice)
for _i := 0; _i < sliceValue.Len(); _i++ {
it := sliceValue.Index(_i).Interface()
_f(it)
}
}
func (f *FuturesGlobalLongShortAccountRatioRequest) isVarSlice(_v interface{}) bool {
rt := reflect.TypeOf(_v)
switch rt.Kind() {
case reflect.Slice:
return true
}
return false
}
func (f *FuturesGlobalLongShortAccountRatioRequest) GetSlugsMap() (map[string]string, error) {
slugs := map[string]string{}
params, err := f.GetSlugParameters()
if err != nil {
return slugs, nil
}
for _k, _v := range params {
slugs[_k] = fmt.Sprintf("%v", _v)
}
return slugs, nil
}
func (f *FuturesGlobalLongShortAccountRatioRequest) Do(ctx context.Context) ([]FuturesGlobalLongShortAccountRatio, error) {
// empty params for GET operation
var params interface{}
query, err := f.GetParametersQuery()
if err != nil {
return nil, err
}
apiURL := "/futures/data/globalLongShortAccountRatio"
req, err := f.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params)
if err != nil {
return nil, err
}
response, err := f.client.SendRequest(req)
if err != nil {
return nil, err
}
var apiResponse []FuturesGlobalLongShortAccountRatio
if err := response.DecodeJSON(&apiResponse); err != nil {
return nil, err
}
return apiResponse, nil
}

View File

@ -0,0 +1,202 @@
// Code generated by "requestgen -method GET -url /futures/data/takerlongshortRatio -type FuturesTakerBuySellVolumeRequest -responseType []FuturesTakerBuySellVolume"; DO NOT EDIT.
package binanceapi
import (
"context"
"encoding/json"
"fmt"
"github.com/c9s/bbgo/pkg/types"
"net/url"
"reflect"
"regexp"
"strconv"
"time"
)
func (f *FuturesTakerBuySellVolumeRequest) Symbol(symbol string) *FuturesTakerBuySellVolumeRequest {
f.symbol = symbol
return f
}
func (f *FuturesTakerBuySellVolumeRequest) Period(period types.Interval) *FuturesTakerBuySellVolumeRequest {
f.period = period
return f
}
func (f *FuturesTakerBuySellVolumeRequest) Limit(limit uint64) *FuturesTakerBuySellVolumeRequest {
f.limit = &limit
return f
}
func (f *FuturesTakerBuySellVolumeRequest) StartTime(startTime time.Time) *FuturesTakerBuySellVolumeRequest {
f.startTime = &startTime
return f
}
func (f *FuturesTakerBuySellVolumeRequest) EndTime(endTime time.Time) *FuturesTakerBuySellVolumeRequest {
f.endTime = &endTime
return f
}
// GetQueryParameters builds and checks the query parameters and returns url.Values
func (f *FuturesTakerBuySellVolumeRequest) GetQueryParameters() (url.Values, error) {
var params = map[string]interface{}{}
query := url.Values{}
for _k, _v := range params {
query.Add(_k, fmt.Sprintf("%v", _v))
}
return query, nil
}
// GetParameters builds and checks the parameters and return the result in a map object
func (f *FuturesTakerBuySellVolumeRequest) GetParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
// check symbol field -> json key symbol
symbol := f.symbol
// assign parameter of symbol
params["symbol"] = symbol
// check period field -> json key period
period := f.period
// assign parameter of period
params["period"] = period
// check limit field -> json key limit
if f.limit != nil {
limit := *f.limit
// assign parameter of limit
params["limit"] = limit
} else {
}
// check startTime field -> json key startTime
if f.startTime != nil {
startTime := *f.startTime
// assign parameter of startTime
// convert time.Time to milliseconds time stamp
params["startTime"] = strconv.FormatInt(startTime.UnixNano()/int64(time.Millisecond), 10)
} else {
}
// check endTime field -> json key endTime
if f.endTime != nil {
endTime := *f.endTime
// assign parameter of endTime
// convert time.Time to milliseconds time stamp
params["endTime"] = strconv.FormatInt(endTime.UnixNano()/int64(time.Millisecond), 10)
} else {
}
return params, nil
}
// GetParametersQuery converts the parameters from GetParameters into the url.Values format
func (f *FuturesTakerBuySellVolumeRequest) GetParametersQuery() (url.Values, error) {
query := url.Values{}
params, err := f.GetParameters()
if err != nil {
return query, err
}
for _k, _v := range params {
if f.isVarSlice(_v) {
f.iterateSlice(_v, func(it interface{}) {
query.Add(_k+"[]", fmt.Sprintf("%v", it))
})
} else {
query.Add(_k, fmt.Sprintf("%v", _v))
}
}
return query, nil
}
// GetParametersJSON converts the parameters from GetParameters into the JSON format
func (f *FuturesTakerBuySellVolumeRequest) GetParametersJSON() ([]byte, error) {
params, err := f.GetParameters()
if err != nil {
return nil, err
}
return json.Marshal(params)
}
// GetSlugParameters builds and checks the slug parameters and return the result in a map object
func (f *FuturesTakerBuySellVolumeRequest) GetSlugParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
return params, nil
}
func (f *FuturesTakerBuySellVolumeRequest) applySlugsToUrl(url string, slugs map[string]string) string {
for _k, _v := range slugs {
needleRE := regexp.MustCompile(":" + _k + "\\b")
url = needleRE.ReplaceAllString(url, _v)
}
return url
}
func (f *FuturesTakerBuySellVolumeRequest) iterateSlice(slice interface{}, _f func(it interface{})) {
sliceValue := reflect.ValueOf(slice)
for _i := 0; _i < sliceValue.Len(); _i++ {
it := sliceValue.Index(_i).Interface()
_f(it)
}
}
func (f *FuturesTakerBuySellVolumeRequest) isVarSlice(_v interface{}) bool {
rt := reflect.TypeOf(_v)
switch rt.Kind() {
case reflect.Slice:
return true
}
return false
}
func (f *FuturesTakerBuySellVolumeRequest) GetSlugsMap() (map[string]string, error) {
slugs := map[string]string{}
params, err := f.GetSlugParameters()
if err != nil {
return slugs, nil
}
for _k, _v := range params {
slugs[_k] = fmt.Sprintf("%v", _v)
}
return slugs, nil
}
func (f *FuturesTakerBuySellVolumeRequest) Do(ctx context.Context) ([]FuturesTakerBuySellVolume, error) {
// empty params for GET operation
var params interface{}
query, err := f.GetParametersQuery()
if err != nil {
return nil, err
}
apiURL := "/futures/data/takerlongshortRatio"
req, err := f.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params)
if err != nil {
return nil, err
}
response, err := f.client.SendRequest(req)
if err != nil {
return nil, err
}
var apiResponse []FuturesTakerBuySellVolume
if err := response.DecodeJSON(&apiResponse); err != nil {
return nil, err
}
return apiResponse, nil
}

View File

@ -0,0 +1,202 @@
// Code generated by "requestgen -method GET -url /futures/data/topLongShortAccountRatio -type FuturesTopTraderLongShortAccountRatioRequest -responseType []FuturesTopTraderLongShortAccountRatio"; DO NOT EDIT.
package binanceapi
import (
"context"
"encoding/json"
"fmt"
"github.com/c9s/bbgo/pkg/types"
"net/url"
"reflect"
"regexp"
"strconv"
"time"
)
func (f *FuturesTopTraderLongShortAccountRatioRequest) Symbol(symbol string) *FuturesTopTraderLongShortAccountRatioRequest {
f.symbol = symbol
return f
}
func (f *FuturesTopTraderLongShortAccountRatioRequest) Period(period types.Interval) *FuturesTopTraderLongShortAccountRatioRequest {
f.period = period
return f
}
func (f *FuturesTopTraderLongShortAccountRatioRequest) Limit(limit uint64) *FuturesTopTraderLongShortAccountRatioRequest {
f.limit = &limit
return f
}
func (f *FuturesTopTraderLongShortAccountRatioRequest) StartTime(startTime time.Time) *FuturesTopTraderLongShortAccountRatioRequest {
f.startTime = &startTime
return f
}
func (f *FuturesTopTraderLongShortAccountRatioRequest) EndTime(endTime time.Time) *FuturesTopTraderLongShortAccountRatioRequest {
f.endTime = &endTime
return f
}
// GetQueryParameters builds and checks the query parameters and returns url.Values
func (f *FuturesTopTraderLongShortAccountRatioRequest) GetQueryParameters() (url.Values, error) {
var params = map[string]interface{}{}
query := url.Values{}
for _k, _v := range params {
query.Add(_k, fmt.Sprintf("%v", _v))
}
return query, nil
}
// GetParameters builds and checks the parameters and return the result in a map object
func (f *FuturesTopTraderLongShortAccountRatioRequest) GetParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
// check symbol field -> json key symbol
symbol := f.symbol
// assign parameter of symbol
params["symbol"] = symbol
// check period field -> json key period
period := f.period
// assign parameter of period
params["period"] = period
// check limit field -> json key limit
if f.limit != nil {
limit := *f.limit
// assign parameter of limit
params["limit"] = limit
} else {
}
// check startTime field -> json key startTime
if f.startTime != nil {
startTime := *f.startTime
// assign parameter of startTime
// convert time.Time to milliseconds time stamp
params["startTime"] = strconv.FormatInt(startTime.UnixNano()/int64(time.Millisecond), 10)
} else {
}
// check endTime field -> json key endTime
if f.endTime != nil {
endTime := *f.endTime
// assign parameter of endTime
// convert time.Time to milliseconds time stamp
params["endTime"] = strconv.FormatInt(endTime.UnixNano()/int64(time.Millisecond), 10)
} else {
}
return params, nil
}
// GetParametersQuery converts the parameters from GetParameters into the url.Values format
func (f *FuturesTopTraderLongShortAccountRatioRequest) GetParametersQuery() (url.Values, error) {
query := url.Values{}
params, err := f.GetParameters()
if err != nil {
return query, err
}
for _k, _v := range params {
if f.isVarSlice(_v) {
f.iterateSlice(_v, func(it interface{}) {
query.Add(_k+"[]", fmt.Sprintf("%v", it))
})
} else {
query.Add(_k, fmt.Sprintf("%v", _v))
}
}
return query, nil
}
// GetParametersJSON converts the parameters from GetParameters into the JSON format
func (f *FuturesTopTraderLongShortAccountRatioRequest) GetParametersJSON() ([]byte, error) {
params, err := f.GetParameters()
if err != nil {
return nil, err
}
return json.Marshal(params)
}
// GetSlugParameters builds and checks the slug parameters and return the result in a map object
func (f *FuturesTopTraderLongShortAccountRatioRequest) GetSlugParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
return params, nil
}
func (f *FuturesTopTraderLongShortAccountRatioRequest) applySlugsToUrl(url string, slugs map[string]string) string {
for _k, _v := range slugs {
needleRE := regexp.MustCompile(":" + _k + "\\b")
url = needleRE.ReplaceAllString(url, _v)
}
return url
}
func (f *FuturesTopTraderLongShortAccountRatioRequest) iterateSlice(slice interface{}, _f func(it interface{})) {
sliceValue := reflect.ValueOf(slice)
for _i := 0; _i < sliceValue.Len(); _i++ {
it := sliceValue.Index(_i).Interface()
_f(it)
}
}
func (f *FuturesTopTraderLongShortAccountRatioRequest) isVarSlice(_v interface{}) bool {
rt := reflect.TypeOf(_v)
switch rt.Kind() {
case reflect.Slice:
return true
}
return false
}
func (f *FuturesTopTraderLongShortAccountRatioRequest) GetSlugsMap() (map[string]string, error) {
slugs := map[string]string{}
params, err := f.GetSlugParameters()
if err != nil {
return slugs, nil
}
for _k, _v := range params {
slugs[_k] = fmt.Sprintf("%v", _v)
}
return slugs, nil
}
func (f *FuturesTopTraderLongShortAccountRatioRequest) Do(ctx context.Context) ([]FuturesTopTraderLongShortAccountRatio, error) {
// empty params for GET operation
var params interface{}
query, err := f.GetParametersQuery()
if err != nil {
return nil, err
}
apiURL := "/futures/data/topLongShortAccountRatio"
req, err := f.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params)
if err != nil {
return nil, err
}
response, err := f.client.SendRequest(req)
if err != nil {
return nil, err
}
var apiResponse []FuturesTopTraderLongShortAccountRatio
if err := response.DecodeJSON(&apiResponse); err != nil {
return nil, err
}
return apiResponse, nil
}

View File

@ -0,0 +1,202 @@
// Code generated by "requestgen -method GET -url /futures/data/topLongShortPositionRatio -type FuturesTopTraderLongShortPositionRatioRequest -responseType []FuturesTopTraderLongShortPositionRatio"; DO NOT EDIT.
package binanceapi
import (
"context"
"encoding/json"
"fmt"
"github.com/c9s/bbgo/pkg/types"
"net/url"
"reflect"
"regexp"
"strconv"
"time"
)
func (f *FuturesTopTraderLongShortPositionRatioRequest) Symbol(symbol string) *FuturesTopTraderLongShortPositionRatioRequest {
f.symbol = symbol
return f
}
func (f *FuturesTopTraderLongShortPositionRatioRequest) Period(period types.Interval) *FuturesTopTraderLongShortPositionRatioRequest {
f.period = period
return f
}
func (f *FuturesTopTraderLongShortPositionRatioRequest) Limit(limit uint64) *FuturesTopTraderLongShortPositionRatioRequest {
f.limit = &limit
return f
}
func (f *FuturesTopTraderLongShortPositionRatioRequest) StartTime(startTime time.Time) *FuturesTopTraderLongShortPositionRatioRequest {
f.startTime = &startTime
return f
}
func (f *FuturesTopTraderLongShortPositionRatioRequest) EndTime(endTime time.Time) *FuturesTopTraderLongShortPositionRatioRequest {
f.endTime = &endTime
return f
}
// GetQueryParameters builds and checks the query parameters and returns url.Values
func (f *FuturesTopTraderLongShortPositionRatioRequest) GetQueryParameters() (url.Values, error) {
var params = map[string]interface{}{}
query := url.Values{}
for _k, _v := range params {
query.Add(_k, fmt.Sprintf("%v", _v))
}
return query, nil
}
// GetParameters builds and checks the parameters and return the result in a map object
func (f *FuturesTopTraderLongShortPositionRatioRequest) GetParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
// check symbol field -> json key symbol
symbol := f.symbol
// assign parameter of symbol
params["symbol"] = symbol
// check period field -> json key period
period := f.period
// assign parameter of period
params["period"] = period
// check limit field -> json key limit
if f.limit != nil {
limit := *f.limit
// assign parameter of limit
params["limit"] = limit
} else {
}
// check startTime field -> json key startTime
if f.startTime != nil {
startTime := *f.startTime
// assign parameter of startTime
// convert time.Time to milliseconds time stamp
params["startTime"] = strconv.FormatInt(startTime.UnixNano()/int64(time.Millisecond), 10)
} else {
}
// check endTime field -> json key endTime
if f.endTime != nil {
endTime := *f.endTime
// assign parameter of endTime
// convert time.Time to milliseconds time stamp
params["endTime"] = strconv.FormatInt(endTime.UnixNano()/int64(time.Millisecond), 10)
} else {
}
return params, nil
}
// GetParametersQuery converts the parameters from GetParameters into the url.Values format
func (f *FuturesTopTraderLongShortPositionRatioRequest) GetParametersQuery() (url.Values, error) {
query := url.Values{}
params, err := f.GetParameters()
if err != nil {
return query, err
}
for _k, _v := range params {
if f.isVarSlice(_v) {
f.iterateSlice(_v, func(it interface{}) {
query.Add(_k+"[]", fmt.Sprintf("%v", it))
})
} else {
query.Add(_k, fmt.Sprintf("%v", _v))
}
}
return query, nil
}
// GetParametersJSON converts the parameters from GetParameters into the JSON format
func (f *FuturesTopTraderLongShortPositionRatioRequest) GetParametersJSON() ([]byte, error) {
params, err := f.GetParameters()
if err != nil {
return nil, err
}
return json.Marshal(params)
}
// GetSlugParameters builds and checks the slug parameters and return the result in a map object
func (f *FuturesTopTraderLongShortPositionRatioRequest) GetSlugParameters() (map[string]interface{}, error) {
var params = map[string]interface{}{}
return params, nil
}
func (f *FuturesTopTraderLongShortPositionRatioRequest) applySlugsToUrl(url string, slugs map[string]string) string {
for _k, _v := range slugs {
needleRE := regexp.MustCompile(":" + _k + "\\b")
url = needleRE.ReplaceAllString(url, _v)
}
return url
}
func (f *FuturesTopTraderLongShortPositionRatioRequest) iterateSlice(slice interface{}, _f func(it interface{})) {
sliceValue := reflect.ValueOf(slice)
for _i := 0; _i < sliceValue.Len(); _i++ {
it := sliceValue.Index(_i).Interface()
_f(it)
}
}
func (f *FuturesTopTraderLongShortPositionRatioRequest) isVarSlice(_v interface{}) bool {
rt := reflect.TypeOf(_v)
switch rt.Kind() {
case reflect.Slice:
return true
}
return false
}
func (f *FuturesTopTraderLongShortPositionRatioRequest) GetSlugsMap() (map[string]string, error) {
slugs := map[string]string{}
params, err := f.GetSlugParameters()
if err != nil {
return slugs, nil
}
for _k, _v := range params {
slugs[_k] = fmt.Sprintf("%v", _v)
}
return slugs, nil
}
func (f *FuturesTopTraderLongShortPositionRatioRequest) Do(ctx context.Context) ([]FuturesTopTraderLongShortPositionRatio, error) {
// empty params for GET operation
var params interface{}
query, err := f.GetParametersQuery()
if err != nil {
return nil, err
}
apiURL := "/futures/data/topLongShortPositionRatio"
req, err := f.client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params)
if err != nil {
return nil, err
}
response, err := f.client.SendRequest(req)
if err != nil {
return nil, err
}
var apiResponse []FuturesTopTraderLongShortPositionRatio
if err := response.DecodeJSON(&apiResponse); err != nil {
return nil, err
}
return apiResponse, nil
}