mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
Port from idoall's codebase (#161)
* 修复火币Post REST API方法不正确的问题,同时增加火币海带丝交易所 * add vendor folder * 修改命名空间依赖 * 第一次提交分支 * 增加取消订单功能 * 修复binance.GetAccount方法 * 更新readme.md * 增加 Gateio 交易所的支持,支持获取K线、支持的交易对、交易市场参数 * 替换HuobiHadax的参数 * 买/卖订单、取消订单 * OKEX 币币交易:增加获取用户信息,下订单,取消订单 * 测试ok kline * 修复 Bitfinex 的 GetAccountInfo 方法 * 做一些不必要的删减 * 修复binfinex不返回错误的bug * 统一我修改交易所的Kline获取方式 * Bitfinex 增加获取最新价格 * update main.go * 更新GetSymbol方法 * 修改火币和海带丝的Kline编号ID类型 * 修改海带丝的默认配置大小写 * okex增加获取最新价格 * 调整okex的参数判断 * 调整比特儿的参数名称 * 修改火币、火币Hadax的参数全名 * 更新海带丝的配置名称 * 修改bintfinex的GetAccountInfo方法 * 去掉一行注释 * 支持zb交易所的部分功能 * 修复获取K线时没有设置参数的错误 * 增加 Binance 取消订单的方法,获取订单状态,获取所有打开的状态以及所有订单 * 修改获取深度和历史订单的数据 * 修改币安获取深度的参数 * 修改火币获取市场深度的参数 * 修改okex获取市场深度的参数 * 修改币安、OKex获取历史订单的参数 * 修复币安提交参数错误的问题 * merge upstrem * merge后,调整一部分命名空间 * 修改ZB时间参数的命名方式 * 继续替换命名空间 * 命名空间的替换 * 继续命名空间的替换 * 测试 * Port code from idoall's PR * Drop errors dep * Start amending PR * Fix commented code * Translate text from Chinese to English (except for ZB). The reasning behind this is that it's a Chinese exchange and the structs are self explanatory in English, but would for other developers in China * Translate Chinese text, basic formatting changes * Remove commented lines and address feedback on PR
This commit is contained in:
@@ -41,6 +41,7 @@ const (
|
||||
HashSHA256
|
||||
HashSHA512
|
||||
HashSHA512_384
|
||||
HashMD5
|
||||
SatoshisPerBTC = 100000000
|
||||
SatoshisPerLTC = 100000000
|
||||
WeiPerEther = 1000000000000000000
|
||||
@@ -121,6 +122,10 @@ func GetHMAC(hashType int, input, key []byte) []byte {
|
||||
{
|
||||
hash = sha512.New384
|
||||
}
|
||||
case HashMD5:
|
||||
{
|
||||
hash = md5.New
|
||||
}
|
||||
}
|
||||
|
||||
hmac := hmac.New(hash, []byte(key))
|
||||
@@ -128,11 +133,24 @@ func GetHMAC(hashType int, input, key []byte) []byte {
|
||||
return hmac.Sum(nil)
|
||||
}
|
||||
|
||||
// Sha1ToHex takes a string, sha1 hashes it and return a hex string of the
|
||||
// result
|
||||
func Sha1ToHex(data string) string {
|
||||
h := sha1.New()
|
||||
h.Write([]byte(data))
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
// HexEncodeToString takes in a hexadecimal byte array and returns a string
|
||||
func HexEncodeToString(input []byte) string {
|
||||
return hex.EncodeToString(input)
|
||||
}
|
||||
|
||||
// ByteArrayToString returns a string
|
||||
func ByteArrayToString(input []byte) string {
|
||||
return fmt.Sprintf("%x", input)
|
||||
}
|
||||
|
||||
// Base64Decode takes in a Base64 string and returns a byte array and an error
|
||||
func Base64Decode(input string) ([]byte, error) {
|
||||
result, err := base64.StdEncoding.DecodeString(input)
|
||||
@@ -538,3 +556,61 @@ func GetOSPathSlash() string {
|
||||
}
|
||||
return "/"
|
||||
}
|
||||
|
||||
// UnixMillis converts a UnixNano timestamp to milliseconds
|
||||
func UnixMillis(t time.Time) int64 {
|
||||
return t.UnixNano() / int64(time.Millisecond)
|
||||
}
|
||||
|
||||
// RecvWindow converts a supplied time.Duration to milliseconds
|
||||
func RecvWindow(d time.Duration) int64 {
|
||||
return int64(d) / int64(time.Millisecond)
|
||||
}
|
||||
|
||||
// FloatFromString format
|
||||
func FloatFromString(raw interface{}) (float64, error) {
|
||||
str, ok := raw.(string)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unable to parse, value not string: %T", raw)
|
||||
}
|
||||
flt, err := strconv.ParseFloat(str, 64)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("unable to parse, value not string: %T", raw)
|
||||
}
|
||||
return flt, nil
|
||||
}
|
||||
|
||||
// IntFromString format
|
||||
func IntFromString(raw interface{}) (int, error) {
|
||||
str, ok := raw.(string)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unable to parse, value not string: %T", raw)
|
||||
}
|
||||
n, err := strconv.Atoi(str)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("unable to parse as int: %T", raw)
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// Int64FromString format
|
||||
func Int64FromString(raw interface{}) (int64, error) {
|
||||
str, ok := raw.(string)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unable to parse, value not string: %T", raw)
|
||||
}
|
||||
n, err := strconv.ParseInt(str, 10, 64)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("unable to parse as int: %T", raw)
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// TimeFromUnixTimestampFloat format
|
||||
func TimeFromUnixTimestampFloat(raw interface{}) (time.Time, error) {
|
||||
ts, ok := raw.(float64)
|
||||
if !ok {
|
||||
return time.Time{}, fmt.Errorf("unable to parse, value not int64: %T", raw)
|
||||
}
|
||||
return time.Unix(0, int64(ts)*int64(time.Millisecond)), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user