common

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2020 License: MIT Imports: 13 Imported by: 15

Documentation

Index

Constants

View Source
const (
	ProductionMode = "production"
	SimulationMode = "simulation"
)
View Source
const (
	MiningStatusMined       = "mined"
	MiningStatusFailed      = "failed"
	MiningStatusSubmitted   = "submitted"
	MiningStatusLost        = "lost"
	MiningStatusPending     = "pending"
	ExchangeStatusDone      = "done"
	ExchangeStatusPending   = "pending"
	ExchangeStatusFailed    = "failed"
	ExchangeStatusSubmitted = "submitted"
	ExchangeStatusLost      = "lost"
	ActionDeposit           = "deposit"
	ActionTrade             = "trade"
	ActionWithdraw          = "withdraw"
	ActionSetRate           = "set_rates"
)

Variables

View Source
var AppVersion string

AppVersion store build version, which set on build

View Source
var SupportedExchanges = map[ExchangeID]Exchange{}

Functions

func BigToFloat

func BigToFloat(b *big.Int, decimal int64) float64

BigToFloat converts a big int to float according to its number of decimal digits Example: - BigToFloat(1100, 3) = 1.1 - BigToFloat(1100, 2) = 11 - BigToFloat(1100, 5) = 0.11

func CmdDirLocation0 added in v0.1.2

func CmdDirLocation0() string

CmdDirLocation returns the absolute location of cmd directory where public settings will be read.

func CombineActivityStorageErrs added in v0.1.1

func CombineActivityStorageErrs(err, sErr error) error

CombineActivityStorageErrs return a combination of error between action error and storage error

func CurrentDir added in v0.1.1

func CurrentDir() string

CurrentDir returns current directory of the caller.

func ErrorToString added in v0.1.1

func ErrorToString(err error) string

ErrorToString returns error as string and an empty string if the error is nil

func EthToWei added in v0.1.1

func EthToWei(n float64) *big.Int

EthToWei converts Gwei as a float to Wei as a big int

func FloatToBigInt added in v0.1.1

func FloatToBigInt(amount float64, decimal int64) *big.Int

FloatToBigInt converts a float to a big int with specific decimal Example: - FloatToBigInt(1, 4) = 10000 - FloatToBigInt(1.234, 4) = 12340

func GetCallerFunctionName added in v0.1.2

func GetCallerFunctionName() string

GetCallerFunctionName return caller function name

func GetTimepoint

func GetTimepoint() uint64

func GetTokenAddressesList added in v0.1.1

func GetTokenAddressesList(tokens []Token) []ethereum.Address

func GweiToWei added in v0.1.1

func GweiToWei(n float64) *big.Int

GweiToWei converts Gwei as a float to Wei as a big int

func RunningMode added in v0.1.1

func RunningMode() string

RunningMode returns the current running mode of application.

func TimeToTimepoint

func TimeToTimepoint(t time.Time) uint64

func TimepointToTime

func TimepointToTime(t uint64) time.Time

func TruncStr added in v0.1.1

func TruncStr(src []byte) []byte

Types

type ActivityID

type ActivityID struct {
	Timepoint uint64
	EID       string
}

func NewActivityID

func NewActivityID(timepoint uint64, eid string) ActivityID

NewActivityStatus creates new Activity ID.

func StringToActivityID

func StringToActivityID(id string) (ActivityID, error)

func (ActivityID) MarshalText

func (ai ActivityID) MarshalText() ([]byte, error)

func (ActivityID) String

func (ai ActivityID) String() string

func (ActivityID) ToBytes added in v0.1.1

func (ai ActivityID) ToBytes() [64]byte

func (*ActivityID) UnmarshalText

func (ai *ActivityID) UnmarshalText(b []byte) error

type ActivityRecord

type ActivityRecord struct {
	Action         string
	ID             ActivityID
	Destination    string
	Params         map[string]interface{}
	Result         map[string]interface{}
	ExchangeStatus string
	MiningStatus   string
	Timestamp      Timestamp
}

func NewActivityRecord added in v0.1.1

func NewActivityRecord(action string, id ActivityID, destination string, params, result map[string]interface{}, exStatus, miStatus string, timestamp Timestamp) ActivityRecord

New ActivityRecord return an activity record with params["token"] only as token.ID

func (ActivityRecord) IsBlockchainPending added in v0.1.1

func (ar ActivityRecord) IsBlockchainPending() bool

func (ActivityRecord) IsExchangePending added in v0.1.1

func (ar ActivityRecord) IsExchangePending() bool

func (ActivityRecord) IsPending added in v0.1.1

func (ar ActivityRecord) IsPending() bool

type ActivityStatus added in v0.1.1

type ActivityStatus struct {
	ExchangeStatus string
	Tx             string
	BlockNumber    uint64
	MiningStatus   string
	Error          error
}

func NewActivityStatus added in v0.1.1

func NewActivityStatus(exchangeStatus, tx string, blockNumber uint64, miningStatus string, err error) ActivityStatus

NewActivityStatus creates a new ActivityStatus instance.

type AddressConfig

type AddressConfig struct {
	Reserve string `json:"reserve"`

	// not officially shown but you can find it here: https://github.com/KyberNetwork/smart-contracts/blob/master/contracts/mock/Wrapper.sol
	Wrapper string `json:"wrapper"`

	// Pricing is ConversionRates contract
	Pricing string `json:"pricing"`

	// as we used to miscalling this contract as network
	// we still keep its json name as network
	// then other component won't be affect
	Proxy string `json:"network"`
}

AddressConfig type defines a list of address attribute available in core.

type AddressesResponse added in v0.1.1

type AddressesResponse struct {
	Addresses map[string]interface{} `json:"addresses"`
}

func NewAddressResponse added in v0.1.1

func NewAddressResponse(addrs map[string]interface{}) *AddressesResponse

type AllBalanceResponse

type AllBalanceResponse struct {
	Version    Version
	Timestamp  Timestamp
	ReturnTime Timestamp
	Data       map[string]BalanceResponse
}

type AllEBalanceResponse

type AllEBalanceResponse struct {
	Version    Version
	Timestamp  Timestamp
	ReturnTime Timestamp
	Data       map[ExchangeID]EBalanceEntry
}

type AllOrderEntry

type AllOrderEntry map[ExchangeID]OrderEntry

type AllOrderResponse

type AllOrderResponse struct {
	Version    Version
	Timestamp  Timestamp
	ReturnTime Timestamp
	Data       AllOrderEntry
}

type AllPriceEntry added in v0.1.1

type AllPriceEntry struct {
	Block uint64
	Data  map[TokenPairID]OnePrice
}

type AllPriceResponse

type AllPriceResponse struct {
	Version    Version
	Timestamp  Timestamp
	ReturnTime Timestamp
	Data       map[TokenPairID]OnePrice
	Block      uint64
}

type AllRateEntry

type AllRateEntry struct {
	Timestamp   Timestamp
	ReturnTime  Timestamp
	Data        map[string]RateEntry
	BlockNumber uint64
}

AllRateEntry contains rates data of all tokens.

type AllRateResponse

type AllRateResponse struct {
	Version       Version
	Timestamp     Timestamp
	ReturnTime    Timestamp
	Data          map[string]RateResponse
	BlockNumber   uint64
	ToBlockNumber uint64
}

AllRateResponse is the response to query all rates.

type AllSettings added in v0.1.1

type AllSettings struct {
	Addresses *AddressesResponse `json:"addresses"`
	Tokens    *TokenResponse     `json:"tokens"`
	Exchanges *ExchangeResponse  `json:"exchanges"`
}

func NewAllSettings added in v0.1.1

func NewAllSettings(addrs *AddressesResponse, toks *TokenResponse, exs *ExchangeResponse) *AllSettings

type AllTradeHistory added in v0.1.1

type AllTradeHistory struct {
	Timestamp Timestamp
	Data      map[ExchangeID]ExchangeTradeHistory
}

type AuthDataRecord added in v0.1.1

type AuthDataRecord struct {
	Timestamp Timestamp
	Data      AuthDataSnapshot
}

func NewAuthDataRecord added in v0.1.1

func NewAuthDataRecord(timestamp Timestamp, data AuthDataSnapshot) AuthDataRecord

NewAuthDataRecord creates a new AuthDataRecord instance.

type AuthDataResponse added in v0.1.1

type AuthDataResponse struct {
	Version    Version
	Timestamp  Timestamp
	ReturnTime Timestamp
	Data       struct {
		Valid             bool
		Error             string
		Timestamp         Timestamp
		ReturnTime        Timestamp
		ExchangeBalances  map[ExchangeID]EBalanceEntry
		ReserveBalances   map[string]BalanceResponse
		PendingActivities []ActivityRecord
		Block             uint64
	}
}

type AuthDataSnapshot added in v0.1.1

type AuthDataSnapshot struct {
	Valid             bool
	Error             string
	Timestamp         Timestamp
	ReturnTime        Timestamp
	ExchangeBalances  map[ExchangeID]EBalanceEntry
	ReserveBalances   map[string]BalanceEntry
	PendingActivities []ActivityRecord
	Block             uint64
}

type BTCData added in v0.1.1

type BTCData struct {
	Timestamp uint64
	Coinbase  CoinbaseData     `json:"CoinbaseBTC"`
	Gemini    GeminiETHBTCData `json:"GeminiBTC"`
}

BTCData is the data returned by /btc-feed API.

type BalanceEntry

type BalanceEntry struct {
	Valid      bool
	Error      string
	Timestamp  Timestamp
	ReturnTime Timestamp
	Balance    RawBalance
}

func (BalanceEntry) ToBalanceResponse

func (be BalanceEntry) ToBalanceResponse(decimal int64) BalanceResponse

type BalanceResponse

type BalanceResponse struct {
	Valid      bool
	Error      string
	Timestamp  Timestamp
	ReturnTime Timestamp
	Balance    float64
}

type BinanceData added in v0.1.1

type BinanceData struct {
	Valid    bool
	Error    string
	Symbol   string `json:"symbol"`
	BidPrice string `json:"bidPrice"`
	BidQty   string `json:"bidQty"`
	AskPrice string `json:"askPrice"`
	AskQty   string `json:"askQty"`
}

BinanceData data return by https://api.binance.com/api/v3/ticker/bookTicker?symbol=ETHUSDC

type BitFinexData added in v0.1.2

type BitFinexData struct {
	Valid           bool
	Error           string
	Bid             float64 `json:"bid"`
	BidSize         float64 `json:"bid_size"`
	Ask             float64 `json:"ask"`
	AskSize         float64 `json:"ask_size"`
	DailyChange     float64 `json:"daily_change"`
	DailyChangePerc float64 `json:"daily_change_perc"`
	LastPrice       float64 `json:"last_price"`
	Volume          float64 `json:"volume"`
	High            float64 `json:"high"`
	Low             float64 `json:"low"`
}

type CoinbaseData added in v0.1.1

type CoinbaseData struct {
	Valid   bool
	Error   string
	TradeID uint64 `json:"trade_id"`
	Price   string `json:"price"`
	Size    string `json:"size"`
	Time    string `json:"time"`
	Bid     string `json:"bid"`
	Ask     string `json:"ask"`
	Volume  string `json:"volume"`
}

CoinBaseData is the response of Coinbase ETH/BTC ticker request. Example: https://api.pro.coinbase.com/products/eth-btc/ticker Response

{
 "trade_id": 7188449,
 "price": "0.02707000",
 "size": "3.43340266",
 "time": "2019-05-13T04:56:14.777Z",
 "bid": "0.02707",
 "ask": "0.02708",
 "volume": "31528.93120442"
}

type DGXGoldData added in v0.1.1

type DGXGoldData struct {
	Valid     bool
	Timestamp uint64
	Status    string     `json:"status"`
	Data      []GoldRate `json:"data"`
	Error     string
}

type EBalanceEntry

type EBalanceEntry struct {
	Valid            bool
	Error            string
	Timestamp        Timestamp
	ReturnTime       Timestamp
	AvailableBalance map[string]float64
	LockedBalance    map[string]float64
	DepositBalance   map[string]float64
	Status           bool
}

type EthClient added in v0.1.2

type EthClient struct {
	*ethclient.Client
	URL string
}

EthClient just a wrap for ethclient.Client with url connect to

func NewEthClient added in v0.1.2

func NewEthClient(url string) (*EthClient, error)

NewEthClient create a new ethclient

type ExStatus added in v0.1.1

type ExStatus struct {
	Timestamp uint64 `json:"timestamp"`
	Status    bool   `json:"status"`
}

type Exchange

type Exchange interface {
	ID() ExchangeID
	// Address return the deposit address of a token and return true if token is supported in the exchange.
	// Otherwise return false. This function will prioritize live address from exchange above the current stored address.
	Address(token Token) (address ethereum.Address, supported bool)
	UpdateDepositAddress(token Token, addr string) error
	Withdraw(token Token, amount *big.Int, address ethereum.Address, timepoint uint64) (string, error)
	Trade(tradeType string, base, quote Token, rate, amount float64, timepoint uint64) (id string, done, remaining float64, finished bool, err error)
	CancelOrder(id, base, quote string) error
	MarshalText() (text []byte, err error)
	GetInfo() (ExchangeInfo, error)
	GetExchangeInfo(TokenPairID) (ExchangePrecisionLimit, error)

	// GetLiveExchangeInfo querry the Exchange Endpoint for exchange precision and limit of a list of tokenPairIDs
	// It return error if occurs.
	GetLiveExchangeInfos([]TokenPairID) (ExchangeInfo, error)
	GetFee() (ExchangeFees, error)
	GetMinDeposit() (ExchangesMinDeposit, error)
	GetTradeHistory(fromTime, toTime uint64) (ExchangeTradeHistory, error)
}

Exchange represents a centralized exchange like Binance, Huobi...

func GetExchange

func GetExchange(id string) (Exchange, error)

type ExchangeActionNoti added in v0.1.1

type ExchangeActionNoti map[string]ExchangeTokenNoti

type ExchangeAddresses added in v0.1.1

type ExchangeAddresses map[string]ethereum.Address

ExchangeAddresses type store a map[tokenID]exchangeDepositAddress

func NewExchangeAddresses added in v0.1.1

func NewExchangeAddresses() *ExchangeAddresses

func (ExchangeAddresses) Get added in v0.1.1

func (ea ExchangeAddresses) Get(tokenID string) (ethereum.Address, bool)

func (ExchangeAddresses) GetData added in v0.1.1

func (ea ExchangeAddresses) GetData() map[string]ethereum.Address

func (ExchangeAddresses) Remove added in v0.1.1

func (ea ExchangeAddresses) Remove(tokenID string)

func (ExchangeAddresses) Update added in v0.1.1

func (ea ExchangeAddresses) Update(tokenID string, address ethereum.Address)

type ExchangeFees added in v0.1.1

type ExchangeFees struct {
	Trading TradingFee
	Funding FundingFee
}

ExchangeFees contains the fee for an exchanges It follow the struct of {trading: map[tokenID]float64, funding: {Withdraw: map[tokenID]float64, Deposit: map[tokenID]float64}}

func NewExchangeFee added in v0.1.1

func NewExchangeFee(tradingFee TradingFee, fundingFee FundingFee) ExchangeFees

type ExchangeID

type ExchangeID string

type ExchangeInfo added in v0.1.1

type ExchangeInfo map[TokenPairID]ExchangePrecisionLimit

ExchangeInfo is written and read concurrently

func NewExchangeInfo added in v0.1.1

func NewExchangeInfo() ExchangeInfo

func (ExchangeInfo) Get added in v0.1.1

func (ExchangeInfo) GetData added in v0.1.1

type ExchangeNotiContent added in v0.1.1

type ExchangeNotiContent struct {
	FromTime  uint64 `json:"fromTime"`
	ToTime    uint64 `json:"toTime"`
	IsWarning bool   `json:"isWarning"`
	Message   string `json:"msg"`
}

type ExchangeNotifications added in v0.1.1

type ExchangeNotifications map[string]ExchangeActionNoti

type ExchangePrecisionLimit added in v0.1.1

type ExchangePrecisionLimit struct {
	Precision   TokenPairPrecision   `json:"precision"`
	AmountLimit TokenPairAmountLimit `json:"amount_limit"`
	PriceLimit  TokenPairPriceLimit  `json:"price_limit"`
	MinNotional float64              `json:"min_notional"`
}

ExchangePrecisionLimit store the precision and limit of a certain token pair on an exchange it is int the struct of [[int int], [float64 float64], [float64 float64], float64]

type ExchangePrice

type ExchangePrice struct {
	Valid      bool
	Error      string
	Timestamp  Timestamp
	Bids       []PriceEntry
	Asks       []PriceEntry
	ReturnTime Timestamp
}

type ExchangeResponse added in v0.1.1

type ExchangeResponse struct {
	Exchanges map[string]*ExchangeSetting `json:"exchanges"`
	Version   uint64                      `json:"version"`
}

func NewExchangeResponse added in v0.1.1

func NewExchangeResponse(exs map[string]*ExchangeSetting, version uint64) *ExchangeResponse

type ExchangeSetting added in v0.1.1

type ExchangeSetting struct {
	DepositAddress ExchangeAddresses   `json:"deposit_address"`
	MinDeposit     ExchangesMinDeposit `json:"min_deposit"`
	Fee            ExchangeFees        `json:"fee"`
	Info           ExchangeInfo        `json:"info"`
}

ExchangeSetting contain the composition of settings necessary for an exchange It is use mainly to group all the setting for DB operations

func NewExchangeSetting added in v0.1.1

func NewExchangeSetting(depoAddr ExchangeAddresses, minDep ExchangesMinDeposit, fee ExchangeFees, info ExchangeInfo) *ExchangeSetting

NewExchangeSetting returns a pointer to A newly created ExchangeSetting instance

type ExchangeTokenNoti added in v0.1.1

type ExchangeTokenNoti map[string]ExchangeNotiContent

type ExchangeTradeHistory added in v0.1.1

type ExchangeTradeHistory map[TokenPairID][]TradeHistory

type ExchangesMinDeposit added in v0.1.1

type ExchangesMinDeposit map[string]float64

type ExchangesStatus added in v0.1.1

type ExchangesStatus map[string]ExStatus

type FeeSetRate added in v0.1.1

type FeeSetRate struct {
	TimeStamp     uint64     `json:"timeStamp"`
	GasUsed       *big.Float `json:"gasUsed"`
	TotalGasSpent *big.Float `json:"totalGasSpent"`
}

type FeedConfiguration added in v0.1.1

type FeedConfiguration struct {
	Name    string `json:"name"`
	Enabled bool   `json:"enabled"`
}

type FeedSetting added in v0.1.2

type FeedSetting struct {
	BaseVolatilitySpread float64 `json:"base_volatility_spread"`
	NormalSpread         float64 `json:"normal_spread"`
}

FeedSetting setting for feed configuration

type FetcherConfiguration added in v0.1.1

type FetcherConfiguration struct {
	BTC bool `json:"btc" binding:"exists"`
}

FetcherConfiguration is configuration of fetcher

type FundingFee added in v0.1.1

type FundingFee struct {
	Withdraw map[string]float64
	Deposit  map[string]float64
}

func NewFundingFee added in v0.1.1

func NewFundingFee(widthraw, deposit map[string]float64) FundingFee

NewFundingFee creates a new instance of FundingFee instance.

func (FundingFee) GetTokenFee added in v0.1.1

func (ff FundingFee) GetTokenFee(token string) float64

type GDAXGoldData added in v0.1.1

type GDAXGoldData struct {
	Valid   bool
	Error   string
	TradeID uint64 `json:"trade_id"`
	Price   string `json:"price"`
	Size    string `json:"size"`
	Bid     string `json:"bid"`
	Ask     string `json:"ask"`
	Volume  string `json:"volume"`
	Time    string `json:"time"`
}

type GeminiETHBTCData added in v0.1.2

type GeminiETHBTCData struct {
	Valid  bool
	Error  string
	Bid    string             `json:"bid"`
	Ask    string             `json:"ask"`
	Volume GeminiVolumeETHBTC `json:"volume"`
	Last   string             `json:"last"`
}

GeminiETHBTCData is the data returns by Gemini ETH/BTC ticker. Example: https://api.gemini.com/v1/pubticker/ethbtc Response

{
 "bid": "0.02686",
 "ask": "0.02694",
 "volume": {
   "ETH": "5595.131076",
   "BTC": "149.60020830467",
   "timestamp": 1557728700000
 },
 "last": "0.02694"
}

type GeminiGoldData added in v0.1.1

type GeminiGoldData struct {
	Valid  bool
	Error  string
	Bid    string `json:"bid"`
	Ask    string `json:"ask"`
	Volume struct {
		ETH       string `json:"ETH"`
		USD       string `json:"USD"`
		Timestamp uint64 `json:"timestamp"`
	} `json:"volume"`
	Last string `json:"last"`
}

type GeminiVolumeETHBTC added in v0.1.2

type GeminiVolumeETHBTC struct {
	ETH       string `json:"ETH"`
	BTC       string `json:"BTC"`
	Timestamp uint64 `json:"timestamp"`
}

type GoldData added in v0.1.1

type GoldData struct {
	Timestamp   uint64
	DGX         DGXGoldData
	OneForgeETH OneForgeGoldData
	OneForgeUSD OneForgeGoldData
	GDAX        GDAXGoldData
	Kraken      KrakenGoldData
	Gemini      GeminiGoldData
}

type GoldRate added in v0.1.1

type GoldRate struct {
	Symbol string  `json:"symbol"`
	Price  float64 `json:"price"`
	Time   uint64  `json:"time"`
}

type HitData added in v0.1.2

type HitData struct {
	Valid       bool
	Error       string
	Ask         string `json:"ask"`
	Bid         string `json:"bid"`
	Last        string `json:"last"`
	Open        string `json:"open"`
	Low         string `json:"low"`
	High        string `json:"high"`
	Volume      string `json:"volume"`
	VolumeQuote string `json:"volumeQuote"`
	Timestamp   string `json:"timestamp"`
	Symbol      string `json:"symbol"`
}

HitData ...

type ImbalanceStepFunction added in v0.1.1

type ImbalanceStepFunction struct {
	XBuy  []*big.Int `json:"x_buy"`
	YBuy  []*big.Int `json:"y_buy"`
	XSell []*big.Int `json:"x_sell"`
	YSell []*big.Int `json:"y_sell"`
}

ImbalanceStepFunction represent an imbalance step function for a token

type KrakenGoldData added in v0.1.1

type KrakenGoldData struct {
	Valid           bool
	Error           string        `json:"network_error"`
	ErrorFromKraken []interface{} `json:"error"`
	Result          map[string]struct {
		A []string `json:"a"`
		B []string `json:"b"`
		C []string `json:"c"`
		V []string `json:"v"`
		P []string `json:"p"`
		T []uint64 `json:"t"`
		L []string `json:"l"`
		H []string `json:"h"`
		O string   `json:"o"`
	} `json:"result"`
}

type MapFeedSetting added in v0.1.2

type MapFeedSetting map[string]FeedSetting

MapFeedSetting map feed name with feed setting

type MetricEntry added in v0.1.1

type MetricEntry struct {
	Timestamp uint64
	// data contain all token metric for all tokens
	Data map[string]TokenMetric
}

type MetricList added in v0.1.1

type MetricList []TokenMetricResponse

MetricList list for one token

type MetricResponse added in v0.1.1

type MetricResponse struct {
	Timestamp  uint64
	ReturnTime uint64
	Data       map[string]MetricList
}

type OneForgeGoldData added in v0.1.1

type OneForgeGoldData struct {
	Value     float64 `json:"value"`
	Text      string  `json:"text"`
	Timestamp uint64  `json:"timestamp"`
	Error     bool    `json:"error"`
	Message   string  `json:"message"`
}

type OnePrice

type OnePrice map[ExchangeID]ExchangePrice

type OnePriceResponse

