Skip to content
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

Feature - Revamp Okx #71

Open
wants to merge 109 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
82c7b3f
Add okx initial files
LucianoPierdona May 18, 2022
2b47809
Add Okx Symbol schema and fixtures
LucianoPierdona May 19, 2022
ffaa3c9
Add Okx Market schema and fixtures
LucianoPierdona May 19, 2022
f614bd4
Add Okx Key schema and fixtures
LucianoPierdona May 19, 2022
38d08aa
Add Okx Balance schema and fixtures
LucianoPierdona May 19, 2022
17e2f0b
Add Okx Symbol parse many and test suite
LucianoPierdona May 19, 2022
b3bdbc2
Add Okx Symbol parse and test suite
LucianoPierdona May 19, 2022
f5a3440
Add Okx Symbol list raw and test suite
LucianoPierdona May 19, 2022
9657a0d
Add Okx Market parse many
LucianoPierdona May 19, 2022
bc963ad
Add Okx Market parse and test suite
LucianoPierdona May 19, 2022
fc1677b
Add Okx Market list raw and test suite
LucianoPierdona May 19, 2022
40bcba3
Add Okx Key fetch details and test suite
LucianoPierdona May 19, 2022
3f33225
Add Okx Balance list raw and test suite
LucianoPierdona May 19, 2022
13ed458
Add Okx Balance parse many
LucianoPierdona May 19, 2022
a8820ec
Add Okx Balance parse and test suite
LucianoPierdona May 19, 2022
240c9bc
Add Okx symbol type enum
LucianoPierdona May 19, 2022
86e1d7c
Add Okx symbol status enum
LucianoPierdona May 19, 2022
92b881a
Add Okx specs and test suite
LucianoPierdona May 19, 2022
219a7f1
Add Okx http and test suite
LucianoPierdona May 19, 2022
23026df
Add Okx Order schema and fixtures
LucianoPierdona May 19, 2022
02f7522
remove okx market status enum
LucianoPierdona May 19, 2022
8293881
add okx order side enum
LucianoPierdona May 19, 2022
70eae9f
add okx order status enum
LucianoPierdona May 19, 2022
65b089d
add okx order type enum
LucianoPierdona May 19, 2022
86bc511
add okx order side adapter and test suite
LucianoPierdona May 19, 2022
a560790
add okx order status adapter and test suite
LucianoPierdona May 19, 2022
7119d87
add okx order type adapter and test suite
LucianoPierdona May 19, 2022
16d19db
add okx order cancel and test suite
LucianoPierdona May 19, 2022
3b719b4
add okx order get raw and test suite
LucianoPierdona May 19, 2022
5ba9634
add okx order place and test suite
LucianoPierdona May 19, 2022
420e72a
add okx order test suite for edit and get
LucianoPierdona May 19, 2022
760425e
add okx order list raw
LucianoPierdona May 19, 2022
d8db406
add okx order parse and test suite
LucianoPierdona May 19, 2022
b6c9257
Fix symbol parse many and test suite
LucianoPierdona May 19, 2022
1605def
linting
LucianoPierdona May 19, 2022
ed6a9d7
Merge remote-tracking branch 'origin/master' into feature/revamp-okx
LucianoPierdona May 20, 2022
f8e8ab5
updates to okx, add 100% test coverage
LucianoPierdona May 20, 2022
b6a200a
linting
LucianoPierdona May 20, 2022
9ffd6c9
fix e2e tests and error handling
LucianoPierdona May 20, 2022
f6ccfb4
linting
LucianoPierdona May 20, 2022
e7e0af2
Add 100% test coverage
LucianoPierdona May 20, 2022
152a914
add okx to aluna-spec.json
LucianoPierdona May 20, 2022
7c48f56
removed TODOs
LucianoPierdona May 20, 2022
1ebb574
draft: add algo orders to main list
LucianoPierdona May 20, 2022
d237c4d
draft: add support to stop-market
LucianoPierdona May 20, 2022
2bf3028
draft: fix stop limit orders
LucianoPierdona May 20, 2022
d9c567e
draft: fix stop order limit
LucianoPierdona May 20, 2022
6da15a5
add 100% test coverage for okx
LucianoPierdona May 23, 2022
4309dc4
linting
LucianoPierdona May 23, 2022
a75733a
review okx symbols and markets to support margin
LucianoPierdona May 28, 2022
2769640
Merge remote-tracking branch 'origin/master' into feature/revamp-okx
LucianoPierdona May 28, 2022
767f25c
add 100% test coverage
LucianoPierdona May 28, 2022
1f30077
add okx position initial files
LucianoPierdona May 29, 2022
c4ca0b3
add new okx specs for positions
LucianoPierdona May 29, 2022
b31f477
add okx position side enum
LucianoPierdona May 29, 2022
fff139d
add okx position side adapter and test suite
LucianoPierdona May 29, 2022
e5a5681
add okx position schema
LucianoPierdona May 29, 2022
613c44a
add okx position close
LucianoPierdona May 29, 2022
851ba96
add okx position getLeverage
LucianoPierdona May 29, 2022
031b3d9
add okx position set leverage
LucianoPierdona May 29, 2022
5cf5d11
add okx position parse
LucianoPierdona May 29, 2022
613ed24
add okx position get raw
LucianoPierdona May 29, 2022
f1be453
add okx position fixtures
LucianoPierdona May 29, 2022
4b41f91
fix test coverage for okx positions
LucianoPierdona May 29, 2022
75e6962
update okx place and test suite
LucianoPierdona May 30, 2022
1f361ea
update okx balance parse and test suite
LucianoPierdona May 30, 2022
29376f7
update okx specs
LucianoPierdona May 30, 2022
f688fcb
add `ACCOUNT` property to aluna wallet enum
LucianoPierdona May 30, 2022
824fa09
update test suite for position parse
LucianoPierdona May 30, 2022
79131e8
fix 'handleOkxRequestError'
Torres-ssf Jun 7, 2022
71bcc73
refact 'handleOkxRequestError' test suite
Torres-ssf Jun 7, 2022
80203ba
made Okx 'fetchDetails' properly verify api key
Torres-ssf Jun 7, 2022
47c4e82
refact test suite for Okx fetchDetails
Torres-ssf Jun 7, 2022
92fd817
refact code
Torres-ssf Jun 7, 2022
57b6bc9
Merge branch 'master' into feature/revamp-okx
Torres-ssf Jun 7, 2022
4fb51a7
conforming with merged changes
Torres-ssf Jun 7, 2022
6dacba1
removing account wallet
Torres-ssf Jun 7, 2022
f2d2609
using proper wallet type for OXK balances
Torres-ssf Jun 7, 2022
b58d371
improve Okx request reponse handling
Torres-ssf Jun 7, 2022
a6944b3
refact para for macro test 'testCache'
Torres-ssf Jun 7, 2022
2224bba
refact 'OkxHttp' test suite
Torres-ssf Jun 7, 2022
e3b9bdb
properly handle okx request errors on 'handleOkxRequestError'
Torres-ssf Jun 7, 2022
4390aef
refact test suite for 'handleOkxRequestError'
Torres-ssf Jun 7, 2022
3083bac
fix macro test call on FtxHttp
Torres-ssf Jun 7, 2022
cad020e
refact Okx key 'fetchDetails' to conform with last changes
Torres-ssf Jun 7, 2022
b428fd9
refact test suite for Okx key 'fetchDetails'
Torres-ssf Jun 7, 2022
0aeb594
fixes to okx configs, schema and fixtures
LucianoPierdona Jun 12, 2022
8f749a3
fix okx place order
LucianoPierdona Jun 12, 2022
1c2f2d2
fix okx get raw
LucianoPierdona Jun 12, 2022
d80ed31
fix okx parse many calculation
LucianoPierdona Jun 12, 2022
27bfef5
fix okx order parse to include baseSymbolId and quoteSymbolId
LucianoPierdona Jun 12, 2022
1085131
Merge remote-tracking branch 'origin/master' into feature/revamp-okx
LucianoPierdona Jun 12, 2022
45aed94
update e2e configs for okx
LucianoPierdona Jun 13, 2022
2f07507
update okx order fixtures and schemas
LucianoPierdona Jun 13, 2022
3e29fd0
update okx list test suites
LucianoPierdona Jun 13, 2022
4e06a9a
update okx order place and test suite
LucianoPierdona Jun 13, 2022
3a4aac9
update okx specs
LucianoPierdona Jun 13, 2022
4b5f483
update okx order type adapter to include `STOP_MARKET` orders
LucianoPierdona Jun 13, 2022
23e57b5
update okx request error to test `code`
LucianoPierdona Jun 13, 2022
698b876
update cancel order to support `STOP` orders
LucianoPierdona Jun 13, 2022
681177f
update okx `edit` order to support `STOP` orders
LucianoPierdona Jun 13, 2022
6ac8b0b
update get okx raw order to support closed and open `STOP` orders
LucianoPierdona Jun 13, 2022
175ec16
update okx `parse` to include proper fields for each order type
LucianoPierdona Jun 13, 2022
e95d491
linting
LucianoPierdona Jun 13, 2022
66ddd14
update `aluna-spec` file
LucianoPierdona Jun 13, 2022
66094ca
update exchanges table
LucianoPierdona Jun 15, 2022
444d079
fix order parse for market orders
LucianoPierdona Jun 15, 2022
d5d6c23
fix okx stop rate on stop limit orders
LucianoPierdona Jun 15, 2022
090d29f
update okx e2e configs
LucianoPierdona Jun 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .alunarc
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ VALR_API_SECRET=
GATE_API_KEY=
GATE_API_SECRET=

