utils

package
v0.0.0-...-087e01a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SecTypeNone secType = iota
	SecTypeAPIKey
	SecTypeSigned
)
View Source
const (
	KeyTypeHmac       = "HMAC"
	KeyTypeHmacBase64 = "HMACBase64"
	KeyTypeHmacHex512 = "KeyTypeHmacHex512"
	KeyTypeRsa        = "RSA"
	KeyTypeEd25519    = "ED25519"
)

Variables

View Source
var (
	Binance_spot          = "https://api.binance.com"
	Binance_futures       = "https://fapi.binance.com"
	Binance_futures_coinm = "https://dapi.binance.com"
	Bingx_spot            = "https://open-api.bingx.com"
	Bingx_futures         = "https://open-api.bingx.com"
	Bybit_spot            = "https://api.bybit.com"
	Bybit_futures         = "https://api.bybit.com"
	Gateio_spot           = "https://api.gateio.ws"
	Gateio_futures        = "https://api.gateio.ws"
	Mexc_spot             = "https://api.mexc.com"
	Mexc_futures          = "https://contract.mexc.com"
	Bitget_spot           = "https://api.bitget.com"
	Bitget_futures        = "https://api.bitget.com"
	Okx_spot              = "https://www.okx.com"
	Okx_futures           = "https://www.okx.com"
	Huobi_spot            = "https://api.huobi.pro"
	Huobi_futures         = "https://api.hbdm.com"
	Bullish_spot          = "https://api.exchange.bullish.com"
	Bullish_futures       = "https://api.exchange.bullish.com"
	Kucoin_spot           = "https://api.kucoin.com"
	Kucoin_futures        = "https://api-futures.kucoin.com"
	Blofin_spot           = "https://openapi.blofin.com"
	Blofin_futures        = "https://openapi.blofin.com"
	Whitebit_spot         = "https://whitebit.com"
	Whitebit_futures      = "https://whitebit.com"
	//================
	BinanceFutureApiMainUrl = "https://fapi.binance.com"
	BybitFutureApiMainUrl   = "https://api.bybit.com"
	MexcFutureApiMainUrl    = "https://futures.mexc.com"
	BingxFutureApiMainUrl   = "https://open-api.bingx.com"
	GateFutureApiMainUrl    = "https://api.gateio.ws"
	BitgetFutureApiMainUrl  = "https://api.bitget.com"
	OKXFutureApiMainUrl     = "https://www.okx.com"
	HuobiFutureApiMainUrl   = "https://api.hbdm.com"

	OKXFutureWsPublicUrl  = "wss://ws.okx.com:8443/ws/v5/public"
	OKXFutureWsPrivateUrl = "wss://ws.okx.com:8443/ws/v5/private"
)

Functions

func CalculateRSI

func CalculateRSI(candles []entity.Futures_MarketCandle, period int, limit int) (rsiArr []entity.RSI)

func CurrentSecondsTimestamp

func CurrentSecondsTimestamp() int64

func CurrentTimestamp

func CurrentTimestamp() int64

func DeriveTPFromBotSettings

func DeriveTPFromBotSettings(entry float64, posSide string, takeProfit float64) float64

DeriveTPFromBotSettings считает TP цену по entry и takeProfit (в %)

func DeriveTPFromOpenOrders

func DeriveTPFromOpenOrders(openOrders []entity.Futures_OrdersList, symbol, posSide string) float64

DeriveTPFromOpenOrders ищет TP по открытым ордерам под конкретную сторону позиции

func Ed25519

func Ed25519(secretKey string, data string) (*string, error)

func FloatToStringAll

func FloatToStringAll(num float64) string

func GetApiEndpoint

func GetApiEndpoint(trade string) string

func GetApiEndpointOption

func GetApiEndpointOption(trade string) string

func GetEndpoint

func GetEndpoint(trade string) string

func GetMD5Hash

func GetMD5Hash(text string) string

func GetPrecisionFromStr

func GetPrecisionFromStr(s string) (pr string)

func GetSHA256Hash

func GetSHA256Hash(text string) string

func GetWsPrivateEndpoint

func GetWsPrivateEndpoint(trade string) string

func GetWsPublicEndpoint

func GetWsPublicEndpoint(trade string) string

func Hmac

func Hmac(secretKey string, data string) (*string, error)

func HmacBase64

func HmacBase64(secretKey string, data string) (*string, error)

func HmacHex512

func HmacHex512(secretKey string, data string) (*string, error)

func Int64ToString

func Int64ToString(num int64) string

func IntToString

func IntToString(num int) string

