mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
make margin order side effect json unmarshallable
This commit is contained in:
parent
f8378957ee
commit
bea750ca97
|
@ -1,8 +1,11 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/slack-go/slack"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/datatype"
|
||||
|
@ -24,6 +27,32 @@ var (
|
|||
SideEffectTypeAutoRepay MarginOrderSideEffectType = "AUTO_REPAY"
|
||||
)
|
||||
|
||||
func (t *MarginOrderSideEffectType) UnmarshalJSON(data []byte) error {
|
||||
var s string
|
||||
var err = json.Unmarshal(data, &s)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "unable to unmarshal side effect type: %s", data)
|
||||
}
|
||||
|
||||
switch strings.ToUpper(s) {
|
||||
|
||||
case string(SideEffectTypeNoSideEffect), "":
|
||||
*t = SideEffectTypeNoSideEffect
|
||||
return nil
|
||||
|
||||
case string(SideEffectTypeMarginBuy):
|
||||
*t = SideEffectTypeMarginBuy
|
||||
return nil
|
||||
|
||||
case string(SideEffectTypeAutoRepay):
|
||||
*t = SideEffectTypeAutoRepay
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
return fmt.Errorf("invalid side effect type: %s", data)
|
||||
}
|
||||
|
||||
// OrderType define order type
|
||||
type OrderType string
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user