Documentation
¶
Index ¶
- Constants
- Variables
- func CalculateRSI(candles []entity.Futures_MarketCandle, period int, limit int) (rsiArr []entity.RSI)
- func CurrentSecondsTimestamp() int64
- func CurrentTimestamp() int64
- func DeriveTPFromBotSettings(entry float64, posSide string, takeProfit float64) float64
- func DeriveTPFromOpenOrders(openOrders []entity.Futures_OrdersList, symbol, posSide string) float64
- func Ed25519(secretKey string, data string) (*string, error)
- func FloatToStringAll(num float64) string
- func GetApiEndpoint(trade string) string
- func GetApiEndpointOption(trade string) string
- func GetEndpoint(trade string) string
- func GetMD5Hash(text string) string
- func GetPrecisionFromStr(s string) (pr string)
- func GetSHA256Hash(text string) string
- func GetWsPrivateEndpoint(trade string) string
- func GetWsPublicEndpoint(trade string) string
- func Hmac(secretKey string, data string) (*string, error)
- func HmacBase64(secretKey string, data string) (*string, error)
- func HmacHex512(secretKey string, data string) (*string, error)
- func Int64ToString(num int64) string
- func IntToString(num int) string
- func NewJSON(data []byte) (j *simplejson.Json, err error)
- func PrecisionFormatFloat64(num float64, scale string) string
- func PrecisionFormatString(ret string, scale string) string
- func Rsa(secretKey string, data string) (*string, error)
- func SetHTTPClient(c *http.Client)
- func SignFunc(keyType string) (func(string, string) (*string, error), error)
- func SizeFromNotionalAndEntry(notional, entry float64) float64
- func StartOfUTCDay(t time.Time) time.Time
- func StartOfUTCWeekMonday(t time.Time) time.Time
- func StringToFloat(num string) float64
- func StringToInt(num string) int
- func StringToInt64(num string) int64
- func TimestampMilliToDateFormat(stamp int64, format string) string
- type DailyFileLogger
- type LogOption
- type Params
- type Request
- func (c *Request) DoFunc(req *http.Request) (*http.Response, error)
- func (r *Request) ParseRequest(opts ...RequestOption) error
- func (c *Request) ReadAllBody(r io.Reader, content string) ([]byte, error)
- func (r *Request) SetFormParam(key string, value interface{}) *Request
- func (r *Request) SetFormParams(m Params) *Request
- func (r *Request) SetParam(key string, value interface{}) *Request
- func (r *Request) SetParams(m Params) *Request
- type RequestOption
Constants ¶
const ( SecTypeNone secType = iota SecTypeAPIKey SecTypeSigned )
const ( KeyTypeHmac = "HMAC" KeyTypeHmacBase64 = "HMACBase64" KeyTypeHmacHex512 = "KeyTypeHmacHex512" KeyTypeRsa = "RSA" KeyTypeEd25519 = "ED25519" )
Variables ¶
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 CurrentSecondsTimestamp ¶
func CurrentSecondsTimestamp() int64
func CurrentTimestamp ¶
func CurrentTimestamp() int64
func DeriveTPFromBotSettings ¶
DeriveTPFromBotSettings считает TP цену по entry и takeProfit (в %)
func DeriveTPFromOpenOrders ¶
func DeriveTPFromOpenOrders(openOrders []entity.Futures_OrdersList, symbol, posSide string) float64
DeriveTPFromOpenOrders ищет TP по открытым ордерам под конкретную сторону позиции
func FloatToStringAll ¶
func GetApiEndpoint ¶
func GetApiEndpointOption ¶
func GetEndpoint ¶
func GetMD5Hash ¶
func GetPrecisionFromStr ¶
func GetSHA256Hash ¶
func GetWsPrivateEndpoint ¶
func GetWsPublicEndpoint ¶
func Int64ToString ¶
func IntToString ¶
func PrecisionFormatFloat64 ¶
func PrecisionFormatString ¶
func SizeFromNotionalAndEntry ¶
SizeFromNotionalAndEntry рассчитывает размер (в базовой монете) из нотионала и цены входа
func StartOfUTCDay ¶
StartOfUTCDay возвращает начало суток UTC для времени t
func StartOfUTCWeekMonday ¶
StartOfUTCWeekMonday возвращает понедельник 00:00 UTC для времени t
func StringToFloat ¶
func StringToInt ¶
func StringToInt64 ¶
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
type LogOption ¶
type LogOption func(*DailyFileLogger)
Опции
func WithBindStdLogger ¶
func WithDateFormat ¶
Кастомный формат даты (по умолчанию "2006-01-02")
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) ParseRequest ¶
func (r *Request) ParseRequest(opts ...RequestOption) error