api

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2019 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InvalidApiID           = -1
	AssetsListAll          = -1
	AssetsMaxBatchSize     = 100
	GetCallOrdersLimit     = 100
	GetLimitOrdersLimit    = 100
	GetSettleOrdersLimit   = 100
	GetTradeHistoryLimit   = 100
	GetAccountHistoryLimit = 100
)

Variables

View Source
var (
	DialerTimeout    = time.Duration(5 * time.Second)
	ReadWriteTimeout = time.Duration(10 * time.Second)
	ErrShutdown      = errors.New("connection is shut down")
)
View Source
var (
	//LoopSeconds = time for one pass to calc dynamic delay
	LoopSeconds = 60
)

Functions

func KeyBagByUserPass

func KeyBagByUserPass(username string, password string) *crypto.KeyBag

func Sha256f

func Sha256f(input []byte, outputEncoding string) string

func UserPasstoPri

func UserPasstoPri(username string, password string) []string

Types

type BestNodeClientProvider

type BestNodeClientProvider struct {
	WebsocketClient
	// contains filtered or unexported fields
}

func (*BestNodeClientProvider) CallAPI

func (p *BestNodeClientProvider) CallAPI(apiID int, method string, args ...interface{}) (interface{}, error)

func (*BestNodeClientProvider) Close

func (p *BestNodeClientProvider) Close() error

type ClientProvider

type ClientProvider interface {
	OnError(fn ErrorFunc)
	Connect() error
	OnNotify(subscriberID int, fn NotifyFunc) error
	CallAPI(apiID int, method string, args ...interface{}) (interface{}, error)
	Close() error
}

func NewBestNodeClientProvider

func NewBestNodeClientProvider(endpointURL string, api CybexAPI) (ClientProvider, error)

func NewSimpleClientProvider

func NewSimpleClientProvider(endpointURL string, api CybexAPI) ClientProvider

type CybexAPI