OKX_API_KEY=
OKX_API_SECRET=
OKX_API_PASSPHRASE=

FTX_API_KEY=
FTX_API_SECRET=
52 changes: 42 additions & 10 deletions .playground/aluna-spec.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"_type": "export",
"__export_format": 4,
"__export_date": "2022-05-19T15:38:33.998Z",
"__export_source": "insomnia.desktop.app:v2022.2.1",
"__export_date": "2022-05-20T15:20:36.520Z",
"__export_source": "insomnia.desktop.app:v2022.3.0",
"resources": [
{
"_id": "req_638f9118078540b8a309cfcf9a6189ee",
Expand Down Expand Up @@ -149,7 +149,7 @@
{
"_id": "req_f44dbbbcceb3496da709be542a08706b",
"parentId": "fld_51ff43abd0e041e7a35891223e170a16",
"modified": 1652316606203,
"modified": 1653053386793,
"created": 1651252489507,
"url": "{{ _.PLAYGROUND_URL }}/exchanges",
"name": "listRaw",
Expand Down Expand Up @@ -453,7 +453,7 @@
{
"_id": "req_b3c64285e4b84d6da77a0046f8224ab3",
"parentId": "fld_f3ad5c457d5b4433a90c91d2d9963d18",
"modified": 1652632762679,
"modified": 1653053366612,
"created": 1651251269522,
"url": "{{ _.PLAYGROUND_URL }}/exchanges",
"name": "fetchDetails",
Expand Down Expand Up @@ -509,7 +509,7 @@
{
"_id": "req_e147340c7ecd4eb785265d1b060ff2a6",
"parentId": "fld_404131e490e9469898d0a610690c9775",
"modified": 1652632757871,
"modified": 1653053200021,
"created": 1652142980199,
"url": "{{ _.PLAYGROUND_URL }}/exchanges",
"name": "getTradableBalance",
Expand Down Expand Up @@ -553,7 +553,7 @@
{
"_id": "req_f17e55c1a50f477aa3747ee7a7b497ca",
"parentId": "fld_404131e490e9469898d0a610690c9775",
"modified": 1652632759741,
"modified": 1653056431259,
"created": 1651516666747,
"url": "{{ _.PLAYGROUND_URL }}/exchanges",
"name": "listRaw",
Expand Down Expand Up @@ -585,7 +585,7 @@
{
"_id": "req_bdd09e4f5a9b4e3a87ecb690dfa739c9",
"parentId": "fld_404131e490e9469898d0a610690c9775",
"modified": 1652632760923,
"modified": 1653053355581,
"created": 1651505463599,
"url": "{{ _.PLAYGROUND_URL }}/exchanges",
"name": "list",
Expand Down Expand Up @@ -617,7 +617,7 @@
{
"_id": "req_db9088aa9fcf45b18e85ddd994aa99c1",
"parentId": "fld_1eb1fdf26dfd46298cacc08fd05b469e",
"modified": 1652632764897,
"modified": 1653053390709,
"created": 1651505373653,
"url": "{{ _.PLAYGROUND_URL }}/exchanges",
"name": "listRaw",
Expand Down Expand Up @@ -757,7 +757,7 @@
{
"_id": "req_0fe5c5ec55604eb48a47233c69fe1ee4",
"parentId": "fld_1eb1fdf26dfd46298cacc08fd05b469e",
"modified": 1652974669549,
"modified": 1653060021597,
"created": 1651595326974,
"url": "{{ _.PLAYGROUND_URL }}/exchanges",
"name": "place:limit",
Expand Down Expand Up @@ -789,7 +789,7 @@
{
"_id": "req_8cc2810f054d4681914645b0e9324e2b",
"parentId": "fld_1eb1fdf26dfd46298cacc08fd05b469e",
"modified": 1652974668889,
"modified": 1653060015308,
"created": 1651597897328,
"url": "{{ _.PLAYGROUND_URL }}/exchanges",
"name": "place:market",
Expand Down Expand Up @@ -1410,6 +1410,38 @@
"metaSortKey": 7,
"_type": "environment"
},
{
"_id": "env_5120e1e15b634398bb1ca97c3b48b386",
"parentId": "env_0294ce45850974a6280b61215be346094da99682",
"modified": 1653060020939,
"created": 1653009615092,
"name": "Okx",
"data": {
"EXCHANGE_ID": "okx",
"KEY": "{% dotenv _.ALUNAJS_RC, 'OKX_API_KEY' %}",
"SECRET": "{% dotenv _.ALUNAJS_RC, 'OKX_API_SECRET' %}",
"PASSPHRASE": "{% dotenv _.ALUNAJS_RC, 'OKX_API_PASSPHRASE' %}",
"ORDER_SYMBOL_PAIR": "BTC-USDT",
"ORDER_RATE": 1000,
"ORDER_AMOUNT": 0.001,
"ORDER_EDITED_AMOUNT": 0.0011
},
"dataPropertyOrder": {
"&": [
"EXCHANGE_ID",
"KEY",
"SECRET",
"PASSPHRASE",
"ORDER_SYMBOL_PAIR",
"ORDER_RATE",
"ORDER_AMOUNT",
"ORDER_EDITED_AMOUNT"
]
},
"color": "#0929aa",
"isPrivate": false,
"metaSortKey": 1653009615092
},
{
"_id": "env_e524d6c1fb6247348832a850cae3e36d",
"parentId": "env_0294ce45850974a6280b61215be346094da99682",
Expand Down
1 change: 1 addition & 0 deletions docs/exchanges-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ Full list of currently supported exchanges.
|Gate|✅ v4|❌|❌|
|Poloniex|✅ v1|—|—|
|Valr|✅ v1|—|—|
|Okx|✅ v5|❌|❌|
|Ftx|✅ v1|❌|❌|
4 changes: 2 additions & 2 deletions src/aluna.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe(__filename, () => {

const exchangeIds = Object.keys(exchanges)

expect(exchangeIds.length).to.eq(8)
expect(exchangeIds.length).to.eq(9)

each(exchangeIds, (exchangeId) => {

Expand Down Expand Up @@ -51,7 +51,7 @@ describe(__filename, () => {

const exchangeIds = Object.keys(exchanges)

expect(exchangeIds.length).to.eq(8)
expect(exchangeIds.length).to.eq(9)

each(exchangeIds, (exchangeId) => {

Expand Down
24 changes: 11 additions & 13 deletions src/exchanges/binance/modules/authed/order/parse.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from 'chai'
import { cloneDeep } from 'lodash'
import { ImportMock } from 'ts-mock-imports'

import { AlunaAccountEnum } from '../../../../../lib/enums/AlunaAccountEnum'
import { IAlunaCredentialsSchema } from '../../../../../lib/schemas/IAlunaCredentialsSchema'
Expand Down Expand Up @@ -181,15 +182,20 @@ describe(__filename, () => {
symbol,
type,
status,
updateTime,
} = rawOrder

const updatedAt = new Date(updateTime!)

const exchange = new BinanceAuthed({ credentials })

const timestamp = new Date()

// mocking

ImportMock.mockFunction(
global,
'Date',
timestamp,
)

const { translateSymbolId } = mockTranslateSymbolId()

translateSymbolId.onFirstCall().returns(baseAsset)
Expand All @@ -214,16 +220,8 @@ describe(__filename, () => {
expect(order.status).to.be.eq(orderStatus)
expect(order.side).to.be.eq(orderSide)
expect(order.type).to.be.eq(orderType)
expect(order.filledAt?.getTime()).to.be.eq(updatedAt.getTime())
expect(order.placedAt
.getTime()
.toString()
.substring(0, 11)).to.be.eq(
new Date()
.getTime()
.toString()
.substring(0, 11),
)
expect(order.filledAt?.getTime()).to.be.eq(timestamp.getTime())
expect(order.placedAt.getTime()).to.be.eq(timestamp.getTime())

})

Expand Down
28 changes: 28 additions & 0 deletions src/exchanges/okx/Okx.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expect } from 'chai'

import { IAlunaSettingsSchema } from '../../lib/schemas/IAlunaSettingsSchema'
import { Okx } from './Okx'



describe(__filename, () => {

it('should contain public modules', async () => {

const settings: IAlunaSettingsSchema = {
referralCode: '123',
}

const okx = new Okx({ settings })

expect(okx.id).to.eq('okx')

expect(okx.symbol).to.be.ok
expect(okx.market).to.be.ok

expect(okx.specs).to.be.ok
expect(okx.settings).to.deep.eq(okx.settings)

})

})
38 changes: 38 additions & 0 deletions src/exchanges/okx/Okx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { IAlunaExchangePublic } from '../../lib/core/IAlunaExchange'
import { IAlunaMarketModule } from '../../lib/modules/public/IAlunaMarketModule'
import { IAlunaSymbolModule } from '../../lib/modules/public/IAlunaSymbolModule'
import { IAlunaExchangeSchema } from '../../lib/schemas/IAlunaExchangeSchema'
import { IAlunaSettingsSchema } from '../../lib/schemas/IAlunaSettingsSchema'
import { buildOkxSpecs } from './okxSpecs'
import { market } from './modules/public/market'
import { symbol } from './modules/public/symbol'



export class Okx implements IAlunaExchangePublic {

public id: string
public specs: IAlunaExchangeSchema
public settings: IAlunaSettingsSchema

public symbol: IAlunaSymbolModule
public market: IAlunaMarketModule



constructor(params: {
settings?: IAlunaSettingsSchema
}) {

const { settings = {} } = params

this.settings = settings
this.specs = buildOkxSpecs({ settings })
this.id = this.specs.id

this.market = market(this)
this.symbol = symbol(this)

}

}
39 changes: 39 additions & 0 deletions src/exchanges/okx/OkxAuthed.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { expect } from 'chai'

import { IAlunaCredentialsSchema } from '../../lib/schemas/IAlunaCredentialsSchema'
import { IAlunaSettingsSchema } from '../../lib/schemas/IAlunaSettingsSchema'
import { OkxAuthed } from './OkxAuthed'



describe(__filename, () => {

it('should contain public & authed modules', async () => {

const credentials: IAlunaCredentialsSchema = {
key: 'some-key',
secret: 'some-secret',
}

const settings: IAlunaSettingsSchema = {
referralCode: '123',
}

const okx = new OkxAuthed({ settings, credentials })

expect(okx.id).to.eq('okx')

expect(okx.symbol).to.be.ok
expect(okx.market).to.be.ok

expect(okx.key).to.be.ok
expect(okx.balance).to.be.ok
expect(okx.order).to.be.ok
expect(okx.position).to.be.ok

expect(okx.specs).to.be.ok
expect(okx.settings).to.deep.eq(okx.settings)

})

})
50 changes: 50 additions & 0 deletions src/exchanges/okx/OkxAuthed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { IAlunaExchangeAuthed } from '../../lib/core/IAlunaExchange'
import { IAlunaBalanceModule } from '../../lib/modules/authed/IAlunaBalanceModule'
import { IAlunaKeyModule } from '../../lib/modules/authed/IAlunaKeyModule'
import { IAlunaOrderWriteModule } from '../../lib/modules/authed/IAlunaOrderModule'
import { IAlunaPositionModule } from '../../lib/modules/authed/IAlunaPositionModule'
import { IAlunaCredentialsSchema } from '../../lib/schemas/IAlunaCredentialsSchema'
import { IAlunaSettingsSchema } from '../../lib/schemas/IAlunaSettingsSchema'
import { balance } from './modules/authed/balance'
import { key } from './modules/authed/key'
import { order } from './modules/authed/order'
import { position } from './modules/authed/position'
import { Okx } from './Okx'



export class OkxAuthed extends Okx implements IAlunaExchangeAuthed {

public credentials: IAlunaCredentialsSchema

public key: IAlunaKeyModule
public order: IAlunaOrderWriteModule
public balance: IAlunaBalanceModule
public position: IAlunaPositionModule



constructor(params: {
settings?: IAlunaSettingsSchema
credentials: IAlunaCredentialsSchema
}) {

const {
settings,
credentials,
} = params

super({ settings })

this.credentials = credentials

this.key = key(this)
this.balance = balance(this)
this.order = order(this)
this.position = position(this)

return this

}

}
Loading