mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 15:09:51 +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>
163 lines
3.7 KiB
Go
163 lines
3.7 KiB
Go
package margin
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestValid(t *testing.T) {
|
|
t.Parallel()
|
|
if !Isolated.Valid() {
|
|
t.Fatal("expected 'true', received 'false'")
|
|
}
|
|
if !Multi.Valid() {
|
|
t.Fatal("expected 'true', received 'false'")
|
|
}
|
|
if Unset.Valid() {
|
|
t.Fatal("expected 'false', received 'true'")
|
|
}
|
|
if Unknown.Valid() {
|
|
t.Fatal("expected 'false', received 'true'")
|
|
}
|
|
if Type(137).Valid() {
|
|
t.Fatal("expected 'false', received 'true'")
|
|
}
|
|
}
|
|
|
|
func TestUnmarshalJSON(t *testing.T) {
|
|
t.Parallel()
|
|
type martian struct {
|
|
M Type `json:"margin"`
|
|
}
|
|
|
|
var alien martian
|
|
jason := []byte(`{"margin":"isolated"}`)
|
|
err := json.Unmarshal(jason, &alien)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if alien.M != Isolated {
|
|
t.Errorf("received '%v' expected 'isolated'", alien.M)
|
|
}
|
|
|
|
jason = []byte(`{"margin":"cross"}`)
|
|
err = json.Unmarshal(jason, &alien)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if alien.M != Multi {
|
|
t.Errorf("received '%v' expected 'Multi'", alien.M)
|
|
}
|
|
|
|
jason = []byte(`{"margin":"hello moto"}`)
|
|
err = json.Unmarshal(jason, &alien)
|
|
if !errors.Is(err, ErrInvalidMarginType) {
|
|
t.Error(err)
|
|
}
|
|
if alien.M != Unknown {
|
|
t.Errorf("received '%v' expected 'isolated'", alien.M)
|
|
}
|
|
}
|
|
|
|
func TestString(t *testing.T) {
|
|
t.Parallel()
|
|
if Unknown.String() != unknownStr {
|
|
t.Errorf("received '%v' expected '%v'", Unknown.String(), unknownStr)
|
|
}
|
|
if Isolated.String() != isolatedStr {
|
|
t.Errorf("received '%v' expected '%v'", Isolated.String(), isolatedStr)
|
|
}
|
|
if Multi.String() != multiStr {
|
|
t.Errorf("received '%v' expected '%v'", Multi.String(), multiStr)
|
|
}
|
|
if Unset.String() != unsetStr {
|
|
t.Errorf("received '%v' expected '%v'", Unset.String(), unsetStr)
|
|
}
|
|
}
|
|
|
|
func TestUpper(t *testing.T) {
|
|
t.Parallel()
|
|
if Unknown.Upper() != strings.ToUpper(unknownStr) {
|
|
t.Errorf("received '%v' expected '%v'", Unknown.String(), strings.ToUpper(unknownStr))
|
|
}
|
|
if Isolated.Upper() != strings.ToUpper(isolatedStr) {
|
|
t.Errorf("received '%v' expected '%v'", Isolated.String(), strings.ToUpper(isolatedStr))
|
|
}
|
|
if Multi.Upper() != strings.ToUpper(multiStr) {
|
|
t.Errorf("received '%v' expected '%v'", Multi.String(), strings.ToUpper(multiStr))
|
|
}
|
|
if Unset.Upper() != strings.ToUpper(unsetStr) {
|
|
t.Errorf("received '%v' expected '%v'", Unset.String(), strings.ToUpper(unsetStr))
|
|
}
|
|
}
|
|
|
|
func TestIsValidString(t *testing.T) {
|
|
t.Parallel()
|
|
if IsValidString("lol") {
|
|
t.Fatal("expected 'false', received 'true'")
|
|
}
|
|
if !IsValidString("isolated") {
|
|
t.Fatal("expected 'true', received 'false'")
|
|
}
|
|
if !IsValidString("cross") {
|
|
t.Fatal("expected 'true', received 'false'")
|
|
}
|
|
if !IsValidString("multi") {
|
|
t.Fatal("expected 'true', received 'false'")
|
|
}
|
|
if !IsValidString("unset") {
|
|
t.Fatal("expected 'true', received 'false'")
|
|
}
|
|
if IsValidString("") {
|
|
t.Fatal("expected 'false', received 'true'")
|
|
}
|
|
if IsValidString("unknown") {
|
|
t.Fatal("expected 'false', received 'true'")
|
|
}
|
|
}
|
|
|
|
func TestStringToMarginType(t *testing.T) {
|
|
t.Parallel()
|
|
resp, err := StringToMarginType("lol")
|
|
if !errors.Is(err, ErrInvalidMarginType) {
|
|
t.Error(err)
|
|
}
|
|
if resp != Unknown {
|
|
t.Errorf("received '%v' expected '%v'", resp, Unknown)
|
|
}
|
|
|
|
resp, err = StringToMarginType("")
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if resp != Unset {
|
|
t.Errorf("received '%v' expected '%v'", resp, Unset)
|
|
}
|
|
|
|
resp, err = StringToMarginType("cross")
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if resp != Multi {
|
|
t.Errorf("received '%v' expected '%v'", resp, Multi)
|
|
}
|
|
|
|
resp, err = StringToMarginType("multi")
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if resp != Multi {
|
|
t.Errorf("received '%v' expected '%v'", resp, Multi)
|
|
}
|
|
|
|
resp, err = StringToMarginType("isolated")
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if resp != Isolated {
|
|
t.Errorf("received '%v' expected '%v'", resp, Isolated)
|
|
}
|
|
}
|