type OnePriceResponse struct {
	Version    Version
	Timestamp  Timestamp
	ReturnTime Timestamp
	Data       OnePrice
	Block      uint64
}

type Order

type Order struct {
	ID          string // standard id across multiple exchanges
	Base        string
	Quote       string
	OrderID     string
	Price       float64
	OrigQty     float64 // original quantity
	ExecutedQty float64 // matched quantity
	TimeInForce string
	Type        string // market or limit
	Side        string // buy or sell
	StopPrice   string
	IcebergQty  string
	Time        uint64
}

type OrderEntry

type OrderEntry struct {
	Valid      bool
	Error      string
	Timestamp  Timestamp
	ReturnTime Timestamp
	Data       []Order
}

type PWIEquation added in v0.1.1

type PWIEquation struct {
	ID   uint64 `json:"id"`
	Data string `json:"data"`
}

type PWIEquationRequestV2 added in v0.1.1

type PWIEquationRequestV2 map[string]PWIEquationTokenV2

PWIEquationRequestV2 is the input SetPWIEquationV2 api.

func (PWIEquationRequestV2) Validate added in v0.1.1

func (input PWIEquationRequestV2) Validate() error

Validate returns nil if the input is valid, otherwise it will return an error with detail which field is invalid. Example input: [{"token_id": {equation_token}}, ...]

type PWIEquationTokenV2 added in v0.1.1

type PWIEquationTokenV2 map[string]PWIEquationV2

PWIEquationTokenV2 is a mapping between a token id and a PWI equation.

type PWIEquationV2 added in v0.1.1

type PWIEquationV2 struct {
	A                   float64 `json:"a"`
	B                   float64 `json:"b"`
	C                   float64 `json:"c"`
	MinMinSpread        float64 `json:"min_min_spread"`
	PriceMultiplyFactor float64 `json:"price_multiply_factor"`
}

PWIEquationV2 contains the information of a PWI equation.

type PriceEntry

type PriceEntry struct {
	Quantity float64
	Rate     float64
}

func NewPriceEntry added in v0.1.1

func NewPriceEntry(quantity, rate float64) PriceEntry

NewPriceEntry creates new instance of PriceEntry.

type QuantityStepFunction added in v0.1.1

type QuantityStepFunction struct {
	XBuy  []*big.Int `json:"x_buy"`
	YBuy  []*big.Int `json:"y_buy"`
	XSell []*big.Int `json:"x_sell"`
	YSell []*big.Int `json:"y_sell"`
}

QuantityStepFunction represent a quatity step function for a token

type RateEntry

type RateEntry struct {
	BaseBuy     *big.Int
	CompactBuy  int8
	BaseSell    *big.Int
	CompactSell int8
	Block       uint64
}

RateEntry contains the buy/sell rates of a token and their compact forms.

func NewRateEntry added in v0.1.1

func NewRateEntry(baseBuy *big.Int, compactBuy int8, baseSell *big.Int, compactSell int8, block uint64) RateEntry

NewRateEntry creates a new RateEntry instance.

type RateResponse

type RateResponse struct {
	Timestamp   Timestamp
	ReturnTime  Timestamp
	BaseBuy     float64
	CompactBuy  int8
	BaseSell    float64
	CompactSell int8
	Rate        float64
	Block       uint64
}

RateResponse is the human friendly format of a rate entry to returns in HTTP APIs.

type RawBalance

type RawBalance big.Int

func (RawBalance) MarshalJSON

func (rb RawBalance) MarshalJSON() ([]byte, error)

func (*RawBalance) ToFloat

func (rb *RawBalance) ToFloat(decimal int64) float64

func (*RawBalance) UnmarshalJSON

func (rb *RawBalance) UnmarshalJSON(text []byte) error

type RebalanceControl added in v0.1.1

type RebalanceControl struct {
	Status bool `json:"status"`
}

RebalanceControl represent status of rebalance, true is enable and false is disable

type RebalanceQuadraticEquation added in v0.1.1

type RebalanceQuadraticEquation struct {
	RebalanceQuadratic struct {
		A float64 `json:"a"`
		B float64 `json:"b"`
		C float64 `json:"c"`
	} `json:"rebalance_quadratic"`
}

RebalanceQuadraticEquation represent an equation

type RebalanceQuadraticRequest added in v0.1.1

type RebalanceQuadraticRequest map[string]RebalanceQuadraticEquation

RebalanceQuadraticRequest represent data request to set rebalance quadratic map[token]equation

type RunnerConfig added in v0.1.2

type RunnerConfig struct {
	OrderBookFetchingInterval  time.Duration
	AuthDataFetchingInterval   time.Duration
	RateFetchingInterval       time.Duration
	BlockFetchingInterval      time.Duration
	GlobalDataFetchingInterval time.Duration
}

RunnerConfig list configs for runner

type SetRateTxInfo added in v0.1.1

