-
Notifications
You must be signed in to change notification settings - Fork 820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exchanges: Okx Update #1420
base: master
Are you sure you want to change the base?
exchanges: Okx Update #1420
Conversation
… into okx_update
… into okx_update
… into okx_update
… into okx_update
… into okx_update
… into okx_update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a comment. Then looks good from me.
exchanges/okx/okx.go
Outdated
// GetLendingOffers get lending-supported currencies and estimated APY. | ||
func (ok *Okx) GetLendingOffers(ctx context.Context, ccy currency.Code, term string) ([]PublicLendingOffer, error) { | ||
params := url.Values{} | ||
if !ccy.IsEmpty() { | ||
params.Set("ccy", ccy.String()) | ||
} | ||
if term != "" { | ||
params.Set("term", term) | ||
} | ||
var resp []PublicLendingOffer | ||
return resp, ok.SendHTTPRequest(ctx, exchange.RestSpot, lendingPublicOfferEPL, http.MethodGet, common.EncodeURLValues("finance/fixed-loan/lending-offers", params), nil, &resp, request.UnauthenticatedRequest) | ||
} | ||
|
||
// GetLendingAPYHistory retrieves a lending history. | ||
func (ok *Okx) GetLendingAPYHistory(ctx context.Context, ccy currency.Code, term string) ([]LendingAPIHistoryItem, error) { | ||
if ccy.IsEmpty() { | ||
return nil, currency.ErrCurrencyCodeEmpty | ||
} | ||
if term == "" { | ||
return nil, errLendingTermIsRequired | ||
} | ||
params := url.Values{} | ||
params.Set("term", term) | ||
params.Set("ccy", ccy.String()) | ||
var resp []LendingAPIHistoryItem | ||
return resp, ok.SendHTTPRequest(ctx, exchange.RestSpot, lendingAPYHistoryEPL, http.MethodGet, common.EncodeURLValues("finance/fixed-loan/lending-apy-history", params), nil, &resp, request.UnauthenticatedRequest) | ||
} | ||
|
||
// GetLendingVolume retrieves a lending volume | ||
func (ok *Okx) GetLendingVolume(ctx context.Context, ccy currency.Code, term string) ([]LendingVolume, error) { | ||
if ccy.IsEmpty() { | ||
return nil, currency.ErrCurrencyCodeEmpty | ||
} | ||
if term == "" { | ||
return nil, errLendingTermIsRequired | ||
} | ||
params := url.Values{} | ||
params.Set("term", term) | ||
params.Set("ccy", ccy.String()) | ||
var resp []LendingVolume | ||
return resp, ok.SendHTTPRequest(ctx, exchange.RestSpot, lendingVolumeEPL, http.MethodGet, common.EncodeURLValues("finance/fixed-loan/pending-lending-volume", params), nil, &resp, request.UnauthenticatedRequest) | ||
} | ||
|
||
// Trading Statistics endpoints. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why were these removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code: 51739 message: This function is temporarily unavailable
We will add them when they are available.
I waited for these endpoints to get back to work and couldn't be updated to work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good! Thanks.
… into okx_update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a test that seems to periodically fail:
https://github.com/thrasher-corp/gocryptotrader/actions/runs/12216182485/job/34079014540?pr=1420#step:10:706
--- FAIL: TestGenerateSubscriptions (0.00s)
okx_test.go:5793:
Error Trace: /home/runner/work/gocryptotrader/gocryptotrader/internal/testing/subscriptions/subscriptions.go:32
/home/runner/work/gocryptotrader/gocryptotrader/exchanges/okx/okx_test.go:5793
Error: Differences:
+ {"channel":"grid-positions"} grid-positions
- {"channel":"account"} myAccount
Test: TestGenerateSubscriptions
Messages: Subscriptions should be equal
Other than that, I'm happy :)
I hope this recent change has resolved the issue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK!
🕊️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎺 tack 🎺
… into okx_update
… into okx_update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work on this massive PR @samuael, really like the types cleanup due to OKX dropping JSON keys similar to Bitfinex. Just some first round nits
exchanges/asset/asset.go
Outdated
@@ -29,6 +29,7 @@ const ( | |||
MarginFunding | |||
Index | |||
Binary | |||
Spread |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be moved to below the futures section since it involves at least one futures contract
exchanges/okx/okx_types.go
Outdated
LiquidationOrders: liquidation, | ||
NumberOfOrders: orders, | ||
// GetItems returns a list of OrderbookItemDetail instances. | ||
func GetItems(data [][4]types.Number) ([]OrderbookItemDetail, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can unexport this func
exchanges/okx/okx_types.go
Outdated
} | ||
|
||
// MarginLendRatioItem represents margin lend ration information and creation timestamp | ||
type MarginLendRatioItem struct { | ||
Timestamp time.Time `json:"ts"` | ||
MarginLendRatio float64 `json:"ratio"` | ||
Timestamp types.Time `json:"ts"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can rid these JSON tags as they're not needed, but this is a sexy solution
exchanges/okx/okx_types.go
Outdated
type LongShortRatio struct { | ||
Timestamp time.Time `json:"ts"` | ||
MarginLendRatio float64 `json:"ratio"` | ||
Timestamp types.Time `json:"ts"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, will stop reporting these as there's a few of them
errExceedLimit = errors.New("limit exceeded") | ||
errOnlyThreeMonthsSupported = errors.New("only three months of trade data retrieval supported") | ||
errOnlyOneResponseExpected = errors.New("one response item expected") | ||
errNoInstrumentFound = errors.New("no instrument found") | ||
) | ||
|
||
/************************************ MarketData Endpoints *************************************************/ | ||
|
||
// OrderTypeFromString returns order.Type instance from string | ||
func (ok *Okx) OrderTypeFromString(orderType string) (order.Type, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requires test coverage
} | ||
|
||
// PlaceAlgoOrder order includes trigger order, oco order, conditional order,iceberg order, twap order and trailing order. | ||
func (ok *Okx) PlaceAlgoOrder(ctx context.Context, arg *AlgoOrderParams) (*AlgoOrder, error) { | ||
if *arg == (AlgoOrderParams{}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage
} | ||
return ok.PlaceAlgoOrder(ctx, arg) | ||
} | ||
|
||
// PlaceTrailingStopOrder to place trailing stop order | ||
func (ok *Okx) PlaceTrailingStopOrder(ctx context.Context, arg *AlgoOrderParams) (*AlgoOrder, error) { | ||
if arg == nil { | ||
return nil, errNilArgument | ||
if *arg == (AlgoOrderParams{}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage for these offline checks
} | ||
if arg.CallbackRatio == 0 && arg.CallbackSpreadVariance == "" { | ||
return nil, errors.New("either \"callbackRatio\" or \"callbackSpread\" is allowed to be passed") | ||
} | ||
return ok.PlaceAlgoOrder(ctx, arg) | ||
} | ||
|
||
// PlaceIcebergOrder to place iceburg algo order | ||
// PlaceIcebergOrder to place iceberg algo order |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for here and the 3 below
orderType = strings.ToLower(orderType) | ||
if orderType == "" { | ||
return nil, errors.New("order type is required") | ||
return nil, order.ErrTypeIsInvalid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs test coverage
if orderType == "" { | ||
return nil, errors.New("order type is required") | ||
return nil, order.ErrTypeIsInvalid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs test coverage, will stop reporting them from here but please re-review the offline ones we can at least test
config_example.json
Outdated
}, | ||
"spread": { | ||
"assetEnabled": true, | ||
"enabled": "BTC-USD-241113-70000-C,BTC-USD-241113-70000-P,BTC-USD-241113-72000-C,BTC-USD-241113-72000-P,BTC-USD-241113-74000-C", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are option symbols, though when running it the expected symbols populate correctly
testdata/configtest.json
Outdated
}, | ||
"spread": { | ||
"assetEnabled": true, | ||
"enabled": "BTC-USD-241113-70000-C,BTC-USD-241113-70000-P,BTC-USD-241113-72000-C,BTC-USD-241113-72000-P,BTC-USD-241113-74000-C", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for these ones
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making those changes! config_example and test config spread symbols looking good + substantial increase in test coverage. Found some additional ones
} | ||
if arg.QuantityType != "" && arg.QuantityType != "base_ccy" && arg.QuantityType != "quote_ccy" { | ||
switch arg.QuantityType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage
if args == nil { | ||
return nil, errNilArgument | ||
func (ok *Okx) CancelAlgoOrder(ctx context.Context, args []AlgoOrderCancelParams) (*AlgoOrder, error) { | ||
if len(args) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage
exchanges/okx/okx.go
Outdated
@@ -1005,7 +747,7 @@ func (ok *Okx) PlaceEasyConvert(ctx context.Context, arg PlaceEasyConvertParam) | |||
return nil, fmt.Errorf("%w, missing 'toCcy'", errMissingRequiredParameter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage for these two params
} | ||
if len(resp) == 1 { | ||
return &resp[0], nil | ||
return nil, errMissingLegs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage for these two params
} | ||
|
||
// CancelMultipleRfqs cancel multiple active Rfqs in a single batch. Maximum 100 Rfq orders can be canceled at a time. | ||
func (ok *Okx) CancelMultipleRfqs(ctx context.Context, arg CancelRfqRequestsParam) ([]CancelRfqResponse, error) { | ||
func (ok *Okx) CancelMultipleRfqs(ctx context.Context, arg *CancelRfqRequestsParam) ([]CancelRfqResponse, error) { | ||
if arg == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Acronym creation: MTC (Missing test coverage 😆 ) and the below len clientRfgIDs > 100 below
|
||
// ManualBorrowAndRepayInQuickMarginMode initiates a new manual borrow and repayment process in Quick Margin mode. | ||
func (ok *Okx) ManualBorrowAndRepayInQuickMarginMode(ctx context.Context, arg *BorrowAndRepay) (*BorrowAndRepay, error) { | ||
if *arg == (BorrowAndRepay{}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MTC
} | ||
|
||
// MasterAccountsManageTransfersBetweenSubaccounts master accounts manage the transfers between sub-accounts applies to master accounts only | ||
func (ok *Okx) MasterAccountsManageTransfersBetweenSubaccounts(ctx context.Context, arg *SubAccountAssetTransferParams) ([]TransferIDInfo, error) { | ||
if arg.Currency == "" { | ||
return nil, errInvalidCurrencyValue | ||
if *arg == (SubAccountAssetTransferParams{}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MTC on these params
func (ok *Okx) PlaceGridAlgoOrder(ctx context.Context, arg *GridAlgoOrder) (*GridAlgoOrderIDResponse, error) { | ||
if arg == nil { | ||
return nil, errNilArgument | ||
if *arg == (GridAlgoOrder{}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate check but also MTC on the params
} | ||
|
||
// GetPublicBlockTrades retrieves the recent block trading transactions of an instrument. Descending order by tradeId. | ||
func (ok *Okx) GetPublicBlockTrades(ctx context.Context, instrumentID string) ([]BlockTrade, error) { | ||
if instrumentID == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MTC
} | ||
|
||
// GetInsuranceFundInformation returns insurance fund balance information. | ||
func (ok *Okx) GetInsuranceFundInformation(ctx context.Context, arg *InsuranceFundInformationRequestParams) (*InsuranceFundInformation, error) { | ||
if arg == nil { | ||
return nil, errNilArgument | ||
if *arg == (InsuranceFundInformationRequestParams{}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MTC
exchanges/okx/okx_websocket.go
Outdated
authDialer.ReadBufferSize = 8192 | ||
authDialer.WriteBufferSize = 8192 | ||
err = ok.WsAuth(context.TODO(), &authDialer) | ||
ok.Websocket.SetCanUseAuthenticatedEndpoints(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can rid this as this is always setting auth to true
… into okx_update
… into okx_update
Selam, ወንድሞች.
PR Description
This pull request incorporates modifications for the Okx exchange, encompassing changes to endpoint methods, rate limits, WebSocket subscriptions and handlers, wrapper functions, and conversion methods. Rigorous testing has been conducted on all facets of the functions to ensure their reliability. The code adheres to the GCT style standards, consistent with practices adopted by other exchanges. To enhance code quality, golangci-lint was utilized for linter testing, effectively rectifying a few errors. Furthermore, this implementation includes endpoint methods that the GCT wrapper did not initially support, ensuring compatibility for future use
The PR updated implementations for REST for trading and other endpoint methods, Web-socket streaming, and Trading through the web socket stream.
Fixes # (issue)
Type of change
Please delete options that are not relevant and add an
x
in[]
as the item is complete.How has this been tested
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration and also, consider improving test coverage whilst working on a certain feature or package.
Checklist