mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
* Adding Public Endpoints and test functions * Adding public endpoints and test functions * Adding private spot endpoints * Adding private endpoints and corresponding tests for margin * Adding Margin Private endpoints * Adding cross margin and flash swap endpoints * Adding futures private endpoints * Adding futures private endpoints and corresponding tests * Adding Options and SubAccount endpoints and their unit tests * Adding Wrapper functions * Complete wrapper functions and corresponding unit test functions * Fixing wrapper issues and adding websocket functions * Update of Spot websocket and adding futures websocket handlers * completed futures WS push data endpoints * Completed Options websocket endpoints * Adding websocket support for delivery futures and slight update on endpoint funcs * Added Delivery websocket support and fix linter issues * Update on Unit tests * fix slight currency format error * Fix slight endpoint tempos * Update on conditional statements and unit tests issues * fixing slight tempos * Slight model and websocket data push method change * Fix unit test tempos and updating models * Fix on code structures and update on unit tests * Slight code fix * Remove print statements * Update on tradable pairs fetch eps * Fix websocket tempos * Adding types to websocket routine manager * Fix slight issues * Slight fixes * Updating wrapper funcs and models * Slight update * Update on test * Update on tradable pairs * update conditional statements * Fixing slight issues * Updating unit tests * Minor fixes depending review comments * Remove redundant method declaration * Adding missing intervals * Updating fetch tradable pairs * update tradable pairs issues * Addressing small tempos * Slight fix on ticker * Minor Fixes * Minor review comment fixes * Unit test and minor code updates * Slight code updates * Minor updates depending review comments * Fixes * Updating incoming message matcher * Fix missing merge issue * Fix minor wrapper issues * Updating ratelimit and other issues * Updating endpoint models and adding missing eps * Update on code structure and models * Minor codespell fixes * Minor update on models * fix unit test panic * Minor race fix * Fix issues in generating signature and unit tests * Minor update on wrapper and unit tests * Minor fix on wrapper * Mini linter issues fix * Minor fix * endpoint fixes and slight update * Minor fixes * Updating exchange functions and unit tests * Unit test and wrapper updates * Remove options candlestick support * Minor unit test and wrapper fix * Unit test update * minor fix on unit test and wrapper * endpoints constants name change * Add minor wrapper issues * endpoint constants update * endpoint url updates * Updating subscriptions * fixing dual mode endpoint methods * minor fix * rm small tempo * Update on websocket orderbook handling * Orderbook and currency pair update * fix linter and test issues * minor helper function update * Fix wrapper coverage and wrapper issues * delete unused variables * Minor fix on ReadData() call * separating websocket handlers * separating websocket handlers * Minor fix on enabled pair * minor fix * check instrument availability in spot * create a separate subscriber for sake of multiple websocket connection * linter fix * minor websocket and gateio endpoints fix * fix nil pointer exception * minor fixes * spelling fix decerializes -> deserializes * fix Bitfinex unit test issues * minor unknown currency pair labling fix * minor currency pair handling fix * slight update on GetDepositAddress wrapper unit test * setting max request job to 200 * fixing numerical and timestamp type convert * fix value overflow error * change method of parsing orderbook price * unifying timestamp conversion types to gateioTime --------- Co-authored-by: Samuael Adnew <samuaelad@Samuaels-MacBook-Air.local>
224 lines
5.4 KiB
Go
224 lines
5.4 KiB
Go
package asset
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
// ErrNotSupported is an error for an unsupported asset type
|
|
ErrNotSupported = errors.New("unsupported asset type")
|
|
)
|
|
|
|
// Item stores the asset type
|
|
type Item uint32
|
|
|
|
// Items stores a list of assets types
|
|
type Items []Item
|
|
|
|
// Const vars for asset package
|
|
const (
|
|
Empty Item = 0
|
|
Spot Item = 1 << iota
|
|
Margin
|
|
CrossMargin
|
|
MarginFunding
|
|
Index
|
|
Binary
|
|
PerpetualContract
|
|
PerpetualSwap
|
|
Futures
|
|
DeliveryFutures
|
|
UpsideProfitContract
|
|
DownsideProfitContract
|
|
CoinMarginedFutures
|
|
USDTMarginedFutures
|
|
USDCMarginedFutures
|
|
Options
|
|
|
|
futuresFlag = PerpetualContract | PerpetualSwap | Futures | DeliveryFutures | UpsideProfitContract | DownsideProfitContract | CoinMarginedFutures | USDTMarginedFutures | USDCMarginedFutures
|
|
supportedFlag = Spot | Margin | CrossMargin | MarginFunding | Index | Binary | PerpetualContract | PerpetualSwap | Futures | DeliveryFutures | UpsideProfitContract | DownsideProfitContract | CoinMarginedFutures | USDTMarginedFutures | USDCMarginedFutures | Options
|
|
|
|
spot = "spot"
|
|
margin = "margin"
|
|
crossMargin = "cross_margin" // for Gateio exchange
|
|
marginFunding = "marginfunding"
|
|
index = "index"
|
|
binary = "binary"
|
|
perpetualContract = "perpetualcontract"
|
|
perpetualSwap = "perpetualswap"
|
|
futures = "futures"
|
|
deliveryFutures = "delivery"
|
|
upsideProfitContract = "upsideprofitcontract"
|
|
downsideProfitContract = "downsideprofitcontract"
|
|
coinMarginedFutures = "coinmarginedfutures"
|
|
usdtMarginedFutures = "usdtmarginedfutures"
|
|
usdcMarginedFutures = "usdcmarginedfutures"
|
|
options = "options"
|
|
)
|
|
|
|
var (
|
|
supportedList = Items{Spot, Margin, CrossMargin, MarginFunding, Index, Binary, PerpetualContract, PerpetualSwap, Futures, DeliveryFutures, UpsideProfitContract, DownsideProfitContract, CoinMarginedFutures, USDTMarginedFutures, USDCMarginedFutures, Options}
|
|
)
|
|
|
|
// Supported returns a list of supported asset types
|
|
func Supported() Items {
|
|
return supportedList
|
|
}
|
|
|
|
// String converts an Item to its string representation
|
|
func (a Item) String() string {
|
|
switch a {
|
|
case Spot:
|
|
return spot
|
|
case Margin:
|
|
return margin
|
|
case CrossMargin:
|
|
return crossMargin
|
|
case MarginFunding:
|
|
return marginFunding
|
|
case Index:
|
|
return index
|
|
case Binary:
|
|
return binary
|
|
case PerpetualContract:
|
|
return perpetualContract
|
|
case PerpetualSwap:
|
|
return perpetualSwap
|
|
case Futures:
|
|
return futures
|
|
case DeliveryFutures:
|
|
return deliveryFutures
|
|
case UpsideProfitContract:
|
|
return upsideProfitContract
|
|
case DownsideProfitContract:
|
|
return downsideProfitContract
|
|
case CoinMarginedFutures:
|
|
return coinMarginedFutures
|
|
case USDTMarginedFutures:
|
|
return usdtMarginedFutures
|
|
case USDCMarginedFutures:
|
|
return usdcMarginedFutures
|
|
case Options:
|
|
return options
|
|
default:
|
|
return ""
|
|
}
|
|
}
|
|
|
|
// Strings converts an asset type array to a string array
|
|
func (a Items) Strings() []string {
|
|
assets := make([]string, len(a))
|
|
for x := range a {
|
|
assets[x] = a[x].String()
|
|
}
|
|
return assets
|
|
}
|
|
|
|
// Contains returns whether or not the supplied asset exists
|
|
// in the list of Items
|
|
func (a Items) Contains(i Item) bool {
|
|
if i.IsValid() {
|
|
for x := range a {
|
|
if a[x] == i {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// JoinToString joins an asset type array and converts it to a string
|
|
// with the supplied separator
|
|
func (a Items) JoinToString(separator string) string {
|
|
return strings.Join(a.Strings(), separator)
|
|
}
|
|
|
|
// IsValid returns whether or not the supplied asset type is valid or
|
|
// not
|
|
func (a Item) IsValid() bool {
|
|
return a != Empty && supportedFlag&a == a
|
|
}
|
|
|
|
// UnmarshalJSON comforms type to the umarshaler interface
|
|
func (a *Item) UnmarshalJSON(d []byte) error {
|
|
var assetString string
|
|
err := json.Unmarshal(d, &assetString)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if assetString == "" {
|
|
return nil
|
|
}
|
|
|
|
ai, err := New(assetString)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
*a = ai
|
|
return nil
|
|
}
|
|
|
|
// MarshalJSON comforms type to the marshaller interface
|
|
func (a Item) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(a.String())
|
|
}
|
|
|
|
// New takes an input matches to relevant package assets
|
|
func New(input string) (Item, error) {
|
|
input = strings.ToLower(input)
|
|
switch input {
|
|
case spot:
|
|
return Spot, nil
|
|
case margin:
|
|
return Margin, nil
|
|
case marginFunding:
|
|
return MarginFunding, nil
|
|
case crossMargin:
|
|
return CrossMargin, nil
|
|
case deliveryFutures:
|
|
return DeliveryFutures, nil
|
|
case index:
|
|
return Index, nil
|
|
case binary:
|
|
return Binary, nil
|
|
case perpetualContract:
|
|
return PerpetualContract, nil
|
|
case perpetualSwap:
|
|
return PerpetualSwap, nil
|
|
case futures:
|
|
return Futures, nil
|
|
case upsideProfitContract:
|
|
return UpsideProfitContract, nil
|
|
case downsideProfitContract:
|
|
return DownsideProfitContract, nil
|
|
case coinMarginedFutures:
|
|
return CoinMarginedFutures, nil
|
|
case usdtMarginedFutures:
|
|
return USDTMarginedFutures, nil
|
|
case usdcMarginedFutures:
|
|
return USDCMarginedFutures, nil
|
|
case options, "option":
|
|
return Options, nil
|
|
default:
|
|
return 0, fmt.Errorf("%w '%v', only supports %s",
|
|
ErrNotSupported,
|
|
input,
|
|
supportedList)
|
|
}
|
|
}
|
|
|
|
// UseDefault returns default asset type
|
|
func UseDefault() Item {
|
|
return Spot
|
|
}
|
|
|
|
// IsFutures checks if the asset type is a futures contract based asset
|
|
func (a Item) IsFutures() bool {
|
|
return a != Empty && futuresFlag&a == a
|
|
}
|