Categorygithub.com/bit-rocket/okex-go-sdk-api
modulepackage
1.0.7
Repository: https://github.com/bit-rocket/okex-go-sdk-api.git
Documentation: pkg.go.dev

# README

OKEx Open API V3 SDK (Golang Version)

项目来源

https://github.com/okcoin-okex/open-api-v3-sdk

联系我们Contact Us
微信号WeChat IDApiSupport
邮 箱E-mail[email protected]

本项目去除了一些其他语言, 修改一些 bug.

1. 下载依赖

go get -u github.com/justinchou/okex-go-sdk-api

2. 编写 golang 文件

测试文件必须以 \*\_test.go 结尾, 例如: okex_open_api_v3_test.go

package gotest

import (
	"fmt"
	"github.com/justinchou/okex-go-sdk-api"
	"testing"
)

func TestOKExServerTime(t *testing.T) {
	serverTime, err := NewOKExClient().GetServerTime()
	if err != nil {
		t.Error(err)
	}
	fmt.Println("OKEx's server time: ", serverTime)
}

func getOKExConfig() okex.Config {
	var config okex.Config

	config.Endpoint = "https://www.okex.com/"
	config.WSEndpoint = "wss://real.okex.com:8443/"

	config.ApiKey = ""
	config.SecretKey = ""
	config.Passphrase = ""
	config.TimeoutSecond = 45
	config.IsPrint = true
	config.I18n = okex.ENGLISH

	return config
}

// 创建 https 客户端
func NewOKExClient() *okex.Client {
	config := getOKExConfig()
	client := okex.NewClient(config)
	return client
}

// 创建 wss 客户端
func NewOKExWss() (client *okex.OKWSAgent, err error) {
	config := getOKExConfig()

	client := &okex.OKWSAgent{}
	err = client.Start(config)
	if err != nil {
		fmt.Println("okex wss connect failed", err)
		return nil
	}

	return client
}

3. 启动测试

go test -v -run TestOKExServerTime okex_open_api_v3_test.go

# Functions

Get api v1 requestPath + requestParams params := okex.NewParams() params["symbol"] = "btc_usd" params["contract_type"] = "this_week" params["status"] = "1" requestPath := "/api/v1/future_explosive.do" return eg: /api/v1/future_explosive.do?api_key=88af5759-61f2-47e9-b2e9-17ce3a390488&contract_type=this_week&status=1&symbol=btc_usd&sign=966ACD0DE5F729BC9C9C03D92ABBEB68 */.
build http get request params, and order eg: params := make(map[string]string) params["bb"] = "222" params["aa"] = "111" params["cc"] = "333" return string: eg: aa=111&bb=222&cc=333 */.
Get api requestPath + requestParams params := NewParams() params["depth"] = "200" params["conflated"] = "0" url := BuildParams("/api/futures/v3/products/BTC-USD-0310/book", params) return eg:/api/futures/v3/products/BTC-USD-0310/book?conflated=0&depth=200 */.
Get a epoch time eg: 1521221737.376 */.
call fmt.Println(...) */.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Set http request headers: Accept: application/json Content-Type: application/json; charset=UTF-8 (default) Cookie: locale=en_US (English) OK-ACCESS-KEY: (Your setting) OK-ACCESS-SIGN: (Use your setting, auto sign and add) OK-ACCESS-TIMESTAMP: (Auto add) OK-ACCESS-PASSPHRASE: Your setting */.
signing a message using: hmac sha256 + base64 eg: message = Pre_hash function comment secretKey = E65791902180E9EF4510DB6A77F6EBAE return signed string = TO6uwdqz+31SIPkd4I+9NiZGmVH74dXi+Fd5X0EzzSQ= */.
int convert string */.
int64 convert string */.
return decimalism string 9223372036854775807 -> "9223372036854775807" */.
No description provided by the author
Get a iso time eg: 2018-03-16T18:02:48.284Z */.
iso time change to time.Time eg: "2018-11-18T16:51:55.933Z" -> 2018-11-18 16:51:55.000000933 +0000 UTC */.
json byte array convert struct */.
json string convert struct */.
No description provided by the author
Get utc +8 -- 1540365300000 -> 2018-10-24 15:15:00 +0800 CST */.
1540365300000 -> 2018-10-24 15:15:00 */.
md5 sign */.
Get a http client */.
Get a new map.eg: {string:string} */.
No description provided by the author
No description provided by the author
Get a http request body is a json string and a byte array.
the pre hash string eg: timestamp = 2018-03-08T10:59:25.789Z method = POST request_path = /orders?before=2&limit=30 body = {"product_id":"BTC-USD-0309","order_id":"377454671037440"} return pre hash string = 2018-03-08T10:59:25.789ZPOST/orders?before=2&limit=30{"product_id":"BTC-USD-0309","order_id":"377454671037440"} */.
No description provided by the author
No description provided by the author
struct convert json string */.
ternary operator replace language: a == b ? c : d */.
ternary operator biz extension */.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
currencies */.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
candles bin size */.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
用户账户信息频道.
4小时k线数据频道.
30分钟k线数据频道.
3分钟k线数据频道.
6小时k线数据频道.
5分钟k线数据频道.
1小时k线数据频道.
12小时k线数据频道.
1week k线数据频道.
1分钟k线数据频道.
2小时k线数据频道.
1day k线数据频道.
15分钟k线数据频道.
深度数据频道,首次200档,后续增量.
深度数据频道,每次返回前5档.
获取预估交割价.
标记价格频道.
用户交易数据频道.
用户持仓信息频道.
限价范围频道.
行情数据频道.
交易信息频道.
用户币币账户信息频道.
4小时k线数据频道.
30分钟k线数据频道.
3分钟k线数据频道.
6小时k线数据频道.
5分钟k线数据频道.
1小时k线数据频道.
12小时k线数据频道.
1week k线数据频道.
1分钟k线数据频道.
2小时k线数据频道.
1day k线数据频道.
15分钟k线数据频道.
深度数据频道,首次200档,后续增量.
深度数据频道,每次返回前5档.
用户杠杆账户信息频道.
用户交易数据频道.
行情数据频道.
交易信息频道.
用户账户信息频道.
4小时k线数据频道.
30分钟k线数据频道.
3分钟k线数据频道.
6小时k线数据频道.
5分钟k线数据频道.
1小时k线数据频道.
12小时k线数据频道.
1week.
1分钟k线数据频道.
2小时k线数据频道.
1day.
15分钟k线数据频道.
深度数据频道,首次200档,后续增量.
深度数据频道,每次返回前5档.
资金费率频道.
标记价格频道.
用户交易数据频道.
用户持仓信息频道.
限价范围频道.
行情数据频道.
交易信息频道.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
margin mode */.
No description provided by the author
i18n: internationalization */.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
http methods */.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
http headers */.
No description provided by the author
No description provided by the author
No description provided by the author
* paging params */.
No description provided by the author
No description provided by the author
No description provided by the author
transaction type */.
No description provided by the author
POST
No description provided by the author
others */.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
zh_TW || zh_HK.
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
OKEX uses cursor pagination for all REST requests which return arrays */.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
OrdersData: Batch create new orders json string.(Max of 5 orders are allowed per request)) */.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Create a new order ClientOid: You setting order id.(optional) Type: The execution type @see file: futures_constants.go InstrumentId: The id of the futures, eg: BTC_USD_0331 Price: The order price: Maximum 1 million Amount: The order amount: Maximum 1 million MatchPrice: Match best counter party price (BBO)? 0: No 1: Yes If yes, the 'price' field is ignored LeverRate: lever, default 10.
No description provided by the author
Order status: 0: waiting for transaction 1: 1: part of the deal 2: all transactions 3: cancelling 4: canceled.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
OKWSAgent OKEx Wss 链接对象.
If OrderId = -1, ErrorCode > 0, error order */.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author