func NewJSON

func NewJSON(data []byte) (j *simplejson.Json, err error)

func PrecisionFormatFloat64

func PrecisionFormatFloat64(num float64, scale string) string

func PrecisionFormatString

func PrecisionFormatString(ret string, scale string) string

func Rsa

func Rsa(secretKey string, data string) (*string, error)

func SetHTTPClient

func SetHTTPClient(c *http.Client)

Возможность переопределить клиент

func SignFunc

func SignFunc(keyType string) (func(string, string) (*string, error), error)

func SizeFromNotionalAndEntry

func SizeFromNotionalAndEntry(notional, entry float64) float64

SizeFromNotionalAndEntry рассчитывает размер (в базовой монете) из нотионала и цены входа

func StartOfUTCDay

func StartOfUTCDay(t time.Time) time.Time

StartOfUTCDay возвращает начало суток UTC для времени t

func StartOfUTCWeekMonday

func StartOfUTCWeekMonday(t time.Time) time.Time

StartOfUTCWeekMonday возвращает понедельник 00:00 UTC для времени t

func StringToFloat

func StringToFloat(num string) float64

func StringToInt

func StringToInt(num string) int

func StringToInt64

func StringToInt64(num string) int64

func TimestampMilliToDateFormat

func TimestampMilliToDateFormat(stamp int64, format string) string

Types

type DailyFileLogger

type DailyFileLogger struct {
	// contains filtered or unexported fields
}

func InitAndBindStdLogger

func InitAndBindStdLogger(path, prefix string, flags int, opts ...LogOption) (*DailyFileLogger, error)

func InitGlobalLogger

func InitGlobalLogger(path, unusedPrefix string, opts ...LogOption) (*DailyFileLogger, error)

InitGlobalLogger упрощает подключение логгера к стандартному log. Пример использования в main:

lf, err := utils.InitGlobalLogger("logAPI.log", "[api] ", utils.WithUTC(), utils.WithAlsoStdout())
if err != nil { log.Panic(err) }
defer lf.Close()
log.SetFlags(log.LstdFlags)

func NewDailyFileLogger

func NewDailyFileLogger(path string, opts ...LogOption) (*DailyFileLogger, error)

NewDailyFileLogger создает ротацию по датам. path может быть: - "logAPI.log" → "logAPI-YYYY-MM-DD.log" - "logAPI" → "logAPI-YYYY-MM-DD.log" - "logs/api.log" → "logs/api-YYYY-MM-DD.log"

func (*DailyFileLogger) Close

func (l *DailyFileLogger) Close() error

func (*DailyFileLogger) Write

func (l *DailyFileLogger) Write(p []byte) (int, error)

type LogOption

type LogOption func(*DailyFileLogger)

Опции

func WithAlsoStdout

func WithAlsoStdout() LogOption

Дублировать вывод в stdout

func WithBindStdLogger

func WithBindStdLogger(prefix string, flags int) LogOption

func WithDateFormat

func WithDateFormat(layout string) LogOption

Кастомный формат даты (по умолчанию "2006-01-02")

func WithLocalTime

func WithLocalTime() LogOption

С локальным временем (по умолчанию — UTC)

func WithUTC

func WithUTC() LogOption

С UTC временем (по умолчанию уже UTC)

type Params

type Params map[string]interface{}

type Request

type Request struct {
	Method      string
	BaseURL     string
	Endpoint    string
	Proxy       string
	BrokerID    string
	TimeOffset  int64
	Query       url.Values
	QueryString string
	Form        url.Values
	RecvWindow  int64
	Timestamp   int64
	SecType     secType
	Sign        string
	Header      http.Header
	Body        io.Reader
	BodyString  string
	FullURL     string
	TmpSig      string
	TmpApi      string
	TmpMemo     string
}

func (*Request) DoFunc

func (c *Request) DoFunc(req *http.Request) (*http.Response, error)

DoFunc — единая точка отправки запроса.

func (*Request) ParseRequest

func (r *Request) ParseRequest(opts ...RequestOption) error

func (*Request) ReadAllBody

func (c *Request) ReadAllBody(r io.Reader, content string) ([]byte, error)

func (*Request) SetFormParam

func (r *Request) SetFormParam(key string, value interface{}) *Request

func (*Request) SetFormParams

func (r *Request) SetFormParams(m Params) *Request

func (*Request) SetParam

func (r *Request) SetParam(key string, value interface{}) *Request

func (*Request) SetParams

func (r *Request) SetParams(m Params) *Request

type RequestOption

type RequestOption func(*Request) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL