Documentation ¶
Index ¶
- Constants
- Variables
- func Ceil(d decimal.Decimal, precision int32) decimal.Decimal
- func Decimal(v string) decimal.Decimal
- func DecodeResponse(resp *resty.Response) ([]byte, error)
- func DecodeRoutes(id string) []int64
- func EncodeAction(action TransactionAction) string
- func EncodeRoutes(ids []int64) string
- func GenerateToken(clientID, sessionID, sessionKey string, exp time.Duration) (string, error)
- func GetClient() *http.Client
- func GetRestyClient() *resty.Client
- func Request(ctx context.Context) *resty.Request
- func TokenFrom(ctx context.Context) (string, bool)
- func UnmarshalResponse(resp *resty.Response, v interface{}) error
- func UseEndpoint(endpoint string)
- func WithToken(ctx context.Context, token string) context.Context
- type AddDepositReq
- type Asset
- type Deposit
- type Error
- type Graph
- type Group
- type Order
- func PreOrder(ctx context.Context, req *PreOrderReq) (*Order, error)
- func PreOrderWithPairs(pairs []*Pair, req *PreOrderReq) (*Order, error)
- func ReadOrder(ctx context.Context, id string) (*Order, error)
- func ReverseRoute(pairs []*Pair, payAssetID, fillAssetID string, fillAmount decimal.Decimal) (*Order, error)
- func Route(pairs []*Pair, payAssetID, fillAssetID string, payAmount decimal.Decimal) (*Order, error)
- type Pair
- type PreOrderReq
- type Result
- type TransactionAction
- type TransferReq
Constants ¶
View Source
const ( DepositStatePending = "Pending" DepositStateCancelled = "Cancelled" DepositStateDone = "Done" )
View Source
const ( OrderStateTrading = "Trading" OrderStateRejected = "Rejected" OrderStateDone = "Done" )
View Source
const ( LegacyEndpoint = "https://legacy-api.4swap.org" ClientID = "a753e0eb-3010-4c4a-a7b2-a7bda4063f62" MtgEndpoint = "https://api.4swap.org" )
View Source
const ( TransactionTypeAdd = "Add" TransactionTypeRemove = "Remove" TransactionTypeSwap = "Swap" )
View Source
const (
MaxRouteDepth = 4
)
Variables ¶
View Source
var (
ErrInsufficientLiquiditySwapped = errors.New("insufficient liquidity swapped")
)
Functions ¶
func DecodeResponse ¶
func DecodeRoutes ¶ added in v1.1.0
func EncodeAction ¶
func EncodeAction(action TransactionAction) string
func EncodeRoutes ¶
func GenerateToken ¶
GenerateToken create a new mixin authorization token store.Scope must be 'FULL'
func GetRestyClient ¶ added in v1.2.1
func GetRestyClient() *resty.Client
func UnmarshalResponse ¶
func UnmarshalResponse(resp *resty.Response, v interface{}) error
func UseEndpoint ¶ added in v1.0.4
func UseEndpoint(endpoint string)
Types ¶
type AddDepositReq ¶
type AddDepositReq struct { BaseAssetID string `json:"base_asset_id,omitempty"` BaseAmount decimal.Decimal `json:"base_amount,omitempty"` QuoteAssetID string `json:"quote_asset_id,omitempty"` QuoteAmount decimal.Decimal `json:"quote_amount,omitempty"` // optional, default 0.01 Slippage decimal.Decimal `json:"slippage,omitempty"` }
type Asset ¶ added in v1.0.4
type Asset struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` Symbol string `json:"symbol,omitempty"` DisplaySymbol string `json:"display_symbol,omitempty"` Logo string `json:"logo,omitempty"` ChainID string `json:"chain_id,omitempty"` Price decimal.Decimal `json:"price,omitempty"` Chain struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` Symbol string `json:"symbol,omitempty"` Logo string `json:"logo,omitempty"` ChainID string `json:"chain_id,omitempty"` Price decimal.Decimal `json:"price,omitempty"` Tag string `json:"tag,omitempty"` } `json:"chain,omitempty"` }
func ListAssets ¶ added in v1.0.4
ListAssets list all assets
type Deposit ¶
type Deposit struct { ID string `json:"id,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"` State string `json:"state,omitempty"` UserID string `json:"user_id,omitempty"` Transfers []*TransferReq `json:"transfers,omitempty"` }
func AddDeposit ¶
func AddDeposit(ctx context.Context, req *AddDepositReq) (*Deposit, error)
type Group ¶ added in v1.0.4
type Order ¶
type Order struct { ID string `json:"id,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"` State string `json:"state,omitempty"` PayAssetID string `json:"pay_asset_id,omitempty"` PayAmount decimal.Decimal `json:"pay_amount,omitempty"` FillAssetID string `json:"fill_asset_id,omitempty"` FillAmount decimal.Decimal `json:"fill_amount,omitempty"` MinAmount decimal.Decimal `json:"min_amount,omitempty"` RouteAssets []string `json:"route_assets,omitempty"` // route id Routes string `json:"routes,omitempty"` // deprecated, Use PayAmount instead Funds decimal.Decimal `json:"funds,omitempty"` // deprecated, Use FillAmount instead Amount decimal.Decimal `json:"amount,omitempty"` }
func PreOrder ¶
func PreOrder(ctx context.Context, req *PreOrderReq) (*Order, error)
PreOrder 预下单
如果要同时对多个交易对预下单,不建议使用这个方法;而是先调用 ListPairs 然后重复使用 Pairs 去 Route 或者 ReverseRoute,这样只需要调用一次 /pairs 接口 不会那么容易触发 Rate Limit
func PreOrderWithPairs ¶ added in v1.0.4
func PreOrderWithPairs(pairs []*Pair, req *PreOrderReq) (*Order, error)
func ReverseRoute ¶
type Pair ¶
type Pair struct { BaseAssetID string `json:"base_asset_id,omitempty"` BaseAmount decimal.Decimal `json:"base_amount,omitempty"` QuoteAssetID string `json:"quote_asset_id,omitempty"` QuoteAmount decimal.Decimal `json:"quote_amount,omitempty"` FeePercent decimal.Decimal `json:"fee_percent,omitempty"` RouteID int64 `json:"route_id,omitempty"` // 池子总的流动性份额 LiquidityAssetID string `json:"liquidity_asset_id,omitempty"` Liquidity decimal.Decimal `json:"liquidity,omitempty"` // 我的流动性份额,需要 WithToken SwapMethod string `json:"swap_method,omitempty"` Version int64 `json:"version,omitempty"` // volume Volume24h decimal.Decimal `json:"volume_24h,omitempty"` BaseVolume24h decimal.Decimal `json:"base_volume_24h,omitempty"` QuoteVolume24h decimal.Decimal `json:"quote_volume_24h,omitempty"` // value BaseValue decimal.Decimal `json:"base_value,omitempty"` QuoteValue decimal.Decimal `json:"quote_value,omitempty"` // stat Fee24h decimal.Decimal `json:"fee_24h,omitempty"` TransactionCount24h int64 `json:"transaction_count_24h,omitempty"` }
type PreOrderReq ¶
type PreOrderReq struct { PayAssetID string `json:"pay_asset_id,omitempty"` FillAssetID string `json:"fill_asset_id,omitempty"` // pay amount 和 fill amount 二选一 PayAmount decimal.Decimal `json:"pay_amount,omitempty"` FillAmount decimal.Decimal `json:"fill_amount,omitempty"` // deprecated Funds decimal.Decimal `json:"funds,omitempty"` // deprecated Amount decimal.Decimal `json:"amount,omitempty"` // deprecated MinAmount decimal.Decimal `json:"min_amount,omitempty"` }
type Result ¶
type Result struct { PayAssetID string PayAmount decimal.Decimal FillAssetID string FillAmount decimal.Decimal FeeAssetID string FeeAmount decimal.Decimal RouteID int64 }
Result represent Swap Result
func ReverseSwap ¶
ReverseSwap is a Reverse version of Swap
type TransactionAction ¶
type TransactionAction struct { // Transaction type add remove swap Type string `json:"t,omitempty" msgpack:"t,omitempty"` // deposit Deposit string `json:"d,omitempty" msgpack:"d,omitempty"` // withdraw Pairs []string `json:"p,omitempty" msgpack:"p,omitempty"` RemovePercent int64 `json:"l,omitempty" msgpack:"l,omitempty"` // 要买的币的 asset id AssetID string `json:"a,omitempty" msgpack:"a,omitempty"` // 路径 id,由 preOrder 得到,为空则由系统分配 Routes string `json:"r,omitempty" msgpack:"r,omitempty"` // 最小买入数量,为空则不限制 Minimum string `json:"m,omitempty" msgpack:"m,omitempty"` }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.