Documentation ¶
Index ¶
- Constants
- Variables
- func CombineSymbol(baseAssetSymbol, quoteAssetSymbol string) string
- func ConvertAndEncode(hrp string, data []byte) (string, error)
- func ConvertBits(data []byte, fromBits, toBits uint8, pad bool) ([]byte, error)
- func Decode(bech string) (string, []byte, error)
- func DecodeAndConvert(bech string) (string, []byte, error)
- func Encode(hrp string, data []byte) (string, error)
- func GenerateOrderID(sequence int64, from AccAddress) string
- func IToOrderType(tpe int8) string
- func IToSide(side int8) string
- func IsValidOrderType(ot int8) bool
- func IsValidSide(side int8) bool
- func IsValidTimeInForce(tif int8) bool
- func MustSortJSON(toSortJSON []byte) []byte
- func RegisterCodec(cdc *amino.Codec)
- func SortJSON(toSortJSON []byte) ([]byte, error)
- func StdSignBytes(chainID string, accnum int64, sequence int64, msgs []Msg, memo string, ...) []byte
- func ValidateSymbol(symbol string) error
- type AccAddress
- type Address
- type BalanceAccount
- type Block
- type BlockMeta
- type Blocks
- type ChainNetwork
- type Client
- type Codec
- type Coin
- type Coins
- func (coins Coins) AmountOf(denom string) int64
- func (coins Coins) IsEqual(coinsB Coins) bool
- func (coins Coins) IsNotNegative() bool
- func (coins Coins) IsPositive() bool
- func (coins Coins) IsValid() bool
- func (coins Coins) IsZero() bool
- func (coins Coins) Len() int
- func (coins Coins) Less(i, j int) bool
- func (coins Coins) Plus(coinsB Coins) Coins
- func (coins Coins) Sort() Coins
- func (coins Coins) Swap(i, j int)
- type ConcreteInfo
- type ConcreteOptions
- type CreateOrderMsg
- func (msg CreateOrderMsg) GetInvolvedAddresses() []AccAddress
- func (msg CreateOrderMsg) GetSignBytes() []byte
- func (msg CreateOrderMsg) GetSigners() []AccAddress
- func (msg CreateOrderMsg) Route() string
- func (msg CreateOrderMsg) String() string
- func (msg CreateOrderMsg) Type() string
- func (msg CreateOrderMsg) ValidateBasic() error
- type CreateOrderResult
- type CryptoJSON
- type Data
- type DisambBytes
- type DisfixBytes
- type Double
- type EncryptedKeyJSON
- type FieldInfo
- type FieldOptions
- type Fixed8
- type Height
- type HeightResp
- type HexBytes
- func (bz HexBytes) Bytes() []byte
- func (bz HexBytes) Format(s fmt.State, verb rune)
- func (bz HexBytes) Marshal() ([]byte, error)
- func (bz HexBytes) MarshalJSON() ([]byte, error)
- func (bz HexBytes) String() string
- func (bz *HexBytes) Unmarshal(data []byte) error
- func (bz *HexBytes) UnmarshalJSON(data []byte) error
- type Input
- type InterfaceInfo
- type InterfaceOptions
- type KeyManager
- type LastBlockHeight
- type MetaHeader
- type Msg
- type NodeInfo
- type Option
- type Output
- type PrefixBytes
- type PrivKey
- type PubKey
- type ResultBlock
- type ResultStatus
- type SResult
- type SendMsg
- type SendTokenResult
- type StdSignDoc
- type StdSignMsg
- type StdSignature
- type StdTx
- type StructInfo
- type SyncInfo
- type Token
- type TokenBalance
- type Transaction
- type Transfer
- type Tx
- type TxCommitResult
- type TxInfo
- type TxMsg
- type TxMsgCoin
- type TxMsgInput
- type TxMsgValue
- type TxResponse
- type TxValue
- type TypeInfo
Constants ¶
const ( DefaultApiSchema = "https" DefaultWSSchema = "wss" DefaultAPIVersionPrefix = "/api/v1" DefaultWSPrefix = "/api/ws" NativeSymbol = "BNB" GoSdkSource = 2 )
const ( RouteNewOrder = "orderNew" RouteCancelOrder = "orderCancel" )
Order routes
const ( PrefixBytesLen = 4 DisambBytesLen = 3 DisfixBytesLen = PrefixBytesLen + DisambBytesLen )
Lengths
const (
AddrLen = 20
)
const Source int64 = 2
Source .
Variables ¶
var ( // Param error AddressMissingError = errors.New("Address is required ") SymbolMissingError = errors.New("Symbol is required ") OffsetOutOfRangeError = errors.New("offset out of range ") LimitOutOfRangeError = errors.New("limit out of range ") TradeSideMisMatchError = errors.New("Trade side is invalid ") StartTimeOutOfRangeError = errors.New("start time out of range ") EndTimeOutOfRangeError = errors.New("end time out of range ") IntervalMissingError = errors.New("interval is required ") EndTimeLessThanStartTimeError = errors.New("end time should great than start time") OrderIdMissingError = errors.New("order id is required ") ExceedABCIPathLengthError = fmt.Errorf("the abci path exceed max length %d ", maxABCIPathLength) ExceedABCIDataLengthError = fmt.Errorf("the abci data exceed max length %d ", maxABCIDataLength) ExceedTxLengthError = fmt.Errorf("the tx data exceed max length %d ", maxTxLength) LimitNegativeError = fmt.Errorf("the limit can't be negative") ExceedMaxUnConfirmedTxsNumError = fmt.Errorf("the limit of unConfirmed tx exceed max limit %d ", maxUnConfirmedTxs) HeightNegativeError = fmt.Errorf("the height can't be negative") MaxMinHeightConflictError = fmt.Errorf("the min height can't be larger than max height") HashLengthError = fmt.Errorf("the length of hash is not 32") ExceedABCIQueryStrLengthError = fmt.Errorf("the query string exceed max length %d ", maxABCIPathLength) ExceedTxSearchQueryStrLengthError = fmt.Errorf("the query string exceed max length %d ", maxTxSearchStrLength) OffsetNegativeError = fmt.Errorf("offset can't be less than 0") SymbolLengthExceedRangeError = fmt.Errorf("length of symbol should be in range [%d,%d]", tokenSymbolMinLen, tokenSymbolMaxLen) PairFormatError = fmt.Errorf("the pair should in format 'symbol1_symbol2'") )
var Cdc = amino.NewCodec()
var Fixed8Decimals = int(math.Pow10(precision))
Fixed8Decimals represents 10^precision (100000000), a value of 1 in Fixed8 format
var Fixed8One = NewFixed8(1)
Fixed8One represetns one unit
var MsgCdc = amino.NewCodec()
MsgCdc .
var Network = ProdNetwork
Network .
var OrderSide = struct { BUY int8 SELL int8 }{1, 2}
OrderSide /TimeInForce /OrderType are const, following FIX protocol convention Used as Enum
var OrderType = struct { LIMIT int8 MARKET int8 }{orderLimit, orderMarket}
OrderType is an enum of order type options supported by the matching engine
var TimeInForce = struct { GTC int8 IOC int8 }{tifGTC, tifIOC}
TimeInForce is an enum of TIF (Time in Force) options supported by the matching engine
Functions ¶
func CombineSymbol ¶
CombineSymbol .
func ConvertAndEncode ¶
ConvertAndEncode converts from a base64 encoded byte string to base32 encoded byte string and then to bech32
func ConvertBits ¶
ConvertBits converts a byte slice where each byte is encoding fromBits bits, to a byte slice where each byte is encoding toBits bits.
func Decode ¶
Decode decodes a bech32 encoded string, returning the human-readable part and the data part excluding the checksum.
func DecodeAndConvert ¶
DecodeAndConvert decodes a bech32 encoded string and converts to base64 encoded bytes
func Encode ¶
Encode encodes a byte slice into a bech32 string with the human-readable part hrb. Note that the bytes must each encode 5 bits (base32).
func GenerateOrderID ¶
func GenerateOrderID(sequence int64, from AccAddress) string
GenerateOrderID generates an order ID
func IsValidOrderType ¶
IsValidOrderType validates that an order type is valid and supported by the matching engine
func IsValidSide ¶
IsValidSide validates that a side is valid and supported by the matching engine
func IsValidTimeInForce ¶
IsValidTimeInForce validates that a tif code is correct
func MustSortJSON ¶
MustSortJSON is like SortJSON but panic if an error occurs, e.g., if the passed JSON isn't valid.
func SortJSON ¶
SortJSON takes any JSON and returns it sorted by keys. Also, all white-spaces are removed. This method can be used to canonicalize JSON to be returned by GetSignBytes, e.g. for the ledger integration. If the passed JSON isn't valid it will return an error.
func StdSignBytes ¶
func StdSignBytes(chainID string, accnum int64, sequence int64, msgs []Msg, memo string, source int64, data []byte) []byte
StdSignBytes returns the bytes to sign for a transaction.
func ValidateSymbol ¶
Types ¶
type AccAddress ¶
type AccAddress []byte
AccAddress .
func (AccAddress) Bytes ¶
func (bz AccAddress) Bytes() []byte
func (AccAddress) Marshal ¶
func (bz AccAddress) Marshal() ([]byte, error)
Marshal needed for protobuf compatibility
func (AccAddress) MarshalJSON ¶
func (bz AccAddress) MarshalJSON() ([]byte, error)
MarshalJSON to Marshals to JSON using Bech32
func (*AccAddress) Unmarshal ¶
func (bz *AccAddress) Unmarshal(data []byte) error
Unmarshal needed for protobuf compatibility
type BalanceAccount ¶
type BalanceAccount struct { Number int64 `json:"account_number"` Address string `json:"address"` Balances []TokenBalance `json:"balances"` PublicKey []uint8 `json:"public_key"` Sequence int64 `json:"sequence"` ChainID string `json:"chain_id"` }
Balance Account definition
type BlockMeta ¶
type BlockMeta struct {
MetaHeader `json:"header"`
}
type ChainNetwork ¶
type ChainNetwork uint8
ChainNetwork .
const ( TestNetwork ChainNetwork = iota ProdNetwork )
func (ChainNetwork) Bech32Prefixes ¶
func (this ChainNetwork) Bech32Prefixes() string
Bech32Prefixes .
func (ChainNetwork) Bech32ValidatorAddrPrefix ¶
func (this ChainNetwork) Bech32ValidatorAddrPrefix() string
Bech32ValidatorAddrPrefix .
type Client ¶
type Client interface { Get(string, map[string]string, bool) ([]byte, int, error) GetAccount(address string) (*BalanceAccount, error) GetBalance(addr string, symbol string) (*TokenBalance, error) Transfer(keyManager KeyManager, transfers []Transfer) (*TxCommitResult, error) GetTokens() ([]Token, error) GetTransactionReceipt(tx string) (*TxResponse, error) GetBlockByNumber(height uint32) (*Blocks, error) BestBlockNumber() (uint32, error) SendRawTransaction(tx []byte) (string, error) }
Client .
type Coins ¶
type Coins []Coin
Coins def
func (Coins) IsNotNegative ¶
func (Coins) IsPositive ¶
type ConcreteInfo ¶
type ConcreteInfo struct { // These fields are only set when registered (as implementing an interface). Registered bool // Registered with RegisterConcrete(). PointerPreferred bool // Deserialize to pointer type if possible. // NilPreferred bool // Deserialize to nil for empty structs if PointerPreferred. Name string // Registered name. Disamb DisambBytes // Disambiguation bytes derived from name. Prefix PrefixBytes // Prefix bytes derived from name. ConcreteOptions // Registration options. // These fields get set for all concrete types, // even those not manually registered (e.g. are never interface values). IsAminoMarshaler bool // Implements MarshalAmino() (<ReprObject>, error). AminoMarshalReprType reflect.Type // <ReprType> IsAminoUnmarshaler bool // Implements UnmarshalAmino(<ReprObject>) (error). AminoUnmarshalReprType reflect.Type // <ReprType> }
ConcreteInfo .
type ConcreteOptions ¶
type ConcreteOptions struct { }
type CreateOrderMsg ¶
type CreateOrderMsg struct { Sender AccAddress `json:"sender"` ID string `json:"id"` Symbol string `json:"symbol"` OrderType int8 `json:"ordertype"` Side int8 `json:"side"` Price int64 `json:"price"` Quantity int64 `json:"quantity"` TimeInForce int8 `json:"timeinforce"` }
CreateOrderMsg def
func (CreateOrderMsg) GetInvolvedAddresses ¶
func (msg CreateOrderMsg) GetInvolvedAddresses() []AccAddress
GetInvolvedAddresses as part of the Msg interface
func (CreateOrderMsg) GetSignBytes ¶
func (msg CreateOrderMsg) GetSignBytes() []byte
GetSignBytes - Get the bytes for the message signer to sign on
func (CreateOrderMsg) GetSigners ¶
func (msg CreateOrderMsg) GetSigners() []AccAddress
GetSigners is part of Msg interface
func (CreateOrderMsg) Route ¶
func (msg CreateOrderMsg) Route() string
Route is part of Msg interface
func (CreateOrderMsg) String ¶
func (msg CreateOrderMsg) String() string
String is part of Msg interface
func (CreateOrderMsg) ValidateBasic ¶
func (msg CreateOrderMsg) ValidateBasic() error
ValidateBasic is used to quickly disqualify obviously invalid messages quickly
type CreateOrderResult ¶
type CreateOrderResult struct { TxCommitResult OrderID string }
CreateOrderResult .
type CryptoJSON ¶
type EncryptedKeyJSON ¶
type EncryptedKeyJSON struct { Address string `json:"address"` Crypto CryptoJSON `json:"crypto"` Id string `json:"id"` Version int `json:"version"` }
type FieldInfo ¶
type FieldInfo struct { Name string // Struct field name Type reflect.Type // Struct field type Index int // Struct field index ZeroValue reflect.Value // Could be nil pointer unlike TypeInfo.ZeroValue. UnpackedList bool // True iff this field should be encoded as an unpacked list. FieldOptions // Encoding options }
type FieldOptions ¶
type FieldOptions struct { JSONName string // (JSON) field name JSONOmitEmpty bool // (JSON) omitempty BinFixed64 bool // (Binary) Encode as fixed64 BinFixed32 bool // (Binary) Encode as fixed32 BinFieldNum uint32 // (Binary) max 1<<29-1 Unsafe bool // e.g. if this field is a float. WriteEmpty bool // write empty structs and lists (default false except for pointers) EmptyElements bool // Slice and Array elements are never nil, decode 0x00 as empty struct. }
type Fixed8 ¶
type Fixed8 int64
Fixed8 represents a fixed-point number with precision 10^-8
func Fixed8DecodeString ¶
Fixed8DecodeString parses s which must be a fixed point number with precision up to 10^-8
func (*Fixed8) MarshalJSON ¶
MarshalJSON implements the json marshaller interface
func (*Fixed8) UnmarshalJSON ¶
UnmarshalJSON implements the json unmarshaller interface
type HexBytes ¶
type HexBytes []byte
The main purpose of HexBytes is to enable HEX-encoding for json/encoding.
func (HexBytes) MarshalJSON ¶
This is the point of Bytes.
func (*HexBytes) UnmarshalJSON ¶
This is the point of Bytes.
type Input ¶
type Input struct { Address AccAddress `json:"address"` Coins Coins `json:"coins"` }
Input Input
func NewInput ¶
func NewInput(addr AccAddress, coins Coins) Input
func (Input) ValidateBasic ¶
ValidateBasic - validate transaction input
type InterfaceInfo ¶
type InterfaceInfo struct { Priority []DisfixBytes // Disfix priority. Implementers map[PrefixBytes][]*TypeInfo // Mutated over time. InterfaceOptions }
InterfaceInfo .
type InterfaceOptions ¶
type InterfaceOptions struct { Priority []string // Disamb priority. AlwaysDisambiguate bool // If true, include disamb for all types. }
InterfaceOptions .
type KeyManager ¶
type KeyManager interface { Sign(StdSignMsg) ([]byte, error) GetPrivKey() PrivKey GetAddr() AccAddress GetPublicKey() crypto.PubKey // ExportAsMnemonic() (string, error) ExportAsPrivateKey() (string, error) }
func NewPrivateKeyManager ¶
func NewPrivateKeyManager(priKey string) (KeyManager, error)
type LastBlockHeight ¶
type LastBlockHeight struct {
BlockHeith string `json:"last_block_height"`
}
LastBlockHeight .
type MetaHeader ¶
type Msg ¶
type Msg interface { // Return the message type. // Must be alphanumeric or empty. Route() string // Returns a human-readable string for the message, intended for utilization // within tags Type() string // ValidateBasic does a simple validation check that // doesn't require access to any other information. ValidateBasic() error // Get the canonical byte representation of the Msg. GetSignBytes() []byte // Signers returns the addrs of signers that must sign. // CONTRACT: All signatures must be present to be valid. // CONTRACT: Returns addrs in some deterministic order. GetSigners() []AccAddress // Get involved addresses of this msg so that we can publish account balance change GetInvolvedAddresses() []AccAddress }
Msg - Transactions messages must fulfill the Msg
type NodeInfo ¶
type NodeInfo struct { // Check compatibility. // Channels are HexBytes so easier to read as JSON Network string `json:"network"` // network/chain ID }
type Output ¶
type Output struct { Address AccAddress `json:"address"` Coins Coins `json:"coins"` }
Transaction Output
func NewOutput ¶
func NewOutput(addr AccAddress, coins Coins) Output
NewOutput - create a transaction output, used with SendMsg
func (Output) GetSignBytes ¶
Return bytes to sign for Output
func (Output) ValidateBasic ¶
ValidateBasic - validate transaction output
type ResultBlock ¶
type ResultStatus ¶
type SendMsg ¶
SendMsg - high level transaction of the coin module
func CreateSendMsg ¶
func CreateSendMsg(from AccAddress, fromCoins Coins, transfers []Transfer) SendMsg
func NewMsgSend ¶
NewMsgSend - construct arbitrary multi-in, multi-out send msg.
func (SendMsg) GetInvolvedAddresses ¶
func (msg SendMsg) GetInvolvedAddresses() []AccAddress
type StdSignDoc ¶
type StdSignDoc struct { ChainID string `json:"chain_id"` AccountNumber int64 `json:"account_number"` Sequence int64 `json:"sequence"` Memo string `json:"memo"` Source int64 `json:"source"` Msgs []json.RawMessage `json:"msgs"` Data []byte `json:"data"` }
StdSignDoc def
type StdSignMsg ¶
type StdSignMsg struct { ChainID string `json:"chain_id"` AccountNumber int64 `json:"account_number"` Sequence int64 `json:"sequence"` Msgs []Msg `json:"msgs"` Memo string `json:"memo"` Source int64 `json:"source"` Data []byte `json:"data"` }
StdSignMsg def
type StdSignature ¶
type StdSignature struct { crypto.PubKey `json:"pub_key"` // optional Signature []byte `json:"signature"` AccountNumber int64 `json:"account_number"` Sequence int64 `json:"sequence"` }
StdSignature Signature
type StdTx ¶
type StdTx struct { Msgs []Msg `json:"msg"` Signatures []StdSignature `json:"signatures"` Memo string `json:"memo"` Source int64 `json:"source"` Data []byte `json:"data"` }
StdTx def
type StructInfo ¶
type StructInfo struct {
Fields []FieldInfo // If a struct.
}
type SyncInfo ¶
type SyncInfo struct {
Height uint32 `json:"latest_block_height"` // latest_block_height
}
type Token ¶
type Token struct { Name string `json:"name"` Symbol string `json:"symbol"` OrigSymbol string `json:"original_symbol"` TotalSupply Fixed8 `json:"total_supply"` Owner AccAddress `json:"owner"` Mintable bool `json:"mintable"` }
Token definition
type TokenBalance ¶
type Transaction ¶
type Transaction struct { GasPrice uint64 GasLimit uint64 From string To string Symbol string Amount int64 Block int64 Tx string T time.Time }
Transaction .
type TxCommitResult ¶
type TxCommitResult struct { Ok bool `json:"ok"` Log string `json:"log"` Hash string `json:"hash"` Code int32 `json:"code"` Data string `json:"data"` }
TxCommitResult for POST tx results
type TxMsg ¶
type TxMsg struct { Type string `json:"type"` Value TxMsgValue `json:"value"` }
TxMsg .
type TxMsgInput ¶
TxMsgInput Input
type TxMsgValue ¶
type TxMsgValue struct { Inputs []TxMsgInput `json:"inputs"` Outputs []TxMsgInput `json:"outputs"` }
TxMsgValue .
type TxResponse ¶
type TxResponse struct { Hash string `json:"hash"` Height string `json:"height"` Ok bool `json:"ok"` Tx TxInfo `json:"tx"` }
TxResponse .
type TypeInfo ¶
type TypeInfo struct { Type reflect.Type // Interface type. PtrToType reflect.Type ZeroValue reflect.Value ZeroProto interface{} InterfaceInfo ConcreteInfo StructInfo }
TypeInfo .