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