type SetRateTxInfo struct {
	BlockNumber      string `json:"blockNumber"`
	TimeStamp        string `json:"timeStamp"`
	TransactionIndex string `json:"transactionIndex"`
	Input            string `json:"input"`
	GasPrice         string `json:"gasPrice"`
	GasUsed          string `json:"gasUsed"`
}

type SetrateControl added in v0.1.1

type SetrateControl struct {
	Status bool `json:"status"`
}

SetrateControl represent status of set rate ability, true is enable and false is disable

type StepFunctionResponse added in v0.1.1

type StepFunctionResponse struct {
	QuantityStepResponse  QuantityStepFunction  `json:"quantity_step_function"`
	ImbalanceStepResponse ImbalanceStepFunction `json:"imbalance_step_function"`
}

StepFunctionResponse api response about a token step function

type StoreSetRateTx added in v0.1.1

type StoreSetRateTx struct {
	TimeStamp uint64 `json:"timeStamp"`
	GasPrice  uint64 `json:"gasPrice"`
	GasUsed   uint64 `json:"gasUsed"`
}

type TXEntry added in v0.1.1

type TXEntry struct {
	Hash           string
	Exchange       string
	Token          string
	MiningStatus   string
	ExchangeStatus string
	Amount         float64
	Timestamp      Timestamp
}

func NewTXEntry added in v0.1.1

func NewTXEntry(hash, exchange, token, miningStatus, exchangeStatus string, amount float64, timestamp Timestamp) TXEntry

NewTXEntry creates new instance of TXEntry.

type TargetQtySet added in v0.1.1

type TargetQtySet struct {
	TotalTarget        float64 `json:"total_target"`
	ReserveTarget      float64 `json:"reserve_target"`
	RebalanceThreshold float64 `json:"rebalance_threshold"`
	TransferThreshold  float64 `json:"transfer_threshold"`
}

TargetQtySet represent a set of target quantity

type TargetQtyV2 added in v0.1.1

type TargetQtyV2 struct {
	SetTarget        TargetQtySet       `json:"set_target"`
	RecommendBalance map[string]float64 `json:"recomend_balance,omitempty"`
	ExchangeRatio    map[string]float64 `json:"exchange_ratio,omitempty"`
}

TargetQtyV2 object for save target qty

type TestExchange added in v0.1.1

type TestExchange struct {
}

func (TestExchange) Address added in v0.1.1

func (te TestExchange) Address(token Token) (address ethereum.Address, supported bool)

func (TestExchange) CancelOrder added in v0.1.1

func (te TestExchange) CancelOrder(id, base, quote string) error

func (TestExchange) GetExchangeInfo added in v0.1.1

func (te TestExchange) GetExchangeInfo(pair TokenPairID) (ExchangePrecisionLimit, error)

func (TestExchange) GetFee added in v0.1.1

func (te TestExchange) GetFee() (ExchangeFees, error)

func (TestExchange) GetInfo added in v0.1.1

func (te TestExchange) GetInfo() (ExchangeInfo, error)

func (TestExchange) GetLiveExchangeInfos added in v0.1.1

func (te TestExchange) GetLiveExchangeInfos(tokenPairIDs []TokenPairID) (ExchangeInfo, error)

func (TestExchange) GetMinDeposit added in v0.1.1

func (te TestExchange) GetMinDeposit() (ExchangesMinDeposit, error)

func (TestExchange) GetTradeHistory added in v0.1.1

func (te TestExchange) GetTradeHistory(fromTime, toTime uint64) (ExchangeTradeHistory, error)

func (TestExchange) ID added in v0.1.1

func (te TestExchange) ID() ExchangeID

func (TestExchange) MarshalText added in v0.1.1

func (te TestExchange) MarshalText() (text []byte, err error)

func (TestExchange) Trade added in v0.1.1

func (te TestExchange) Trade(tradeType string, base Token, quote Token, rate float64, amount float64, timepoint uint64) (id string, done float64, remaining float64, finished bool, err error)

func (TestExchange) UpdateDepositAddress added in v0.1.1

func (te TestExchange) UpdateDepositAddress(token Token, address string) error

func (TestExchange) Withdraw added in v0.1.1

func (te TestExchange) Withdraw(token Token, amount *big.Int, address ethereum.Address, timepoint uint64) (string, error)

type Timestamp

type Timestamp string

func GetTimestamp

func GetTimestamp() Timestamp

func (Timestamp) MustToUint64 added in v0.1.1

func (ts Timestamp) MustToUint64() uint64

type Token

type Token struct {
	ID                   string `json:"id"`
	Name                 string `json:"name"`
	Address              string `json:"address"`
	Decimals             int64  `json:"decimals"`
	Active               bool   `json:"active"`
	Internal             bool   `json:"internal"`
	LastActivationChange uint64 `json:"last_activation_change"`
	CreationTime         uint64 `json:"creation_time"`
}

func NewToken added in v0.1.1

func NewToken(id, name, address string, decimal int64, active, internal bool, timepoint uint64) Token

NewToken creates a new Token.

func (Token) IsETH

func (t Token) IsETH() bool

type TokenExchangeSetting added in v0.1.1

type TokenExchangeSetting struct {
	DepositAddress string       `json:"deposit_address"`
	Info           ExchangeInfo `json:"exchange_info"`
	Fee            TokenFee     `json:"fee"`
	MinDeposit     float64      `json:"min_deposit"`
}

TokenExchangeSetting contains necessary information on exchange to List a token on the fly

type TokenFee added in v0.1.1

type TokenFee struct {
	Withdraw float64 `json:"withdraw"`
	Deposit  float64 `json:"deposit"`
}

type TokenMetric added in v0.1.1

type TokenMetric struct {
	AfpMid float64
	Spread float64
}

type TokenMetricResponse added in v0.1.1

type TokenMetricResponse struct {
	Timestamp uint64
	AfpMid    float64
	Spread    float64
}

type TokenPair

type TokenPair struct {
	Base  Token
	Quote Token
}

func NewTokenPair

func NewTokenPair(base, quote Token) TokenPair

func (*TokenPair) GetBaseQuoteID added in v0.1.1

func (tp *TokenPair) GetBaseQuoteID() (string, string)

GetBaseQuoteID return base and quoteID as strings

func (*TokenPair) PairID

func (tp *TokenPair) PairID() TokenPairID

type TokenPairAmountLimit added in v0.1.1

type TokenPairAmountLimit struct {
	Min float64 `json:"min"`
	Max float64 `json:"max"`
}

TokenPairAmountLimit represent amount min and max when trade a token pair

type TokenPairID

type TokenPairID string

func NewTokenPairID

func NewTokenPairID(base, quote string) TokenPairID

type TokenPairPrecision added in v0.1.1

type TokenPairPrecision struct {
	Amount int `json:"amount"`
	Price  int `json:"price"`
}

TokenPairPrecision represent precision when trading a token pair

type TokenPairPriceLimit added in v0.1.1

type TokenPairPriceLimit struct {
	Min float64 `json:"min"`
	Max float64 `json:"max"`
}

type TokenResponse added in v0.1.1

type TokenResponse struct {
	Tokens  []Token `json:"tokens"`
	Version uint64  `json:"version"`
}

func NewTokenResponse added in v0.1.1

func NewTokenResponse(tokens []Token, version uint64) *TokenResponse

type TokenTargetQty added in v0.1.1

type TokenTargetQty struct {
	ID        uint64
	Timestamp uint64
	Data      string
	Status    string
	Type      int64
}

type TokenTargetQtyV2 added in v0.1.1

type TokenTargetQtyV2 map[string]TargetQtyV2

TokenTargetQtyV2 represent a map of token and its target quantity struct

type TokenUpdate added in v0.1.1

type TokenUpdate struct {
	Token       Token                           `json:"token"`
	Exchanges   map[string]TokenExchangeSetting `json:"exchanges"`
	PWIEq       PWIEquationTokenV2              `json:"pwis_equation"`
	TargetQty   TargetQtyV2                     `json:"target_qty"`
	QuadraticEq RebalanceQuadraticEquation      `json:"rebalance_quadratic"`
}

type TradeHistory added in v0.1.1

type TradeHistory struct {
	ID        string
	Price     float64
	Qty       float64
	Type      string // buy or sell
	Timestamp uint64
}

func NewTradeHistory added in v0.1.1

func NewTradeHistory(id string, price, qty float64, typ string, timestamp uint64) TradeHistory

NewTradeHistory creates a new TradeHistory instance. typ: "buy" or "sell"

type TradingFee added in v0.1.1

type TradingFee map[string]float64

type TransactionInfo added in v0.1.1

type TransactionInfo struct {
	BlockNumber string `json:"blockNumber"`
	TimeStamp   string `json:"timeStamp"`
	Value       string `json:"value"`
	GasPrice    string `json:"gasPrice"`
	GasUsed     string `json:"gasUsed"`
}

type USDData added in v0.1.1

type USDData struct {
	Timestamp    uint64
	CoinbaseUSD  CoinbaseData   `json:"CoinbaseUSD"`
	GeminiUSD    GeminiGoldData `json:"GeminiUSD"` // gold and usd use the same url
	CoinbaseUSDC CoinbaseData   `json:"CoinbaseUSDC"`
	BinanceUSDC  BinanceData    `json:"BinanceUSDC"`
	CoinbaseDAI  CoinbaseData   `json:"CoinbaseDAI"`
	HitDAI       HitData        `json:"HitDAI"`
	BitFinex     BitFinexData   `json:"BitFinexUSD"`
	BinanceUSDT  BinanceData    `json:"BinanceUSDT"`
	BinancePAX   BinanceData    `json:"BinancePAX"`
	BinanceTUSD  BinanceData    `json:"BinanceTUSD"`
}

USDData ...

type Version

type Version uint64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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