mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
okx: GetDefaultConfig fix & ticker field improvements (#1227)
* okx: updaterooo (cherry pick) * okx: add in target currency handling in spot market orders * okx:don't adjust order.Submit variables. * spell checker * okx_wrapper: updateTradablePairs true bool * thrasher: nits * purge default env vars * point to CI env var * print out environment * lol --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
This commit is contained in:
@@ -19,3 +19,4 @@
|
||||
wsTradeExecuted = "te"
|
||||
wsBalanceUpdate = "bu"
|
||||
"59512": errors.New("unable to set up this permission for ND brokers sub accounts. by default, all ND sub accounts can transfer funds out"),
|
||||
currency.MIS: 0.002,
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
)
|
||||
|
||||
func TestLoadConfigWithSettings(t *testing.T) {
|
||||
@@ -338,3 +341,42 @@ func TestSettingsPrint(t *testing.T) {
|
||||
s = &Settings{}
|
||||
s.PrintLoadedSettings()
|
||||
}
|
||||
|
||||
func TestGetDefaultConfigurations(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
man := NewExchangeManager()
|
||||
for x := range exchange.Exchanges {
|
||||
target := exchange.Exchanges[x]
|
||||
t.Run(target, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
exch, err := man.NewExchangeByName(target)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if isCITest() && common.StringDataContains(blockedCIExchanges, target) {
|
||||
t.Skipf("skipping %s due to CI test restrictions", target)
|
||||
}
|
||||
|
||||
cfg, err := exch.GetDefaultConfig(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if cfg == nil {
|
||||
t.Fatal("expected config")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func isCITest() bool {
|
||||
ci := os.Getenv("CI")
|
||||
return ci == "true" /* github actions */ || ci == "True" /* appveyor */
|
||||
}
|
||||
|
||||
// blockedCIExchanges are exchanges that are not able to be tested on CI
|
||||
var blockedCIExchanges = []string{
|
||||
"binance", // binance API is banned from executing within the US where github Actions is ran
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ type TickerResponse struct {
|
||||
LastTradeSize okxNumericalValue `json:"lastSz"`
|
||||
BestAskPrice okxNumericalValue `json:"askPx"`
|
||||
BestAskSize okxNumericalValue `json:"askSz"`
|
||||
BidPrice okxNumericalValue `json:"bidPx"`
|
||||
BidSize okxNumericalValue `json:"bidSz"`
|
||||
BestBidPrice okxNumericalValue `json:"bidPx"`
|
||||
BestBidSize okxNumericalValue `json:"bidSz"`
|
||||
Open24H okxNumericalValue `json:"open24h"`
|
||||
High24H okxNumericalValue `json:"high24h"`
|
||||
Low24H okxNumericalValue `json:"low24h"`
|
||||
|
||||
@@ -1218,9 +1218,9 @@ func (ok *Okx) wsProcessTickers(data []byte) error {
|
||||
QuoteVolume: quoteVolume,
|
||||
High: response.Data[i].High24H.Float64(),
|
||||
Low: response.Data[i].Low24H.Float64(),
|
||||
Bid: response.Data[i].BidPrice.Float64(),
|
||||
Bid: response.Data[i].BestBidPrice.Float64(),
|
||||
Ask: response.Data[i].BestAskPrice.Float64(),
|
||||
BidSize: response.Data[i].BidSize.Float64(),
|
||||
BidSize: response.Data[i].BestBidSize.Float64(),
|
||||
AskSize: response.Data[i].BestAskSize.Float64(),
|
||||
Last: response.Data[i].LastTradePrice.Float64(),
|
||||
AssetType: a,
|
||||
|
||||
@@ -43,13 +43,13 @@ func (ok *Okx) GetDefaultConfig(ctx context.Context) (*config.Exchange, error) {
|
||||
exchCfg.HTTPTimeout = exchange.DefaultHTTPTimeout
|
||||
exchCfg.BaseCurrencies = ok.BaseCurrencies
|
||||
|
||||
err := ok.Setup(exchCfg)
|
||||
err := ok.SetupDefaults(exchCfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if ok.Features.Supports.RESTCapabilities.AutoPairUpdates {
|
||||
err := ok.UpdateTradablePairs(ctx, false)
|
||||
err = ok.UpdateTradablePairs(ctx, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -381,8 +381,10 @@ func (ok *Okx) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item)
|
||||
Last: mdata.LastTradePrice.Float64(),
|
||||
High: mdata.High24H.Float64(),
|
||||
Low: mdata.Low24H.Float64(),
|
||||
Bid: mdata.BidPrice.Float64(),
|
||||
Bid: mdata.BestBidPrice.Float64(),
|
||||
BidSize: mdata.BestBidSize.Float64(),
|
||||
Ask: mdata.BestAskPrice.Float64(),
|
||||
AskSize: mdata.BestAskSize.Float64(),
|
||||
Volume: baseVolume,
|
||||
QuoteVolume: quoteVolume,
|
||||
Open: mdata.Open24H.Float64(),
|
||||
@@ -424,8 +426,10 @@ func (ok *Okx) UpdateTickers(ctx context.Context, assetType asset.Item) error {
|
||||
Last: ticks[y].LastTradePrice.Float64(),
|
||||
High: ticks[y].High24H.Float64(),
|
||||
Low: ticks[y].Low24H.Float64(),
|
||||
Bid: ticks[y].BidPrice.Float64(),
|
||||
Bid: ticks[y].BestBidPrice.Float64(),
|
||||
BidSize: ticks[y].BestBidSize.Float64(),
|
||||
Ask: ticks[y].BestAskPrice.Float64(),
|
||||
AskSize: ticks[y].BestAskSize.Float64(),
|
||||
Volume: ticks[y].Vol24H.Float64(),
|
||||
QuoteVolume: ticks[y].VolCcy24H.Float64(),
|
||||
Open: ticks[y].Open24H.Float64(),
|
||||
@@ -762,14 +766,26 @@ func (ok *Okx) SubmitOrder(ctx context.Context, s *order.Submit) (*order.SubmitR
|
||||
} else {
|
||||
sideType = order.Sell.Lower()
|
||||
}
|
||||
|
||||
amount := s.Amount
|
||||
var targetCurrency string
|
||||
if s.AssetType == asset.Spot && s.Type == order.Market {
|
||||
targetCurrency = "base_ccy" // Default to base currency
|
||||
if s.QuoteAmount > 0 {
|
||||
amount = s.QuoteAmount
|
||||
targetCurrency = "quote_ccy"
|
||||
}
|
||||
}
|
||||
|
||||
var orderRequest = &PlaceOrderRequestParam{
|
||||
InstrumentID: instrumentID,
|
||||
TradeMode: tradeMode,
|
||||
Side: sideType,
|
||||
OrderType: s.Type.Lower(),
|
||||
Amount: s.Amount,
|
||||
Amount: amount,
|
||||
ClientSupplierOrderID: s.ClientOrderID,
|
||||
Price: s.Price,
|
||||
QuantityType: targetCurrency,
|
||||
}
|
||||
switch s.Type.Lower() {
|
||||
case OkxOrderLimit, OkxOrderPostOnly, OkxOrderFOK, OkxOrderIOC:
|
||||
|
||||
Reference in New Issue
Block a user