github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/pkg/models/fundingoffer/submit.go (about)

     1  package fundingoffer
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  
     7  	"github.com/bitfinexcom/bitfinex-api-go/pkg/models/common"
     8  )
     9  
    10  type SubmitRequest struct {
    11  	Type   string
    12  	Symbol string
    13  	Amount float64
    14  	Rate   float64
    15  	Period int64
    16  	Hidden bool
    17  }
    18  
    19  func (sr *SubmitRequest) ToJSON() ([]byte, error) {
    20  	aux := struct {
    21  		Type   string  `json:"type"`
    22  		Symbol string  `json:"symbol"`
    23  		Amount float64 `json:"amount,string"`
    24  		Rate   float64 `json:"rate,string"`
    25  		Period int64   `json:"period"`
    26  		Flags  int     `json:"flags,omitempty"`
    27  	}{
    28  		Type:   sr.Type,
    29  		Symbol: sr.Symbol,
    30  		Amount: sr.Amount,
    31  		Rate:   sr.Rate,
    32  		Period: sr.Period,
    33  	}
    34  	if sr.Hidden {
    35  		aux.Flags = aux.Flags + common.OrderFlagHidden
    36  	}
    37  	return json.Marshal(aux)
    38  }
    39  
    40  // MarshalJSON converts the offer submit object into the format required by the
    41  // bitfinex websocket service.
    42  func (sr *SubmitRequest) MarshalJSON() ([]byte, error) {
    43  	aux, err := sr.ToJSON()
    44  	if err != nil {
    45  		return nil, err
    46  	}
    47  	return []byte(fmt.Sprintf("[0, \"fon\", null, %s]", string(aux))), nil
    48  }