forked from nntaoli-project/goex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWallet.go
124 lines (97 loc) · 3.07 KB
/
Wallet.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package huobi
import (
"encoding/json"
"errors"
"fmt"
. "github.com/nntaoli-project/goex"
"github.com/nntaoli-project/goex/internal/logger"
"net/url"
"strings"
)
type Wallet struct {
pro *HuoBiPro
}
func NewWallet(c *APIConfig) *Wallet {
return &Wallet{pro: NewHuobiWithConfig(c)}
}
//获取钱包资产
func (w *Wallet) GetAccount() (*Account, error) {
return nil, errors.New("not implement")
}
func (w *Wallet) Withdrawal(param WithdrawParameter) (withdrawId string, err error) {
return "", errors.New("not implement")
}
func (w *Wallet) Transfer(param TransferParameter) error {
if param.From == SUB_ACCOUNT || param.To == SUB_ACCOUNT ||
param.From == SPOT_MARGIN || param.To == SPOT_MARGIN {
return errors.New("not implements")
}
httpParam := url.Values{}
httpParam.Set("currency", strings.ToLower(param.Currency))
httpParam.Set("amount", FloatToString(param.Amount, 8))
path := ""
if (param.From == SPOT && param.To == FUTURE) ||
(param.From == FUTURE && param.To == SPOT) {
path = "/v1/futures/transfer"
}
if param.From == SWAP || param.From == SWAP_USDT ||
param.To == SWAP || param.To == SWAP_USDT {
path = "/v2/account/transfer"
}
if param.From == SPOT && param.To == FUTURE {
httpParam.Set("type", "pro-to-futures")
}
if param.From == FUTURE && param.To == SPOT {
httpParam.Set("type", "futures-to-pro")
}
if param.From == SPOT && param.To == SWAP {
httpParam.Set("from", "spot")
httpParam.Set("to", "swap")
}
if param.From == SPOT && param.To == SWAP_USDT {
httpParam.Set("currency", "usdt")
httpParam.Set("from", "spot")
httpParam.Set("to", "linear-swap")
httpParam.Set("margin-account", fmt.Sprintf("%s-usdt", strings.ToLower(param.Currency)))
}
if param.From == SWAP && param.To == SPOT {
httpParam.Set("from", "swap")
httpParam.Set("to", "spot")
}
if param.From == SWAP_USDT && param.To == SPOT {
httpParam.Set("currency", "usdt")
httpParam.Set("from", "linear-swap")
httpParam.Set("to", "spot")
httpParam.Set("margin-account",
fmt.Sprintf("%s-usdt", strings.ToLower(param.Currency)))
}
w.pro.buildPostForm("POST", path, &httpParam)
postJsonParam, _ := ValuesToJson(httpParam)
responseBody, err := HttpPostForm3(w.pro.httpClient,
fmt.Sprintf("%s%s?%s", w.pro.baseUrl, path, httpParam.Encode()),
string(postJsonParam),
map[string]string{"Content-Type": "application/json", "Accept-Language": "zh-cn"})
if err != nil {
return err
}
logger.Debugf("[response body] %s", string(responseBody))
var responseRet map[string]interface{}
err = json.Unmarshal(responseBody, &responseRet)
if err != nil {
return err
}
if responseRet["status"] != nil &&
responseRet["status"].(string) == "ok" {
return nil
}
if responseRet["code"] != nil && responseRet["code"].(float64) == 200 {
return nil
}
return errors.New(string(responseBody))
}
func (w *Wallet) GetWithDrawHistory(currency *Currency) ([]DepositWithdrawHistory, error) {
return nil, errors.New("not implement")
}
func (w *Wallet) GetDepositHistory(currency *Currency) ([]DepositWithdrawHistory, error) {
return nil, errors.New("not implement")
}