mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 07:26:47 +00:00
* init * surprise train commit * basic distinctions * the terms of binance are confusing * renames and introduction of allocatedMargin * add new margin funcs * pulling out wires * implement proper getposition stuff * bad coding day * investigate order manager next * a broken mess, but a progressing one * finally completes some usdtmargined stuff * coinMfutures eludes me * expand to okx * imports fix * completes okx wrapper implementations * cleans and polishes before rpc implementations * rpc setup, order manager features, exch features * more rpc, collateral and margin things * mini test * looking at rpc response, expansion of features * reorganising before the storm * changing how futures requests work * cleanup and tests of cli usage * remove silly client side logic * cleanup * collateral package, typo fix, margin err, rpc derive * uses convert.StringToFloat ONLY ON STRUCTS FROM THIS PR * fix binance order history bug * niteroos * adds new funcs to exchange standards testing * more post merge fixes * fix binance * replace simepletimeformat * fix for merge * merge fixes * micro fixes * order side now required for leverage * fix up the rest * global -> portfolio collateral * Update exchanges/collateral/collateral_test.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * adds fields and todos * rm field redundancy * lint fix oopsie daisy * fixes panic, expands error and cli explanations (sorry shaz) * ensures casing is appropriate for underlying * Adds a shiny TODO --------- Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
68 lines
1.5 KiB
Go
68 lines
1.5 KiB
Go
package margin
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// Valid returns whether the margin type is valid
|
|
func (t Type) Valid() bool {
|
|
return t != Unset && supported&t == t
|
|
}
|
|
|
|
// UnmarshalJSON converts json into margin type
|
|
func (t *Type) UnmarshalJSON(d []byte) error {
|
|
var marginType string
|
|
err := json.Unmarshal(d, &marginType)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*t, err = StringToMarginType(marginType)
|
|
return err
|
|
}
|
|
|
|
// String returns the string representation of the margin type in lowercase
|
|
// the absence of a lower func should hopefully highlight that String is lower
|
|
func (t Type) String() string {
|
|
switch t {
|
|
case Unset:
|
|
return unsetStr
|
|
case Isolated:
|
|
return isolatedStr
|
|
case Multi:
|
|
return multiStr
|
|
case Unknown:
|
|
return unknownStr
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// Upper returns the upper case string representation of the margin type
|
|
func (t Type) Upper() string {
|
|
return strings.ToUpper(t.String())
|
|
}
|
|
|
|
// IsValidString checks to see if the supplied string is a valid margin type
|
|
func IsValidString(m string) bool {
|
|
switch strings.ToLower(m) {
|
|
case isolatedStr, multiStr, unsetStr, crossedStr, crossStr:
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
// StringToMarginType converts a string to a margin type
|
|
// doesn't error, just returns unknown if the string is not recognised
|
|
func StringToMarginType(m string) (Type, error) {
|
|
switch strings.ToLower(m) {
|
|
case isolatedStr:
|
|
return Isolated, nil
|
|
case multiStr, crossedStr, crossStr:
|
|
return Multi, nil
|
|
case "":
|
|
return Unset, nil
|
|
}
|
|
return Unknown, fmt.Errorf("%w %v", ErrInvalidMarginType, m)
|
|
}
|