forked from nntaoli-project/goex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OKCoin_COM.go
90 lines (71 loc) · 2.38 KB
/
OKCoin_COM.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
package okcoin
import (
"encoding/json"
"errors"
. "github.com/nntaoli-project/GoEx"
"net/http"
"net/url"
"strconv"
)
const (
EXCHANGE_NAME_COM = "okcoin.com"
)
type OKCoinCOM_API struct {
OKCoinCN_API
}
func NewCOM(client *http.Client, api_key, secret_key string) *OKCoinCOM_API {
return &OKCoinCOM_API{OKCoinCN_API{client, api_key, secret_key, "https://www.okcoin.com/api/v1/"}}
}
func (ctx *OKCoinCOM_API) GetAccount() (*Account, error) {
postData := url.Values{}
err := ctx.buildPostForm(&postData)
if err != nil {
return nil, err
}
body, err := HttpPostForm(ctx.client, ctx.api_base_url+url_userinfo, postData)
if err != nil {
return nil, err
}
// println(string(body))
var respMap map[string]interface{}
err = json.Unmarshal(body, &respMap)
if err != nil {
return nil, err
}
if !respMap["result"].(bool) {
errcode := strconv.FormatFloat(respMap["error_code"].(float64), 'f', 0, 64)
return nil, errors.New(errcode)
}
info := respMap["info"].(map[string]interface{})
funds := info["funds"].(map[string]interface{})
asset := funds["asset"].(map[string]interface{})
free := funds["free"].(map[string]interface{})
freezed := funds["freezed"].(map[string]interface{})
account := new(Account)
account.Exchange = ctx.GetExchangeName()
account.Asset, _ = strconv.ParseFloat(asset["total"].(string), 64)
account.NetAsset, _ = strconv.ParseFloat(asset["net"].(string), 64)
var btcSubAccount SubAccount
var ltcSubAccount SubAccount
var cnySubAccount SubAccount
btcSubAccount.Currency = BTC
btcSubAccount.Amount, _ = strconv.ParseFloat(free["btc"].(string), 64)
btcSubAccount.LoanAmount = 0
btcSubAccount.ForzenAmount, _ = strconv.ParseFloat(freezed["btc"].(string), 64)
ltcSubAccount.Currency = LTC
ltcSubAccount.Amount, _ = strconv.ParseFloat(free["ltc"].(string), 64)
ltcSubAccount.LoanAmount = 0
ltcSubAccount.ForzenAmount, _ = strconv.ParseFloat(freezed["ltc"].(string), 64)
cnySubAccount.Currency = CNY
cnySubAccount.Amount, _ = strconv.ParseFloat(free["usd"].(string), 64)
cnySubAccount.LoanAmount = 0
cnySubAccount.ForzenAmount, _ = strconv.ParseFloat(freezed["usd"].(string), 64)
account.SubAccounts = make(map[Currency]SubAccount, 3)
account.SubAccounts[BTC] = btcSubAccount
account.SubAccounts[LTC] = ltcSubAccount
account.SubAccounts[USD] = cnySubAccount
return account, nil
}
func (ctx *OKCoinCOM_API) GetExchangeName() string {
return OKCOIN_COM
}