-
Notifications
You must be signed in to change notification settings - Fork 822
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
Open
samuael
wants to merge
164
commits into
thrasher-corp:master
Choose a base branch
from
samuael:okx_update
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
exchanges: Okx Update #1420
Changes from 158 commits
Commits
Show all changes
164 commits
Select commit
Hold shift + click to select a range
1c049bb
update acccount ratelimits and added missing endpoints
samuael 5ba4043
completed mapping missing trade accoung REST endpoints and Rate Limit
samuael 57ebd02
added orderbook trading missing REST endpoints
samuael 372a0be
Added few missing endpoints and unit tests
samuael b448b2d
Completed grid trading and signal bot trading with unit tests
samuael c8ec145
Added Recurring Buy endpoints and corresponding unit tests
samuael de333e1
Added copy trading endpoints and unit tests
samuael 474b7ee
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 5e44c1c
added newly added block trading and spread endpoints
samuael b25bca0
completed mapping spread endpoints
samuael 6444789
Added new endpoints and unit tests
samuael 02581e0
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 29c2901
Added round 1: Okx types and converts update.
samuael af5a97b
Update endpoints handling and types update
samuael 3112408
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 9d19df1
Removed constants, updated unit tests, and updated endpoint methods
samuael 8cbcca1
Slight endpoint and unit test update
samuael 716c294
Added spread and other websocket endpoints and update
samuael a8e6f43
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 770b878
completed Spread WS Orderbook handler
samuael 32a0bce
Added missing spread channels and handlers
samuael 1a7f33c
Adding Bussinss websocket and missing subscriptions, update unit test…
samuael fe3c28e
Added spread endpoints to wrapper and unit tests update
samuael 6a6cd71
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 42a9826
Added missing websocket subscriptions and copy trading endpoints
samuael b20386c
Added missing endpoints and re-organize business websocket handlers
samuael ddb379d
Docs update
samuael 0bf59bc
Endpoints code updates
samuael 7360c8e
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 6c60fde
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael ab5ff5e
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael b472922
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 7579c09
types, unit test and endpoints update
samuael 3c6524f
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 340f5a8
Minor unit tests update
samuael 44ce688
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 2834e29
spelling fix
samuael d7143fa
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 3c82295
fix unit test issues
samuael 6ab81da
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael bdddb53
Updating unit tests error handling
samuael b4de8e5
Updating unit tests error handling
samuael 41174d1
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael c6d4274
Unit tests assertion handling update
samuael 70f57b8
Unit tests update
samuael b971949
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 1ef68e5
Resolve linter issues
samuael f383383
linter issues fix
samuael 960c2b3
Orderbook unit test error fix
samuael 314d5b4
Minor fixes
samuael 9a36a29
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael a20435b
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 03ad8e5
Change on test handling and types
samuael fdf7e4a
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael b6b2e3e
Updating unit tests and cleanups
samuael ede9af8
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 54f3a0a
Fix unit test issues
samuael 8106d20
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael efa96e8
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 4b4c518
Add ratelimit test and update unit tests and methods
samuael c647b48
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 40d97d0
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael e7c2b7c
Update method parameters and error declarations
samuael 213888f
Added lending endpoints, unit tests, and update endpoint methods and …
samuael 719f310
Update ratelimiters, add missing lending and trading endpoints and un…
samuael 804b839
Update websocket authentication and subscription handling
samuael 58685b5
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 0c2265d
Minor update to unit test and types
samuael cfc8519
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael fb7fa19
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 9a9711b
Types, error handling, and other minor updates
samuael d6dbee7
Update unit tests and endpoint functions
samuael 7c07649
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael d388a4b
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 980d30a
error declarations update and unit tests
samuael b8c5264
Overall update on unit endpoint, unit tests, and types
samuael 95dc4e0
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael e406221
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 06300af
Adding review fixes
samuael 82a77d0
Update on endpoints, order types, and unit tests
samuael 6c08ec3
Update unit tests and endpoint functions
samuael 439c460
Update on endpoint and update missing parameters
samuael 9394e26
Implemented and tested newly added trading endpoints
samuael e877122
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael b77e1d8
endpoints update and unit tests
samuael 0a55411
Update missing endpoints and update overall code
samuael 14dd03a
added and testing funding and fiat related endpoints
samuael 87c1a37
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael f003f9b
Update on convert and fiat related endpoints
samuael 8985235
linter fix, types, endpoints, and unit tests update
samuael b3e7d71
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 736e267
linter issues fix
samuael 30e576e
revert changes on tempos
samuael c00ce6d
Fix Panic and update websocket auth calls handling
samuael 6266ad2
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 5ffd43f
config linter issue fix
samuael c16906d
Fix panic issues and update unit tests
samuael ef765f4
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael f5e0728
Fix race condition, TestAllExchangeWrappers unit test issues
samuael 43624d7
Fix withdrawal manager test issue
samuael f6220a4
Rename ClosePositionForContractrID --> ClosePositionForContractID
samuael f75c7e5
Rename ClosePositionForContractrID --> ClosePositionForContractID
samuael d7a6065
Fix error
samuael 5d1e0d7
endpoints update and fix unit test issues
samuael 2e4e1a1
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 735728c
Merge branch 'okx_update' of https://github.com/samuael/gocryptotrade…
samuael 567c9c3
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael f89574c
added unit tests, updated comments, and code sections
samuael 36792ea
revert change in defaultSubscriptions
samuael c27d51b
few types comments update
samuael 5a9edd5
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 90479fe
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 22fdf03
Minor changes
samuael 9bd5e7e
remove lending endpoints
samuael d485dcb
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael b52b6d7
rm mistakenly added code
samuael 5406298
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 53fe0c7
fix unit test
samuael 084753b
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael cf31fb5
minor unit test fix
samuael 1429501
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 62fac9c
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael d884ecb
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 121b6a0
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 18badd9
Adding offline error tests, update endpoints function, config update
samuael 076719b
Update unit test coverage for offline error handliing
samuael 7c1cb10
Updating wrapper algo order coverage, endpoint calls, and unit tests
samuael 0291113
Updating wrapper trade functions to accomodate algo orders
samuael cdddf2e
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 53e09ce
update wrapper unit tests
samuael 2df3ee7
Fix wrapper order functions offline errors handling
samuael d2ccc2d
Tested and updated wrapper order functions
samuael 131126f
Address review comments
samuael 54ac698
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael a5ebd9f
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 7822c9f
update order unit tests, and okx endpoint functions
samuael 8bf71ac
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 6dd557e
finalize affected order, endpoint, and margin endpoints
samuael 0dde48a
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael b1b120d
Slight change on margin unit test
samuael 39006e5
fix margin unit test issues
samuael 7551b58
Minor change on unit test
samuael 7bf2273
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael e4a2f35
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 7527375
updates on contract settlement and future contract wrapper function
samuael 86b6a9c
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 087b420
add test coverage for contract functions and minor fix on wrapper
samuael 8b36c4b
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael fe6ef5e
Overall update and unit testing
samuael 0a4b400
codespell, unit tests, type declaration and naming, and code-structur…
samuael 38e7566
margin types value and validation function fix
samuael 91dd78e
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 4a0ce09
Update tests and helper funcs
samuael 9cb7a76
Improve test coverage
samuael ca03367
helper functions and unit tests update
samuael 4b2f00c
Fix margin unit test
samuael 4e97b06
Minor review updates
samuael 340aa80
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael 8864f57
minor fix on if statement
samuael 64936a8
Update helper functions
samuael 2fc191f
error handling and functions naming update
samuael 43955ad
update comment
samuael 4258a29
minor error return fixes
samuael b74b459
Merge branch 'master' of http://github.com/thrasher-corp/gocryptotrad…
samuael File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package futures | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
"time" | ||
|
||
"github.com/shopspring/decimal" | ||
|
@@ -9,6 +11,11 @@ import ( | |
"github.com/thrasher-corp/gocryptotrader/exchanges/fundingrate" | ||
) | ||
|
||
// var error definitions | ||
var ( | ||
ErrInvalidContractSettlementType = errors.New("invalid contract settlement type") | ||
) | ||
|
||
// Contract holds details on futures contracts | ||
type Contract struct { | ||
Exchange string | ||
|
@@ -41,6 +48,7 @@ const ( | |
Inverse | ||
Quanto | ||
LinearOrInverse | ||
Hybrid | ||
) | ||
|
||
// String returns the string representation of a contract settlement type | ||
|
@@ -56,11 +64,34 @@ func (d ContractSettlementType) String() string { | |
return "quanto" | ||
case LinearOrInverse: | ||
return "linearOrInverse" | ||
case Hybrid: | ||
return "hybrid" | ||
default: | ||
return "unknown" | ||
} | ||
} | ||
|
||
// StringToContractSettlementType for converting case insensitive contract settlement type | ||
func StringToContractSettlementType(cstype string) (ContractSettlementType, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While you are here can you please expand coverage across this file please 🙏 |
||
cstype = strings.ToLower(cstype) | ||
switch cstype { | ||
case UnsetSettlementType.String(), "": | ||
return UnsetSettlementType, nil | ||
case Linear.String(): | ||
return Linear, nil | ||
case Inverse.String(): | ||
return Inverse, nil | ||
case Quanto.String(): | ||
return Quanto, nil | ||
case "linearorinverse": | ||
return LinearOrInverse, nil | ||
case Hybrid.String(): | ||
return Hybrid, nil | ||
default: | ||
return UnsetSettlementType, ErrInvalidContractSettlementType | ||
} | ||
} | ||
|
||
// ContractType holds the various style of contracts offered by futures exchanges | ||
type ContractType uint8 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package futures | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestStringToContractSettlementType(t *testing.T) { | ||
t.Parallel() | ||
contractSettlementTypesMap := map[string]struct { | ||
CT ContractSettlementType | ||
Error error | ||
}{ | ||
"lInear": {Linear, nil}, | ||
"LINEAR": {Linear, nil}, | ||
"Inverse": {Inverse, nil}, | ||
"unset": {UnsetSettlementType, nil}, | ||
"hybRiD": {Hybrid, nil}, | ||
"LinearOrInverse": {LinearOrInverse, nil}, | ||
"": {UnsetSettlementType, nil}, | ||
"Quanto": {Quanto, nil}, | ||
"QUANTO": {Quanto, nil}, | ||
"Unknown": {UnsetSettlementType, ErrInvalidContractSettlementType}, | ||
} | ||
for x, v := range contractSettlementTypesMap { | ||
val, err := StringToContractSettlementType(x) | ||
assert.Equal(t, v.CT, val) | ||
assert.ErrorIs(t, err, v.Error) | ||
} | ||
} | ||
|
||
func TestContractSettlementTypeString(t *testing.T) { | ||
t.Parallel() | ||
contractSettlementTypeToStringMap := map[ContractSettlementType]string{ | ||
UnsetSettlementType: "unset", | ||
Linear: "linear", | ||
Inverse: "inverse", | ||
Quanto: "quanto", | ||
LinearOrInverse: "linearOrInverse", | ||
Hybrid: "hybrid", | ||
ContractSettlementType(200): "unknown", | ||
} | ||
for k, v := range contractSettlementTypeToStringMap { | ||
assert.Equal(t, v, k.String()) | ||
} | ||
} | ||
|
||
func TestContractTypeToString(t *testing.T) { | ||
t.Parallel() | ||
contractTypeToStringMap := map[ContractType]string{ | ||
Daily: "day", | ||
Perpetual: "perpetual", | ||
LongDated: "long_dated", | ||
Weekly: "weekly", | ||
Fortnightly: "fortnightly", | ||
ThreeWeekly: "three-weekly", | ||
Monthly: "monthly", | ||
Quarterly: "quarterly", | ||
SemiAnnually: "semi-annually", | ||
HalfYearly: "half-yearly", | ||
NineMonthly: "nine-monthly", | ||
Yearly: "yearly", | ||
Unknown: "unknown", | ||
UnsetContractType: "unset", | ||
ContractType(200): "unset", | ||
} | ||
for k, v := range contractTypeToStringMap { | ||
assert.Equal(t, v, k.String()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Need a config version to add spread to assetTypes for user's config:)
If this is the next PR to be merged, then it can be the next V* on master.
@thrasher- can confirm.
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.
I don't understand what you mean by for user's config. If it is in the config.json files it is already done.
Correct me if I understood what you mean wrong
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 PR is indeed targeted to be merged as soon as it's ready 🚀
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.
@samuael I don't see that it's already done.
If I check out your branch, and run it
spread
is not added to the assets listed in pairs.I thought I might be wrong and your call to
SetGlobalPairsManager
inSetDefaults
might add it.I'm thinking you want something like this which adds an entry for spread on upgrade.
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.
@gbjk I am getting it and I deleted the reference from config just to make sure:
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.
Something like this
I put a hardcoded symbol in because without it the first run won't go smoothly. Can't see a way around that for this kind of asset. If they were all dated then ... Really don't know how we'd make it safe for first run.
ensureOneEnabled
thing would need to have new available pairs first.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.
Okay, so:
Which is kinda okay, cos the asset isn't enabled.
Think it'd probably interact okay with #1735 as well.
enabled
will be populated, and assetEnabled set to true, and everything is okayThis gives us a weird inconsistency on upgrade.
I'd vote for having a config upgrade to give us a sane available pairs base-state.
Also can choose if you want to enable or disable the asset by default. I'm assuming enable.
Also accepting if we just ignore this, but it feels unnecessarily harsh on upgraders to have different results on subsequent runs.
Also sparing a thought for users who run
-dry
in containersThere 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.
Note: No input from anyone else on this.
I think it's still actionable, and I provided an example solution above :)