api

package
v0.0.0-...-a287f25 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2021 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinOrderExpiration and MaxOrderExpiration represents the valid range of order expiration time;
	MinOrderExpiration = time.Hour * 24
	MaxOrderExpiration = time.Hour * 24 * 90
)
View Source
const ADDRESS_ZERO = "0x0000000000000000000000000000000000000000"

Variables

This section is empty.

Functions

func CheckAuthMiddleware

func CheckAuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc

func CheckJwtAuthByCookie

func CheckJwtAuthByCookie(c echo.Context) error

func CommonHandler

func CommonHandler(params Param, fn func(Param) (interface{}, error)) echo.HandlerFunc

func ErrorHandler

func ErrorHandler(err error, c echo.Context)

func GenericHTTPCollector

func GenericHTTPCollector() echo.MiddlewareFunc

GenericHTTPCollector create a new metrics collector with given config

func GetJwtAuth

func GetJwtAuth(param Param) (interface{}, error)

func GetOrderFromPalceOrderReq

func GetOrderFromPalceOrderReq(params *PlaceOrderReq) (*model.Order, error)

func InitMaiApiContext

func InitMaiApiContext(next echo.HandlerFunc) echo.HandlerFunc

func JwtAuthMiddleware

func JwtAuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc

func MaiAuthMiddleware

func MaiAuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc

func RecoverHandler

func RecoverHandler(next echo.HandlerFunc) echo.HandlerFunc

Types

type ApiError

type ApiError struct {
	Code   int
	Desc   string
	Params []string
	// contains filtered or unexported fields
}

ApiError represents error occurs in api requests, containing extra error infomation.

func AddressNotInWhiteListError

func AddressNotInWhiteListError() *ApiError

func AuthError

func AuthError(desc string, err error) *ApiError

func BadSignatureError

func BadSignatureError() *ApiError

func BindError

func BindError(err error) *ApiError

BindError represents ...

func BrokerAddressError

func BrokerAddressError(address string) *ApiError

func ChainIDError

func ChainIDError(chainID int64) *ApiError

func CloseOnlyError

func CloseOnlyError() *ApiError

func ContractSettledError

func ContractSettledError() *ApiError

func EchoHTTPError

func EchoHTTPError(err *echo.HTTPError) *ApiError

func GasBalanceError

func GasBalanceError() *ApiError

func InsufficientAllowanceError

func InsufficientAllowanceError(token string, need, has decimal.Decimal) *ApiError

func InsufficientBalanceError

func InsufficientBalanceError() *ApiError

func InternalError

func InternalError(err error) *ApiError

InternalError represents error caused by internal server error

func InvalidExpiresError

func InvalidExpiresError() *ApiError

func InvalidOrderTypeError

func InvalidOrderTypeError() *ApiError

func InvalidPriceAmountError

func InvalidPriceAmountError(desc string) *ApiError

func MaxOrderNumReachError

func MaxOrderNumReachError() *ApiError

func OrderAuthError

func OrderAuthError(id string) *ApiError

func OrderExpired

func OrderExpired() *ApiError

func OrderHashExistError

func OrderHashExistError(orderHash string) *ApiError

func OrderIDNotExistError

func OrderIDNotExistError(id string) *ApiError

func PerpetualNotFoundError

func PerpetualNotFoundError(perpetual string, index int64) *ApiError

PerpetualNotFoundError represents error caused by not existe market contract

func RateLimitError

func RateLimitError(desc string, err error) *ApiError

func ValidationError

func ValidationError(message string) *ApiError

ValidationError represents error caused by validation failure

func ValidatorError

func ValidatorError(errors validator.ValidationErrors) *ApiError

func (*ApiError) Error

func (e *ApiError) Error() string

func (*ApiError) Unwrap

func (e *ApiError) Unwrap() error

Unwrap extract internal error in ApiError

type BaseReq

type BaseReq struct {
	Address string `json:"address" query:"address"`
}

BaseReq represents a basic request data containing wallet addresses from which the request is sent

func (*BaseReq) GetAddress

func (b *BaseReq) GetAddress() string

func (*BaseReq) SetAddress

func (b *BaseReq) SetAddress(address string)

type BaseResp

type BaseResp struct {
	Status int    `json:"status"`
	Desc   string `json:"desc"`
}

BaseResp represents a basic response data containing status and description to indicates the executing result of an api request

type CancelAllOrdersReq

type CancelAllOrdersReq struct {
	BaseReq
}

type CancelOrderReq

type CancelOrderReq struct {
	BaseReq
	OrderHash string `json:"orderHash" param:"orderHash" validate:"required,len=66"`
}

type GetBrokerRelayReq

type GetBrokerRelayReq struct {
	BaseReq
	LiquidityPoolAddress string `json:"liquidityPoolAddress" validate:"required"`
	PerpetualIndex       int64  `json:"perpetualIndex"`
}

type GetBrokerRelayResp