type CybexAPI interface {
	//Common functions
	CallWsAPI(apiID int, method string, args ...interface{}) (interface{}, error)
	Close() error
	Connect() error
	DatabaseAPIID() int
	HistoryAPIID() int
	BroadcastAPIID() int
	SetCredentials(username, password string)
	OnError(ErrorFunc)
	OnNotify(subscriberID int, notifyFn func(msg interface{}) error) error
	BuildSignedTransaction(keyBag *crypto.KeyBag, feeAsset types.GrapheneObject, ops ...types.Operation) (*types.SignedTransaction, error)
	VerifySignedTransaction(keyBag *crypto.KeyBag, tx *types.SignedTransaction) (bool, error)
	SignTransaction(keyBag *crypto.KeyBag, trx *types.SignedTransaction) error
	SignWithKeys(types.PrivateKeys, *types.SignedTransaction) error

	//Websocket API functions
	BroadcastTransaction(tx *types.SignedTransaction) error
	ValidateTransaction(tx *types.SignedTransaction) error
	CancelAllSubscriptions() error
	CancelOrder(orderID types.GrapheneObject, broadcast bool) (*types.SignedTransaction, error)
	GetAccountBalances(account types.GrapheneObject, assets ...types.GrapheneObject) (types.AssetAmounts, error)
	GetAccountByName(name string) (*types.Account, error)
	GetAccountHistory(account types.GrapheneObject, stop types.GrapheneObject, limit int, start types.GrapheneObject) (types.OperationHistories, error)
	GetAccounts(accountIDs ...types.GrapheneObject) (types.Accounts, error)
	GetFullAccounts(accountIDs ...types.GrapheneObject) (types.FullAccountInfos, error)
	GetBlock(number uint64) (interface{}, error)
	GetCallOrders(assetID types.GrapheneObject, limit int) (types.CallOrders, error)
	GetChainID() (string, error)
	GetDynamicGlobalProperties() (*types.DynamicGlobalProperties, error)
	GetLimitOrders(base, quote types.GrapheneObject, limit int) (types.LimitOrders, error)
	GetOrderBook(base, quote types.GrapheneObject, depth int) (types.OrderBook, error)
	GetMarginPositions(accountID types.GrapheneObject) (types.CallOrders, error)
	GetObjects(objectIDs ...types.GrapheneObject) ([]interface{}, error)
	GetPotentialSignatures(tx *types.SignedTransaction) (types.PublicKeys, error)
	GetRequiredSignatures(tx *types.SignedTransaction, keys types.PublicKeys) (types.PublicKeys, error)
	GetRequiredFees(ops types.Operations, feeAsset types.GrapheneObject) (types.AssetAmounts, error)
	GetSettleOrders(assetID types.GrapheneObject, limit int) (types.SettleOrders, error)
	GetTradeHistory(base, quote types.GrapheneObject, toTime, fromTime time.Time, limit int) (types.MarketTrades, error)
	ListAssets(lowerBoundSymbol string, limit int) (types.Assets, error)
	SetSubscribeCallback(notifyID int, clearFilter bool) error
	SubscribeToMarket(notifyID int, base types.GrapheneObject, quote types.GrapheneObject) error
	UnsubscribeFromMarket(base types.GrapheneObject, quote types.GrapheneObject) error
	Get24Volume(base types.GrapheneObject, quote types.GrapheneObject) (types.Volume24, error)

	//Wallet API functions
	WalletListAccountBalances(account types.GrapheneObject) (types.AssetAmounts, error)
	WalletLock() error
	WalletUnlock(password string) error
	WalletIsLocked() (bool, error)
	WalletBorrowAsset(account types.GrapheneObject, amountToBorrow string, symbolToBorrow types.GrapheneObject, amountOfCollateral string, broadcast bool) (*types.SignedTransaction, error)
	WalletBuy(account types.GrapheneObject, base, quote types.GrapheneObject, rate string, amount string, broadcast bool) (*types.SignedTransaction, error)
	WalletBuyEx(account types.GrapheneObject, base, quote types.GrapheneObject, rate float64, amount float64, broadcast bool) (*types.SignedTransaction, error)
	WalletGetBlock(number uint64) (*types.Block, error)
	WalletGetRelativeAccountHistory(account types.GrapheneObject, stop int64, limit int, start int64) (types.OperationRelativeHistories, error)
	WalletGetDynamicGlobalProperties() (*types.DynamicGlobalProperties, error)
	WalletReadMemo(memo *types.Memo) (string, error)
	WalletSell(account types.GrapheneObject, base, quote types.GrapheneObject, rate string, amount string, broadcast bool) (*types.SignedTransaction, error)
	WalletSellEx(account types.GrapheneObject, base, quote types.GrapheneObject, rate float64, amount float64, broadcast bool) (*types.SignedTransaction, error)
	WalletSellAsset(account types.GrapheneObject, amountToSell string, symbolToSell types.GrapheneObject, minToReceive string, symbolToReceive types.GrapheneObject, timeout uint32, fillOrKill bool, broadcast bool) (*types.SignedTransaction, error)
	WalletSignTransaction(tx *types.SignedTransaction, broadcast bool) (*types.SignedTransaction, error)
	WalletSerializeTransaction(tx *types.SignedTransaction) (string, error)
	//WalletTransfer2(from, to types.GrapheneObject, amount string, asset types.GrapheneObject, memo string) (*types.SignedTransactionWithTransactionId, error)
	Send(from string, to string, amount string, asset string, memo string, password string) (*types.SignedTransaction, error)
	Sends(tosends []types.SimpleSend) (*types.SignedTransaction, error)
	PreSends(tosends []types.SimpleSend) (*types.SignedTransaction, error)
	LimitOrder(user string, base string, quote string, action string, price string, amount string, password string) (*types.SignedTransaction, error)
	LimitOrderGet(user string) (types.LimitOrders, error)
	LimitOrderCancel(user string, orderid string, password string) (*types.SignedTransaction, error)
	LoginVerify(fund types.Fund, sign string) (re bool, err error)
	VerifySign(accountName string, toSign string, sign string) (re bool, err error)
	SignStr(toSign string, prikey string) (sign string, err error)
	GetAsset(lowerBoundSymbol string) (types.Asset, error)
}

func New

func New(wsEndpointURL, rpcEndpointURL string) CybexAPI

New creates a new CybexAPI interface. wsEndpointURL: Is a mandatory websocket node URL. rpcEndpointURL: Is an optional RPC endpoint to your local `cli_wallet`. The use of wallet functions without this argument will throw an error. If you do not use wallet API, provide an empty string.

