common

package module
v0.0.0-...-30a366f Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2022 License: MIT Imports: 13 Imported by: 0

README

common

common types, variables, functions, etc.

Documentation

Index

Constants

View Source
const (
	USDT = "USDT"
	CNY  = "CNY"
	USD  = "USD"
)
View Source
const (
	BUY  = Side("buy")
	SELL = Side("sell")
)
View Source
const (
	Taker = Role("taker") // 吃单: 你满足人家的挂单, 佣金稍低
	Maker = Role("maker") // 挂单: 挂上去人家来满足你, 佣金稍高
)
View Source
const (
	Success    = 0 // success
	SuccessMsg = "SUCCESS"

	UnknownErr    = 1
	UnknownErrMsg = "unknown error message"

	UndefinedErr    = 2
	UndefinedErrMsg = "undefined error message"
)
View Source
const (
	ErrDbConnect    = 102001 // connect error
	ErrDbConnectMsg = "mysql:connect error"

	ErrDbAdd    = 102002 // add error
	ErrDbAddMsg = "mysql:add error"

	ErrDbDel    = 102003 // delete error
	ErrDbDelMsg = "mysql:delete error"

	ErrDbQuery    = 102004 // query error
	ErrDbQueryMsg = "mysql:query error"

	ErrDbUpdate    = 102005 // update error
	ErrDbUpdateMsg = "mysql:update error"

	ErrDbRecordNotFound    = 102006 // record not found
	ErrDbRecordNotFoundMsg = "mysql:record not found"
)

102 db error

View Source
const (
	ErrParameter    = 104400 // 0: 参数格式错误
	ErrParameterMsg = "invalid parameter"

	ErrUnauthorized    = 104401                     // 1: unauthorized
	ErrUnauthorizedMsg = "request unauthorized api" // 1: unauthorized

	ErrNotFound         = 104404 // 4: request path not found
	ErrNotSupportMethod = 104405 // 5: not support method
)

104 parameter error

View Source
const (
	ErrGateioApi       = 105001
	ErrGateioApiErrMsg = "gateio api error"
)

105 collector error

View Source
const (
	ErrRdsSet    = 106001
	ErrRdsSetMsg = "redis set error"

	ErrRdsGet    = 106002
	ErrRdsGetMsg = "redis get error"

	ErrRdsDel    = 106003
	ErrRdsDelMsg = "redis del error"
)

106 redis error

View Source
const (
	ErrMail    = 107001
	ErrMailMsg = "send mail error"

	ErrInvalidVerify    = 107002
	ErrInvalidVerifyMsg = "invalid verify code"

	ErrUserExists    = 107003
	ErrUserExistsMsg = "register: user exists"

	ErrGeneratePassword    = 107004
	ErrGeneratePasswordMsg = "generate password error"

	ErrTokenGenerate    = 107005
	ErrTokenGenerateMsg = "token generated  error"

	ErrUserNotFound    = 107006
	ErrUserNotFoundMsg = "user account not found"

	ErrInvalidPwd    = 107007
	ErrInvalidPwdMsg = "invalid password"

	ErrTokenExpired    = 107007
	ErrTokenExpiredMsg = "token expired"
)

107 business err

View Source
const (
	SnowflakeMode = 1152921504606846976 // 雪花算法第一bit没用到, 此处去掉, 保留时间戳(41bit),node节点(10bit),序列号(12)
)

Variables

View Source
var (
	GOOS           = runtime.GOOS
	GOARCH         = runtime.GOARCH
	GoVersion      = runtime.Version()
	BuildTimestamp string
	BuildTime      time.Time
	BuildUser      string
	Branch         string
	Version        string
	Commit         string
	Author         string
	Email          string
)
View Source
var (
	Node *snowflake.Node
)

Functions

func DatetimeToTime

func DatetimeToTime(t *datetime.DateTime) time.Time

func MD5

func MD5(data []byte) string

func Print

func Print(program string) string

Print returns version information.

func TimeToDatetime

func TimeToDatetime(t time.Time) *datetime.DateTime

Types

type Channel

type Channel struct {
	Id        snowflake.ID `json:"id"`
	SecretKey string       `json:"secret_key"`
	TTL       int          `json:"ttl"`
	Access    string       `json:"access"`
	KEY       string       `json:"key"`
	Topic     string       `json:"topic"`
	CreatedAt time.Time    `json:"created_at"`
	UpdatedAt time.Time    `json:"updated_at"`
}

type QuoteType

type QuoteType string

type Role

type Role string

Role only taker/maker

func (*Role) String

func (role *Role) String() string

type Side

type Side string

Side only buy|sell

func (*Side) String

func (s *Side) String() string

type T

type T struct {
	Price  decimal.Decimal `json:"price" example:"41914.12"`
	Amount decimal.Decimal `json:"amount" example:"23.23"`
}

T TODO 表示买N/卖N 的价格+量的合体

type Ticket

type Ticket struct {
	TicketTopic string          `json:"ticket_topic" example:"/gateio/BTC_USDT/ticket/"`
	OrderTopic  string          `json:"order_topic"  example:"/gateio/BTC_USDT/order/"`
	Base        string          `json:"base"     example:"BTC"`
	Quote       string          `json:"quote"    example:"USDT"`
	Name        string          `json:"name"     example:"南方航空"`
	Currency    string          `json:"currency" example:"BTC_USDT"`
	Latest      decimal.Decimal `json:"latest"   example:"41913.47"`
	Ask         []T             `json:"ask"`
	Bid         []T             `json:"bid"`
	Time        int64           `json:"time"     example:"1644822272084"` // 毫秒单位
	Raw         json.RawMessage `json:"raw"`
}

Ticket x

// huobi ticket

{
    "ch":"market.btcusdt.ticker",
    "ts":1630982370526,
    "tick":{
        "open":51732,
        "high":52785.64,
        "low":51000,
        "close":52735.63,
        "amount":13259.24137056181,
        "vol":687640987.4125315,
        "count":448737,
        "bid":52732.88,
        "bidSize":0.036,
        "ask":52732.89,
        "askSize":0.583653,
        "lastPrice":52735.63,
        "lastSize":0.03
    }
}

// gateio ticket

{
	"time":1644821166,
	"channel":"spot.tickers",
	"event":"update",
	"result":{
		"currency_pair":"BTC_USDT",
		"last":"41913.47",
		"lowest_ask":"41914",
		"highest_bid":"41913.99",
		"change_percentage":"-1.0202",
		"base_volume":"861.5026739119",
		"quote_volume":"36375443.997132",
		"high_24h":"45816.6",
		"low_24h":"32944.17"
	}
}

Directories

Path Synopsis
protobuf
go/protobuf
Package protobuf is a reverse proxy.
Package protobuf is a reverse proxy.

Jump to

Keyboard shortcuts

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