Files
gocryptotrader/exchanges/okex/okex_test.go
Adrian Gallagher c63f1b0ff6 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
2018-08-04 08:30:20 +10:00

285 lines
7.1 KiB
Go

package okex
import (
"testing"
"github.com/thrasher-/gocryptotrader/config"
)
var o OKEX
// Please supply you own test keys here for due diligence testing.
const (
apiKey = ""
apiSecret = ""
)
func TestSetDefaults(t *testing.T) {
o.SetDefaults()
if o.GetName() != "OKEX" {
t.Error("Test Failed - Bittrex - SetDefaults() error")
}
}
func TestSetup(t *testing.T) {
cfg := config.GetConfig()
cfg.LoadConfig("../../testdata/configtest.json")
okexConfig, err := cfg.GetExchangeConfig("OKEX")
if err != nil {
t.Error("Test Failed - Okex Setup() init error")
}
okexConfig.AuthenticatedAPISupport = true
okexConfig.APIKey = apiKey
okexConfig.APISecret = apiSecret
o.Setup(okexConfig)
}
func TestGetContractPrice(t *testing.T) {
t.Parallel()
_, err := o.GetContractPrice("btc_usd", "this_week")
if err != nil {
t.Error("Test failed - okex GetContractPrice() error", err)
}
_, err = o.GetContractPrice("btc_bla", "123525")
if err == nil {
t.Error("Test failed - okex GetContractPrice() error", err)
}
_, err = o.GetContractPrice("btc_bla", "this_week")
if err == nil {
t.Error("Test failed - okex GetContractPrice() error", err)
}
}
func TestGetContractMarketDepth(t *testing.T) {
t.Parallel()
_, err := o.GetContractMarketDepth("btc_usd", "this_week")
if err != nil {
t.Error("Test failed - okex GetContractMarketDepth() error", err)
}
_, err = o.GetContractMarketDepth("btc_bla", "123525")
if err == nil {
t.Error("Test failed - okex GetContractMarketDepth() error", err)
}
_, err = o.GetContractMarketDepth("btc_bla", "this_week")
if err == nil {
t.Error("Test failed - okex GetContractMarketDepth() error", err)
}
}
func TestGetContractTradeHistory(t *testing.T) {
t.Parallel()
_, err := o.GetContractTradeHistory("btc_usd", "this_week")
if err != nil {
t.Error("Test failed - okex GetContractTradeHistory() error", err)
}
_, err = o.GetContractTradeHistory("btc_bla", "123525")
if err == nil {
t.Error("Test failed - okex GetContractTradeHistory() error", err)
}
_, err = o.GetContractTradeHistory("btc_bla", "this_week")
if err == nil {
t.Error("Test failed - okex GetContractTradeHistory() error", err)
}
}
func TestGetContractIndexPrice(t *testing.T) {
t.Parallel()
_, err := o.GetContractIndexPrice("btc_usd")
if err != nil {
t.Error("Test failed - okex GetContractIndexPrice() error", err)
}
_, err = o.GetContractIndexPrice("lol123")
if err == nil {
t.Error("Test failed - okex GetContractTradeHistory() error", err)
}
}
func TestGetContractExchangeRate(t *testing.T) {
t.Parallel()
_, err := o.GetContractExchangeRate()
if err != nil {
t.Error("Test failed - okex GetContractExchangeRate() error", err)
}
}
func TestGetContractCandlestickData(t *testing.T) {
t.Parallel()
_, err := o.GetContractCandlestickData("btc_usd", "1min", "this_week", 1, 2)
if err != nil {
t.Error("Test failed - okex GetContractCandlestickData() error", err)
}
_, err = o.GetContractCandlestickData("btc_bla", "1min", "this_week", 1, 2)
if err == nil {
t.Error("Test failed - okex GetContractCandlestickData() error", err)
}
_, err = o.GetContractCandlestickData("btc_usd", "min", "this_week", 1, 2)
if err == nil {
t.Error("Test failed - okex GetContractCandlestickData() error", err)
}
_, err = o.GetContractCandlestickData("btc_usd", "1min", "this_wok", 1, 2)
if err == nil {
t.Error("Test failed - okex GetContractCandlestickData() error", err)
}
}
func TestGetContractHoldingsNumber(t *testing.T) {
t.Parallel()
_, _, err := o.GetContractHoldingsNumber("btc_usd", "this_week")
if err != nil {
t.Error("Test failed - okex GetContractHoldingsNumber() error", err)
}
_, _, err = o.GetContractHoldingsNumber("btc_bla", "this_week")
if err == nil {
t.Error("Test failed - okex GetContractHoldingsNumber() error", err)
}
_, _, err = o.GetContractHoldingsNumber("btc_usd", "this_bla")
if err == nil {
t.Error("Test failed - okex GetContractHoldingsNumber() error", err)
}
}
func TestGetContractlimit(t *testing.T) {
t.Parallel()
_, err := o.GetContractlimit("btc_usd", "this_week")
if err != nil {
t.Error("Test failed - okex GetContractlimit() error", err)
}
_, err = o.GetContractlimit("btc_bla", "this_week")
if err == nil {
t.Error("Test failed - okex GetContractlimit() error", err)
}
_, err = o.GetContractlimit("btc_usd", "this_bla")
if err == nil {
t.Error("Test failed - okex GetContractlimit() error", err)
}
}
func TestGetContractUserInfo(t *testing.T) {
t.Parallel()
err := o.GetContractUserInfo()
if err == nil {
t.Error("Test failed - okex GetContractUserInfo() error", err)
}
}
func TestGetContractPosition(t *testing.T) {
t.Parallel()
err := o.GetContractPosition("btc_usd", "this_week")
if err == nil {
t.Error("Test failed - okex GetContractPosition() error", err)
}
}
func TestPlaceContractOrders(t *testing.T) {
t.Parallel()
_, err := o.PlaceContractOrders("btc_usd", "this_week", "1", 10, 1, 1, true)
if err == nil {
t.Error("Test failed - okex PlaceContractOrders() error", err)
}
}
func TestGetContractFuturesTradeHistory(t *testing.T) {
t.Parallel()
err := o.GetContractFuturesTradeHistory("btc_usd", "1972-01-01", 0)
if err == nil {
t.Error("Test failed - okex GetContractTradeHistory() error", err)
}
}
func TestGetLatestSpotPrice(t *testing.T) {
t.Parallel()
_, err := o.GetLatestSpotPrice("ltc_btc")
if err != nil {
t.Error("Test failed - okex GetLatestSpotPrice() error", err)
}
}
func TestGetSpotTicker(t *testing.T) {
t.Parallel()
_, err := o.GetSpotTicker("ltc_btc")
if err != nil {
t.Error("Test failed - okex GetSpotTicker() error", err)
}
}
func TestGetSpotMarketDepth(t *testing.T) {
t.Parallel()
_, err := o.GetSpotMarketDepth(ActualSpotDepthRequestParams{
Symbol: "eth_btc",
Size: 2,
})
if err != nil {
t.Error("Test failed - okex GetSpotMarketDepth() error", err)
}
}
func TestGetSpotRecentTrades(t *testing.T) {
t.Parallel()
_, err := o.GetSpotRecentTrades(ActualSpotTradeHistoryRequestParams{
Symbol: "ltc_btc",
Since: 0,
})
if err != nil {
t.Error("Test failed - okex GetSpotRecentTrades() error", err)
}
}
func TestGetSpotKline(t *testing.T) {
t.Parallel()
arg := KlinesRequestParams{
Symbol: "ltc_btc",
Type: TimeIntervalFiveMinutes,
Size: 100,
}
_, err := o.GetSpotKline(arg)
if err != nil {
t.Error("Test failed - okex GetSpotCandleStick() error", err)
}
}
func TestSpotNewOrder(t *testing.T) {
t.Parallel()
if o.APIKey == "" || o.APISecret == "" {
t.Skip()
}
_, err := o.SpotNewOrder(SpotNewOrderRequestParams{
Symbol: "ltc_btc",
Amount: 1.1,
Price: 10.1,
Type: SpotNewOrderRequestTypeBuy,
})
if err != nil {
t.Error("Test failed - okex SpotNewOrder() error", err)
}
}
func TestSpotCancelOrder(t *testing.T) {
t.Parallel()
if o.APIKey == "" || o.APISecret == "" {
t.Skip()
}
_, err := o.SpotCancelOrder("ltc_btc", 519158961)
if err != nil {
t.Error("Test failed - okex SpotCancelOrder() error", err)
}
}
func TestGetUserInfo(t *testing.T) {
t.Parallel()
if o.APIKey == "" || o.APISecret == "" {
t.Skip()
}
_, err := o.GetUserInfo()
if err != nil {
t.Error("Test failed - okex GetUserInfo() error", err)
}
}