From 7def6e5e4bc2f7fbd43206dc039078a3ae54feea Mon Sep 17 00:00:00 2001 From: Travis CI Date: Tue, 10 Nov 2020 04:50:14 +0000 Subject: [PATCH] 1.37.43 [ci skip] --- README.md | 6 +- ccxt.js | 2 +- dist/ccxt.browser.js | 248 ++++++++++++++++++++- package-lock.json | 2 +- package.json | 2 +- php/base/Exchange.php | 4 +- php/okex.php | 246 ++++++++++++++++++++ python/README.md | 6 +- python/ccxt/__init__.py | 2 +- python/ccxt/async_support/__init__.py | 2 +- python/ccxt/async_support/base/exchange.py | 2 +- python/ccxt/async_support/okex.py | 241 ++++++++++++++++++++ python/ccxt/base/exchange.py | 2 +- python/ccxt/okex.py | 241 ++++++++++++++++++++ python/package.json | 2 +- wiki/Install.md | 6 +- 16 files changed, 994 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index b96ca513a43e..962af68c1456 100644 --- a/README.md +++ b/README.md @@ -226,13 +226,13 @@ console.log (ccxt.exchanges) // print all available exchanges All-in-one browser bundle (dependencies included), served from a CDN of your choice: -* jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@1.37.42/dist/ccxt.browser.js -* unpkg: https://unpkg.com/ccxt@1.37.42/dist/ccxt.browser.js +* jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@1.37.43/dist/ccxt.browser.js +* unpkg: https://unpkg.com/ccxt@1.37.43/dist/ccxt.browser.js CDNs are not updated in real-time and may have delays. Defaulting to the most recent version without specifying the version number is not recommended. Please, keep in mind that we are not responsible for the correct operation of those CDN servers. ```HTML - + ``` Creates a global `ccxt` object: diff --git a/ccxt.js b/ccxt.js index 0b881007dd55..1a9a45e7a06d 100644 --- a/ccxt.js +++ b/ccxt.js @@ -35,7 +35,7 @@ const Exchange = require ('./js/base/Exchange') //----------------------------------------------------------------------------- // this is updated by vss.js when building -const version = '1.37.42' +const version = '1.37.43' Exchange.ccxtVersion = version diff --git a/dist/ccxt.browser.js b/dist/ccxt.browser.js index b58552620544..63849a20cfbf 100644 --- a/dist/ccxt.browser.js +++ b/dist/ccxt.browser.js @@ -43,7 +43,7 @@ const Exchange = require ('./js/base/Exchange') //----------------------------------------------------------------------------- // this is updated by vss.js when building -const version = '1.37.42' +const version = '1.37.43' Exchange.ccxtVersion = version @@ -90133,6 +90133,7 @@ module.exports = class okex extends Exchange { 'option': { 'get': [ 'accounts', + 'position', '{underlying}/position', 'accounts/{underlying}', 'orders/{underlying}', @@ -92800,6 +92801,251 @@ module.exports = class okex extends Exchange { return await this.fetchMyTrades (symbol, since, limit, this.extend (request, params)); } + async fetchPositions (symbol = undefined, since = undefined, limit = undefined, params = {}) { + await this.loadMarkets (); + let method = undefined; + let market = undefined; + const request = { + // 'instrument_id': market['id'], + // 'order_id': id, // string + // 'after': '1', // pagination of data to return records earlier than the requested ledger_id + // 'before': '1', // P=pagination of data to return records newer than the requested ledger_id + // 'limit': limit, // optional, number of results per request, default = maximum = 100 + }; + let type = undefined; + if (symbol === undefined) { + const defaultType = this.safeString2 (this.options, 'fetchPositions', 'defaultType'); + type = this.safeString (params, 'type', defaultType); + } else { + market = this.market (symbol); + type = market['type']; + request['instrument_id'] = market['id']; + } + if ((type === 'futures') || (type === 'swap')) { + if (market === undefined) { + method = type + 'GetPosition'; + } else { + method = type + 'GetInstrumentIdPosition'; + } + } else if (type === 'option') { + const underlying = this.safeString (params, 'underlying'); + if (underlying === undefined) { + throw new ArgumentsRequired (this.id + ' fetchPositions() requires an underlying parameter for ' + type + ' market ' + symbol); + } + method = type + 'GetUnderlyingPosition'; + } else { + throw new NotSupported (this.id + ' fetchPositions() does not support ' + type + ' market ' + symbol + ', supported market types are futures, swap or option'); + } + params = this.omit (params, 'type'); + const response = await this[method] (this.extend (request, params)); + // + // futures + // + // symbol not specified + // + // { + // "result": true, + // "holding": [ + // [ + // { ... }, + // ] + // ] + // } + // + // symbol specified, crossed margin mode + // + // { + // "result": true, + // "holding": [ + // { + // "long_qty": "2", + // "long_avail_qty": "2", + // "long_avg_cost": "8260", + // "long_settlement_price": "8260", + // "realised_pnl": "0.00020928", + // "short_qty": "2", + // "short_avail_qty": "2", + // "short_avg_cost": "8259.99", + // "short_settlement_price": "8259.99", + // "liquidation_price": "113.81", + // "instrument_id": "BTC-USD-191227", + // "leverage": "10", + // "created_at": "2019-09-25T07:58:42.129Z", + // "updated_at": "2019-10-08T14:02:51.029Z", + // "margin_mode": "crossed", + // "short_margin": "0.00242197", + // "short_pnl": "6.63E-6", + // "short_pnl_ratio": "0.002477997", + // "short_unrealised_pnl": "6.63E-6", + // "long_margin": "0.00242197", + // "long_pnl": "-6.65E-6", + // "long_pnl_ratio": "-0.002478", + // "long_unrealised_pnl": "-6.65E-6", + // "long_settled_pnl": "0", + // "short_settled_pnl": "0", + // "last": "8257.57" + // } + // ], + // "margin_mode": "crossed" + // } + // + // symbol specified, fixed margin mode + // + // { + // "result": true, + // "holding": [ + // { + // "long_qty": "4", + // "long_avail_qty": "4", + // "long_margin": "0.00323844", + // "long_liqui_price": "7762.09", + // "long_pnl_ratio": "0.06052306", + // "long_avg_cost": "8234.43", + // "long_settlement_price": "8234.43", + // "realised_pnl": "-0.00000296", + // "short_qty": "2", + // "short_avail_qty": "2", + // "short_margin": "0.00241105", + // "short_liqui_price": "9166.74", + // "short_pnl_ratio": "0.03318052", + // "short_avg_cost": "8295.13", + // "short_settlement_price": "8295.13", + // "instrument_id": "BTC-USD-191227", + // "long_leverage": "15", + // "short_leverage": "10", + // "created_at": "2019-09-25T07:58:42.129Z", + // "updated_at": "2019-10-08T13:12:09.438Z", + // "margin_mode": "fixed", + // "short_margin_ratio": "0.10292507", + // "short_maint_margin_ratio": "0.005", + // "short_pnl": "7.853E-5", + // "short_unrealised_pnl": "7.853E-5", + // "long_margin_ratio": "0.07103743", + // "long_maint_margin_ratio": "0.005", + // "long_pnl": "1.9841E-4", + // "long_unrealised_pnl": "1.9841E-4", + // "long_settled_pnl": "0", + // "short_settled_pnl": "0", + // "last": "8266.99" + // } + // ], + // "margin_mode": "fixed" + // } + // + // swap + // + // symbol not specified + // + // [ + // { + // "margin_mode": "fixed", + // "timestamp": "2019-09-27T03:47:37.230Z", + // "holding": [ + // { ... } + // ] + // }, + // { + // "margin_mode": "crossed", + // "timestamp": "2019-09-27T03:49:02.018Z", + // "holding": [ + // { ... }, + // ] + // } + // ] + // + // symbol specified, fixed margin mode + // + // { + // "margin_mode": "fixed", + // "timestamp": "2019-09-27T03:47:37.230Z", + // "holding": [ + // { + // "avail_position": "20", + // "avg_cost": "8025.0", + // "instrument_id": "BTC-USD-SWAP", + // "last": "8113.1", + // "leverage": "15.00", + // "liquidation_price": "7002.6", + // "maint_margin_ratio": "0.0050", + // "margin": "0.0454", + // "position": "20", + // "realized_pnl": "-0.0001", + // "unrealized_pnl": "0", + // "settled_pnl": "0.0076", + // "settlement_price": "8279.2", + // "side": "long", + // "timestamp": "2019-09-27T03:47:37.230Z" + // } + // ] + // } + // + // symbol specified, crossed margin mode + // + // { + // "margin_mode": "crossed", + // "timestamp": "2019-09-27T03:49:02.018Z", + // "holding": [ + // { + // "avail_position": "3", + // "avg_cost": "59.49", + // "instrument_id": "LTC-USD-SWAP", + // "last": "55.98", + // "leverage": "10.00", + // "liquidation_price": "4.37", + // "maint_margin_ratio": "0.0100", + // "margin": "0.0536", + // "position": "3", + // "realized_pnl": "0.0000", + // "unrealized_pnl": "0", + // "settled_pnl": "-0.0330", + // "settlement_price": "55.84", + // "side": "long", + // "timestamp": "2019-09-27T03:49:02.018Z" + // }, + // ] + // } + // + // option + // + // { + // "holding":[ + // { + // "instrument_id":"BTC-USD-190927-12500-C", + // "position":"20", + // "avg_cost":"3.26", + // "avail_position":"20", + // "settlement_price":"0.017", + // "total_pnl":"50", + // "pnl_ratio":"0.3", + // "realized_pnl":"40", + // "unrealized_pnl":"10", + // "pos_margin":"100", + // "option_value":"70", + // "created_at":"2019-08-30T03:09:20.315Z", + // "updated_at":"2019-08-30T03:40:18.318Z" + // }, + // { + // "instrument_id":"BTC-USD-190927-12500-P", + // "position":"20", + // "avg_cost":"3.26", + // "avail_position":"20", + // "settlement_price":"0.019", + // "total_pnl":"50", + // "pnl_ratio":"0.3", + // "realized_pnl":"40", + // "unrealized_pnl":"10", + // "pos_margin":"100", + // "option_value":"70", + // "created_at":"2019-08-30T03:09:20.315Z", + // "updated_at":"2019-08-30T03:40:18.318Z" + // } + // ] + // } + // + // todo unify parsePosition/parsePositions + return response; + } + async fetchLedger (code = undefined, since = undefined, limit = undefined, params = {}) { await this.loadMarkets (); const defaultType = this.safeString2 (this.options, 'fetchLedger', 'defaultType'); diff --git a/package-lock.json b/package-lock.json index 5f259dbabc86..666ea22aee71 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ccxt", - "version": "1.37.42", + "version": "1.37.43", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 7dca0248e27b..c87e513a54d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ccxt", - "version": "1.37.42", + "version": "1.37.43", "description": "A JavaScript / Python / PHP cryptocurrency trading library with support for 130+ exchanges", "main": "./ccxt.js", "unpkg": "dist/ccxt.browser.js", diff --git a/php/base/Exchange.php b/php/base/Exchange.php index d66fc9cd607e..604ec86276f4 100644 --- a/php/base/Exchange.php +++ b/php/base/Exchange.php @@ -36,7 +36,7 @@ use Elliptic\EdDSA; use BN\BN; -$version = '1.37.42'; +$version = '1.37.43'; // rounding mode const TRUNCATE = 0; @@ -55,7 +55,7 @@ class Exchange { - const VERSION = '1.37.42'; + const VERSION = '1.37.43'; private static $base58_alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'; private static $base58_encoder = null; diff --git a/php/okex.php b/php/okex.php index ac98af1d1309..d6ccc9c0d7fc 100644 --- a/php/okex.php +++ b/php/okex.php @@ -261,6 +261,7 @@ public function describe() { 'option' => array( 'get' => array( 'accounts', + 'position', '{underlying}/position', 'accounts/{underlying}', 'orders/{underlying}', @@ -2928,6 +2929,251 @@ public function fetch_order_trades($id, $symbol = null, $since = null, $limit = return $this->fetch_my_trades($symbol, $since, $limit, array_merge($request, $params)); } + public function fetch_positions($symbol = null, $since = null, $limit = null, $params = array ()) { + $this->load_markets(); + $method = null; + $market = null; + $request = array( + // 'instrument_id' => $market['id'], + // 'order_id' => id, // string + // 'after' => '1', // pagination of data to return records earlier than the requested ledger_id + // 'before' => '1', // P=pagination of data to return records newer than the requested ledger_id + // 'limit' => $limit, // optional, number of results per $request, default = maximum = 100 + ); + $type = null; + if ($symbol === null) { + $defaultType = $this->safe_string_2($this->options, 'fetchPositions', 'defaultType'); + $type = $this->safe_string($params, 'type', $defaultType); + } else { + $market = $this->market($symbol); + $type = $market['type']; + $request['instrument_id'] = $market['id']; + } + if (($type === 'futures') || ($type === 'swap')) { + if ($market === null) { + $method = $type . 'GetPosition'; + } else { + $method = $type . 'GetInstrumentIdPosition'; + } + } else if ($type === 'option') { + $underlying = $this->safe_string($params, 'underlying'); + if ($underlying === null) { + throw new ArgumentsRequired($this->id . ' fetchPositions() requires an $underlying parameter for ' . $type . ' $market ' . $symbol); + } + $method = $type . 'GetUnderlyingPosition'; + } else { + throw new NotSupported($this->id . ' fetchPositions() does not support ' . $type . ' $market ' . $symbol . ', supported $market types are futures, swap or option'); + } + $params = $this->omit($params, 'type'); + $response = $this->$method (array_merge($request, $params)); + // + // futures + // + // $symbol not specified + // + // { + // "result" => true, + // "holding" => array( + // array( + // array( ... ), + // ) + // ) + // } + // + // $symbol specified, crossed margin mode + // + // { + // "result" => true, + // "holding" => array( + // { + // "long_qty" => "2", + // "long_avail_qty" => "2", + // "long_avg_cost" => "8260", + // "long_settlement_price" => "8260", + // "realised_pnl" => "0.00020928", + // "short_qty" => "2", + // "short_avail_qty" => "2", + // "short_avg_cost" => "8259.99", + // "short_settlement_price" => "8259.99", + // "liquidation_price" => "113.81", + // "instrument_id" => "BTC-USD-191227", + // "leverage" => "10", + // "created_at" => "2019-09-25T07:58:42.129Z", + // "updated_at" => "2019-10-08T14:02:51.029Z", + // "margin_mode" => "crossed", + // "short_margin" => "0.00242197", + // "short_pnl" => "6.63E-6", + // "short_pnl_ratio" => "0.002477997", + // "short_unrealised_pnl" => "6.63E-6", + // "long_margin" => "0.00242197", + // "long_pnl" => "-6.65E-6", + // "long_pnl_ratio" => "-0.002478", + // "long_unrealised_pnl" => "-6.65E-6", + // "long_settled_pnl" => "0", + // "short_settled_pnl" => "0", + // "last" => "8257.57" + // } + // ), + // "margin_mode" => "crossed" + // } + // + // $symbol specified, fixed margin mode + // + // { + // "result" => true, + // "holding" => array( + // { + // "long_qty" => "4", + // "long_avail_qty" => "4", + // "long_margin" => "0.00323844", + // "long_liqui_price" => "7762.09", + // "long_pnl_ratio" => "0.06052306", + // "long_avg_cost" => "8234.43", + // "long_settlement_price" => "8234.43", + // "realised_pnl" => "-0.00000296", + // "short_qty" => "2", + // "short_avail_qty" => "2", + // "short_margin" => "0.00241105", + // "short_liqui_price" => "9166.74", + // "short_pnl_ratio" => "0.03318052", + // "short_avg_cost" => "8295.13", + // "short_settlement_price" => "8295.13", + // "instrument_id" => "BTC-USD-191227", + // "long_leverage" => "15", + // "short_leverage" => "10", + // "created_at" => "2019-09-25T07:58:42.129Z", + // "updated_at" => "2019-10-08T13:12:09.438Z", + // "margin_mode" => "fixed", + // "short_margin_ratio" => "0.10292507", + // "short_maint_margin_ratio" => "0.005", + // "short_pnl" => "7.853E-5", + // "short_unrealised_pnl" => "7.853E-5", + // "long_margin_ratio" => "0.07103743", + // "long_maint_margin_ratio" => "0.005", + // "long_pnl" => "1.9841E-4", + // "long_unrealised_pnl" => "1.9841E-4", + // "long_settled_pnl" => "0", + // "short_settled_pnl" => "0", + // "last" => "8266.99" + // } + // ), + // "margin_mode" => "fixed" + // } + // + // swap + // + // $symbol not specified + // + // array( + // array( + // "margin_mode" => "fixed", + // "timestamp" => "2019-09-27T03:47:37.230Z", + // "holding" => array( + // array( ... ) + // ) + // ), + // { + // "margin_mode" => "crossed", + // "timestamp" => "2019-09-27T03:49:02.018Z", + // "holding" => array( + // array( ... ), + // ) + // } + // ) + // + // $symbol specified, fixed margin mode + // + // { + // "margin_mode" => "fixed", + // "timestamp" => "2019-09-27T03:47:37.230Z", + // "holding" => array( + // { + // "avail_position" => "20", + // "avg_cost" => "8025.0", + // "instrument_id" => "BTC-USD-SWAP", + // "last" => "8113.1", + // "leverage" => "15.00", + // "liquidation_price" => "7002.6", + // "maint_margin_ratio" => "0.0050", + // "margin" => "0.0454", + // "position" => "20", + // "realized_pnl" => "-0.0001", + // "unrealized_pnl" => "0", + // "settled_pnl" => "0.0076", + // "settlement_price" => "8279.2", + // "side" => "long", + // "timestamp" => "2019-09-27T03:47:37.230Z" + // } + // ) + // } + // + // $symbol specified, crossed margin mode + // + // { + // "margin_mode" => "crossed", + // "timestamp" => "2019-09-27T03:49:02.018Z", + // "holding" => array( + // array( + // "avail_position" => "3", + // "avg_cost" => "59.49", + // "instrument_id" => "LTC-USD-SWAP", + // "last" => "55.98", + // "leverage" => "10.00", + // "liquidation_price" => "4.37", + // "maint_margin_ratio" => "0.0100", + // "margin" => "0.0536", + // "position" => "3", + // "realized_pnl" => "0.0000", + // "unrealized_pnl" => "0", + // "settled_pnl" => "-0.0330", + // "settlement_price" => "55.84", + // "side" => "long", + // "timestamp" => "2019-09-27T03:49:02.018Z" + // ), + // ) + // } + // + // option + // + // { + // "holding":array( + // array( + // "instrument_id":"BTC-USD-190927-12500-C", + // "position":"20", + // "avg_cost":"3.26", + // "avail_position":"20", + // "settlement_price":"0.017", + // "total_pnl":"50", + // "pnl_ratio":"0.3", + // "realized_pnl":"40", + // "unrealized_pnl":"10", + // "pos_margin":"100", + // "option_value":"70", + // "created_at":"2019-08-30T03:09:20.315Z", + // "updated_at":"2019-08-30T03:40:18.318Z" + // ), + // { + // "instrument_id":"BTC-USD-190927-12500-P", + // "position":"20", + // "avg_cost":"3.26", + // "avail_position":"20", + // "settlement_price":"0.019", + // "total_pnl":"50", + // "pnl_ratio":"0.3", + // "realized_pnl":"40", + // "unrealized_pnl":"10", + // "pos_margin":"100", + // "option_value":"70", + // "created_at":"2019-08-30T03:09:20.315Z", + // "updated_at":"2019-08-30T03:40:18.318Z" + // } + // ) + // } + // + // todo unify parsePosition/parsePositions + return $response; + } + public function fetch_ledger($code = null, $since = null, $limit = null, $params = array ()) { $this->load_markets(); $defaultType = $this->safe_string_2($this->options, 'fetchLedger', 'defaultType'); diff --git a/python/README.md b/python/README.md index b96ca513a43e..962af68c1456 100644 --- a/python/README.md +++ b/python/README.md @@ -226,13 +226,13 @@ console.log (ccxt.exchanges) // print all available exchanges All-in-one browser bundle (dependencies included), served from a CDN of your choice: -* jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@1.37.42/dist/ccxt.browser.js -* unpkg: https://unpkg.com/ccxt@1.37.42/dist/ccxt.browser.js +* jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@1.37.43/dist/ccxt.browser.js +* unpkg: https://unpkg.com/ccxt@1.37.43/dist/ccxt.browser.js CDNs are not updated in real-time and may have delays. Defaulting to the most recent version without specifying the version number is not recommended. Please, keep in mind that we are not responsible for the correct operation of those CDN servers. ```HTML - + ``` Creates a global `ccxt` object: diff --git a/python/ccxt/__init__.py b/python/ccxt/__init__.py index dac0b9994d6f..67a911c433fa 100644 --- a/python/ccxt/__init__.py +++ b/python/ccxt/__init__.py @@ -22,7 +22,7 @@ # ---------------------------------------------------------------------------- -__version__ = '1.37.42' +__version__ = '1.37.43' # ---------------------------------------------------------------------------- diff --git a/python/ccxt/async_support/__init__.py b/python/ccxt/async_support/__init__.py index 770b8d28ec0a..b4964f8fe472 100644 --- a/python/ccxt/async_support/__init__.py +++ b/python/ccxt/async_support/__init__.py @@ -4,7 +4,7 @@ # ----------------------------------------------------------------------------- -__version__ = '1.37.42' +__version__ = '1.37.43' # ----------------------------------------------------------------------------- diff --git a/python/ccxt/async_support/base/exchange.py b/python/ccxt/async_support/base/exchange.py index e9c9daade708..ff463380ab81 100644 --- a/python/ccxt/async_support/base/exchange.py +++ b/python/ccxt/async_support/base/exchange.py @@ -2,7 +2,7 @@ # ----------------------------------------------------------------------------- -__version__ = '1.37.42' +__version__ = '1.37.43' # ----------------------------------------------------------------------------- diff --git a/python/ccxt/async_support/okex.py b/python/ccxt/async_support/okex.py index cf6328320312..b1db66e7e718 100644 --- a/python/ccxt/async_support/okex.py +++ b/python/ccxt/async_support/okex.py @@ -282,6 +282,7 @@ def describe(self): 'option': { 'get': [ 'accounts', + 'position', '{underlying}/position', 'accounts/{underlying}', 'orders/{underlying}', @@ -2803,6 +2804,246 @@ async def fetch_order_trades(self, id, symbol=None, since=None, limit=None, para } return await self.fetch_my_trades(symbol, since, limit, self.extend(request, params)) + async def fetch_positions(self, symbol=None, since=None, limit=None, params={}): + await self.load_markets() + method = None + market = None + request = { + # 'instrument_id': market['id'], + # 'order_id': id, # string + # 'after': '1', # pagination of data to return records earlier than the requested ledger_id + # 'before': '1', # P=pagination of data to return records newer than the requested ledger_id + # 'limit': limit, # optional, number of results per request, default = maximum = 100 + } + type = None + if symbol is None: + defaultType = self.safe_string_2(self.options, 'fetchPositions', 'defaultType') + type = self.safe_string(params, 'type', defaultType) + else: + market = self.market(symbol) + type = market['type'] + request['instrument_id'] = market['id'] + if (type == 'futures') or (type == 'swap'): + if market is None: + method = type + 'GetPosition' + else: + method = type + 'GetInstrumentIdPosition' + elif type == 'option': + underlying = self.safe_string(params, 'underlying') + if underlying is None: + raise ArgumentsRequired(self.id + ' fetchPositions() requires an underlying parameter for ' + type + ' market ' + symbol) + method = type + 'GetUnderlyingPosition' + else: + raise NotSupported(self.id + ' fetchPositions() does not support ' + type + ' market ' + symbol + ', supported market types are futures, swap or option') + params = self.omit(params, 'type') + response = await getattr(self, method)(self.extend(request, params)) + # + # futures + # + # symbol not specified + # + # { + # "result": True, + # "holding": [ + # [ + # {...}, + # ] + # ] + # } + # + # symbol specified, crossed margin mode + # + # { + # "result": True, + # "holding": [ + # { + # "long_qty": "2", + # "long_avail_qty": "2", + # "long_avg_cost": "8260", + # "long_settlement_price": "8260", + # "realised_pnl": "0.00020928", + # "short_qty": "2", + # "short_avail_qty": "2", + # "short_avg_cost": "8259.99", + # "short_settlement_price": "8259.99", + # "liquidation_price": "113.81", + # "instrument_id": "BTC-USD-191227", + # "leverage": "10", + # "created_at": "2019-09-25T07:58:42.129Z", + # "updated_at": "2019-10-08T14:02:51.029Z", + # "margin_mode": "crossed", + # "short_margin": "0.00242197", + # "short_pnl": "6.63E-6", + # "short_pnl_ratio": "0.002477997", + # "short_unrealised_pnl": "6.63E-6", + # "long_margin": "0.00242197", + # "long_pnl": "-6.65E-6", + # "long_pnl_ratio": "-0.002478", + # "long_unrealised_pnl": "-6.65E-6", + # "long_settled_pnl": "0", + # "short_settled_pnl": "0", + # "last": "8257.57" + # } + # ], + # "margin_mode": "crossed" + # } + # + # symbol specified, fixed margin mode + # + # { + # "result": True, + # "holding": [ + # { + # "long_qty": "4", + # "long_avail_qty": "4", + # "long_margin": "0.00323844", + # "long_liqui_price": "7762.09", + # "long_pnl_ratio": "0.06052306", + # "long_avg_cost": "8234.43", + # "long_settlement_price": "8234.43", + # "realised_pnl": "-0.00000296", + # "short_qty": "2", + # "short_avail_qty": "2", + # "short_margin": "0.00241105", + # "short_liqui_price": "9166.74", + # "short_pnl_ratio": "0.03318052", + # "short_avg_cost": "8295.13", + # "short_settlement_price": "8295.13", + # "instrument_id": "BTC-USD-191227", + # "long_leverage": "15", + # "short_leverage": "10", + # "created_at": "2019-09-25T07:58:42.129Z", + # "updated_at": "2019-10-08T13:12:09.438Z", + # "margin_mode": "fixed", + # "short_margin_ratio": "0.10292507", + # "short_maint_margin_ratio": "0.005", + # "short_pnl": "7.853E-5", + # "short_unrealised_pnl": "7.853E-5", + # "long_margin_ratio": "0.07103743", + # "long_maint_margin_ratio": "0.005", + # "long_pnl": "1.9841E-4", + # "long_unrealised_pnl": "1.9841E-4", + # "long_settled_pnl": "0", + # "short_settled_pnl": "0", + # "last": "8266.99" + # } + # ], + # "margin_mode": "fixed" + # } + # + # swap + # + # symbol not specified + # + # [ + # { + # "margin_mode": "fixed", + # "timestamp": "2019-09-27T03:47:37.230Z", + # "holding": [ + # {...} + # ] + # }, + # { + # "margin_mode": "crossed", + # "timestamp": "2019-09-27T03:49:02.018Z", + # "holding": [ + # {...}, + # ] + # } + # ] + # + # symbol specified, fixed margin mode + # + # { + # "margin_mode": "fixed", + # "timestamp": "2019-09-27T03:47:37.230Z", + # "holding": [ + # { + # "avail_position": "20", + # "avg_cost": "8025.0", + # "instrument_id": "BTC-USD-SWAP", + # "last": "8113.1", + # "leverage": "15.00", + # "liquidation_price": "7002.6", + # "maint_margin_ratio": "0.0050", + # "margin": "0.0454", + # "position": "20", + # "realized_pnl": "-0.0001", + # "unrealized_pnl": "0", + # "settled_pnl": "0.0076", + # "settlement_price": "8279.2", + # "side": "long", + # "timestamp": "2019-09-27T03:47:37.230Z" + # } + # ] + # } + # + # symbol specified, crossed margin mode + # + # { + # "margin_mode": "crossed", + # "timestamp": "2019-09-27T03:49:02.018Z", + # "holding": [ + # { + # "avail_position": "3", + # "avg_cost": "59.49", + # "instrument_id": "LTC-USD-SWAP", + # "last": "55.98", + # "leverage": "10.00", + # "liquidation_price": "4.37", + # "maint_margin_ratio": "0.0100", + # "margin": "0.0536", + # "position": "3", + # "realized_pnl": "0.0000", + # "unrealized_pnl": "0", + # "settled_pnl": "-0.0330", + # "settlement_price": "55.84", + # "side": "long", + # "timestamp": "2019-09-27T03:49:02.018Z" + # }, + # ] + # } + # + # option + # + # { + # "holding":[ + # { + # "instrument_id":"BTC-USD-190927-12500-C", + # "position":"20", + # "avg_cost":"3.26", + # "avail_position":"20", + # "settlement_price":"0.017", + # "total_pnl":"50", + # "pnl_ratio":"0.3", + # "realized_pnl":"40", + # "unrealized_pnl":"10", + # "pos_margin":"100", + # "option_value":"70", + # "created_at":"2019-08-30T03:09:20.315Z", + # "updated_at":"2019-08-30T03:40:18.318Z" + # }, + # { + # "instrument_id":"BTC-USD-190927-12500-P", + # "position":"20", + # "avg_cost":"3.26", + # "avail_position":"20", + # "settlement_price":"0.019", + # "total_pnl":"50", + # "pnl_ratio":"0.3", + # "realized_pnl":"40", + # "unrealized_pnl":"10", + # "pos_margin":"100", + # "option_value":"70", + # "created_at":"2019-08-30T03:09:20.315Z", + # "updated_at":"2019-08-30T03:40:18.318Z" + # } + # ] + # } + # + # todo unify parsePosition/parsePositions + return response + async def fetch_ledger(self, code=None, since=None, limit=None, params={}): await self.load_markets() defaultType = self.safe_string_2(self.options, 'fetchLedger', 'defaultType') diff --git a/python/ccxt/base/exchange.py b/python/ccxt/base/exchange.py index e60444f732f2..ec10ad01f98d 100644 --- a/python/ccxt/base/exchange.py +++ b/python/ccxt/base/exchange.py @@ -4,7 +4,7 @@ # ----------------------------------------------------------------------------- -__version__ = '1.37.42' +__version__ = '1.37.43' # ----------------------------------------------------------------------------- diff --git a/python/ccxt/okex.py b/python/ccxt/okex.py index 559fe4031abb..3e5b32a986c1 100644 --- a/python/ccxt/okex.py +++ b/python/ccxt/okex.py @@ -282,6 +282,7 @@ def describe(self): 'option': { 'get': [ 'accounts', + 'position', '{underlying}/position', 'accounts/{underlying}', 'orders/{underlying}', @@ -2803,6 +2804,246 @@ def fetch_order_trades(self, id, symbol=None, since=None, limit=None, params={}) } return self.fetch_my_trades(symbol, since, limit, self.extend(request, params)) + def fetch_positions(self, symbol=None, since=None, limit=None, params={}): + self.load_markets() + method = None + market = None + request = { + # 'instrument_id': market['id'], + # 'order_id': id, # string + # 'after': '1', # pagination of data to return records earlier than the requested ledger_id + # 'before': '1', # P=pagination of data to return records newer than the requested ledger_id + # 'limit': limit, # optional, number of results per request, default = maximum = 100 + } + type = None + if symbol is None: + defaultType = self.safe_string_2(self.options, 'fetchPositions', 'defaultType') + type = self.safe_string(params, 'type', defaultType) + else: + market = self.market(symbol) + type = market['type'] + request['instrument_id'] = market['id'] + if (type == 'futures') or (type == 'swap'): + if market is None: + method = type + 'GetPosition' + else: + method = type + 'GetInstrumentIdPosition' + elif type == 'option': + underlying = self.safe_string(params, 'underlying') + if underlying is None: + raise ArgumentsRequired(self.id + ' fetchPositions() requires an underlying parameter for ' + type + ' market ' + symbol) + method = type + 'GetUnderlyingPosition' + else: + raise NotSupported(self.id + ' fetchPositions() does not support ' + type + ' market ' + symbol + ', supported market types are futures, swap or option') + params = self.omit(params, 'type') + response = getattr(self, method)(self.extend(request, params)) + # + # futures + # + # symbol not specified + # + # { + # "result": True, + # "holding": [ + # [ + # {...}, + # ] + # ] + # } + # + # symbol specified, crossed margin mode + # + # { + # "result": True, + # "holding": [ + # { + # "long_qty": "2", + # "long_avail_qty": "2", + # "long_avg_cost": "8260", + # "long_settlement_price": "8260", + # "realised_pnl": "0.00020928", + # "short_qty": "2", + # "short_avail_qty": "2", + # "short_avg_cost": "8259.99", + # "short_settlement_price": "8259.99", + # "liquidation_price": "113.81", + # "instrument_id": "BTC-USD-191227", + # "leverage": "10", + # "created_at": "2019-09-25T07:58:42.129Z", + # "updated_at": "2019-10-08T14:02:51.029Z", + # "margin_mode": "crossed", + # "short_margin": "0.00242197", + # "short_pnl": "6.63E-6", + # "short_pnl_ratio": "0.002477997", + # "short_unrealised_pnl": "6.63E-6", + # "long_margin": "0.00242197", + # "long_pnl": "-6.65E-6", + # "long_pnl_ratio": "-0.002478", + # "long_unrealised_pnl": "-6.65E-6", + # "long_settled_pnl": "0", + # "short_settled_pnl": "0", + # "last": "8257.57" + # } + # ], + # "margin_mode": "crossed" + # } + # + # symbol specified, fixed margin mode + # + # { + # "result": True, + # "holding": [ + # { + # "long_qty": "4", + # "long_avail_qty": "4", + # "long_margin": "0.00323844", + # "long_liqui_price": "7762.09", + # "long_pnl_ratio": "0.06052306", + # "long_avg_cost": "8234.43", + # "long_settlement_price": "8234.43", + # "realised_pnl": "-0.00000296", + # "short_qty": "2", + # "short_avail_qty": "2", + # "short_margin": "0.00241105", + # "short_liqui_price": "9166.74", + # "short_pnl_ratio": "0.03318052", + # "short_avg_cost": "8295.13", + # "short_settlement_price": "8295.13", + # "instrument_id": "BTC-USD-191227", + # "long_leverage": "15", + # "short_leverage": "10", + # "created_at": "2019-09-25T07:58:42.129Z", + # "updated_at": "2019-10-08T13:12:09.438Z", + # "margin_mode": "fixed", + # "short_margin_ratio": "0.10292507", + # "short_maint_margin_ratio": "0.005", + # "short_pnl": "7.853E-5", + # "short_unrealised_pnl": "7.853E-5", + # "long_margin_ratio": "0.07103743", + # "long_maint_margin_ratio": "0.005", + # "long_pnl": "1.9841E-4", + # "long_unrealised_pnl": "1.9841E-4", + # "long_settled_pnl": "0", + # "short_settled_pnl": "0", + # "last": "8266.99" + # } + # ], + # "margin_mode": "fixed" + # } + # + # swap + # + # symbol not specified + # + # [ + # { + # "margin_mode": "fixed", + # "timestamp": "2019-09-27T03:47:37.230Z", + # "holding": [ + # {...} + # ] + # }, + # { + # "margin_mode": "crossed", + # "timestamp": "2019-09-27T03:49:02.018Z", + # "holding": [ + # {...}, + # ] + # } + # ] + # + # symbol specified, fixed margin mode + # + # { + # "margin_mode": "fixed", + # "timestamp": "2019-09-27T03:47:37.230Z", + # "holding": [ + # { + # "avail_position": "20", + # "avg_cost": "8025.0", + # "instrument_id": "BTC-USD-SWAP", + # "last": "8113.1", + # "leverage": "15.00", + # "liquidation_price": "7002.6", + # "maint_margin_ratio": "0.0050", + # "margin": "0.0454", + # "position": "20", + # "realized_pnl": "-0.0001", + # "unrealized_pnl": "0", + # "settled_pnl": "0.0076", + # "settlement_price": "8279.2", + # "side": "long", + # "timestamp": "2019-09-27T03:47:37.230Z" + # } + # ] + # } + # + # symbol specified, crossed margin mode + # + # { + # "margin_mode": "crossed", + # "timestamp": "2019-09-27T03:49:02.018Z", + # "holding": [ + # { + # "avail_position": "3", + # "avg_cost": "59.49", + # "instrument_id": "LTC-USD-SWAP", + # "last": "55.98", + # "leverage": "10.00", + # "liquidation_price": "4.37", + # "maint_margin_ratio": "0.0100", + # "margin": "0.0536", + # "position": "3", + # "realized_pnl": "0.0000", + # "unrealized_pnl": "0", + # "settled_pnl": "-0.0330", + # "settlement_price": "55.84", + # "side": "long", + # "timestamp": "2019-09-27T03:49:02.018Z" + # }, + # ] + # } + # + # option + # + # { + # "holding":[ + # { + # "instrument_id":"BTC-USD-190927-12500-C", + # "position":"20", + # "avg_cost":"3.26", + # "avail_position":"20", + # "settlement_price":"0.017", + # "total_pnl":"50", + # "pnl_ratio":"0.3", + # "realized_pnl":"40", + # "unrealized_pnl":"10", + # "pos_margin":"100", + # "option_value":"70", + # "created_at":"2019-08-30T03:09:20.315Z", + # "updated_at":"2019-08-30T03:40:18.318Z" + # }, + # { + # "instrument_id":"BTC-USD-190927-12500-P", + # "position":"20", + # "avg_cost":"3.26", + # "avail_position":"20", + # "settlement_price":"0.019", + # "total_pnl":"50", + # "pnl_ratio":"0.3", + # "realized_pnl":"40", + # "unrealized_pnl":"10", + # "pos_margin":"100", + # "option_value":"70", + # "created_at":"2019-08-30T03:09:20.315Z", + # "updated_at":"2019-08-30T03:40:18.318Z" + # } + # ] + # } + # + # todo unify parsePosition/parsePositions + return response + def fetch_ledger(self, code=None, since=None, limit=None, params={}): self.load_markets() defaultType = self.safe_string_2(self.options, 'fetchLedger', 'defaultType') diff --git a/python/package.json b/python/package.json index 7dca0248e27b..c87e513a54d0 100644 --- a/python/package.json +++ b/python/package.json @@ -1,6 +1,6 @@ { "name": "ccxt", - "version": "1.37.42", + "version": "1.37.43", "description": "A JavaScript / Python / PHP cryptocurrency trading library with support for 130+ exchanges", "main": "./ccxt.js", "unpkg": "dist/ccxt.browser.js", diff --git a/wiki/Install.md b/wiki/Install.md index 9c742b21460d..21a53c011448 100644 --- a/wiki/Install.md +++ b/wiki/Install.md @@ -58,13 +58,13 @@ If that does not help, please, follow here: https://github.com/nodejs/node-gyp#o All-in-one browser bundle (dependencies included), served from a CDN of your choice: -* jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@1.37.42/dist/ccxt.browser.js -* unpkg: https://unpkg.com/ccxt@1.37.42/dist/ccxt.browser.js +* jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@1.37.43/dist/ccxt.browser.js +* unpkg: https://unpkg.com/ccxt@1.37.43/dist/ccxt.browser.js You can obtain a live-updated version of the bundle by removing the version number from the URL (the `@a.b.c` thing) — however, we do not recommend to do that, as it may break your app eventually. Also, please keep in mind that we are not responsible for the correct operation of those CDN servers. ```HTML - + ``` Creates a global `ccxt` object: