mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
* public endpoints methods added * Completing mapping REST endpoints * Binanceus Wrapper methods -Partially * Binanceus Wrapper methods -Partially * BinaWra functions with test funs; Not Completed * Finalizing wrapper methods & test * Fix & Complete wrapper functions * Finalizing wrapper methods & test * Adding Stream Datas * WS Test functions * CI: Fix golangci-lint linter issues * CI: Fix reverting unnessesary changes and type conversion issues * CI: Fix reverting unnessesary changes and type conversion issues * Adding Public endpoints and tests * Adding Market and Public Endpoints * Adding Public endoints * Public Trading Endpoints & Authenticated Trade order methods * Adding Authenticated Methods and Tests * Adding algo and Funding Authenticated endpoints * Adding funding trading endpoints and correspondint tests * adding authenticated endpoints * Completing Block Trading endpoints and added subaccount endpoints * Completing sub account and grid Trading endpoints * Adding Rate Limit and missing endpoints * Wrapper and Websocket handlers * Fixing Websocket Test and Push Data Handler Issues * Fixing Websocket Test and Push Data Handler Issues * Fixing linter issues, package dependency, and other slight tempos * Fixing linter and slight tempos * Update on test functions, and Rest and Websocket Endpoint handlers * Remove okex, adding comments, and slight fixes on endpoints. * Fixing linter issues and adding comments * Slight code changes, updating documentation, and n and linter issues * Fix context and configuration endpoint issues * slight fixes on config and test files * adding some missing test and fix linter issues * fix linter issue * Slight fixes on code structure, shorthand exp,and ot and other * Fix slight linter issue * Slight code fixes and fixing linter issues * fixing linter iissues * fixing linter iissues * slight linter issue fix * slight linter issue fix * Fix on models, type convert funcs and endpoints * Adding Error messages map and update of models * Fix on error message string and linter issues * Fix slight linter issue * Fix slight linter issue * Fixing type converts, models, and linter issues * Adding Ws fixes * Slight fix on websocket and other issues * Adding slight websocket fixes * Remove 'books5' channel default subscription * Small changes on default subscription and checksum * Fix slight websocket tempos * Fix Wrapper function tempost and linter issues * Resolving slight naming and other issues * Resolve slight pointer issues * resolve slight linter issues * Resolve config files issue * Update websocket and wrapper funcs with test and docs * fixs on websocket multiplexer, types, and other slight issues * fix slight linter issues * slight update on web-socket orderbook and tickers * fix slight issues and websocket runtime errors * Slight unit test fix and assing simple semaphore * FIx race issue * Update on authenticated endpoints * Fix wsSetupRun check in websocket 'setupWsAuth' func * Update wsSetupRun check in websocket 'setupWsAuth' func * Slight update on websocket handling * Fix some race conditions * fix slight tempos * fix authenticated test issues * Update on conditional statements * slight update on unit test * fix unit test tempos * Fix slight tempos * Change check map from struct valued to bool valued * slight fix trial * Slight unit test update * Fix websocket timeout error * Updating websocket subscription endpoints, and unit tests * update unit tests * Slight issue on wrapper method 'GetActiveOrders' * Overall code update * Addressing missing review comments * Fix unit test tempo and linter issue * Monor fix * Slight update * Slight unit test fix * Slight fixes * Slight fixes * Fixing on missing review comments * Adding WS Fixes * slight fix * Monor fix on unit test * Minor convert issue * Minor change on WS * Monor logic fix * Fix code structure and logic issues * Fixing small typos * fix slight data format issue * Update on trade and order wrapper methods * Adding slight update * fix on order detail * Slight update on FetchTradablePairs wrapper method * Slight update on wrapper * Update on deserialization and other slight issues * Final update * Resolve missing review comments * Slight update on config and unit test * minor fix on GetDepositAddress param * Minor fix
147 lines
3.8 KiB
Go
147 lines
3.8 KiB
Go
package currency
|
|
|
|
import (
|
|
"encoding/json"
|
|
)
|
|
|
|
// EMPTYFORMAT defines an empty pair format
|
|
var EMPTYFORMAT = PairFormat{}
|
|
|
|
// String returns a currency pair string
|
|
func (p Pair) String() string {
|
|
return p.Base.String() + p.Delimiter + p.Quote.String()
|
|
}
|
|
|
|
// Lower converts the pair object to lowercase
|
|
func (p Pair) Lower() Pair {
|
|
p.Base = p.Base.Lower()
|
|
p.Quote = p.Quote.Lower()
|
|
return p
|
|
}
|
|
|
|
// Upper converts the pair object to uppercase
|
|
func (p Pair) Upper() Pair {
|
|
p.Base = p.Base.Upper()
|
|
p.Quote = p.Quote.Upper()
|
|
return p
|
|
}
|
|
|
|
// UnmarshalJSON comforms type to the umarshaler interface
|
|
func (p *Pair) UnmarshalJSON(d []byte) error {
|
|
var pair string
|
|
err := json.Unmarshal(d, &pair)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if pair == "" {
|
|
*p = EMPTYPAIR
|
|
return nil
|
|
}
|
|
|
|
newPair, err := NewPairFromString(pair)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
*p = newPair
|
|
return nil
|
|
}
|
|
|
|
// MarshalJSON conforms type to the marshaler interface
|
|
func (p Pair) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(p.String())
|
|
}
|
|
|
|
// Format changes the currency based on user preferences overriding the default
|
|
// String() display
|
|
func (p Pair) Format(pf PairFormat) Pair {
|
|
p.Delimiter = pf.Delimiter
|
|
if pf.Uppercase {
|
|
return p.Upper()
|
|
}
|
|
return p.Lower()
|
|
}
|
|
|
|
// Equal compares two currency pairs and returns whether or not they are equal
|
|
func (p Pair) Equal(cPair Pair) bool {
|
|
return p.Base.Equal(cPair.Base) && p.Quote.Equal(cPair.Quote)
|
|
}
|
|
|
|
// EqualIncludeReciprocal compares two currency pairs and returns whether or not
|
|
// they are the same including reciprocal currencies.
|
|
func (p Pair) EqualIncludeReciprocal(cPair Pair) bool {
|
|
return (p.Base.Equal(cPair.Base) && p.Quote.Equal(cPair.Quote)) ||
|
|
(p.Base.Equal(cPair.Quote) && p.Quote.Equal(cPair.Base))
|
|
}
|
|
|
|
// IsCryptoPair checks to see if the pair is a crypto pair e.g. BTCLTC
|
|
func (p Pair) IsCryptoPair() bool {
|
|
return p.Base.IsCryptocurrency() && p.Quote.IsCryptocurrency()
|
|
}
|
|
|
|
// IsCryptoFiatPair checks to see if the pair is a crypto fiat pair e.g. BTCUSD
|
|
func (p Pair) IsCryptoFiatPair() bool {
|
|
return (p.Base.IsCryptocurrency() && p.Quote.IsFiatCurrency()) ||
|
|
(p.Base.IsFiatCurrency() && p.Quote.IsCryptocurrency())
|
|
}
|
|
|
|
// IsFiatPair checks to see if the pair is a fiat pair e.g. EURUSD
|
|
func (p Pair) IsFiatPair() bool {
|
|
return p.Base.IsFiatCurrency() && p.Quote.IsFiatCurrency()
|
|
}
|
|
|
|
// IsCryptoStablePair checks to see if the pair is a crypto stable pair e.g.
|
|
// LTC-USDT
|
|
func (p Pair) IsCryptoStablePair() bool {
|
|
return (p.Base.IsCryptocurrency() && p.Quote.IsStableCurrency()) ||
|
|
(p.Base.IsStableCurrency() && p.Quote.IsCryptocurrency())
|
|
}
|
|
|
|
// IsStablePair checks to see if the pair is a stable pair e.g. USDT-DAI
|
|
func (p Pair) IsStablePair() bool {
|
|
return p.Base.IsStableCurrency() && p.Quote.IsStableCurrency()
|
|
}
|
|
|
|
// IsInvalid checks invalid pair if base and quote are the same
|
|
func (p Pair) IsInvalid() bool {
|
|
return p.Base.Equal(p.Quote)
|
|
}
|
|
|
|
// Swap turns the currency pair into its reciprocal
|
|
func (p Pair) Swap() Pair {
|
|
return Pair{Base: p.Quote, Quote: p.Base}
|
|
}
|
|
|
|
// IsEmpty returns whether or not the pair is empty or is missing a currency
|
|
// code
|
|
func (p Pair) IsEmpty() bool {
|
|
return p.Base.IsEmpty() && p.Quote.IsEmpty()
|
|
}
|
|
|
|
// Contains checks to see if a pair contains a specific currency
|
|
func (p Pair) Contains(c Code) bool {
|
|
return p.Base.Equal(c) || p.Quote.Equal(c)
|
|
}
|
|
|
|
// Len derives full length for match exclusion.
|
|
func (p Pair) Len() int {
|
|
return len(p.Base.String()) + len(p.Quote.String())
|
|
}
|
|
|
|
// Other returns the other currency from pair, if not matched returns empty code.
|
|
func (p Pair) Other(c Code) (Code, error) {
|
|
if p.Base.Equal(c) {
|
|
return p.Quote, nil
|
|
}
|
|
if p.Quote.Equal(c) {
|
|
return p.Base, nil
|
|
}
|
|
return EMPTYCODE, ErrCurrencyCodeEmpty
|
|
}
|
|
|
|
// IsPopulated returns true if the currency pair have both non-empty values for base and quote.
|
|
func (p Pair) IsPopulated() bool {
|
|
return !p.Base.IsEmpty() && !p.Quote.IsEmpty()
|
|
}
|