ftx: add conversion helper

This commit is contained in:
ycdesu 2021-03-13 09:51:16 +08:00
parent 778ceb2985
commit 506fdcd84f
2 changed files with 51 additions and 0 deletions

View File

@ -21,6 +21,10 @@ func TrimUpperString(original string) string {
return strings.ToUpper(strings.TrimSpace(original))
}
func TrimLowerString(original string) string {
return strings.ToLower(strings.TrimSpace(original))
}
var errUnsupportedOrderStatus = fmt.Errorf("unsupported order status")
func toGlobalOrderFromOpenOrder(r order) (types.Order, error) {

View File

@ -49,3 +49,50 @@ func Test_toGlobalOrderFromOpenOrder(t *testing.T) {
assert.Equal(t, types.OrderStatusPartiallyFilled, o.Status)
assert.Equal(t, float64(10), o.ExecutedQuantity)
}
func TestTrimLowerString(t *testing.T) {
type args struct {
original string
}
tests := []struct {
name string
args args
want string
}{
{
name: "spaces",
args: args{
original: " ",
},
want: "",
},
{
name: "uppercase",
args: args{
original: " HELLO ",
},
want: "hello",
},
{
name: "lowercase",
args: args{
original: " hello",
},
want: "hello",
},
{
name: "upper/lower cases",
args: args{
original: " heLLo ",
},
want: "hello",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := TrimLowerString(tt.args.original); got != tt.want {
t.Errorf("TrimLowerString() = %v, want %v", got, tt.want)
}
})
}
}