mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 07:26:47 +00:00
@@ -430,6 +430,29 @@
|
||||
"Delimiter": "_"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "OKEX",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"UseSandbox": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"AvailablePairs": "ltc_btc,eth_btc,etc_btc,bch_btc,btc_usdt,eth_usdt,ltc_usdt,etc_usdt,bch_usdt,etc_eth,bt1_btc,bt2_btc,btg_btc,qtum_btc,hsr_btc,neo_btc,gas_btc,qtum_usdt,hsr_usdt,neo_usdt,gas_usdt,btc_usd,ltc_usd,eth_usd,etc_usd,bch_usd",
|
||||
"EnabledPairs": "btc_usd,ltc_usd",
|
||||
"BaseCurrencies": "USD",
|
||||
"AssetTypes": "SPOT,this_week,next_week,quarter",
|
||||
"ConfigCurrencyPairFormat": {
|
||||
"Uppercase": false,
|
||||
"Delimiter": "_"
|
||||
},
|
||||
"RequestCurrencyPairFormat": {
|
||||
"Uppercase": false,
|
||||
"Delimiter": "_"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "Poloniex",
|
||||
"Enabled": true,
|
||||
@@ -477,4 +500,4 @@
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
1002
exchanges/okex/okex.go
Normal file
1002
exchanges/okex/okex.go
Normal file
File diff suppressed because it is too large
Load Diff
221
exchanges/okex/okex_test.go
Normal file
221
exchanges/okex/okex_test.go
Normal file
@@ -0,0 +1,221 @@
|
||||
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 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("eth_btc", "2")
|
||||
if err != nil {
|
||||
t.Error("Test failed - okex GetSpotMarketDepth() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetSpotRecentTrades(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := o.GetSpotRecentTrades("ltc_btc", "0")
|
||||
if err != nil {
|
||||
t.Error("Test failed - okex GetSpotRecentTrades() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetSpotCandleStick(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := o.GetSpotCandleStick("ltc_btc", "1min", 2, 0)
|
||||
if err != nil {
|
||||
t.Error("Test failed - okex GetSpotCandleStick() error", err)
|
||||
}
|
||||
}
|
||||
158
exchanges/okex/okex_types.go
Normal file
158
exchanges/okex/okex_types.go
Normal file
@@ -0,0 +1,158 @@
|
||||
package okex
|
||||
|
||||
// ContractPrice holds date and ticker price price for contracts.
|
||||
type ContractPrice struct {
|
||||
Date string `json:"date"`
|
||||
Ticker struct {
|
||||
Buy float64 `json:"buy"`
|
||||
ContractID int `json:"contract_id"`
|
||||
High float64 `json:"high"`
|
||||
Low float64 `json:"low"`
|
||||
Last float64 `json:"last"`
|
||||
Sell float64 `json:"sell"`
|
||||
UnitAmount float64 `json:"unit_amount"`
|
||||
Vol float64 `json:"vol"`
|
||||
} `json:"ticker"`
|
||||
Result bool `json:"result"`
|
||||
Error interface{} `json:"error_code"`
|
||||
}
|
||||
|
||||
// ContractDepth response depth
|
||||
type ContractDepth struct {
|
||||
Asks []interface{} `json:"asks"`
|
||||
Bids []interface{} `json:"bids"`
|
||||
Result bool `json:"result"`
|
||||
Error interface{} `json:"error_code"`
|
||||
}
|
||||
|
||||
// ActualContractDepth better manipulated structure to return
|
||||
type ActualContractDepth struct {
|
||||
Asks []struct {
|
||||
Price float64
|
||||
Volume float64
|
||||
}
|
||||
Bids []struct {
|
||||
Price float64
|
||||
Volume float64
|
||||
}
|
||||
}
|
||||
|
||||
// ActualContractTradeHistory holds contract trade history
|
||||
type ActualContractTradeHistory struct {
|
||||
Amount float64 `json:"amount"`
|
||||
DateInMS float64 `json:"date_ms"`
|
||||
Date float64 `json:"date"`
|
||||
Price float64 `json:"price"`
|
||||
TID float64 `json:"tid"`
|
||||
Type string `json:"buy"`
|
||||
}
|
||||
|
||||
// CandleStickData holds candlestick data
|
||||
type CandleStickData struct {
|
||||
Timestamp float64 `json:"timestamp"`
|
||||
Open float64 `json:"open"`
|
||||
High float64 `json:"high"`
|
||||
Low float64 `json:"low"`
|
||||
Close float64 `json:"close"`
|
||||
Volume float64 `json:"volume"`
|
||||
Amount float64 `json:"amount"`
|
||||
}
|
||||
|
||||
// Info holds individual information
|
||||
type Info struct {
|
||||
AccountRights float64 `json:"account_rights"`
|
||||
KeepDeposit float64 `json:"keep_deposit"`
|
||||
ProfitReal float64 `json:"profit_real"`
|
||||
ProfitUnreal float64 `json:"profit_unreal"`
|
||||
RiskRate float64 `json:"risk_rate"`
|
||||
}
|
||||
|
||||
// UserInfo holds a collection of user data
|
||||
type UserInfo struct {
|
||||
Info struct {
|
||||
BTC Info `json:"btc"`
|
||||
LTC Info `json:"ltc"`
|
||||
} `json:"info"`
|
||||
Result bool `json:"result"`
|
||||
}
|
||||
|
||||
// HoldData is a sub type for FuturePosition
|
||||
type HoldData struct {
|
||||
BuyAmount float64 `json:"buy_amount"`
|
||||
BuyAvailable float64 `json:"buy_available"`
|
||||
BuyPriceAvg float64 `json:"buy_price_avg"`
|
||||
BuyPriceCost float64 `json:"buy_price_cost"`
|
||||
BuyProfitReal float64 `json:"buy_profit_real"`
|
||||
ContractID int `json:"contract_id"`
|
||||
ContractType string `json:"contract_type"`
|
||||
CreateDate int `json:"create_date"`
|
||||
LeverRate float64 `json:"lever_rate"`
|
||||
SellAmount float64 `json:"sell_amount"`
|
||||
SellAvailable float64 `json:"sell_available"`
|
||||
SellPriceAvg float64 `json:"sell_price_avg"`
|
||||
SellPriceCost float64 `json:"sell_price_cost"`
|
||||
SellProfitReal float64 `json:"sell_profit_real"`
|
||||
Symbol string `json:"symbol"`
|
||||
}
|
||||
|
||||
// FuturePosition contains an array of holding types
|
||||
type FuturePosition struct {
|
||||
ForceLiquidationPrice float64 `json:"force_liqu_price"`
|
||||
Holding []HoldData `json:"holding"`
|
||||
}
|
||||
|
||||
// FutureTradeHistory will contain futures trade data
|
||||
type FutureTradeHistory struct {
|
||||
Amount float64 `json:"amount"`
|
||||
Date int `json:"date"`
|
||||
Price float64 `json:"price"`
|
||||
TID float64 `json:"tid"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
// SpotPrice holds date and ticker price price for contracts.
|
||||
type SpotPrice struct {
|
||||
Date string `json:"date"`
|
||||
Ticker struct {
|
||||
Buy float64 `json:"buy,string"`
|
||||
ContractID int `json:"contract_id"`
|
||||
High float64 `json:"high,string"`
|
||||
Low float64 `json:"low,string"`
|
||||
Last float64 `json:"last,string"`
|
||||
Sell float64 `json:"sell,string"`
|
||||
UnitAmount float64 `json:"unit_amount,string"`
|
||||
Vol float64 `json:"vol.string"`
|
||||
} `json:"ticker"`
|
||||
Result bool `json:"result"`
|
||||
Error interface{} `json:"error_code"`
|
||||
}
|
||||
|
||||
// SpotDepth response depth
|
||||
type SpotDepth struct {
|
||||
Asks []interface{} `json:"asks"`
|
||||
Bids []interface{} `json:"bids"`
|
||||
Result bool `json:"result"`
|
||||
Error interface{} `json:"error_code"`
|
||||
}
|
||||
|
||||
// ActualSpotDepth better manipulated structure to return
|
||||
type ActualSpotDepth struct {
|
||||
Asks []struct {
|
||||
Price float64
|
||||
Volume float64
|
||||
}
|
||||
Bids []struct {
|
||||
Price float64
|
||||
Volume float64
|
||||
}
|
||||
}
|
||||
|
||||
// ActualSpotTradeHistory holds contract trade history
|
||||
type ActualSpotTradeHistory struct {
|
||||
Amount float64 `json:"amount"`
|
||||
DateInMS float64 `json:"date_ms"`
|
||||
Date float64 `json:"date"`
|
||||
Price float64 `json:"price"`
|
||||
TID float64 `json:"tid"`
|
||||
Type string `json:"buy"`
|
||||
}
|
||||
25
testdata/configtest.json
vendored
25
testdata/configtest.json
vendored
@@ -453,6 +453,29 @@
|
||||
"Delimiter": "_"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "OKEX",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"UseSandbox": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"AvailablePairs": "ltc_btc,eth_btc,etc_btc,bch_btc,btc_usdt,eth_usdt,ltc_usdt,etc_usdt,bch_usdt,etc_eth,bt1_btc,bt2_btc,btg_btc,qtum_btc,hsr_btc,neo_btc,gas_btc,qtum_usdt,hsr_usdt,neo_usdt,gas_usdt,btc_usd,ltc_usd,eth_usd,etc_usd,bch_usd",
|
||||
"EnabledPairs": "btc_usd,ltc_usd",
|
||||
"BaseCurrencies": "USD",
|
||||
"AssetTypes": "SPOT,this_week,next_week,quarter",
|
||||
"ConfigCurrencyPairFormat": {
|
||||
"Uppercase": false,
|
||||
"Delimiter": "_"
|
||||
},
|
||||
"RequestCurrencyPairFormat": {
|
||||
"Uppercase": false,
|
||||
"Delimiter": "_"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "Poloniex",
|
||||
"Enabled": true,
|
||||
@@ -477,4 +500,4 @@
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user