type GetBrokerRelayResp struct {
	BrokerAddress  string `json:"brokerAddress"`
	Version        int    `json:"version"`
	RelayerAddress string `json:"relayerAddress"`
}

type GetPerpetualReq

type GetPerpetualReq struct {
	BaseReq
	LiquidityPoolAddress string `json:"liquidityPoolAddress" validate:"required"`
	PerpetualIndex       int64  `json:"perpetualIndex"`
}

type GetPerpetualResp

type GetPerpetualResp struct {
	Perpetual *model.Perpetual `json:"perpetual"`
}

type MaiApiContext

type MaiApiContext struct {
	echo.Context
	// If address is not empty means this user is authenticated.
	Address string
}

MaiApiContext holds user information for API requests

type Param

type Param interface {
	GetAddress() string
	SetAddress(address string)
}

type PlaceOrderReq

type PlaceOrderReq struct {
	BaseReq
	OrderHash            string `json:"orderHash"  validate:"required"`
	LiquidityPoolAddress string `json:"liquidityPoolAddress" validate:"required"`
	PerpetualIndex       int64  `json:"perpetualIndex"`
	BrokerAddress        string `json:"brokerAddress" validate:"required"`
	RelayerAddress       string `json:"relayerAddress" validate:"required"`
	ReferrerAddress      string `json:"referrerAddress"`
	OrderType            int    `json:"orderType" validate:"required,oneof=0 1 2"`
	Price                string `json:"price"     validate:"required"`
	TriggerPrice         string `json:"triggerPrice"`
	Amount               string `json:"amount"    validate:"required"`
	MinTradeAmount       string `json:"minTradeAmount" validate:"required"`
	BrokerFeeLimit       int64  `json:"brokerFeeLimit"`
	Salt                 int64  `json:"salt" validate:"required"`
	ExpiresAt            int64  `json:"expiresAt" validate:"required"`
	R                    string `json:"r" validate:"required"`
	S                    string `json:"s" validate:"required"`
	V                    string `json:"v" validate:"required"`
	SignType             string `json:"signType" validate:"required"`
	IsCloseOnly          bool   `json:"isCloseOnly"`
	ChainID              int64  `json:"chainID" validate:"required"`
}

type PlaceOrderResp

type PlaceOrderResp struct {
	Order *model.Order `json:"order"`
}

type QueryOrderReq

type QueryOrderReq struct {
	BaseReq
	LiquidityPoolAddress string `json:"liquidityPoolAddress" query:"liquidityPoolAddress"`
	PerpetualIndex       int64  `json:"perpetualIndex" query:"perpetualIndex"`
	Status               string `json:"status" query:"status"`
	BeforeOrderHash      string `json:"beforeOrderHash" query:"beforeOrderHash"`
	AfterOrderHash       string `json:"afterOrderHash"  query:"afterOrderHash"`
	BeginTime            int64  `json:"beginTime" query:"beginTime"`
	EndTime              int64  `json:"endTime" query:"endTime"`
	Limit                int    `json:"limit" query:"limit"`
}

type QueryOrdersByOrderHashsReq

type QueryOrdersByOrderHashsReq struct {
	BaseReq
	OrderHashs []string `json:"orderIDs" validate:"required"`
}

type QueryOrdersResp

type QueryOrdersResp struct {
	Orders []*model.Order `json:"orders"`
}

type QuerySingleOrderReq

type QuerySingleOrderReq struct {
	BaseReq
	OrderHash string `json:"orderHash" param:"orderHash" validate:"required"`
}

type QuerySingleOrderResp

type QuerySingleOrderResp struct {
	Order *model.Order `json:"order"`
}

type Response

type Response struct {
	Status int         `json:"status"`
	Desc   string      `json:"desc"`
	Data   interface{} `json:"data,omitempty"`
}

type Server

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

func New

func New(ctx context.Context, cli chain.ChainClient, dao dao.DAO, match *match.Server) (*Server, error)

func (*Server) CancelAllOrders

func (s *Server) CancelAllOrders(p Param) (interface{}, error)

func (*Server) CancelOrder

func (s *Server) CancelOrder(p Param) (interface{}, error)

func (*Server) GetBrokerRelay

func (s *Server) GetBrokerRelay(p Param) (interface{}, error)

func (*Server) GetOrderByOrderHash

func (s *Server) GetOrderByOrderHash(p Param) (interface{}, error)

func (*Server) GetOrders

func (s *Server) GetOrders(p Param) (interface{}, error)

func (*Server) GetOrdersByOrderHashs

func (s *Server) GetOrdersByOrderHashs(p Param) (interface{}, error)

func (*Server) GetPerpetual

func (s *Server) GetPerpetual(p Param) (interface{}, error)

func (*Server) PlaceOrder

func (s *Server) PlaceOrder(p Param) (interface{}, error)

func (*Server) Start

func (s *Server) Start() error

Jump to

Keyboard shortcuts

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