forked from nntaoli-project/goex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Wallet.go
118 lines (92 loc) · 2.73 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
package binance
import (
"encoding/json"
"errors"
"fmt"
"net/url"
. "github.com/soulsplit/goex"
"github.com/soulsplit/goex/internal/logger"
)
type Wallet struct {
ba *Binance
conf *APIConfig
}
func NewWallet(c *APIConfig) *Wallet {
return &Wallet{ba: NewWithConfig(c), conf: 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 {
transferUrl := w.conf.Endpoint + "/sapi/v1/futures/transfer"
postParam := url.Values{}
postParam.Set("asset", param.Currency)
postParam.Set("amount", fmt.Sprint(param.Amount))
if param.From == SPOT && param.To == SWAP_USDT {
postParam.Set("type", "1")
}
if param.From == SWAP_USDT && param.To == SPOT {
postParam.Set("type", "2")
}
if param.From == SPOT && param.To == FUTURE {
postParam.Set("type", "3")
}
if param.From == FUTURE && param.To == SPOT {
postParam.Set("type", "4")
}
w.ba.buildParamsSigned(&postParam)
resp, err := HttpPostForm2(w.ba.httpClient, transferUrl, postParam,
map[string]string{"X-MBX-APIKEY": w.ba.accessKey})
if err != nil {
return err
}
respmap := make(map[string]interface{})
err = json.Unmarshal(resp, &respmap)
if err != nil {
return err
}
if respmap["tranId"] != nil && ToInt64(respmap["tranId"]) > 0 {
return nil
}
return errors.New(string(resp))
}
func (w *Wallet) GetWithDrawHistory(currency *Currency) ([]DepositWithdrawHistory, error) {
//historyUrl := w.conf.Endpoint + "/wapi/v3/withdrawHistory.html"
historyUrl := w.conf.Endpoint + "/sapi/v1/accountSnapshot"
postParam := url.Values{}
postParam.Set("type", "SPOT")
w.ba.buildParamsSigned(&postParam)
resp, err := HttpGet5(w.ba.httpClient, historyUrl+"?"+postParam.Encode(),
map[string]string{"X-MBX-APIKEY": w.ba.accessKey})
if err != nil {
return nil, err
}
logger.Debugf("response body: %s", string(resp))
respmap := make(map[string]interface{})
err = json.Unmarshal(resp, &respmap)
if err != nil {
return nil, err
}
return nil, nil
}
func (w *Wallet) GetDepositHistory(currency *Currency) ([]DepositWithdrawHistory, error) {
historyUrl := w.conf.Endpoint + "/wapi/v3/depositHistory.html"
postParam := url.Values{}
postParam.Set("asset", currency.Symbol)
w.ba.buildParamsSigned(&postParam)
resp, err := HttpGet5(w.ba.httpClient, historyUrl+"?"+postParam.Encode(),
map[string]string{"X-MBX-APIKEY": w.ba.accessKey})
if err != nil {
return nil, err
}
logger.Debugf("response body: %s", string(resp))
respmap := make(map[string]interface{})
err = json.Unmarshal(resp, &respmap)
if err != nil {
return nil, err
}
return nil, nil
}