func NewWithAutoEndpoint

func NewWithAutoEndpoint(startupEndpointURL, rpcEndpointURL string) (CybexAPI, error)

NewWithAutoEndpoint creates a new CybexAPI interface with automatic node latency checking. It's best to use this API instance type for a long API lifecycle because the latency tester takes time to unleash its magic. startupEndpointURL: Iss a mandatory websocket node URL to startup the latency tester quickly. rpcEndpointURL: Is an optional RPC endpoint to your local `cli_wallet`. The use of wallet functions without this argument will throw an error. If you do not use wallet API, provide an empty string.

type ErrorFunc

type ErrorFunc func(error)

type LatencyTester

type LatencyTester interface {
	Start()
	Close() error
	String() string
	AddEndpoint(ep string)
	OnTopNodeChanged(fn func(string) error)
	TopNodeEndpoint() string
	TopNodeClient() WebsocketClient
	Done() <-chan struct{}
}

func NewLatencyTester

func NewLatencyTester(fallbackURL string) (LatencyTester, error)

func NewLatencyTesterWithContext

func NewLatencyTesterWithContext(ctx context.Context, fallbackURL string) (LatencyTester, error)

type NodeStats

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

NodeStats holds stat data for each endpoint

func NewNodeStats

func NewNodeStats(wsRPCEndpoint string) *NodeStats

NewNodeStats creates a new stat object

func (*NodeStats) Equals

func (p *NodeStats) Equals(n *NodeStats) bool

func (*NodeStats) Latency

func (p *NodeStats) Latency() time.Duration

Latency returns the nodes latency

func (*NodeStats) Score

func (p *NodeStats) Score() int64

Score returns reliability score for each node. The less the better.

func (*NodeStats) String

func (p *NodeStats) String() string

String returns the stats string representation

type NotifyFunc

type NotifyFunc func(msg interface{}) error

type RPCCall

type RPCCall struct {
	Method  string
	Request rpcRequest
	Reply   interface{}
	Error   error
	Done    chan *RPCCall
}

type RPCClient

type RPCClient interface {
	CallAPI(method string, args ...interface{}) (interface{}, error)
	Close() error
	Connect() error
}

func NewRPCClient

func NewRPCClient(rpcEndpointURL string) RPCClient

NewRPCClient creates a new RPC Client

type ResponseError

type ResponseError struct {
	Code    int               `json:"code"`
	Message string            `json:"message"`
	Data    ResponseErrorData `json:"data"`
}

func (ResponseError) Error

func (p ResponseError) Error() string

type ResponseErrorContext

type ResponseErrorContext struct {
	Level      string `json:"level"`
	File       string `json:"file"`
	Line       int    `json:"line"`
	Method     string `json:"method"`
	Hostname   string `json:"hostname"`
	ThreadName string `json:"thread_name"`
	Timestamp  string `json:"timestamp"`
}

type ResponseErrorData

type ResponseErrorData struct {
	Code    int                  `json:"code"`
	Name    string               `json:"name"`
	Message string               `json:"message"`
	Stack   []ResponseErrorStack `json:"stack"`
}

type ResponseErrorStack

type ResponseErrorStack struct {
	Context ResponseErrorContext `json:"context"`
	Format  string               `json:"format"`
	Data    interface{}          `json:"data"`
}

type SimpleClientProvider

type SimpleClientProvider struct {
	WebsocketClient
	// contains filtered or unexported fields
}

func (*SimpleClientProvider) CallAPI

func (p *SimpleClientProvider) CallAPI(apiID int, method string, args ...interface{}) (interface{}, error)

type WebsocketClient

type WebsocketClient interface {
	IsConnected() bool
	OnError(fn ErrorFunc)
	OnNotify(subscriberID int, fn NotifyFunc) error
	Call(method string, args []interface{}) (*RPCCall, error)
	CallAPI(apiID int, method string, args ...interface{}) (interface{}, error)
	Close() error
	Connect() error
}

func NewWebsocketClient

func NewWebsocketClient(endpointURL string) WebsocketClient

Jump to

Keyboard shortcuts

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